其他分享
首页 > 其他分享> > cobbler实现系统自动化部署

cobbler实现系统自动化部署

作者:互联网

一、Cobbler

 

1.pex的二次封装,由Python开发,提供CLI和Web管理,cobbler在epel源中,安装时需要配置epel源。

 

 

2.工作原理:

复制代码
client裸机配置了从网络启动后,开机后会广播包请求DHCP服务器(cobbler server)发送其分配
好的一个IP
DHCP服务器(cobbler server)收到请求后发送responese,包括其ip地址
client裸机拿到ip后再向cobbler server发送请求OS引导文件的请求
cobbler server告诉裸机OS引导文件的名字和TFTP server的ip和port
client裸机通过上面告知的TFTP server地址通信,下载引导文件
client裸机执行执行该引导文件,确定加载信息,选择要安装的os,期间会再向cobbler server请求
kickstart文件和os image
cobbler server发送请求的kickstart和os iamge
client裸机加载kickstart文件
client裸机接收os image,安装该os image
复制代码

3.配置文件:

复制代码
/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 #cobbler模块的配置文件
复制代码

4.数据目录:

/var/lib/cobbler/config/     #用于存放distros,system,profiles 等信息的配置文件
/var/lib/cobbler/triggers/   #用于存放用户定义的cobbler命令
/var/lib/cobbler/kickstarts/  # 默认存放kickstart文件
/var/lib/cobbler/loaders/     #存放各种引导程序

5.镜像目录

/var/log/cobbler/installing  #客户端安装日志
/var/log/cobbler/cobbler.log #cobbler日志

6.cobbler常用命令

复制代码
cobbler check 核对当前设置是否有问题

cobbler list 列出所有的cobbler元素

cobbler report 列出元素的详细信息

cobbler sync 同步配置到数据目录,更改配置最好都要执行下

cobbler reposync 同步yum仓库

cobbler distro 查看导入的发行版系统信息

cobbler system 查看添加的系统信息

cobbler profile 查看配置信息

cobbler profile report --name=xxxx 查看ks文件的详细信息
复制代码

范例:centos7基于cobbler实现系统的自动化安装

安装cobbler包和dhcp包

[root@centos7 ~]#yum -y install dhcp cobbler

因为cobbler包对httpd和tftp有依赖关系,所以顺带装了

启用httpd,tftp,dhcpd,cobblerd服务

[root@centos7 ~]# systemctl enable --now cobblerd dhcpd httpd tftp

dhcp暂时起不来,我们需要进行配置

执行cobbler check命令

复制代码
[root@centos7 ~]# 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 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
    https://github.com/cobbler/cobbler/wiki/Selinux
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
5 : Some network boot-loaders are missing from /var/lib/cobbler/loaders.  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.
6 : enable and start rsyncd.service with systemctl
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
8 : 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
9 : 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.
复制代码

找到server:/etc/cobbler/settings,并修改配置

[root@centos7 ~]# vim /etc/cobbler/settings

 

 

自己生成一个密码,并修改其文件将原密码替换

[root@centos7 ~]# openssl passwd -1 123456
$1$ggsV53Cw$XE2391b9SWl64gT1BNxO5.

 

 重启cobbler服务

[root@centos7 ~]# systemctl restart cobblerd

执行cobbler get-loaders命令下载相关文件

[root@centos7 ~]# cobbler get-loaders

如果该命令失效,则需要复制两个文件

