Cobbler:批量自动安装CentOS7-荒岛

Cobbler:批量自动安装CentOS7-荒岛

如果要在几十上百台机器内批量安装CentOS7,以前常用的办法就是PXE+DHCP+TFTP+Kickstart,但这套环境部署起来很麻烦,所以就有了Cobbler的诞生。

Cobbler相当于是把PXE+DHCP+TFTP+Kickstart集合在了一起,我们可以借助Cobbler快速把这一套环境部署起来。

安装Cobbler和需要用到的工具:

yum -y update  yum -y install epel-release  yum -y install cobbler cobbler-web dhcp debmirror pykickstart fence-agents

这里有个坑,cobbler-web包安装的Django版本高了,会导致WEB界面打不开报错500,所以我们自己降级一下Django的版本:

yum -y install python-pip  pip install Django==1.8.19

关防火墙:

systemctl stop firewalld  systemctl disable firewalld

关SELinux:

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config  setenforce 0

启动cobbler/apache/tftp服务:

systemctl start cobblerd httpd rsyncd tftp  systemctl enable cobblerd httpd rsyncd tftp

用https协议去访问一下web界面看能不能正常访问:

https://你的本机IP/cobbler_web

注:默认的管理员账号都是cobbler

回到终端修改默认管理员的密码:

htdigest /etc/cobbler/users.digest "Cobbler" cobbler

设置安装系统时的ROOT密码:

openssl passwd -1 -salt 'lala.im'

编辑如下配置文件:

nano /etc/cobbler/settings

将之前生成的密码替换到:default_password_crypted,如图所示:

然后修改server/next_server为本机IP:

sed -i 's/server: 127.0.0.1/server: 本机IP/g' /etc/cobbler/settings  sed -i 's/next_server: 127.0.0.1/next_server: 本机IP/g' /etc/cobbler/settings

让Cobbler接管DHCP服务:

sed -i 's/manage_dhcp: 0/manage_dhcp: 1/g' /etc/cobbler/settings

修改debmirror的配置文件(不改也没啥事,这是装Debian系统时需要用到的)

sed -i 's/@dists="sid";/#@dists="sid";/g' /etc/debmirror.conf  sed -i 's/@arches="i386";/#@arches="i386";/g' /etc/debmirror.conf

编辑TFTP配置文件:

nano /etc/xinetd.d/tftp

更改disable为no,如图所示:

下载引导文件:

cobbler get-loaders

如图所示,如果国内机器下载慢,可以自己按照图内的链接下载到对应目录:

编辑dhcp配置文件:

nano /etc/cobbler/dhcp.template

根据自己的网络环境配置DHCP服务:

subnet 95.xxx.xxx.160 netmask 255.255.255.248 {       option routers             95.xxx.xxx.161;       option domain-name-servers 8.8.8.8;       option subnet-mask         255.255.255.248;       range dynamic-bootp        95.xxx.xxx.164 95.xxx.xxx.166;       default-lease-time         21600;       max-lease-time             43200;

重启cobbler,然后同步配置:

systemctl restart cobblerd  cobbler sync

最后检查看看有没有报错提示,有的话根据提示去修复:

cobbler check

下载ISO镜像:

挂载ISO镜像并导入到Cobbler:

mkdir /mnt/iso  mount CentOS-7-x86_64-Minimal-1810.iso /mnt/iso  cobbler import