一、cobbler介绍
1.cobbler概念
Cobbler是一个Linux服务器快速网络安装的服务,由python开发,小巧轻便(15k行python代码),可以通过PXE的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS,TFTP、RSYNC以及yum仓库、构造系统ISO镜像。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
2.配置目录及文件介绍
配置文件目录:
/etc/cobbler
/etc/cobbler/settings : #cobbler 主配置文件
/etc/cobbler/iso/: #iso模板配置文件
/etc/cobbler/pxe: #pxe模板文件
/etc/cobbler/power: #电源配置文件
/etc/cobbler/user.conf: #web服务授权配置文件
/etc/cobbler/users.digest: #web访问的用户名密码配置文件
/etc/cobbler/dhcp.template : #dhcp服务器的的配置末班
/etc/cobbler/dnsmasq.template : #dns服务器的配置模板
/etc/cobbler/tftpd.template : #tftp服务的配置模板
/etc/cobbler/modules.conf : #模块的配置文件
数据目录:
/var/lib/cobbler/config/: #用于存放distros,system,profiles 等信
息配置文件
/var/lib/cobbler/triggers/: #用于存放用户定义的cobbler命令
/var/lib/cobbler/kickstart/: #默认存放kickstart文件
/var/lib/cobbler/loaders/: #存放各种引导程序 镜像目录
/var/www/cobbler/ks_mirror/: #导入的发行版系统的所有数据
/var/www/cobbler/images/ : #导入发行版的kernel和initrd镜像用于
远程网络启动
/var/www/cobbler/repo_mirror/: #yum 仓库存储目录
日志目录:
/var/log/cobbler/installing: #客户端安装日志
/var/log/cobbler/cobbler.log : #cobbler日志
/etc/cobbler
/etc/cobbler/settings : #cobbler 主配置文件
/etc/cobbler/iso/: #iso模板配置文件
/etc/cobbler/pxe: #pxe模板文件
/etc/cobbler/power: #电源配置文件
/etc/cobbler/user.conf: #web服务授权配置文件
/etc/cobbler/users.digest: #web访问的用户名密码配置文件
/etc/cobbler/dhcp.template : #dhcp服务器的的配置末班
/etc/cobbler/dnsmasq.template : #dns服务器的配置模板
/etc/cobbler/tftpd.template : #tftp服务的配置模板
/etc/cobbler/modules.conf : #模块的配置文件
数据目录:
/var/lib/cobbler/config/: #用于存放distros,system,profiles 等信
息配置文件
/var/lib/cobbler/triggers/: #用于存放用户定义的cobbler命令
/var/lib/cobbler/kickstart/: #默认存放kickstart文件
/var/lib/cobbler/loaders/: #存放各种引导程序 镜像目录
/var/www/cobbler/ks_mirror/: #导入的发行版系统的所有数据
/var/www/cobbler/images/ : #导入发行版的kernel和initrd镜像用于
远程网络启动
/var/www/cobbler/repo_mirror/: #yum 仓库存储目录
日志目录:
/var/log/cobbler/installing: #客户端安装日志
/var/log/cobbler/cobbler.log : #cobbler日志
3.cobbler命令介绍
cobbler commands介绍
cobbler check #核对当前设置是否有问题
cobbler list #列出所有的cobbler元素
cobbler report #列出元素的详细信息
cobbler sync #同步配置到数据目录,更改配置最好都要执行下
cobbler reposync #同步yum仓库
cobbler distro #查看导入的发行版系统信息
cobbler system #查看添加的系统信息
cobbler profile #查看配置信息
cobbler check #核对当前设置是否有问题
cobbler list #列出所有的cobbler元素
cobbler report #列出元素的详细信息
cobbler sync #同步配置到数据目录,更改配置最好都要执行下
cobbler reposync #同步yum仓库
cobbler distro #查看导入的发行版系统信息
cobbler system #查看添加的系统信息
cobbler profile #查看配置信息
二、cobbler安装系统实践
#安装相关服务 [root@cobbler ~]# yum install -y cobbler cobbler-web dhcp tftp-server httpd python-django pykickstart [root@cobbler ~]# systemctl start httpd cobblerd.service #配置部署 [root@cobbler ~]# 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 : enable and start rsyncd.service with systemctl 6 : debmirror package is not installed, it will be required to manage debian deployments and repositories 7 : 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 8 : 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. 根据以上提示执行以下命令: #大概 390行 和 278行 更改ip为本机的ip [root@cobbler ~]# vim +390 /etc/cobbler/settings server: 172.16.1.100 [root@cobbler ~]# vim +278 /etc/cobbler/settings next_server: 172.16.1.100 #将service层disable值改为no [root@cobbler ~]# vim /etc/xinetd.d/tftp disable = no #需要相关文件 [root@cobbler ~]# cobbler get-loaders #启动rsynd并且加入开机自启动 [root@cobbler ~]# systemctl restart rsyncd [root@cobbler ~]# systemctl enable rsyncd #不能使用默认的密码用户(生成加密秘钥 并找到文件中default_password_crypted参数改为生成的秘钥) [root@cobbler ~]# openssl passwd -1 -salt 'lx' '123456' $1$lx$sDWZmB0pQ7ewwXUyiEw/41 [root@cobbler ~]# vim /etc/cobbler/settings default_password_crypted: "$1$lx$sDWZmB0pQ7ewwXUyiEw/41" #重启cobblerd并执行cobbler check [root@cobbler ~]# systemctl restart cobblerd.service [root@cobbler ~]# cobbler check The following are potential configuration items that you may want to fix: 1 : debmirror package is not installed, it will be required to manage debian deployments and repositories 2 : 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. #在文件中执行下面的vim命令 :%s#192.168#172.16#g [root@cobbler ~]# vim /etc/cobbler/dhcp.template subnet 172.16.1.0 netmask 255.255.255.0 { #option routers 172.16.1.5; #option domain-name-servers 172.16.1.1; option subnet-mask 255.255.255.0; range dynamic-bootp 172.16.1.100 172.16.1.200; #使用cobbler服务管理dhcp服务 [root@cobbler ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings #启动cobbler相关服务程序 [root@cobbler ~]# systemctl restart httpd.service rsyncd.service tftp.socket cobblerd.service #同步数据 [root@cobbler ~]# cobbler sync
三、cobbler-web页面配置
1.登录cobbler
浏览器访问:https://10.0.0.100/cobbler_web
注意:cobbler是基于https的
注意:cobbler是基于https的
2.挂载镜像及导入镜像
[root@cobbler ~]# mount /dev/cdrom /mnt mount: /dev/sr0 is write-protected, mounting read-only [root@cobbler ~]# df -h /dev/sr0 4.3G 4.3G 0 100% /mnt
Actions — DVD Importer — 进行以下配置 — run
Prefix — 定义导入镜像的名称(注意:中间不能有空格)
Arch — 定义系统镜像的架构
Breed — 指定使用系统发现版本
Path — 指定本地挂载光驱镜像的挂载点路径
Prefix — 定义导入镜像的名称(注意:中间不能有空格)
Arch — 定义系统镜像的架构
Breed — 指定使用系统发现版本
Path — 指定本地挂载光驱镜像的挂载点路径
3.rsync同步
#查看同步的进度 [root@cobbler ~]# du -sh /var/www/cobbler/ks_mirror/centos-7.6-x86_64/ 1.8G /var/www/cobbler/ks_mirror/centos-7.6-x86_64/ [root@cobbler ~]# du -sh /var/www/cobbler/ks_mirror/centos-7.6-x86_64/ 4.3G /var/www/cobbler/ks_mirror/centos-7.6-x86_64/
4.系统安装过程配置
四、批量化安装系统
[root@cobbler ~]# vim /etc/cobbler/dhcp.template subnet 10.0.0.0 netmask 255.255.255.0 { option routers 10.0.0.254; option domain-name-servers 223.5.5.5; option subnet-mask 255.255.255.0; range dynamic-bootp 10.0.0.100 10.0.0.200; default-lease-time 21600; max-lease-time 43200; next-server 10.0.0.200; } [root@cobbler ~]# systemctl restart cobblerd.service httpd.service tftp.socket [root@cobbler ~]# cobbler sync 00:50:56:35:8B:A2 00:50:56:32:9B:DF [root@cobbler ~]# cobbler system add --name=cobbler02 --mac=00:50:56:35:8B:A2 --profile=centos-7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-7.6.cfg --interface=eth0 --hostname=qls [root@cobbler ~]# cobbler system edit --name=cobbler02 --mac=00:50:56:32:9B:DF --profile=centos-7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-7.6.cfg --interface=eth1 [root@cobbler ~]# cobbler sync