13、chrony時(shí)間同步與cobbler自動(dòng)化裝機(jī)

1财搁、配置chrony服務(wù)蘸炸,實(shí)現(xiàn)服務(wù)器時(shí)間自動(dòng)同步

  1. 準(zhǔn)備工作
    服務(wù)器:192.168.45.202,CentOS7系統(tǒng)尖奔,系統(tǒng)已禁用selinux和firewall
    客戶端:192.168.45.203搭儒,CentOS7系統(tǒng),系統(tǒng)已禁用selinux和firewall
  2. 服務(wù)器端配置
    2.1 由于CentOS7中已默認(rèn)安裝chrony包提茁,因此無需安裝淹禾,直接啟動(dòng)即可
[root@s202 ~]# systemctl start chronyd
[root@s202 ~]# systemctl enable chronyd

2.2 配置chrony
 vim /etc/chrony.conf

[root@s202 ~]# cat /etc/chrony.conf |sed '/^$/d'|sed '/^#/d'
server 192.168.45.202 iburst #設(shè)置作為NTP的IP或域名
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
allow 192.168.45.0/16 #設(shè)置允許同步的IP段
local stratum 10  ##開啟,即使server指令中時(shí)間服務(wù)器不可用茴扁,也允許將本地時(shí)間作為標(biāo)準(zhǔn)時(shí)間授予其他客戶端
logdir /var/log/chrony

2.3 重啟chronyd服務(wù)

[root@s202 ~]# systemctl restart chronyd
  1. 客戶端配置
    3.1 啟動(dòng)chronyd服務(wù)
[root@s203 ~]# systemctl start chronyd

3.2 修改/etc/chrony.conf

[root@s203 ~]# vim /etc/chrony.conf 
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 192.168.45.202 iburst

3.3 重新啟動(dòng)chronyd服務(wù)

[root@s203 ~]# systemctl restart chronyd

查看時(shí)間源的同步信息

[root@s203 ~]# chronyc sources -v
210 Number of sources = 1

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 192.168.45.202               11   7   377    88   +161us[ +168us] +/-   87ms
  1. 驗(yàn)證:
    修改客戶端的時(shí)間為2021/07/12
[root@s203 ~]# date -s 07/12/2021
Mon Jul 12 00:00:00 CST 2021
[root@s203 ~]# date
Mon Jul 12 00:00:02 CST 2021

然后等待一會(huì)兒查看結(jié)果:

[root@centos7 ~]# chronyc sources -v
210 Number of sources = 1

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^? 192.168.45.202               11   6    37    65  +43272m[+43272m] +/- 6218us
[root@centos7 ~]# chronyc sources -v
210 Number of sources = 1

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 192.168.45.202               11   6   177     3  -1229ns[+43272m] +/-   12ms
[root@centos7 ~]# date
Sun Jul 12 22:51:13 CST 2020

2铃岔、實(shí)現(xiàn)cobbler+pxe自動(dòng)化裝機(jī)

1) 安裝cobbler包及相關(guān)依賴程序

注:cobbler需要啟用epel源安裝

[root@centos7 ~]#yum install cobbler dhcp tftp tftp-server httpd -y
2) 啟動(dòng)cobbler
[root@centos7 ~]# systemctl start cobblerd
[root@centos7 ~]# systemctl enable cobblerd
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.

3) 對(duì)cobbler配置項(xiàng)進(jìn)行檢查
[root@centos7 ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

Restart cobblerd and then run 'cobbler sync' to apply changes.
4) 根據(jù)cobbler檢查結(jié)果進(jìn)行完善

①修改/etc/cobbler/settings

manage_dhcp: 1
next_server: 192.168.45.135
server: 192.168.45.135

②修改/etc/cobbler/settings中默認(rèn)密碼
首先生成一個(gè)加密密碼

[root@centos7 ~]# openssl passwd -1
Password: 
Verifying - Password: 
$1$7xkUcdUT$TMeUcl5TOEztKxCuPdX5N.

對(duì)default_password_crypted進(jìn)行替換

default_password_crypted: "$1$7xkUcdUT$TMeUcl5TOEztKxCuPdX5N."

③執(zhí)行cobbler get-loaders