[root@centos7 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@centos7 ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/

再执行cobbler sync

[root@centos7 ~]# cobbler sync

修改/etc/cobbler/settings

修改dhcp模板配置文件/etc/cobbler/dhcp.template

[root@centos7 ~]# vim /etc/cobbler/dhcp.template 

 

 重启cobbler服务,并同步到真正的dhcp的配置文件/etc/dhcp/dhcp.conf

[root@centos7 ~]# systemctl restart cobblerd
[root@centos7 ~]# cobbler sync

查看dhcpd服务

[root@centos7 ~]# systemctl status dhcpd

 

 现在菜单已经生成了,但是里面什么都没有

[root@centos7 ~]# tree /var/lib/tftpboot/
[root@centos7 ~]# cat /var/lib/tftpboot/pxelinux.cfg/default 

 

 彻底修改菜单名

[root@centos7 ~]# vim /etc/cobbler/pxe/pxedefault.template

 

 执行cobbler sync同步

[root@centos7 ~]# cobbler sync

 将centos7光盘导入

[root@centos7 test1]# cobbler import --name=centos-7-x86_64 --path=/mnt/test1 -- arch=x86_64

实际是将centos7安装文件拷到/var/www/cobbler中

在这个机器上再增加一个8的光盘,将其挂载,然后也将其导入

先扫描出新光盘

[root@centos7 test1]# echo '- - -'  > /sys/class/scsi_host/host0/scan;echo '- - -'  > /sys/class/scsi_host/host1/scan;echo '- - -'  > /sys/class/scsi_host/host2/scan

将其挂载

[root@centos7 test1]# mkdir /mnt/test2
[root@centos7 test1]# mount /dev/sr1 /mnt/test2
mount: /dev/sr1 is write-protected, mounting read-only

将centos8光盘导入

[root@centos7 test1]# cobbler import --name=centos-8-x86_64 --path=/mnt/test2 -- arch=x86_64

我的是8.5的有bug不能直接导,需要修改配置文件

[root@centos7 ~]#vim /var/lib/cobbler/distro_signatures.json

#修改第70行添加centos-linux

 

 重新启动cobbler服务并同步

[root@centos7 ~]# systemctl restart cobblerd
[root@centos7 ~]# cobbler sync

再次导入

[root@centos7 ~]# cobbler import --name=centos-8-x86_64 --path=/mnt/test2 -- arch=x86_64

 

 将centos7、8的应答文件备好并修改

[root@centos8 ks]# vim centos7.cfg 

[root@centos8 ks]# vim centos8.cfg 

 

 

 正常情况下我们现在就有两个菜单了

[root@centos7 ~]# cobbler distro list
   centos-7-x86_64
   centos-8-x86_64

将应答文件关联,并加至菜单

[root@centos7 ~]# cp centos* /var/lib/cobbler/kickstarts/

 

[root@centos7 ~]# cobbler profile add --name=CentOS-8_mini --distro=CentOS-8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos8.cfg
[root@centos7 ~]# cobbler profile add --name=CentOS-7_mini --distro=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg

现在我们有四个菜单

[root@centos7 ~]# cat /var/lib/tftpboot/pxelinux.cfg/default 

将系统两个菜单删掉

[root@centos7 ~]# cobbler profile remove --name=centos-8-x86_64
[root@centos7 ~]# cobbler profile remove --name=centos-7-x86_64
[root@centos7 ~]# cobbler profile list
   CentOS-7_mini
   CentOS-8_mini

大功告成!

支持UEFI安装

注意:CentOS 6 的虚拟机不支持UEFI

修改文件设置时间,默认不显示菜单

#修改模版文件
[root@cobbler-centos7 ~]#vim /etc/cobbler/pxe/efidefault.template
[root@cobbler-centos7 ~]#cat /var/lib/tftpboot/grub/efidefault
default=0
timeout=60 
$grub_menu_items
#使模版生效
[root@cobbler-centos7 ~]#cobbler sync
#验证生效
[root@cobbler-centos7 ~]#head -n 2 /var/lib/tftpboot/grub/efidefault
default=0
timeout=60

设置客户端的启动使用UEFI

 

 

 扩展:cobbler实现web功能

安装cobbler-web包

[root@centos7 ~]# yum -y install cobbler-web

重启httpd服务

[root@centos7 ~]# systemctl status httpd

 

 

修改cobbler用户名和密码

创建一个给Cobbler服务用的账号

[root@centos7 ~]# htdigest -c /etc/cobbler/users.digest Cobbler weilan

这里的-c表示重新创建,如果想加一个账号就把-c去了

查看存放账号密码的文件

[root@centos7 ~]# cat /etc/cobbler/users.digest

 

 拿新账号登录

 

 

标签:部署,centos7,etc,cobbler,自动化,var,--,root
来源: https://www.cnblogs.com/qingfeng111111/p/16306601.html