一、環境準備
[root@master ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@master ~]# uname -a
Linux master 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@master ~]# ip addr
ens33:
inet 192.168.0.201/24 brd 192.168.0.255 scope global ens33
二、關閉防火牆和selinux
[root@master ~]# systemctl disable firewalld.service
[root@master ~]# systemctl stop firewalld.service
[root@master ~]# setenforce 0
[root@master ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
三、安裝依賴包
[root@master ~]# yum -y install httpd dhcp tftp-server xinetd cobbler cobbler-web pykickstart
四、啓動httpd服務
[root@master ~]# systemctl enable httpd
[root@master ~]# systemctl start httpd
五、啓動cobbler服務
[root@master ~]# systemctl enable cobblerd
[root@master ~]# systemctl start cobblerd
六、檢查cobbler啓動狀態
[root@master ~]# 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.
七、解決步驟六中的問題
1、“server”不能設置爲“localhost”:
[root@master ~]# sed -i 's/server: 127.0.0.1/server: 192.168.0.201/g' /etc/cobbler/settings
2、“next_server”不能設置爲“127.0.0.1”:
[root@master ~]# sed -i 's/next_server: 127.0.0.1/next_server: 192.168.0.201/g' /etc/cobbler/settings
3、要將/etc/xinetd.d/tftp中的“disable”由“yes”改爲“no”。
4、提示需要運行“cobbler get-loaders”,運行需要一些時間:
[root@master ~]# cobbler get-loaders
task started: 2020-04-14_195348_get_loaders
task started (id=Download Bootloader Content, time=Tue Apr 14 19:53:48 2020)
……
*** TASK COMPLETE ***
5、需要啓用rsyncd服務:
[root@master ~]# systemctl enable rsyncd
[root@master ~]# systemctl start rsyncd
6、Debian系統需要注意的安裝包debmirror。此處不做處理。
7、需要修改“/etc/cobbler/settings”文件中“default_password_crypted”的值:
將密碼加密(‘123456’將會作爲新安裝操作系統的root用戶密碼):
[root@master ~]# openssl passwd -1 -salt 'cobbler' '123456'
$1$cobbler$sqDDOBeLKJVmxTCZr52/11
8、需要安裝“cman” 或 “fence-agents”:
[root@master ~]# yum -y install fence-agents
八、 啓動xinet服務
[root@master ~]# systemctl enable xinetd
[root@master ~]# systemctl start xinetd
九、重啓cobblerd並重新檢查cobbler狀態
[root@master ~]# systemctl restart cobblerd
[root@master ~]# cobbler check
十、配置DHCP服務
將由cobbler管理DHCP:
[root@master ~]# sed -i "s/manage_dhcp: 0/manage_dhcp: 1/g" /etc/cobbler/settings
編輯cobbler的DHCP模板:
cat /etc/cobbler/dhcp.template #只顯示需要的部分
subnet 192.168.0.0 netmask 255.255.255.0 { # 192.168.0.0 指子網的網段
option routers 192.168.0.1; # 192.168.0.1 指網關IP
option domain-name-servers 223.5.5.5; # 配置DNS
option subnet-mask 255.255.255.0; # 子網掩碼
range dynamic-bootp 192.168.0.205 192.168.0.210; # 可分配的IP地址範圍
十一、同步cobbler配置
[root@master ~]# systemctl restart cobblerd
[root@master ~]# cobbler sync # 過程中會生成dhcp.conf文件,並啓動dhcpd服務
……
generating /etc/dhcp/dhcpd.conf
……
running: service dhcpd restart
十二、掛載cdrom
如果主機爲VMWare虛擬機,需要注意虛擬機的光驅是否已經連接:
查看虛擬機的光驅是否已經連接
[root@master ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 寫保護,將以只讀方式掛載
十三、爲cobbler導入CentOS 7系統鏡像
[root@master ~]# cobbler import --name=CentOS-7-x86_64 --path=/mnt/ --arch=x86_64
查看導入的鏡像:
[root@master ~]# cobbler distro list
CentOS-7-x86_64
[root@master ~]# cobbler report distro
十四、管理profile
導入鏡像時,cobbler默認創建了同名profile,併爲其指定了默認的kickstart文件“sample_end.ks”。
查看已有的profile:
[root@master ~]# cobbler profile list
CentOS-7-x86_64
[root@master ~]# cobbler profile report
……
Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks
……
自定義的kickstart文件:
[root@master ~]# cat /var/lib/cobbler/kickstarts/ks.cfg
# This kickstart file should only be used with EL > 5 and/or Fedora > 7.
# For older versions please use the sample.ks kickstart file.
# Install OS instead of upgrade
install
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# System timezone
timezone Asia/ShangHai
#Root password
rootpw --iscrypted $default_password_crypted
# System authorization information
auth --useshadow --enablemd5
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Use network installation
url --url=$tree
# Clear the Master Boot Record
zerombr
# System bootloader configuration
bootloader --location=gpt
# Partition clearing information
clearpart --all --initlabel
part /boot --fstype=xfs --size=500
part swap --fstype=swap --size=2048
part / --fstype=xfs --grow --size=1
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Do not configure the X Window System
skipx
# Run the Setup Agent on first boot
firstboot --disable
# Reboot after installation
reboot
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
$SNIPPET('func_install_if_enabled')
@core
%end
%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end
%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
%end
將默認的“sample_end.ks”改爲“ks.cfg”:
[root@master ~]# cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks.cfg
十五、最後執行一次sync
[root@master ~]# cobbler sync
十六、新建虛擬機進行測試
新建虛擬機:
新建虛擬機設置
獲取IP
十七、報錯處理
安裝過程中出現的“No space left on device”:
該問題由於虛擬機內存不足引起,在新建虛擬機時,將虛擬機內存調整到2G以上。