1. Cobbler介绍
Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
1.1 Cobbler集成的服务
PXE服务支持
DHCP服务管理
DNS服务管理(可选bind,dnsmasq)
电源管理
Kickstart服务支持
YUM仓库管理
TFTP(PXE启动时需要)
2 Cobbler所需软件包(默认存在epel repo)
]# yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd xinetd
3 启动相关服务并设置开机自启
systemctl start httpd
systemctl enable httpd
systemctl start cobblerd
systemctl enable cobblerd
systemctl start rsyncd
systemctl enable rsyncd
systemctl start dhcpd
systemctl enable dhcpd
systemctl start xinetd
systemctl enable xinetd
3 根据cobbler提示配置文件
cobbler check
3.1 修改/etc/cobbler/settings文件,将默认server的127.0.0.1替换为本机IP地址
sed -i 's#^server: 127.0.0.1#server: 192.168.50.101#' /etc/cobbler/settings
3.2 修改/etc/cobbler/settings文件,将默认next_server的127.0.0.1替换为本机IP地址
sed -i 's#^next_server: 127.0.0.1#next_server: 192.168.50.101#' /etc/cobbler/settings
3.3 用Cobbler管理DHCP
sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings #也可以自行配置DHCP服务而无需cobbler管理
3.4 设置通过PXE安装系统密码。根据'cobbler check'提示6中的格式
"openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'"
"openssl passwd -1 -salt 'ankon' '123456'"
生成的随机码:$1$ankon$3lP2z1SgXln3JB/WPLXyM/
vim /etc/cobbler/settings
default_password_crypted: "$1$ankon$3lP2z1SgXln3JB/WPLXyM/"
3.5 下载cobbler引导程序
cobbler get-loaders
3.6 开启tftp服务,修改'disable'为'no'
vim /etc/xinetd.d/tftp
disable = no
systemctl restart xinetd.service
3.7 重启cobbler服务
systemctl restart cobbler
cobbler check #检查cobbler配置是否正确
出现debian和fence信息。可以不用管,如果需要支持debian和fence,可以yum install对应包
4 配置dhcp服务
vim /etc/cobbler/dhcp.template
--------------------
根据你上面配置的/etc/cobbler/settings 里设置的IP地址自动生成
subnet 192.168.50.0 netmask 255.255.255.0 {
option routers 192.168.50.1; #网关地址(也可以填写本机IP)
option domain-name-servers 192.168.50.1; #DNS(也可以填写本机IP)
option subnet-mask 255.255.255.0; #掩码
range dynamic-bootp 192.168.50.120 192.168.50.130; #网段
5 同步cobbler配置
cobbler sysnc
6 导入镜像
mount /dev/cdrom /mnt/ # 挂载CentOS7的系统镜像。
cobbler import --path=/mnt/ --name=CentOS-7 --arch=x86_64
cobbler distro list # 查看镜像列表
7 编辑kickstart文件
在第一次导入系统镜像后,Cobbler会给镜像指定一个默认的kickstart自动安装文件在/var/lib/cobbler/kickstarts下的sample_end.ks。
也可以导入自定义ks文件
cp ks.cfg /var/lib/cobbler/kickstarts/
7.1 查看安装镜像文件信息
cobbler distro report --name=CentOS-7-x86_64
7.2 编辑profile,修改关联的ks文件
cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/sample_end.ks
进行PXE过程中,可能出现python的字符集编码不一致造成的错误
1 Exception occured:'exceptions.UnicodeDecodeError'> 2 Exception value: 'ascii' codec can't decode byte 0xe8 in position 117: ordinal not in range(128) 3 Exception Info: 4 File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 82, in run 5 rc = self._run(self) 6 File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 191, in runner 7 return self.remote.api.validateks(logger=self.logger) 8 File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 750, in validateks 9 return validator.run() 10 File "/usr/lib/python2.7/site-packages/cobbler/action_validate.py", line 52, in run 11 (result, errors) = self.checkfile(x, True) 12 File "/usr/lib/python2.7/site-packages/cobbler/action_validate.py", line 96, in checkfile 13 self.kickgen.generate_kickstart_for_profile(obj.name) 14 File "/usr/lib/python2.7/site-packages/cobbler/kickgen.py", line 295, in generate_kickstart_for_profile 15 return self.generate_kickstart(profile=g) 16 File "/usr/lib/python2.7/site-packages/cobbler/kickgen.py", line 277, in generate_kickstart 17 data = self.templar.render(raw_data, meta, None, obj) 18 File "/usr/lib/python2.7/site-packages/cobbler/templar.py", line 116, in render 19 data_out = self.render_cheetah(raw_data, search_table, subject) 20 File "/usr/lib/python2.7/site-packages/cobbler/templar.py", line 201, in render_cheetah 21 t = Template(source=raw_data, searchList=[search_table], compilerSettings={'useStackFrame':False}) 22 File "DynamicallyCompiledCheetahTemplate.py", line 58, in __init__ 23 File "_etc_cobbler_cheetah_macros.py", line 58, in __init__ 24 File "/usr/lib64/python2.7/site-packages/Cheetah/Template.py", line 1259, in __init__ 25 self._compile(source, file, compilerSettings=compilerSettings) 26 File "/usr/lib64/python2.7/site-packages/Cheetah/Template.py", line 1553, in _compile 27 keepRefToGeneratedCode=True) 28 File "/usr/lib/python2.7/site-packages/cobbler/template_api.py", line 127, in compile 29 return Cheetah.Template.Template.compile(*args, **kwargs) 30 File "/usr/lib64/python2.7/site-packages/Cheetah/Template.py", line 740, in compile 31 settings=(compilerSettings or {})) 32 File "/usr/lib64/python2.7/site-packages/Cheetah/Compiler.py", line 1575, in __init__ 33 source = unicode(source) 34 35 !!! TASK FAILED !!!
修改对应字符集:
1 cat >> /usr/lib/python2.7/site-packages/sitecustomize.py <<EOF 2 # encoding=utf8 3 import sys 4 reload(sys) 5 sys.setdefaultencoding('utf8') 6 EOF