Linux运维自动化工具 Cobbler

关于操作系统安装方面的自动化,早前我们使用 RedHat 推出的 Kickstart 来批量安装操作系统,近年来 RedHat 又推出一个 Cobbler

Cobbler 使用 Python 开发,小巧轻便,能够完成系统安装、甚至一些服务的管理。( 号称是补鞋匠都能学会的工具 )

Cobbler 支持命令行管理、web 界面管理、还提供了 API 接口,以便二次开法。

## 关闭 SELinux 、iptables !!!

一、支撑环境安装

shell > yum -y install epel-release ## 安装 epel 源

shell > yum -y install cobbler httpd rsync tftp-server xinetd dhcp pykickstart fence-agents

二、配置 Tftp 、Rsync

shell > vim /etc/xinetd.d/tftp

service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no ## 原为 yes
per_source = 11
cps = 100 2
flags = IPv4
}

shell > vim /etc/xinetd.d/rsync

service rsync
{
disable = no ## 原为 yes
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}

shell > vim /etc/httpd/conf

ServerName 127.0.0.1:80

## 这个东西大家都知道。

二、配置 Cobbler

shell > openssl passwd -1 -salt 'random-phrase-here' '123456'
$1$random-p$mzxQ/Sx848sXgvfwJCoZM0

## 生成 root 密码( 此密码为新安装的客户机 root 密码 )

shell > vim /etc/cobbler/settings

manage_dhcp: 1 ## 原为 0

manage_tftpd: 1

manage_rsync: 1 ## 原为 0

next_server: 192.168.214.10 ## 本机 IP

server: 192.168.214.10 ## 本机 IP

default_password_crypted: "$1$random-p$mzxQ/Sx848sXgvfwJCoZM0" ## 生成的 root 密码

三、配置 DHCP

shell > vim /etc/cobbler/dhcp.template ## 直接修改这个文件即可

subnet 192.168.214.0 netmask 255.255.255.0 {
option routers 192.168.214.2;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.214.100 192.168.214.120;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;

## 只修改这个区域的 IP 为合适的 IP 即可

shell > chkconfig --add httpd
shell > chkconfig --add xinetd
shell > chkconfig --add dhcpd
shell > chkconfig --add cobblerd
shell > service httpd start
正在启动 httpd:
shell > service xinetd start
正在启动 xinetd: [确定]
shell > service dhcpd start
正在启动 dhcpd: [失败]
shell > service cobblerd start
Starting cobbler daemon: [确定]

shell > cobbler check ## 检查配置
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 655, 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)
File "/usr/lib64/python2.6/xmlrpclib.py", line 1489, in __request
verbose=self.__verbose
File "/usr/lib64/python2.6/xmlrpclib.py", line 1253, in request
return self._parse_response(h.getfile(), sock)
File "/usr/lib64/python2.6/xmlrpclib.py", line 1392, in _parse_response
return u.close()
File "/usr/lib64/python2.6/xmlrpclib.py", line 838, in close
raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 1: "<class 'cobbler.cexceptions.CX'>:'login failed'">

shell > cobbler get-loaders ( 解决方法 )

[shell > cobbler check ## 再次检查
The following are potential configuration items that you may want to fix:

1 : service dhcpd is not running
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories

Restart cobblerd and then run 'cobbler sync' to apply changes.

## 1 :提示 dhcpd 没有运行,先不管
## 2 :提示 debmirror 没有安装。如果不是安装 debian 之类的系统,可以忽略此提示。
(如需安装,下载地址为:?query=debmirror)

shell > cobbler sync ## 同步操作
task started: 2015-05-27_010456_sync
task started (id=Sync, time=Wed May 27 01:04:56 2015)
running pre-sync triggers
cleaning trees
mkdir: /var/lib/tftpboot/pxelinux.cfg
mkdir: /var/lib/tftpboot/grub
mkdir: /var/lib/tftpboot/s390x
mkdir: /var/lib/tftpboot/ppc
mkdir: /var/lib/tftpboot/etc
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
rendering Rsync files
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout:
received on stderr:
running: service dhcpd restart
received on stdout: 正在启动 dhcpd:[确定]

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/6305ad7386157ea79726f1e8f235b725.html