PXE-cobbler无人值守装机
Cobbler介绍
Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
环境准备
1.查看系统版本和内核
2.关闭防火墙和selinux
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# setenforce 0
安装cobbler与相关组件
1.下载epel 源
[[email protected] ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
2.安装相关环境
[[email protected] ~]# yum install -y cobbler cobbler-web dhcp kickstart httpd tftp-server
3.启动httpd与cobblerd服务并将其设为开机自启动
[[email protected] ~]# systemctl enable httpd
[[email protected] ~]# systemctl enable cobblerd
[[email protected] ~]# systemctl start cobblerd
[[email protected] ~]# systemctl start httpd
运行cobbler check 命令
1.根据结果提示更改参数
[[email protected] ~]# cobbler check
2.修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机相应的IP地址或主机名,如server: 10.0.0.41
[[email protected] ~]# sed -i ‘s/server: 127.0.0.1/server: 10.0.0.41/’ /etc/cobbler/settings
3.修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址,如next_server: 10.0.0.41
[[email protected] ~]# sed -i ‘s/next_server: 127.0.0.1/next_server: 10.0.0.41/’ /etc/cobbler/settings
4.修改/etc/xinetd.d/tftp文件中的disabled参数的值为no
[[email protected] ~]# sed -i ‘s/disable.= yes/disable = no/g’ /etc/xinetd.d/tftp
5.执行cobbler get-loaders 命令
[[email protected] ~]# cobbler get-loaders
6.开启rsyncd.service服务命令并将其设为开机自启动
[[email protected] ~]# systemctl enable rsyncd
[[email protected] ~]# systemctl start rsyncd
7.安装debmirror 服务
[[email protected] ~]# yum -y install debmirror
8.生成密码来取代默认密码
[[email protected] ~]# openssl passwd -1 -salt ‘pxepxe’ ‘12345’
[[email protected] ~]# openssl passwd -1 -salt ‘pxepxe’ ‘12345’ $ 1$pxepxe$283B/mrqHX6irt0NeAFtf.
[[email protected] ~]# sed -i s/'default_password_crypted:.’/‘default_password_crypted: “default_password_crypted: $1 $pxepxe$283B/mrqHX6irt0NeAFtf.”’/g /etc/cobbler/settings
9.安装cman fence-agents
[[email protected] ~]# yum install -y cman fence-agents
10.重启cobblerd 服务,重新check
[[email protected] ~]# systemctl restart cobblerd
[[email protected] ~]# cobbler check
#在/etc/debmirror.conf文件中将’dists’和‘arches’两行注释掉
[[email protected] ~]# vim /etc/debmirror.conf
#注释掉之后重新check后无报错
11.其他一些没有提示报错的小修改
#用cobbler管理DHCP,修改242行manage_dhcp: 0
[[email protected] ~]# sed -i ‘s/manage_dhcp: 0/manage_dhcp: 1/g’ /etc/cobbler/settings
#防止循环装系统,适用于服务器第一启动项是PXE启动,修改298行pxe_just_once: 0
[[email protected] ~]# sed -i ‘s/pxe_just_once: 0/pxe_just_once: 1/g’ /etc/cobbler/settings
#修改完后重启服务再次检测
[[email protected] ~]# systemctl restart cobblerd
[[email protected] ~]# cobbler check
12.修改cobbler 的dhcp模板参数
[[email protected] ~]# vim /etc/cobbler/dhcp.template
13.启动相关服务设置开机自启动
[[email protected] ~]# systemctl enable httpd
[[email protected] ~]# systemctl enable cobblerd
[[email protected] ~]# systemctl enable dhcpd
[[email protected] ~]# systemctl enable rsyncd
[[email protected] ~]# systemctl enable tftp
[[email protected] ~]# systemctl restart httpd
[[email protected] ~]# systemctl restart cobblerd
[[email protected] ~]# systemctl restart rsyncd
[[email protected] ~]# systemctl restart dhcpd
[[email protected] ~]# systemctl restart tftp
导入镜像
#–path 镜像路径
#–name 为安装源定义一个名字
#–arch 指定安装源是32位、64位还是ia64.
#查看镜像
[[email protected] ~]# cobbler list
#默认模板安装
[[email protected] kickstarts]# cp sample_end.ks CentOS7mini.cfg
#查看安装镜像信息
#查看所有profile 设置
#查看指定profile 设置
#可以看到此时ks文件为默认模板文件
#编辑profile,修改关联的ks文件
#可以看到此时ks文件已改为自定义ks文件
#修改安装系统的内核参数
[[email protected] kickstarts]# cobbler profile edit --name=CentOS7-x86_64 --kopts=‘net.ifnames=0 biosdevname=0’
#更改完参数需要同步镜像
#上面我们使用openssl passwd 命令设置密码的时候生成了一个秘钥文件。
[[email protected] kickstarts]# grep “default_password” /etc/cobbler/settings
#将密码复制到ks文件中
[[email protected] kickstarts]# vim /var/lib/cobbler/kickstarts/sample_end.ks
#安装成功