[root@centos7 ~]# cobbler get-loaders
task started: 2020-07-19_215436_get_loaders
task started (id=Download Bootloader Content, time=Sun Jul 19 21:54:36 2020)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***

執(zhí)行同步操作cobbler sync,但報(bào)dhcp錯(cuò)誤

received on stdout: 
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
Job for dhcpd.service failed because the control process exited with error code. See "systemctl status dhcpd.service" and "journalctl -xe" for details.

Exception occured: <class 'cobbler.cexceptions.CX'>
Exception value: 'cobbler trigger failed: cobbler.modules.sync_post_restart_services'
Exception Info:
  File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 82, in run
    rc = self._run(self)
   File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 181, in runner
    return self.remote.api.sync(self.options.get("verbose",False),logger=self.logger)
   File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 763, in sync
    return sync.run()
   File "/usr/lib/python2.7/site-packages/cobbler/action_sync.py", line 144, in run
    utils.run_triggers(self.api, None, "/var/lib/cobbler/triggers/sync/post/*", logger=self.logger)
   File "/usr/lib/python2.7/site-packages/cobbler/utils.py", line 928, in run_triggers
    raise CX("cobbler trigger failed: %s" % m.__name__)

!!! TASK FAILED !!!

④配置DHCP峭火,修改/etc/cobbler/dhcp.template模板文件

subnet 192.168.45.0 netmask 255.255.255.0 {
     option routers             192.168.45.2;
     option domain-name-servers 192.168.45.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.45.210 192.168.45.230;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;

⑤執(zhí)行同步cobbler sync,并啟動(dòng)DHCP服務(wù)

[root@centos7 ~]# cobbler sync
5) 啟動(dòng)dhcp/tftp/httpd等服務(wù)
[root@centos7 ~]# systemctl start dhcpd tftp httpd
6) 導(dǎo)入要安裝的系統(tǒng)文件
[root@centos7 ~]# mount /dev/sr0 /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos7 ~]# cobbler import --name=centos7 --path=/mnt
task started: 2020-07-19_221235_import
task started (id=Media import, time=Sun Jul 19 22:12:35 2020)

Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/centos7:
creating new distro: centos7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos7 -> /var/www/cobbler/links/centos7-x86_64
creating new profile: centos7-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/centos7 for centos7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos7
need to process repo/comps: /var/www/cobbler/ks_mirror/centos7
looking for /var/www/cobbler/ks_mirror/centos7/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7/repodata
*** TASK COMPLETE ***

此時(shí)cobbler已經(jīng)自動(dòng)將導(dǎo)入的系統(tǒng)加入菜單毁习,系統(tǒng)已可以進(jìn)行最小化自動(dòng)化安裝

[root@centos7 ~]# cat /var/lib/tftpboot/pxelinux.cfg/default 
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1

LABEL centos7-x86_64
        kernel /images/centos7-x86_64/vmlinuz
        MENU LABEL centos7-x86_64
        append initrd=/images/centos7-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.45.135/cblr/svc/op/ks/profile/centos7-x86_64
        ipappend 2

MENU end
7) 設(shè)置自定義kickstart文件,可以手工設(shè)置卖丸,也可以使用kickstart工具纺且,這里使用kickstart工具
kickstart工具需要安裝
[root@centos7 ~]# yum install system-config-kickstart
[root@centos7 ~]# system-config-kickstart 
/usr/share/system-config-kickstart/kickstartGui.py:104: GtkWarning: GtkSpinButton: setting an adjustment with non-zero page size is deprecated
  xml = gtk.glade.XML ("/usr/share/system-config-kickstart/system-config-kickstart.glade", domain="system-config-kickstart")
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration

在彈出的配置界面按步驟進(jìn)行設(shè)置即可,設(shè)置完成后保存至/var/lib/cobbler/kickstarts中備用(cobbler中的kickstart文件均放置在/var/lib/cobbler/kickstarts中)


kickstart設(shè)置界面

結(jié)果:

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$7WGID/oq$shmwTbH1j6Thxir1ceo/u.
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=ens33
# Halt after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url=$tree
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="xfs" --size=102400
part /boot --fstype="xfs" --size=1024
part swap --fstype="swap" --size=4096
part /data --fstype="xfs" --grow --size=1

