Linux随笔15-Ubuntu20.04允许root用户图形界面登录、chrony局域网时间同步服务、ipxe实现系统自动化安装
Contents
- 1. Ubuntu20.04-LTS允許root在圖形界面登錄
- 1.1. Ubuntu Server 20.04安裝GNome圖形環境
- 1.2. 允許root用戶在圖形界面登錄
- 1.3. 總結
- 2. chrony局域網時間同步
- 2.1. 設置NTP服務器
- 2.2. 設置NTP客戶端
- 3. kvm-qemu環境通過ipxe實現CentOS7系統自動化安裝
- 3.1. iPXE介紹
- 3.2. iPXE環境準備
- 3.3. 通過iPXE安裝系統
- 4. References
1. Ubuntu20.04-LTS允許root在圖形界面登錄
Ubuntu默認是不允許root用戶在圖形界面直接登錄的,至于原因,在 /var/log/auth.log 文件中有詳細的記載。由于我的虛擬機是采用的Ubuntu-20.04.2-live-server-amd64.iso安裝的,所以默認并沒有圖形界面。為此需要先準備圖形界面環境。
1.1. Ubuntu Server 20.04安裝GNome圖形環境
采用系統默認的軟件鏡像源,安裝GNome圖形環境有兩種方式:通過apt命令以及通過tasksel命令。
通過apt install gnome gnome-session gdm3安裝即可,這種方式安裝的圖形界面環境由于只安裝圖形環境相關的軟件包,所以消耗的資源更少一些,對于一些軟件,也是沒有直接被安裝上的。安裝過程大致如下:root@ubuntu20u04:~# apt install gnome gnome-session gdm3 ... aspell-autobuildhash: processing: en [en_GB-ize-wo_accents-only]. aspell-autobuildhash: processing: en [en_GB-variant_0]. aspell-autobuildhash: processing: en [en_GB-variant_1]. aspell-autobuildhash: processing: en [en_US-w_accents-only]. aspell-autobuildhash: processing: en [en_US-wo_accents-only]. Processing triggers for rygel (0.38.3-1ubuntu1) ... Processing triggers for libgdk-pixbuf2.0-0:amd64 (2.40.0+dfsg-3ubuntu0.2) ... Processing triggers for libc-bin (2.31-0ubuntu9.2) ... Processing triggers for dbus (1.12.16-2ubuntu2.1) ... Processing triggers for systemd (245.4-4ubuntu3.4) ... Processing triggers for sgml-base (1.29.1) ... root@ubuntu20u04:~# 等待上述命令執行完成即可。
使用tasksel命令可以安裝完整的GNome圖形環境。先確認下系統是否已經安裝了該命令,如果沒有安裝該命令,需要執行apt install tasksel安裝這個命令。具體如下所示:root@ubuntu20u04:~# dpkg -l | egrep tasksel ii tasksel 3.34ubuntu16 all tool for selecting tasks for installation on Debian systems ii tasksel-data 3.34ubuntu16 all official tasks used for installation of Debian systems root@ubuntu20u04:~# 這個命令的使用幫助信息,如下所示:root@ubuntu20u04:~# tasksel --help Unknown option: help Usage: tasksel install <task>... tasksel remove <task>... tasksel [options] -t, --test test mode; don't really do anything--new-install automatically install some tasks--list-tasks list tasks that would be displayed and exit--task-packages list available packages in a task--task-desc returns the description of a task root@ubuntu20u04:~# 然后使用這個命令安裝完整的GNome圖形桌面環境,具體如下所示:root@ubuntu20u04:~# tasksel --list-tasks | egrep desktop u kubuntu-desktop Kubuntu desktop u lubuntu-desktop Lubuntu Desktop u ubuntu-budgie-desktop Ubuntu Budgie desktop u ubuntu-desktop Ubuntu desktop u ubuntu-desktop-default-languages Ubuntu desktop default languages u ubuntu-desktop-minimal Ubuntu minimal desktop u ubuntu-desktop-minimal-default-languages Ubuntu minimal desktop default languages u ubuntu-mate-desktop Ubuntu MATE desktop u ubuntustudio-desktop Ubuntu Studio desktop u ubuntustudio-desktop-core Ubuntu Studio minimal DE installation u xubuntu-desktop Xubuntu desktop root@ubuntu20u04:~# 上述列出了可以安裝的GNome圖形環境,其中 ubuntu-desktop 這個是我們需要安裝的,執行如下命令進行安裝:root@ubuntu20u04:~# tasksel install ubuntu-desktop xserver-xorg install root@ubuntu20u04:~# 執行完上述命令之后,如下圖所示:
執行完成,即可安裝完整的圖形界面,包含所需要的一些軟件也會被自動安裝上。
執行完上述操作之后,才是重啟系統仍然會進入圖形界面。要自動進入圖形界面,需要修改運行級別。通過systemctl get-default命令可以查看系統的當前運行級別。通過systemctl set-default graphical.target命令可以設置系統的默認運行級別。通過systemctl list-units --type target命令可以列出系統已經裝載并且處于活動狀態的target對象(運行級別)都有哪些,具體如下所示:
root@ubuntu20u04:~# systemctl list-units --type targetUNIT LOAD ACTIVE SUB DESCRIPTION basic.target loaded active active Basic System cryptsetup.target loaded active active Local Encrypted Volumes getty.target loaded active active Login Prompts graphical.target loaded active active Graphical Interface local-fs-pre.target loaded active active Local File Systems (Pre) local-fs.target loaded active active Local File Systems multi-user.target loaded active active Multi-User System network-online.target loaded active active Network is Online network-pre.target loaded active active Network (Pre) network.target loaded active active Network nss-lookup.target loaded active active Host and Network Name Lookupsnss-user-lookup.target loaded active active User and Group Name Lookups paths.target loaded active active Paths remote-fs-pre.target loaded active active Remote File Systems (Pre) remote-fs.target loaded active active Remote File Systems rpcbind.target loaded active active RPC Port Mapper slices.target loaded active active Slices sockets.target loaded active active Sockets sound.target loaded active active Sound Card swap.target loaded active active Swap sysinit.target loaded active active System Initialization time-set.target loaded active active System Time Set time-sync.target loaded active active System Time Synchronized timers.target loaded active active Timers LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.24 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'. root@ubuntu20u04:~# root@ubuntu20u04:~# systemctl get-default multi-user.target root@ubuntu20u04:~# systemctl set-default graphical.target Created symlink /etc/systemd/system/default.target → /lib/systemd/system/graphical.target. root@ubuntu20u04:~# ls /etc/systemd/system/default.target -lh lrwxrwxrwx 1 root root 36 Jun 26 10:36 /etc/systemd/system/default.target -> /lib/systemd/system/graphical.target root@ubuntu20u04:~# systemctl reboot從上述輸出中可以看出,將graphical.target設置為默認的運行級別的結果就是再 /etc/systemd/system/ 這個目錄中創建一個符號鏈接文件,該符號鏈接文件指向 /lib/systemd/system/graphical.target 這個文件。
設置完成之后,重啟系統即可進入圖形界面環境。
1.2. 允許root用戶在圖形界面登錄
在virtual-manager中打開對應的ubuntu虛擬機,然后從圖形界面中輸入root用戶名進行登錄,具體如下:
按下回車鍵之后,輸入密碼,此時提示如下所示:
此時, /var/log/auth.log 中記錄的日志信息內容如下所示:
上述日志輸出中提示: pam_succeed_if(gdm-password:auth): requirement “user != root” not met by user "root" ,即pam_succeed_if這個pam模塊會對圖形界面登錄的用戶進行檢查,如果用戶名是root,那么就禁止該用戶登錄系統。所以需要在系統的pam配置文件目錄中找到記錄了 pam_succeed_if 這個模塊的配置文件。具體如下所示:
root@ubuntu20u04:~# egrep -l 'pam_succeed_if' /etc/pam.d/* /etc/pam.d/gdm-autologin /etc/pam.d/gdm-fingerprint /etc/pam.d/gdm-password root@ubuntu20u04:~#上述輸出顯示3個文件中均包含這個模塊,分別查看下3個模塊中的具體相關參數,如下所示:
root@ubuntu20u04:~# egrep -o '.*pam_succeed_if.*' /etc/pam.d/gdm-autologin auth required pam_succeed_if.so user != root quiet_success root@ubuntu20u04:~# egrep -o '.*pam_succeed_if.*' /etc/pam.d/gdm-fingerprint auth required pam_succeed_if.so user != root quiet_success root@ubuntu20u04:~# egrep -o '.*pam_succeed_if.*' /etc/pam.d/gdm-password auth required pam_succeed_if.so user != root quiet_success root@ubuntu20u04:~#將上述3個文件中的對應行注釋掉,如下所示:
root@ubuntu20u04:~# sed -n -re '/pam_succeed_if/s/^/#/p' /etc/pam.d/gdm-password #auth required pam_succeed_if.so user != root quiet_success root@ubuntu20u04:~# sed -i.bak -re '/pam_succeed_if/s/^/#/' /etc/pam.d/gdm-password root@ubuntu20u04:~# sed -i.bak -re '/pam_succeed_if/s/^/#/' /etc/pam.d/gdm-fingerprint root@ubuntu20u04:~# sed -i.bak -re '/pam_succeed_if/s/^/#/' /etc/pam.d/gdm-autologin root@ubuntu20u04:~# egrep -o '.*pam_succeed_if.*' /etc/pam.d/gdm-autologin #auth required pam_succeed_if.so user != root quiet_success root@ubuntu20u04:~# egrep -o '.*pam_succeed_if.*' /etc/pam.d/gdm-fingerprint #auth required pam_succeed_if.so user != root quiet_success root@ubuntu20u04:~# egrep -o '.*pam_succeed_if.*' /etc/pam.d/gdm-password #auth required pam_succeed_if.so user != root quiet_success root@ubuntu20u04:~#此時再次嘗試在圖形界面登錄,并觀察 /var/log/auth.log 文件的內容變化:
root@ubuntu20u04:~# tail -f /var/log/auth.log Jun 26 14:53:21 ubuntu20u04 gdm-password]: pam_unix(gdm-password:auth): Couldn't open /etc/securetty: No such file or directory Jun 26 14:53:23 ubuntu20u04 gdm-password]: pam_unix(gdm-password:auth): Couldn't open /etc/securetty: No such file or directory Jun 26 14:53:23 ubuntu20u04 gdm-password]: pam_unix(gdm-password:auth): authentication failure; logname= uid=0 euid=0 tty=/dev/tty1 ruser= rhost= user=root Jun 26 14:53:27 ubuntu20u04 gdm-password]: pam_unix(gdm-password:auth): Couldn't open /etc/securetty: No such file or directory此時圖形界面登錄依然失敗,但是已經不再是pam_succeed_if這個模塊作祟了。提示沒有/etc/securetty這個文件,所以不給登錄。查看下哪個包提供了這個文件,然后安裝這個包
root@ubuntu20u04:~# apt-file search /etc/securetty rear: /usr/share/rear/skel/Linux-ia64/etc/securetty root@ubuntu20u04:~# apt install rear Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed:attr extlinux isolinux keyutils libisoburn1 libnfsidmap2 libtirpc-common libtirpc3 nfs-common rpcbind xorriso Suggested packages:watchdog xorriso-tcltk jigit cdck The following NEW packages will be installed:attr extlinux isolinux keyutils libisoburn1 libnfsidmap2 libtirpc-common libtirpc3 nfs-common rear rpcbind xorriso 0 upgraded, 12 newly installed, 0 to remove and 41 not upgraded. Need to get 1,696 kB of archives. After this operation, 6,702 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://cn.archive.ubuntu.com/ubuntu focal/main amd64 libtirpc-common all 1.2.5-1 [7,632 B] ... root@ubuntu20u04:~# cat /usr/share/rear/skel/Linux-ia64/etc/securetty console vc/1 vc/2 vc/3 vc/4 vc/5 vc/6 vc/7 vc/8 vc/9 vc/10 vc/11 tty1 tty2 tty3 tty4 tty5 tty6 tty7 tty8 tty9 tty10 tty11 ttyS1 root@ubuntu20u04:~# cp /usr/share/rear/skel/Linux-ia64/etc/securetty /etc/securetty從上述輸出中可以看出,securetty 這個文件是由 rear 這個軟件包提供的,執行命令apt install rear安裝這個軟件包。然后將軟件包中提供的文件 /usr/share/rear/skel/Linux-ia64/etc/securetty 拷貝到 /etc/securetty 之后,再次嘗試再圖形界面以root身份登錄,此時可以正常登錄。具體如下所示:
root@ubuntu20u04:~# tail -f /var/log/auth.log Jun 26 14:59:54 ubuntu20u04 gdm-password]: pam_unix(gdm-password:session): session opened for user root by (uid=0) Jun 26 14:59:54 ubuntu20u04 systemd-logind[927]: New session 8 of user root. Jun 26 14:59:54 ubuntu20u04 gdm-password]: gkr-pam: gnome-keyring-daemon started properly and unlocked keyring Jun 26 14:59:56 ubuntu20u04 gnome-keyring-daemon[11782]: The Secret Service was already initialized Jun 26 14:59:56 ubuntu20u04 gnome-keyring-daemon[11782]: The PKCS#11 component was already initialized Jun 26 14:59:57 ubuntu20u04 polkitd(authority=local): Registered Authentication Agent for unix-session:8 (system bus name :1.156 [/usr/bin/gnome-shell], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) Jun 26 15:00:01 ubuntu20u04 CRON[12389]: pam_unix(cron:session): session opened for user root by (uid=0) Jun 26 15:00:01 ubuntu20u04 CRON[12389]: pam_unix(cron:session): session closed for user root Jun 26 15:00:03 ubuntu20u04 gdm-launch-environment]: pam_unix(gdm-launch-environment:session): session closed for user gdm Jun 26 15:00:03 ubuntu20u04 systemd-logind[927]: Session c2 logged out. Waiting for processes to exit. Jun 26 15:00:03 ubuntu20u04 systemd-logind[927]: Removed session c2. Jun 26 15:00:03 ubuntu20u04 polkitd(authority=local): Unregistered Authentication Agent for unix-session:c2 (system bus name :1.132, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus) Jun 26 15:00:08 ubuntu20u04 dbus-daemon[905]: [system] Failed to activate service 'org.bluez': timed out (service_start_timeout=25000ms)如下圖所示:
1.3. 總結
為了使root用戶能在圖形界面中登錄,需要做如下操作:
完成上述3步之后,由于pam模塊的配置文件修改是即時生效的,所以無需重啟系統即可實現root用戶的圖形界面登錄。
2. chrony局域網時間同步
集群環境中的各個服務器之間要共同實現一些操作,最基本的需求就是要一致的時間。為此就需要在集群中設置時間同步服務器。RHEL/CentOS7.x開始,從默認的ntp服務切換為chronyd服務來實現時間同步。雖然服務名稱不一樣了,但是底層協議都是ntp協議,配置文件內容基本是一樣的。
為了避免單點故障,集群環境中,通常將2臺服務器作為NTP服務器,從互聯網上同步時間,其他服務器從這兩臺服務器上同步時間。所以此處的實驗以3臺服務器來模擬時間同步服務的配置。三臺服務器的角色描述如下表:
| c7u6s1 | ntp服務器 | 從互聯網同步時間 |
| c7u6s2 | ntp服務器 | 從互聯網同步時間 |
| c7u6s3 | ntp客戶端 | 從c7u6s1和c7u6s2同步時間 |
要實現該服務,需要確保各個節點上都已經安裝了chrony這個軟件包。其中提供了 chrony.conf 這個配置文件,以及服務后臺命令chronyd以及用戶交互命令chronyc。具體如下所示:
[root@c7u6s1 security]# rpm -qa | egrep chrony chrony-3.2-2.el7.x86_64 [root@c7u6s1 security]# rpm -ql chrony /etc/NetworkManager/dispatcher.d/20-chrony /etc/chrony.conf /etc/chrony.keys /etc/dhcp/dhclient.d/chrony.sh /etc/logrotate.d/chrony /etc/sysconfig/chronyd /usr/bin/chronyc /usr/lib/systemd/ntp-units.d/50-chronyd.list /usr/lib/systemd/system/chrony-dnssrv@.service /usr/lib/systemd/system/chrony-dnssrv@.timer /usr/lib/systemd/system/chrony-wait.service /usr/lib/systemd/system/chronyd.service /usr/libexec/chrony-helper /usr/sbin/chronyd /usr/share/doc/chrony-3.2 /usr/share/doc/chrony-3.2/COPYING /usr/share/doc/chrony-3.2/FAQ /usr/share/doc/chrony-3.2/NEWS /usr/share/doc/chrony-3.2/README /usr/share/man/man1/chronyc.1.gz /usr/share/man/man5/chrony.conf.5.gz /usr/share/man/man8/chronyd.8.gz /var/lib/chrony /var/lib/chrony/drift /var/lib/chrony/rtc /var/log/chrony [root@c7u6s1 security]#接下來分別設置NTP的服務器和客戶端。
2.1. 設置NTP服務器
修改配置文件 /etc/chrony.conf ,添加國內的互聯網時間服務器。具體如下所示:
[root@c7u6s1 security]# vim /etc/chrony.conf [root@c7u6s1 security]# cat /etc/chrony.conf | egrep '^[^#$].*' pool cn.pool.ntp.org iburst maxsources 4 server ntp.aliyun.com iburst server s1a.time.edu.cn iburst driftfile /var/lib/chrony/drift makestep 1.0 3 rtcsync allow 192.168.122.0/24 local stratum 10 logdir /var/log/chrony [root@c7u6s1 security]#上述輸出中過濾掉了注釋和空行之后的有效配置內容,前3行增加了1個時間池和2個時間服務器(阿里云的時間服務器和北京郵電大學的時間服務器)。然后接下來在allow 192.168.122.0/24這一行指定了哪些主機可以連接到這個服務器同步時間,指定了192.168.122.0/24這個網段的主機可以連接到c7u6s1上進行時間同步。由于c7u6s1要當作內網的NTP服務器,建議開啟local stratum 10這一行,表示即便c7u6s1與互聯網時間服務器之間的時間同步操作失敗,也允許客戶端從該服務器進行時間同步。
修改完配置文件之后,重啟服務,然后查看時間源信息,具體如下所示:
上述輸出內容記錄在圖片中,如下圖所示:
^*表示c7u6s1與這臺時間服務器進行了時間同步,從上圖中可以看出IP地址是203.107.6.88,對應的域名是ntp.aliyun.com。即c7u6s1與ntp.aliyun.com這臺時間服務器進行了時間同步。
上圖中各個域的符號含義解釋如下:
第一列的 MS 的含義是時間源的模式(M)以及時間源的狀態(S),其中M支持的符號有3種,分別如下所示:
- ^: 表示時間服務器
- =: 表示同級時間服務器(peer)
- #: 表示已經連接的局域網參考時間()
S支持的額符號有6種,分別如下所示: - *: 表示當前已經完成了與該時間源的時間同步
- +: 表示可接受的時間源,可以與已經選擇的時間源進行組合的(combined)時間源
- -: 表示非組合的(not combined),即雖然是可接受的時間源,但是被組合算法排斥的時間源
- ?: 表示該時間源不可達,即該時間源的連接丟失,或者到該時間源發送的數據包沒有通過全部測試,這種狀態通常出現在剛啟動的時候,直到從該時間源接受了至少3次嘗試(samples)
- x: 表示該時間源的時間可能存在錯誤(即chronyd認為該時間源與其他主要的時間源之間存在時間不一致的情況)
- ~: 表示時間頻繁變動(time too variable),即該時間源的時間不穩定
上述輸出顯示,c7u6s1已經與阿里云的時間源完成了時間同步。查看chronyd服務是否處于開機自動運行狀態,如果沒有處于enabled狀態,那么需要執行命令systemctl enable chronyd將其設置為開機自動啟動。具體如下所示:
[root@c7u6s1 security]# systemctl status chronyd . chronyd.service - NTP client/serverLoaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)Active: active (running) since Sat 2021-06-26 17:43:35 CST; 26min agoDocs: man:chronyd(8)man:chrony.conf(5)Process: 9358 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)Process: 9354 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)Main PID: 9356 (chronyd)CGroup: /system.slice/chronyd.service└─9356 /usr/sbin/chronydJun 26 17:43:35 c7u6s1 systemd[1]: Stopped NTP client/server. Jun 26 17:43:35 c7u6s1 systemd[1]: Starting NTP client/server... Jun 26 17:43:35 c7u6s1 chronyd[9356]: chronyd version 3.2 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SECHASH +SIGND +A... +DEBUG) Jun 26 17:43:35 c7u6s1 chronyd[9356]: Frequency -5.366 +/- 0.975 ppm read from /var/lib/chrony/drift Jun 26 17:43:35 c7u6s1 systemd[1]: Started NTP client/server. Jun 26 17:43:49 c7u6s1 chronyd[9356]: Selected source 162.159.200.1 Jun 26 17:43:50 c7u6s1 chronyd[9356]: Selected source 203.107.6.88 Jun 26 17:46:06 c7u6s1 chronyd[9356]: Source 193.182.111.142 replaced with 139.199.215.251 Hint: Some lines were ellipsized, use -l to show in full. [root@c7u6s1 security]#上述輸出顯示,其處于開機自動運行狀態,所以無需執行systemctl enable chronyd命令。
接下來備份另一臺NTP服務器的配置文件,并將 chrony.conf 這個配置文件拷貝過去,然后重啟chronyd服務。具體如下:
在c7u6s2上備份配置文件
[root@c7u6s2 ~]# mv /etc/chrony.conf{,.bak} [root@c7u6s2 ~]#將c7u6s1上的配置文件拷貝到c7u6s2
[root@c7u6s1 security]# rsync -av --progress -e 'ssh -p 22 -l root' /etc/chrony.conf c7u6s2:/etc/ root@c7u6s2's password: sending incremental file list chrony.conf1,234 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/1)sent 1,331 bytes received 35 bytes 248.36 bytes/sec total size is 1,234 speedup is 0.90 [root@c7u6s1 security]#在c7u6s2上重啟chronyd這個服務
[root@c7u6s2 ~]# systemctl restart chronyd [root@c7u6s2 ~]# systemctl status chronyd . chronyd.service - NTP client/serverLoaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)Active: active (running) since Sat 2021-06-26 18:13:24 CST; 3s agoDocs: man:chronyd(8)man:chrony.conf(5)Process: 8903 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)Process: 8899 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)Main PID: 8901 (chronyd)CGroup: /system.slice/chronyd.service└─8901 /usr/sbin/chronydJun 26 18:13:24 c7u6s2 systemd[1]: Starting NTP client/server... Jun 26 18:13:24 c7u6s2 chronyd[8901]: chronyd version 3.2 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SECHASH +SIGND +A... +DEBUG) Jun 26 18:13:24 c7u6s2 chronyd[8901]: Frequency -5.396 +/- 0.039 ppm read from /var/lib/chrony/drift Jun 26 18:13:24 c7u6s2 systemd[1]: Started NTP client/server. Hint: Some lines were ellipsized, use -l to show in full. [root@c7u6s2 ~]#chronyd服務也是處于開機自動運行狀態,所以無需執行systemctl enable chronyd命令。
查看c7u6s2的時間源以及時間同步情況,具體如下所示:
c7u6s2同樣與阿里云的時間源完成了時間同步。
至此,2臺局域網環境的時間服務器設置完成。接下來將這兩臺服務器作為內網集群的時間源,同步其他客戶端服務器的時間。
2.2. 設置NTP客戶端
將需要時間同步的客戶端的配置文件修改,注釋掉原有的時間服務器,然后將服務器指定為上述兩臺服務器的IP地址。具體如下所示:
[root@c7u6s3 ~]# vim /etc/chrony.conf [root@c7u6s3 ~]# cat /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 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server 192.168.122.11 iburst server 192.168.122.12 iburst# Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift# Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3# Enable kernel synchronization of the real-time clock (RTC). rtcsync# Enable hardware timestamping on all interfaces that support it. #hwtimestamp *# Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2# Allow NTP client access from local network. #allow 192.168.0.0/16# Serve time even if not synchronized to a time source. #local stratum 10# Specify file containing keys for NTP authentication. #keyfile /etc/chrony.keys# Specify directory for log files. logdir /var/log/chrony# Select which information is logged. #log measurements statistics tracking上述輸出的第9、10行即為新添加的內網NTP服務器的IP地址。接下來在客戶端上查看NTP服務器的時間源,具體如下所示:
[root@c7u6s3 ~]# chronyc sources -v 210 Number of sources = 4.-- 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 =============================================================================== ^+ tick.ntp.infomaniak.ch 1 10 377 792 +2963us[+3739us] +/- 68ms ^- time.cloudflare.com 3 10 377 710 -6278us[-5499us] +/- 102ms ^- time.cloudflare.com 3 10 377 804 -6067us[-5292us] +/- 102ms ^* 119.28.206.193 2 10 377 606 +355us[+1136us] +/- 48ms [root@c7u6s3 ~]# chronyc sources 210 Number of sources = 4 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^+ tick.ntp.infomaniak.ch 1 10 377 811 +2963us[+3739us] +/- 68ms ^- time.cloudflare.com 3 10 377 729 -6278us[-5499us] +/- 102ms ^- time.cloudflare.com 3 10 377 823 -6067us[-5292us] +/- 102ms ^* 119.28.206.193 2 10 377 625 +355us[+1136us] +/- 48ms [root@c7u6s3 ~]# !vim vim /etc/chrony.conf [root@c7u6s3 ~]# systemctl reload chronyd Failed to reload chronyd.service: Job type reload is not applicable for unit chronyd.service. See system logs and 'systemctl status chronyd.service' for details. [root@c7u6s3 ~]# systemctl restart chronyd [root@c7u6s3 ~]# chronyc sources 210 Number of sources = 2 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* c7u6s1.localhost 3 6 7 1 +289us[-4222us] +/- 20ms ^+ c7u6s2.localhost 3 6 7 1 -424us[-4935us] +/- 20ms [root@c7u6s3 ~]# [root@c7u6s3 ~]# chronyc sources -v 210 Number of sources = 2.-- 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 =============================================================================== ^* c7u6s1.localhost 3 6 377 45 +994us[ +996us] +/- 20ms ^+ c7u6s2.localhost 3 10 377 491 -1214us[-1223us] +/- 21ms [root@c7u6s3 ~]#從上述輸出種可以看出,在客戶端上修改了配置文件之后,也需要重啟chronyd,否則無法加載配置文件中更新的內容。從上述的時間源狀態中可以看出,c7u6s3已經與c7u6s1這臺時間源完成了時間同步。
至此,集群環境的2臺時間源服務器和1臺客戶端配置操作就完成了。
3. kvm-qemu環境通過ipxe實現CentOS7系統自動化安裝
3.1. iPXE介紹
iPXE是開源的網絡啟動固件,提供了增強版的PXE特性,比如:
- 可以從http協議的web服務器上啟動系統
- 可以從iSCSI的SAN存儲上啟動
- 可以通過FCoE從Fibre Channel的SAN存儲上啟動
- 可以從AoE SAN存儲上啟動
- 可以從無線網絡啟動
- 可以從廣域網啟動
- 可以從Infiniband網絡啟動
- 使用腳本控制啟動流程
可以將iPXE燒錄到網卡的ROM芯片中替代原有的PXE;也可以通過chainload的形式在PXE的基礎上啟動系統,而無需將iPXE燒錄到網卡的ROM芯片中。
下面將c7u6s1配置為iPXE服務器,通過c7u6s1安裝CentOS7.6系統。
3.2. iPXE環境準備
要準備iPXE環境,c7u6s1上需要啟動dhcpd、httpd以及tftp服務。其中dhcpd服務用于給新安裝的虛擬機分配IP地址,httpd服務用于提供kickstart文件以及安裝的軟件源,tftp服務用于提供啟動文件,比如此處的undionly.kpxe。
接下來準備這些服務:
dhcp服務需要做一些額外的配置,來配合iPXE啟動,需要在指定分配的IP地址范圍之外,將filename指定為 ***undionly.kpxe***這個文件,同時需要next-server指定tftp服務器的IP地址。具體如下所示:[root@c7u6s1 tftpboot]# yum install -y dhcp Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile* base: mirrors.163.com* epel: mirrors.bfsu.edu.cn* extras: mirrors.163.com* updates: mirrors.163.com Package 12:dhcp-4.2.5-83.el7.centos.1.x86_64 already installed and latest version Nothing to do [root@c7u6s1 tftpboot]# systemctl enable --now dhcpd Created symlink from /etc/systemd/system/multi-user.target.wants /dhcpd.service to /usr/lib/systemd/system/dhcpd.service. [root@c7u6s1 tftpboot]# systemctl status dhcpd . dhcpd.service - DHCPv4 Server DaemonLoaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled; vendor preset: disabled)Active: active (running) since Wed 2021-06-30 16:41:17 CST; 4h 40min agoDocs: man:dhcpd(8)man:dhcpd.conf(5)Main PID: 12935 (dhcpd)Status: "Dispatching packets..."CGroup: /system.slice/dhcpd.service└─12935 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pidJun 30 21:17:14 c7u6s1 dhcpd[12935]: DHCPREQUEST for 192.168.122.105 from 52:54:00:7b:5d:97 (c7u6sx) via eth0 Jun 30 21:17:17 c7u6s1 dhcpd[12935]: ns1.example.org: host unknown. Jun 30 21:17:19 c7u6s1 dhcpd[12935]: ns2.example.org: host unknown. Jun 30 21:17:19 c7u6s1 dhcpd[12935]: DHCPACK on 192.168.122.105 to 52:54:00:7b:5d:97 (c7u6sx) via eth0 Jun 30 21:17:19 c7u6s1 dhcpd[12935]: DHCPREQUEST for 192.168.122.105 from 52:54:00:7b:5d:97 (c7u6sx) via eth0 Jun 30 21:17:19 c7u6s1 dhcpd[12935]: DHCPACK on 192.168.122.105 to 52:54:00:7b:5d:97 (c7u6sx) via eth0 Jun 30 21:21:21 c7u6s1 dhcpd[12935]: DHCPREQUEST for 192.168.122.105 from 52:54:00:7b:5d:97 (c7u6sx) via eth0 Jun 30 21:21:24 c7u6s1 dhcpd[12935]: ns1.example.org: host unknown. Jun 30 21:21:27 c7u6s1 dhcpd[12935]: ns2.example.org: host unknown. Jun 30 21:21:27 c7u6s1 dhcpd[12935]: DHCPACK on 192.168.122.105 to 52:54:00:7b:5d:97 (c7u6sx) via eth0 [root@c7u6s1 tftpboot]# [root@c7u6s1 tftpboot]# cat /etc/dhcp/dhcpd.conf | egrep '^[^$|^#].*' option domain-name "example.org"; option domain-name-servers ns1.example.org, ns2.example.org; default-lease-time 600; max-lease-time 7200; log-facility local7; subnet 192.168.122.0 netmask 255.255.255.0 {range 192.168.122.100 192.168.122.150; option routers 192.168.122.1;filename "undionly.kpxe";next-server 192.168.122.11; } [root@c7u6s1 tftpboot]# 上述就是完整的dhcp服務配置文件的內容。此處
上面的服務準備好之后,就需要準備iPXE實現自動啟動所需要的文件了。具體分為下面幾部分:
上述就是iPXE網絡自動安裝系統所需要準備的文件。其中第一個文件 undionly.kpxe 在系統軟件包有提供。但是使用這個默認提供的文件,會導致網絡引導階段的死循環。要使用默認提供的文件,需要執行下面的操作,安裝iPXE相關的軟件包。在c7u6s1虛擬機上安裝ipxe相關的軟件包,具體如下所示:
[root@c7u6s1 tftpboot]# yum list | egrep '^ipxe.*' | gawk '{print $1}' | xargs -i yum install -y {} Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile* base: mirrors.163.com* epel: mirrors.bfsu.edu.cn* extras: mirrors.163.com* updates: mirrors.163.com Package ipxe-bootimgs-20180825-3.git133f4c.el7.noarch already installed and latest version Nothing to do Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile* base: mirrors.163.com* epel: mirrors.ustc.edu.cn* extras: mirrors.163.com* updates: mirrors.163.com Package ipxe-roms-20180825-3.git133f4c.el7.noarch already installed and latest version Nothing to do Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile* base: mirrors.163.com* epel: mirrors.ustc.edu.cn* extras: mirrors.163.com* updates: mirrors.163.com Package ipxe-roms-qemu-20180825-3.git133f4c.el7.noarch already installed and latest version Nothing to do [root@c7u6s1 tftpboot]#安裝好之后,由于此處使用BIOS的形式,而非UEFI,所以可以將/usr/share/ipxe/undionly.kpxe這個文件拷貝到tftp服務器的家目錄中。具體如下所示:
[root@c7u6s1 tftpboot]# cp /usr/share/ipxe/undionly.kpxe .此時如果新建一個虛擬機并指定從網絡引導,會出現如下圖所示的情況:
反復重復上述的過程。
官方文檔提供了一種解決方案,就是自己編譯。具體過程如下所示:
上述第4條命令是在config目錄下的所有.h頭文件在config/local/目錄下創建對應的鏈接文件,否則下面編譯的時候會報錯。
除此之外,還需要安裝開發環境,以及xz-devel。具體如下所示:
上述軟件包安裝完成之后,就可以著手編譯了。具體如下所示:
#準備一個ipxe腳本文件,告知undionly.kpxe去哪里找網絡引導所需要的內核以及虛擬內存文件。 [root@c7u6s1 src]# pwd /root/softwares/ipxe/src [root@c7u6s1 src]# vim demo.ipxe [root@c7u6s1 src]# cat demo.ipxe #!ipxedhcp chain http://192.168.122.11/boot.ipxe [root@c7u6s1 src]# [root@c7u6s1 src]# make bin/undionly.kpxe EMBED=demo.ipxe上述的demo.ipxe文件中指定了引導腳本的路徑為c7u6s1(192.168.122.11)服務器上的web服務器根目錄下的boot.ipxe這個腳本文件。這個文件默認并不存在,需要后面創建。
等待上述過程完成,在src/bin/目錄下就生成了對應的undionly.kpxe這個文件。然后將這個文件拷貝到/var/lib/tftpboot/目錄下。具體如下所示:
接下來準備boot.ipxe這個iPXE腳本文件,具體如下所示:
[root@c7u6s1 src]# pwd /root/softwares/ipxe/src [root@c7u6s1 src]# cd /var/www/html/ [root@c7u6s1 html]# vim boot.ipxe [root@c7u6s1 html]# cat boot.ipxe #!ipxe:start menu PXE Boot Options item shell iPXE shell item centos7-net CentOS 7 installation item exit Exit to BIOSchoose --default centos7-net --timeout 6000 option && goto ${option}:shell shell:centos7-net set server_root http://192.168.122.11/centos7 initrd ${server_root}/iso/images/pxeboot/initrd.img #kernel ${server_root}/iso/images/pxeboot/vmlinuz inst.repo=${server_root}/ ip=dhcp ipv6.disable initrd=initrd.img inst.geoloc=0 devfs=nomount kernel ${server_root}/iso/images/pxeboot/vmlinuz inst.ks=${server_root}/c7u6_virt_host.cfg ip=dhcp ipv6.disable initrd=initrd.img inst.geoloc=0 devfs=nomount boot:exit exit [root@c7u6s1 html]#上述腳本中指定了1個菜單項,即CentOS7-net,并在其中指定了網絡啟動所需要的內核文件以及虛擬內存文件。同時在內核文件中通過參數inst.ks指定了kickstart文件的路徑。這三個文件都是通過web服務器提供的。
接下來準備上述的光盤ISO鏡像掛載,由于我系統上已經通過fstab自動掛載了iso文件到/media/iso這個目錄下,所以此處只需要在/var/www/html/目錄下創建對應的發行版目錄centos7/iso/,然后將/media/iso綁定到/var/www/html/centos7/iso/目錄上即可。具體如下所示:
[root@c7u6s1 html]# cat /etc/fstab | tail -n1 /dev/sr1 /media/iso iso9660 defaults,loop 0 0 [root@c7u6s1 html]# mkdir -p centos7/iso [root@c7u6s1 html]# mount --bind /media/iso /var/www/html/centos7/iso [root@c7u6s1 iso]# pwd /var/www/html/centos7/iso [root@c7u6s1 iso]# ls images/ efiboot.img pxeboot TRANS.TBL [root@c7u6s1 iso]# ls images/pxeboot/ initrd.img TRANS.TBL vmlinuz [root@c7u6s1 iso]#上述就完成了光盤鏡像文件的準備操作,注意使用絕對路徑。
最后準備kickstart文件,具體如下所示:
[root@c7u6s1 centos7]# pwd /var/www/html/centos7 [root@c7u6s1 centos7]# [root@c7u6s1 centos7]# vim c7u6_virt_host.cfg [root@c7u6s1 centos7]# cat c7u6_virt_host.cfg #version=DEVEL # System authorization information auth --enableshadow --passalgo=sha512 # Use CDROM installation media #cdrom # Use text mode install install text reboot url --url=http://192.168.122.11/centos7/iso # Run the Setup Agent on first boot firstboot --enable ignoredisk --only-use=vda # Keyboard layouts keyboard --vckeymap=us --xlayouts='' # System language lang en_US.UTF-8# Network informationnetwork --bootproto=dhcp --device=eth0 --onboot=yes --ipv6=no --no-activate #network --bootproto=dhcp --device=eth1 --onboot=off --ipv6=autonetwork --hostname=c7u6sx# Root password rootpw --iscrypted $6$wYQ4sQUHYVmetic4$ULf257dlixXfr3zfXj5bRZ6wzt0zZDGWDYg3zvsEFNggMWhob7zU0ZCNoM4dyxWNfcb7EkOMYW3..oePpZjqJ. # System services services --enabled="chronyd" selinux --disabled firewall --disabled # Do not configure the X Window System skipx # System timezone timezone Asia/Shanghai --isUtc user --groups=wheel --name=albert --password=$6$TsBO3LGhk7nFEV.V$U4.Ke7W5M2Gjc.4wgA91Of7tUC1wRMBatHpM51Uj2xSGMTXr6H3EdY3LKvPdgWjZjVlZrJdsProzVnCuzeu2I/ --iscrypted --gecos="Albert Qee" # System bootloader configuration bootloader --location=mbr --boot-drive=vda #autopart --type=lvm # Partition clearing information clearpart --all --initlabel --drives=vda # Disk partitioning information part /boot --fstype="ext4" --size=512 part swap --fstype="swap" --size=1024 part pv.01 --fstype="lvmpv" --size=1 --grow volgroup vg0 --pesize=4096 pv.01 #logvol / --fstype='xfs' --size=39424 --name=root --vgname=vg0 logvol / --fstype="xfs" --size=1 --name=root --vgname=vg0 --grow%packages @base @core chrony vim-enhanced tree %end%addon com_redhat_kdump --disable --reserve-mb='auto'%end%anaconda pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty %end%post mkdir /root/.ssh -m 600 cat > /root/.ssh/authorized_keys << EOF ssh-rsa AAAAB3NzaC1yc2EAAABDAQABAAABgQC8u+h0pbgbTZ+n54HyWVl8GoGEEjLDjA7O5Zrt55pZes0Dkwr4XqqlO+Wse/UJ3BqsAmLVoZEk7b8KbUxuGu5gauWEn0TAl4FzhP1h8YdUIfMWVKrzXH+7/IMXnrwHyaNFqoadp5KLTZeU4gKM6TVjvU2NZ6qIXU6L7OFMSZ+74g9Z2U8Ce7xp1AnodD1rGR4LoXcd8I/mCPZN0RP7rzH4UXdoe9cP431XYbWfiPPu4EjBpPylxXQ5Uq2drS0f+3ZRf1tIicXtWcGqb8M3T1efRy2MjgFhuC6YPU0+JDCCV8oNrBUyu5ifsRtbjaFpPrlkrmV7dm2Q2A1F3kYjCod9Ri5hDQ/oPIcBvAmCv7zDmK6HAX9Va9qNWL5uzVeUXGneTLtThBaHiQu//LNTSSTaPHYwZQbnMtBEG790hLCjCXAabpDWWr/jQFPNozMIqBDx5xjLqC2kwnomRuC2p8days/LVnVXsCur+vscmHu0oA6MX3aRj/xn3sqXjBVbG88= root@amdhost EOF chmod 600 /root/.ssh/authorized_keys %end #reboot #halt #poweroff上述就是kickstart文件的全部內容,在上述kickstart文件的末尾通過腳本腳宿主機的root用戶的公鑰文件加入到新建虛擬機的root用戶的/root/.ssh/authorized_keys這個文件中,并且設置對應目錄和文件的權限為適當的權限。以便系統安裝完成之后,就可以自動完成root身份的公鑰驗證登錄。
至此,iPXE服務器就準備完成了。在開始安裝之前,需要設置下Virt-Manager的網絡,將virbr0的DHCP功能關閉。具體如下所示:
[root@LiuXianQiE networks]# virsh net-listName State Autostart Persistent --------------------------------------------default active yes yesvnet11 active yes yesvnet12 active yes yesvnet13 active yes yesvnet14 active yes yes[root@LiuXianQiE networks]# virsh net-edit default <network><name>default</name><uuid>7b03db65-aa5e-44ed-8961-d72ece83ce95</uuid><forward mode='nat'/><bridge name='virbr0' stp='on' delay='0'/><mac address='52:54:00:45:1e:56'/><ip address='192.168.122.1' netmask='255.255.255.0'><!--<dhcp><range start="192.168.122.2" end="192.168.122.254" /></dhcp>--></ip> </network>上述命令將<ip> ... </ip>這個里面的<dhcp> ... </dhcp>注釋掉了。而上述命令實際編輯的就是/etc/libvirt/qemu/networks/defaut.xml這個文件,具體如下所示:
[root@LiuXianQiE networks]# pwd /etc/libvirt/qemu/networks [root@LiuXianQiE networks]# ls autostart default.xml [root@LiuXianQiE networks]# cat default.xml <!-- WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:virsh net-edit default or other application using the libvirt API. --><network><name>default</name><uuid>7b03db65-aa5e-44ed-8961-d72ece83ce95</uuid><forward mode='nat'/><bridge name='virbr0' stp='on' delay='0'/><mac address='52:54:00:45:1e:56'/><ip address='192.168.122.1' netmask='255.255.255.0'></ip> </network> [root@LiuXianQiE networks]#注釋掉之后,退出virsh net-edit default之后,就自動將注釋的內容刪除了。所以從命令行直接查看該文件的時候,就發現該文件的dhcp部分已經消失了。
至此,新建的虛擬機就不會從virbr0自動獲取IP地址了,而是從c7u6s1這個虛擬機上配置的DHCP服務器上獲取IP地址。接下來就可以準備新的虛擬機,并通過iPXE自動安裝系統了。
3.3. 通過iPXE安裝系統
在Virtual Machine Manager的圖形界面中創建新的虛擬機,具體如下所示:
點擊上圖的棕色方框創建新的虛擬機,彈出窗口如下:
選擇第三項PXE,然后點擊Forward進行下一步設置。具體如下所示:
在搜索框中輸入要安裝的發行版名稱,然后在自動彈出的下拉框中選擇對應的發行版,此處選擇CentOS 7,因為我們這里將要安裝CentOS 7.6。
接下來設置新虛擬機的內存,和CPU核心數,具體如下所示:
此處的內存容量不宜低于2G,如果低于2G,在安裝的時候將會報錯。
接下來設置存儲,具體如下所示:
接下來指定虛擬機的名稱,這里的名稱是Virtual Machine Manager以及virsh命令管理的時候所看到的名稱,而不是虛擬機的主機名。具體如下所示:
點擊完成之后,由于Virtual Machine Manager中默認沒有選中網絡啟動,所以還需要設置下網絡啟動。具體如下所示:
將網絡啟動設置為第一啟動項,在完成安裝之后,需要再將本地硬盤作為第一啟動項,即上圖的第二個啟動項。
此時點擊啟動虛擬機的按鈕,即可開始自動系統安裝,具體如下所示:
上述就是在給虛擬機從DHCP服務器請求IP地址,請求完成之后,就會進入到iPXE的啟動引導菜單,具體如下所示:
默認等待6秒,就開始從默認的CentOS 7開始進行安裝。具體如下所示:
上述完成了磁盤分區并且已經開始了軟件包安裝。等待安裝過程完成即可。
安裝完成之后,將啟動項修改為本地磁盤啟動即可。
上述即為從本地硬盤啟動之后的視圖。
從宿主機上連接上述虛擬機,具體如下所示:
上述執行virsh domifaddr c7u6s9命令查看新建虛擬機的IP地址,然后通過ssh -o StrictHostKeyChecking=no 192.168.122.60連接到新建的虛擬機,表示不詢問直接將遠程主機的公鑰加入到本地主機的known_hosts這個文件中。第一次加入之后,第二次連接就不會再提示了,所以可以省略掉-o StrictHostKeyChecking=no這個選項。
說明我們在kickstart文件的%post...%end部分指定的后向安裝腳本正常生效了。
另外,我們在dhcpd服務的配置文件中指定的自動分配的IP地址范圍是100-150,但是這里虛擬機安裝完系統之后獲得IP地址是192.168.122.60,并不在這個范圍。猜測應該是Virutal Machine Manager在啟動虛擬機的時候,自動給其分配了IP地址,此時查看Virutal Machine Manager中的virbr0的配置文件,具體如下所示:
此時查看dhcpd服務的狀態信息,發現在系統安裝階段,確實分配了100-150這個網段范圍內的IP地址,具體如下所示:
[root@c7u6s1 tftpboot]# systemctl status dhcpd ● dhcpd.service - DHCPv4 Server DaemonLoaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled; vendor preset: disabled)Active: active (running) since Wed 2021-06-30 16:41:17 CST; 6h agoDocs: man:dhcpd(8)man:dhcpd.conf(5)Main PID: 12935 (dhcpd)Status: "Dispatching packets..."CGroup: /system.slice/dhcpd.service└─12935 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pidJun 30 23:22:56 c7u6s1 dhcpd[12935]: ns2.example.org: host unknown. Jun 30 23:22:56 c7u6s1 dhcpd[12935]: DHCPACK on 192.168.122.105 to 52:54:00:7b:5d:97 (c7u6sx) via eth0 Jun 30 23:27:27 c7u6s1 dhcpd[12935]: DHCPREQUEST for 192.168.122.105 from 52:54:00:7b:5d:97 (c7u6sx) via eth0 Jun 30 23:27:30 c7u6s1 dhcpd[12935]: ns1.example.org: host unknown. Jun 30 23:27:33 c7u6s1 dhcpd[12935]: ns2.example.org: host unknown. Jun 30 23:27:33 c7u6s1 dhcpd[12935]: DHCPACK on 192.168.122.105 to 52:54:00:7b:5d:97 (c7u6sx) via eth0 Jun 30 23:32:07 c7u6s1 dhcpd[12935]: DHCPREQUEST for 192.168.122.105 from 52:54:00:7b:5d:97 (c7u6sx) via eth0 Jun 30 23:32:10 c7u6s1 dhcpd[12935]: ns1.example.org: host unknown. Jun 30 23:32:13 c7u6s1 dhcpd[12935]: ns2.example.org: host unknown. Jun 30 23:32:13 c7u6s1 dhcpd[12935]: DHCPACK on 192.168.122.105 to 52:54:00:7b:5d:97 (c7u6sx) via eth0 [root@c7u6s1 tftpboot]#從上述輸出中可以看出,在系統安裝過程中,給虛擬機分配了192.168.122.106這個IP地址。查看日志信息如下所示:
[root@c7u6s1 tftpboot]# less /var/log/messages Jun 30 23:16:04 c7u6s1 in.tftpd[14467]: Client ::ffff:192.168.122.106 finished undionly.kpxe Jun 30 23:16:05 c7u6s1 dhcpd: DHCPDISCOVER from 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:05 c7u6s1 dhcpd: DHCPOFFER on 192.168.122.106 to 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:06 c7u6s1 dhcpd: DHCPDISCOVER from 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:06 c7u6s1 dhcpd: DHCPOFFER on 192.168.122.106 to 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:08 c7u6s1 dhcpd: DHCPREQUEST for 192.168.122.106 (192.168.122.11) from 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:08 c7u6s1 dhcpd: DHCPACK on 192.168.122.106 to 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:09 c7u6s1 dhcpd: DHCPDISCOVER from 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:09 c7u6s1 dhcpd: DHCPOFFER on 192.168.122.106 to 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:10 c7u6s1 in.tftpd[14468]: Client ::ffff:192.168.122.11 timed out Jun 30 23:16:10 c7u6s1 in.tftpd[14469]: Client ::ffff:192.168.122.11 timed out Jun 30 23:16:10 c7u6s1 in.tftpd[14470]: Client ::ffff:192.168.122.11 timed out Jun 30 23:16:11 c7u6s1 dhcpd: DHCPREQUEST for 192.168.122.106 (192.168.122.11) from 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:11 c7u6s1 dhcpd: DHCPACK on 192.168.122.106 to 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:12 c7u6s1 dhcpd: DHCPDISCOVER from 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:12 c7u6s1 dhcpd: DHCPOFFER on 192.168.122.106 to 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:14 c7u6s1 dhcpd: DHCPREQUEST for 192.168.122.106 (192.168.122.11) from 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:14 c7u6s1 dhcpd: DHCPACK on 192.168.122.106 to 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:15 c7u6s1 dhcpd: DHCPDISCOVER from 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:15 c7u6s1 dhcpd: DHCPOFFER on 192.168.122.106 to 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:17 c7u6s1 dhcpd: DHCPREQUEST for 192.168.122.106 (192.168.122.11) from 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:17 c7u6s1 dhcpd: DHCPACK on 192.168.122.106 to 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:18 c7u6s1 dhcpd: DHCPDISCOVER from 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:18 c7u6s1 dhcpd: DHCPOFFER on 192.168.122.106 to 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:20 c7u6s1 dhcpd: DHCPREQUEST for 192.168.122.106 (192.168.122.11) from 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:20 c7u6s1 dhcpd: DHCPACK on 192.168.122.106 to 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:34 c7u6s1 dhcpd: DHCPDISCOVER from 52:54:00:4d:aa:a8 via eth0 Jun 30 23:16:34 c7u6s1 dhcpd: DHCPREQUEST for 192.168.122.60 (192.168.122.1) from 52:54:00:4d:aa:a8 via eth0: unknown lease 192.168.122.60.但是后面確實通過c7u6s1的dhcp服務為其分配了192.168.122.60這個IP地址。
至此,通過iPXE基于kickstart實現的自動化CentOS7.6系統安裝操作就完成了。
4. References
[1]. How to install Gnome on Ubuntu 20.04 LTS Focal Fossa
[2]. Build your own PXE boot server
[3]. iPXE
[4]. Chainloading iPXE
[5]. Disable DHCP on a QEMU/libvirt/KVM Network
總結
以上是生活随笔為你收集整理的Linux随笔15-Ubuntu20.04允许root用户图形界面登录、chrony局域网时间同步服务、ipxe实现系统自动化安装的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mc服务器右上角信号格,手机右上角的网络
- 下一篇: Linux循环登录怎么解决,文本模式循环