Linux運維:cobbler
: Ago linux運維群:93324526
學習cobbler的話,必須先搞懂kickstart,原理不是,不懂如何排錯。
kickstart部署請點擊這里
1. Cobbler介紹
Cobbler是一個Linux服務器安裝的服務,可以通過網絡啟動(PXE)的方式來快速安裝、重裝物理服務器和虛擬機,同時還可以管理DHCP,DNS等。
Cobbler可以使用命令行方式管理,也提供了基於Web的界面管理工具(cobbler-web),還提供了API接口,可以方便二次開發使用。
Cobbler是較早前的kickstart的升級版,優點是比較容易配置,還自帶web界面比較易於管理。
Cobbler內置了一個輕量級配置管理系統,但它也支持和其它配置管理系統集成,如Puppet,暫時不支持SaltStack。
cobbler官網
1.1 Cobbler集成的服務
- PXE服務支持
- DHCP服務管理
- DNS服務管理(可選bind,dnsmasq)
- 電源管理
- Kickstart服務支持
- YUM倉庫管理
- TFTP(PXE啟動時需要)
- Apache(提供kickstart的安裝源,並提供定制化的kickstart配置)
1.2 系統環境准備
[root@CentOS6 ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@CentOS6 ~]# uname -r
2.6.32-642.el6.x86_64
[root@CentOS6 ~]# getenforce
Disabled
[root@CentOS6 ~]# /etc/init.d/iptables status
iptables: Firewall is not running.
[root@CentOS6 ~]# ifconfig eth0|awk -F "[ :]+" 'NR==2 {print $4}'
10.0.0.101
[root@CentOS6 ~]# hostname
CentOS6
[root@CentOS6 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
注意:
- 虛擬機網卡采用NAT模式,不要使用橋接模式,因為稍后我們會搭建DHCP服務器,在同一局域網多個DHCP服務會有沖突。
- VMware的NAT模式的dhcp服務也關閉,避免干擾。
2.1 安裝Cobbler
需要epel源
[root@CentOS6 ~]# yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd
[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/images # 導入的系統鏡像啟動文件
/var/www/cobbler/repo_mirror # yum源存儲目錄
/var/log/cobbler # 日志目錄
/var/log/cobbler/install.log # 客戶端系統安裝日志
/var/log/cobbler/cobbler.log # cobbler日志
2.2 配置Cobbler
cobbler check
[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 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 : change 'disable' to 'no' in /etc/xinetd.d/rsync
6 : file /etc/xinetd.d/rsync does not exist
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/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
9 : 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.
解釋一下9條內容
1.改變server的主機名
2.第二是DHCP的next_server改成172.16.1.101
3.改xined的tftp disable等於no
4.
5./etc/xinetd.d/rsync 也改成no
6.bug,已經存在
7.debin系統的源
8.生成密碼並設置openssl passwd -1 -salt
9.fencing tools 高可用的硬件設備。
修改配置文件
命令直接復制粘貼即可
cp /etc/cobbler/settings{,.ori} #備份
sed -i 's/server: 127.0.0.1/server: 172.16.1.101/' /etc/cobbler/settings #服務端IP
sed -i 's/next_server: 127.0.0.1/next_server: 172.16.1.101/' /etc/cobbler/settings #服務端IP
sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings #dhcp只獲取一次
sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings #cobbler只執行一遍
sed -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt 'oldboy' '123456'`\"#" /etc/cobbler/settings #設置密碼為123456
sed -i 's#yes#no#' /etc/xinetd.d/rsync #xinet 管理rsync
sed -i 's#yes#no#' /etc/xinetd.d/tftp #xinet 管理tftp
cobbler get-loaders #下載
sed -i 's#192.168.1#172.16.1#g;22d;23d' /etc/cobbler/dhcp.template # 修改dhcp配置文件
cobbler sync #寫入磁盤
/etc/init.d/xinetd restart #啟動三個必須啟動的服務。詳情請看kickstart
/etc/init.d/cobblerd restart
/etc/init.d/httpd restart
cobbler sync # 修改配置文件等,沒事就來一次。保證沒事
CentOS-6.8-x86_64.cfg
# 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
圖片詳解,ks配置文件請看上方
1.登錄界面
2.導入鏡像,記得掛載光盤或者鏡像文件
鏡像位置/var/www/cobbler/ks_mirror/
3.自定義KS配置文件。請看上方
4.創建一個全局變量
5.制作yum倉庫
6.導入yum倉庫並創建全局變量
7.創建system