cobbler系统自动安装运维工具
1.1 Cobbler简介
? ? ? ?Cobbler通过将设置和管理一个安装服务所涉及的任务集中在一起,从而简化了系统配置,相当于Cobbler封装了DHCP、TFTP、XINTED等服务,结合了PXE、kickstart等安装方法,可以实现自动化安装操作系统。
? ? ? ?Cobbler程序是python语言编写的,且提供了Cli和Web的管理形式。
1.2 Cobbler安装准备
[[email protected] ~]# cat /etc/centos-release #查看系统版本
CentOS release 6.10 (Final)
[[email protected] ~]# getenforce #关闭Selinux
Disabled
[[email protected] ~]# service iptables stop #关闭防火墙功能
[[email protected] ~]# yum -y install cobbler dhcp tftp-server pykickstart httpd #安装cobbler和依赖软件
Cobbler软件是在epel源中提供的,此处yum已配置好了搜狐fedora-epel仓库,其余dhcp、tftp、httpd等是依赖的软件,pykickstart提供检查kickstart文件语法错误的功能,这些最好一起安装上。
[[email protected] ~]# cd /etc/cobbler/ #安装完成后,生成的配置文件
[[email protected] cobbler]# ls
auth.conf iso reporting users.digest
cheetah_macros ldap rsync.exclude version
cobbler_bash modules.conf rsync.template zone.template
completions mongodb.conf secondary.template zone_templates
dhcp.template named.template settings
dnsmasq.template power tftpd.template
import_rsync_whitelist pxe users.conf
[[email protected] cobbler]# service httpd start #必须要先启动httpd服务,然后在启动cobblerd服务器,不然会报错。
Starting httpd:
[[email protected] cobbler]# service cobblerd start
Starting cobbler daemon: [ OK ]
[[email protected] cobbler]#
[[email protected] /]# cobbler check # 此处check报错,原因不明,解决方案是重启cobblerd服务,再次运行该命令即可。
Traceback (most recent call last):
File "/usr/bin/cobbler", line 36, in <module>
sys.exit(app.main())
File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 657, in main
rc = cli.run(sys.argv)
File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 270, in run
self.token = self.remote.login("", self.shared_secret)
File "/usr/lib64/python2.6/xmlrpclib.py", line 1199, in __call__
return self.__send(self.__name, args)
[[email protected] /]# service cobblerd restart # 重启cobblerd服务,继续执行check命令。
Stopping cobbler daemon: [ OK ]
Starting cobbler daemon: [ OK ]
[[email protected] /]# cobbler check
[[email protected] /]# 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 : 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.
4 : change ‘disable‘ to ‘no‘ in /etc/xinetd.d/rsync
5 : debmirror package is not installed, it will be required to manage debian deployments and repositories
6 : 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
7 : 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.
依照上述报错,修改配置文件/etc/cobbler/settings解决。
[[email protected] /]# vi /etc/cobbler/settings #修改如下字段
1. server 192.168.36.30,修改为主机对应的可用的网卡地址,localhost以外的地址。
2. next_server 192.168.36.30,修改为对应pxe服务器的ip地址。
3. 获取pxelinux.0和menu.c32文件。
4. 修改etc/xinetd.d/rsync 文件中的disable参数修改为 disable = no。
5. 注释掉/etc/debmirror.conf中相关项,可以忽略该错误,不影响。
6. 生成密码来取代默认的密码,openssl passwd -1生成的密码来取代default_password_crypted字段的值。
7. 电源管理有关,可忽略。
完成以上修改,重启cobbler,然后运行cobbler sync命令。
[[email protected] /]# service cobblerd restart
Stopping cobbler daemon: [ OK ]
Starting cobbler daemon: [ OK ]
[[email protected] /]# 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
[[email protected] /]# cobbler sync # 同步cobbler的配置。
task started: 2019-04-21_194919_sync
task started (id=Sync, time=Sun Apr 21 19:49:19 2019)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
copying bootloaders
......
至此,cobbler程序已安装完成且正常启动。
1.3 配置dhcp服务和tftp服务
[[email protected] dhcp]# cat dhcpd.conf # dchp服务配置,如果在/etc/cobbler/setting中设置了manage_dhcp:1,表示由cobbler管理dhcp,默认为0即人为手动管理,此处采用手动管理方式。
ddns-update-style none;
ignore client-updates;
subnet 192.168.36.0 netmask 255.255.255.0 {
range 192.168.36.50 192.168.36.80;
option routers 192.168.36.60;
default-lease-time 86400;
max-lease-time 259200;
filename "pxelinux.0"; #/var/lib/tftpboot/目录下的pxelinux.0文件
next-server 192.168.36.30; #tftp服务器的地址
}
[[email protected] /]# vi /etc/xinetd.d/tftp #开启tftp服务
service tftp
{
disable = no
socket_type = dgram
......
1.4 挂载系统镜像,并导入镜像。
[[email protected] /]# mount /dev/sr0 /mnt/dvd #挂载光盘
[[email protected] /]# cobbler import --path=/mnt/dvd --name=centos6.10 --arch=x86_64
等待导入完成,表示distro生成完成。
[[email protected] /]# cobbler distro list
CentOS6.10-x86_64
1.5 提供kickstart文件和profile
提供符合安装系统版本的ks文件,然后提供profile。在导入安装镜像后生成distro的过程中,Cobbler会给镜像指定一个默认的kickstart文件,自动安装文件在/var/lib/cobbler/kickstarts下的sample_end.ks。
[[email protected] kickstarts]# cobbler profile edit --name=CentOS-6.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.10-x86_64.cfg
1.6 开始自动化安装
? ? ? ?以上步骤均完成后,确认每一步的实验效果,然后开启另外一台设备进行网络启动,验证设备是否可以自动安装。
原文地址:https://blog.51cto.com/13932385/2382342
时间: 2024-10-19 00:38:33