%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
kexec-tools
autofs
%end
8) 新增自定義啟動(dòng)菜單稍浆,將自定義的kickstart文件添加到啟動(dòng)項(xiàng)中(自定義kickstart為自動(dòng)安裝桌面版系統(tǒng))
[root@centos7 kickstarts]# cobbler profile add --name=centos7.6-x86_64_desktop --distro=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.ks

此時(shí)啟動(dòng)菜單中已自動(dòng)新增一行菜單

[root@centos7 kickstarts]# cat /var/lib/tftpboot/pxelinux.cfg/default 
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1

LABEL centos7-x86_64
        kernel /images/centos7-x86_64/vmlinuz
        MENU LABEL centos7-x86_64
        append initrd=/images/centos7-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.45.135/cblr/svc/op/ks/profile/centos7-x86_64
        ipappend 2

LABEL centos7.6-x86_64_desktop
        kernel /images/centos7-x86_64/vmlinuz
        MENU LABEL centos7.6-x86_64_desktop
        append initrd=/images/centos7-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.45.135/cblr/svc/op/ks/profile/centos7.6-x86_64_desktop
        ipappend 2

至此cobbler配置完成载碌,新建一個(gè)虛擬機(jī)進(jìn)行安裝測試


啟動(dòng)猜嘱,選擇自定義的配置進(jìn)行安裝測試

開始執(zhí)行引導(dǎo)

根據(jù)kickstart設(shè)置進(jìn)行自動(dòng)配置

開始安裝


安裝完成后自動(dòng)重啟

根據(jù)DHCP的IP范圍設(shè)定自動(dòng)分配有效IP地址

測試成功,完成嫁艇。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末朗伶,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子步咪,更是在濱河造成了極大的恐慌腕让,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,277評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件歧斟,死亡現(xiàn)場離奇詭異纯丸,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)静袖,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評(píng)論 3 393
  • 文/潘曉璐 我一進(jìn)店門觉鼻,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人队橙,你說我怎么就攤上這事坠陈。” “怎么了捐康?”我有些...
    開封第一講書人閱讀 163,624評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵仇矾,是天一觀的道長。 經(jīng)常有香客問我解总,道長贮匕,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,356評(píng)論 1 293
  • 正文 為了忘掉前任花枫,我火速辦了婚禮刻盐,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘劳翰。我一直安慰自己敦锌,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,402評(píng)論 6 392
  • 文/花漫 我一把揭開白布佳簸。 她就那樣靜靜地躺著乙墙,像睡著了一般。 火紅的嫁衣襯著肌膚如雪生均。 梳的紋絲不亂的頭發(fā)上听想,一...
    開封第一講書人閱讀 51,292評(píng)論 1 301
  • 那天,我揣著相機(jī)與錄音疯特,去河邊找鬼哗魂。 笑死肛走,一個(gè)胖子當(dāng)著我的面吹牛漓雅,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 40,135評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼邻吞,長吁一口氣:“原來是場噩夢啊……” “哼组题!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起抱冷,我...
    開封第一講書人閱讀 38,992評(píng)論 0 275
  • 序言:老撾萬榮一對(duì)情侶失蹤崔列,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后旺遮,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體赵讯,經(jīng)...
    沈念sama閱讀 45,429評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,636評(píng)論 3 334
  • 正文 我和宋清朗相戀三年耿眉,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了边翼。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,785評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡鸣剪,死狀恐怖组底,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情筐骇,我是刑警寧澤债鸡,帶...
    沈念sama閱讀 35,492評(píng)論 5 345
  • 正文 年R本政府宣布,位于F島的核電站铛纬,受9級(jí)特大地震影響厌均,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜告唆,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,092評(píng)論 3 328
  • 文/蒙蒙 一莫秆、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧悔详,春花似錦镊屎、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至归苍,卻和暖如春用狱,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背拼弃。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評(píng)論 1 269
  • 我被黑心中介騙來泰國打工夏伊, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人吻氧。 一個(gè)月前我還...
    沈念sama閱讀 47,891評(píng)論 2 370
  • 正文 我出身青樓溺忧,卻偏偏與公主長得像咏连,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子鲁森,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,713評(píng)論 2 354