Cobbler是一個Linux服務器安裝的服務,可以通過網絡啓動(PXE)的方式來快速安裝、重裝物理服務器和虛擬機,同時還可以管理DHCP,DNS等。
Cobbler可以使用命令行方式管理,也提供了基於Web的界面管理工具(cobbler-web),還提供了API接口,可以方便二次開發使用。
Cobbler是較早前的kickstart的升級版,優點是比較容易配置,還自帶web界面比較易於管理。
Cobbler內置了一個輕量級配置管理系統,但它也支持和其它配置管理系統集成,如Puppet,暫時不支持SaltStack。
kickstart是由dhcp、tftp、http這三種服務有機組成,爲有pxe功能的客戶端提供自動裝機服務。kickstart只是這套系統的名字,並沒有這個獨立的軟件。
cobbler是對kickstart進行二次開發,安裝cobbler的過程中,其實已經悄悄地安裝了和kickstart一樣的服務,因此在工作中安裝cobbler直接一條yum命令即可,不需要先把kickstart服務安裝配置好。
環境
Linux CentOS6 2.6.32-642.el6.x86_64
cobbler-2.6.11-1.el6.x86_64
cobbler-web-2.6.11-1.el6.noarch
dhcp-4.1.1-51.P1.el6.centos.x86_64
tftp-server-0.49-8.el6.x86_64
pykickstart-1.74.20-1.el6.noarch
httpd-2.2.15-56.el6.centos.3.x86_64
系統環境準備
[root@CentOS6 ~]# getenforce Disabled [root@CentOS6 ~]# /etc/init.d/iptables status iptables: Firewall is not running. [root@CentOS6 ~]# cat /etc/redhat-release CentOS release 6.8 (Final) [root@CentOS6 ~]#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
注意:虛擬機VMware模式的DHCP服務關閉,同一臺機器上面不允許兩個DHCP服務
Cobbler安裝配置
[root@CentOS6 ~]# yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd [root@CentOS6 ~]# /etc/init.d/httpd restart [root@CentOS6 ~]# /etc/init.d/cobblerd restart [root@CentOS6 ~]# /etc/init.d/xinetd restart
[root@CentOS6 ~]# rpm -ql cobbler
/etc/cobbler # 配置文件目錄
/etc/cobbler/settings # cobbler主配置文件,這個文件是YAML格式,Cobbler是python寫的程序。
/etc/cobbler/dhcp.template # DHCP服務的配置模板
/etc/cobbler/tftpd.template # tftp服務的配置模板
/etc/cobbler/rsync.template # rsync服務的配置模板
/etc/cobbler/iso # iso模板配置文件目錄
/etc/cobbler/pxe # pxe模板文件目錄
/etc/cobbler/power # 電源的配置文件目錄
/etc/cobbler/users.conf # Web服務授權配置文件
/etc/cobbler/users.digest # 用於web訪問的用戶名密碼配置文件
/etc/cobbler/dnsmasq.template # DNS服務的配置模板
/etc/cobbler/modules.conf # Cobbler模塊配置文件
/var/lib/cobbler # Cobbler數據目錄
/var/lib/cobbler/config # 配置文件
/var/lib/cobbler/kickstarts # 默認存放kickstart文件
/var/lib/cobbler/loaders # 存放的各種引導程序
/var/www/cobbler # 系統安裝鏡像目錄
/var/www/cobbler/ks_mirror # 導入的系統鏡像列表
/var/www/cobbler/p_w_picpaths # 導入的系統鏡像啓動文件
/var/www/cobbler/repo_mirror # yum源存儲目錄
/var/log/cobbl # 日誌目錄
/var/log/cobbler/install.log # 客戶端系統安裝日誌
/var/log/cobbler/cobbler.log # cobbler日誌
配置Cobbler
[root@CentOS6 ~]# 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 th
em, 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 : change 'disable' to 'no' in /etc/xinetd.d/rsync
6 : file /etc/xinetd.d/rsync does not exist # 這是一個bug
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
8 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobb
ler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one9 : 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.
[root@CentOS6 ~]cp /etc/cobbler/settings{,.ori} ##備份 1.[root@CentOS6 ~]# sed -i 's#server: 127.0.0.1#server: 172.16.1.101#' /etc/cobbler/settings ###指定cobbler服務器地址 2.[root@CentOS6 ~]#sed -i 's#yes#no#' /etc/xinetd.d/rsync 3.[root@CentOS6 ~]# sed 's#manage_dhcp: 0#manage_dhcp: 1#' /etc/cobbler/settings ##用Cobbler管理DHCP 4.[root@CentOS6 ~]# sed -n 's/pxe_just_once: 0/ pxe_just_once: 1/' /etc/cobbler/settings ##防止循環裝系統,適用於服務器第一啓動項是PXE啓動。務 5.[root@CentOS6 ~]# sed -i 's#yes#no#' /etc/xinetd.d/tftp 6.[root@CentOS6 ~]# sed -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt 'oldboy' '123456'`\"#" /etc/cobbler/settings 7.[root@CentOS6 ~]# sed -i 's/next_server: 127.0.0.1/next_server: 172.16.1.101/' /etc/cobbler/settings
問題4解決方法
####http://pan.baidu.com/s/1kVqhMT5###需要從官網下載,我這裏已經下載好了。
tar xfP cobbler_load.tar.gz
配置DHCP
[root@CentOS6 ~] vim /etc/cobbler/dhcp.template
:%s/192.168.1/172.16.1/g
鏡像掛載
這裏我用的是虛擬機VMware,需要把你的鏡像文件掛載一下。
創建掛載目錄
[root@CentOS6 ~]# mount /dev/cdrom /mnt
Kickstart創建
# Cobbler for Kickstart Configurator for CentOS 6.8 by yao zhang
install
url --url=$tree
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
$SNIPPET('network_config')
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw --iscrypted $default_password_crypted
clearpart --all --initlabel
part /boot --fstype=ext4 --asprimary --size=200
part swap --size=1024
part / --fstype=ext4 --grow --asprimary --size=200
firstboot --disable
selinux --disabled
firewall --disabled
logging --level=info
reboot
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
@base
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
%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
使用瀏覽器訪問主頁,進一步進行cobber網頁配置
點擊“import DVD”--》“DVD importer”,這裏需要註明路徑必須填寫,然後單擊“run”把鏡像文件上傳到服務器上面,這裏上傳的方式使用rsync上傳,rsync服務是批量增加的。
點擊“events”查看日誌。
剛剛上傳鏡像目錄
創建yum源文件,yum源可以使用本地yum源也可以使用外網yum源。
創建完yum源以後需要“reposync”進行同步一下,方可以生效
自定義系統文件