cobbler简介
cobbler是什么?
cobbler 是基于pxe底层使用 python 编写的快速网络安装操作系统服务。
支持众多的Linux发行版:Red Hat、Fedora、CentOS、Debian、Ubuntu和SuSE,也可以支持网络安装windows。
cobbler 核心内容
1.安装树
repo +yum
2.系统镜像
3.pxe引导
vmlinuz+initrd.img
4.ks脚本
Kickstart
自动化安装=安装树 + pxe引导 +系统镜像 +ks脚本
cobbler 实现架构
1.需要 dhcpd 分发IP+引导地址
2.需要 tftp 共享pxe引导文件
3.需要 xinted 启动tftp
4.需要 apache 共享安装树
5.需要 cobbler组件 简化安装程序
实现cobbler
准备环境
0.一台centos7主机,IP为192.168.1.20,自定义nat网络模式
1.关闭防火墙与selinux
systemctl stop firewalld && systemctl disable firewalld && setenforce 0
2.清空旧 yum 源
cd /etc/yum.repos.d/
rm -rf *
3.添加 aliyun 源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
4.添加 epel 扩展源
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
5.yum 缓存
yum clean all
yum makecache
cobbler安装
1.安装cobbler组件
yum install cobbler dhcp dhcp-common tftp tftp-server xinetd syslinux pykickstart debmirror -y
2.修改cobbler基本配置
vi /etc/cobbler/settings
manage_dhcp: 0 //0人为管理DHCP,1为cobbler管理
manage_tftpd: 0
server: 192.168.1.20 //指定cobbler监听的端口
next_server: 192.168.1.20 //指定安装树地址
3.启动组件服务
systemctl start httpd
systemctl start cobblerd
4.cobbler自检并按照提示修改
cobbler check
5.按需求修改完之后重启cobbler服务
systemctl restart cobblerd.service
cobbler sync //刷新cobbler配置
此时已经在 /var/lib/tftpboot目录下生成基于pxe启动相关文件
cobbler使用
1.修改dhcp配置文件
vi /etc/dhcp/dhcpd.conf
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.120;
option routers 192.168.1.2;
option domain-name-servers 8.8.8.8;
filename "pxelinux.0";
}
2.启动dhcpd,xinetd,tftp
3.挂载光盘
mount /dev/sr0 /mnt/
4.在cobbler中导入centos7镜像
cobbler import --path=/mnt/ --name=centos7
5.导入成功后执行一次sync
cobbler sync
6.到这里就可以实现基本的自动化安装系统了,因为 DHCP分发服务做好了,tftp里的 pxe 引导文件也存在,系统镜像 在cobbler导入的时候做了一个将
系统镜像复制到 /var/www/cobbler 目录下的操作 ,所以需要安装的机器就可以通过网络访问到 需要安装的 系统镜像。
同时cobbler 有自己默认的ks脚本文件,你不去手动指定的化也能完成自动化安装。
7.新建一个虚拟机尝试安装系统 ,内存必须要2g 以上,不够会超时报错
cobbler 定制profile
1.由于生产环境中不可能用默认的安装脚本,所以需要根据要求自定义 ks 脚本来封装一个profile ,也就是系统镜像。
2.ks文件默认在家目录就有一个 anaconda-ks.cfg ,可以使用这个作为模板进行使用。
3.安装树地址在 http://192.168.1.20/cobbler/ks_mirror/centos7/
4.修改 anaconda-ks.cfg
vi anaconda-ks.cfg
增加:url --url=http://192.168.1.20/cobbler/ks_mirror/centos7/
增加:reboot
删除:network --bootproto=static --device=ens33 --gateway=192.168.1.2 --ip=192.168.1.11 --nameserver=114.114.114.114 --netmask=255.255.255.0 --ipv6=auto --activate
保存退出:wq
5.ks 文件固定在 /var/lib/cobbler/kickstarts/
6.移动 ks 文件 至 /var/lib/cobbler/kickstarts/
mv anaconda-ks.cfg /var/lib/cobbler/kickstarts/
7.创建profile
cobbler profile add --distro=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/anaconda-ks.cfg --name=profile_centos7
8.cobbler 刷新配置
cobbler sync
9.新建虚拟机测试装系统,收工。