关于操作系统安装方面的自动化,早前我们使用 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/tftpservice tftp{socket_type = dgramprotocol = udpwait = yesuser = rootserver = /usr/sbin/in.tftpdserver_args = -s /var/lib/tftpbootdisable = no ## 原为 yesper_source = 11cps = 100 2flags = IPv4}shell > vim /etc/xinetd.d/rsyncservice rsync{disable = no ## 原为 yesflags = IPv6socket_type = streamwait = nouser = rootserver = /usr/bin/rsyncserver_args = --daemonlog_on_failure += USERID}shell > vim /etc/httpd/confServerName 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/settingsmanage_dhcp: 1 ## 原为 0manage_tftpd: 1manage_rsync: 1 ## 原为 0next_server: 192.168.214.10 ## 本机 IPserver: 192.168.214.10 ## 本机 IPdefault_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 httpdshell > chkconfig --add xinetdshell > chkconfig --add dhcpdshell > chkconfig --add cobblerdshell > service httpd start正在启动 httpd:shell > service xinetd start正在启动 xinetd: [确定]shell > service dhcpd start正在启动 dhcpd: [失败]shell > service cobblerd startStarting cobbler daemon: [确定]shell > cobbler check ## 检查配置Traceback (most recent call last):File "/usr/bin/cobbler", line 36, insys.exit(app.main())File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 655, in mainrc = cli.run(sys.argv)File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 270, in runself.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 __requestverbose=self.__verboseFile "/usr/lib64/python2.6/xmlrpclib.py", line 1253, in requestreturn self._parse_response(h.getfile(), sock)File "/usr/lib64/python2.6/xmlrpclib.py", line 1392, in _parse_responsereturn u.close()File "/usr/lib64/python2.6/xmlrpclib.py", line 838, in closeraise Fault(**self._stack[0])xmlrpclib.Fault: :'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 running2 : debmirror package is not installed, it will be required to manage debian deployments and repositoriesRestart cobblerd and then run 'cobbler sync' to apply changes.## 1 :提示 dhcpd 没有运行,先不管## 2 :提示 debmirror 没有安装。如果不是安装 debian 之类的系统,可以忽略此提示。(如需安装,下载地址为:http://rpmfind.net/linux/rpm2html/search.php?query=debmirror)shell > cobbler sync ## 同步操作task started: 2015-05-27_010456_synctask started (id=Sync, time=Wed May 27 01:04:56 2015)running pre-sync triggerscleaning treesmkdir: /var/lib/tftpboot/pxelinux.cfgmkdir: /var/lib/tftpboot/grubmkdir: /var/lib/tftpboot/s390xmkdir: /var/lib/tftpboot/ppcmkdir: /var/lib/tftpboot/etcremoving: /var/lib/tftpboot/grub/imagescopying bootloaderstrying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboottrying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efitrying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.eficopying distros to tftpbootcopying imagesgenerating PXE configuration filesgenerating PXE menu structurerendering DHCP filesgenerating /etc/dhcp/dhcpd.confrendering TFTPD filesgenerating /etc/xinetd.d/tftpcleaning link cachesrendering Rsync filesrunning post-sync triggersrunning python triggers from /var/lib/cobbler/triggers/sync/post/*running python trigger cobbler.modules.sync_post_restart_servicesrunning: dhcpd -t -qreceived on stdout:received on stderr:running: service dhcpd restartreceived on stdout: 正在启动 dhcpd:[确定]received on stderr:running shell triggers from /var/lib/cobbler/triggers/sync/post/*running python triggers from /var/lib/cobbler/triggers/change/*running python trigger cobbler.modules.scm_trackrunning shell triggers from /var/lib/cobbler/triggers/change/**** TASK COMPLETE ***shell > service xinetd restart停止 xinetd: [确定]正在启动 xinetd: [确定]shell > service cobblerd restartStopping cobbler daemon: [确定]Starting cobbler daemon: [确定]
三、导入安装源
shell > mount /dev/cdrom /mnt/shell > cobbler import --path=/mnt/ --arch=x86_64 --name=Centos-6.6-minimal
## 输出信息略(Cobbler 将镜像拷贝一份放在 /var/www/cobbler/ks_mirror/Centos-6.6-minimal-x86_64 目录下)
(同时会创建一个名为 Centos-6.6-minimal-x86_64 的发布版本及 profile 文件)shell > cobbler listdistros:Centos-6.6-minimal-x86_64profiles:Centos-6.6-minimal-x86_64systems:repos:images:mgmtclasses:packages:files:
四、创建 ks 文件
shell > vim /var/lib/cobbler/kickstarts/Centos-6.6_minimal-x86_64.ks# platform=x86, AMD64, 或 Intel EM64T# version=DEVEL# Firewall configurationfirewall --disabled# Install OS instead of upgradeinstall# Use network installationurl --url="http://192.168.214.10/cobbler/ks_mirror/Centos-6.6-minimal-x84_64/"# Root passwordrootpw --iscrypted $1$hk0MvN4A$Dz.sYvyDjac1.cMVTk9270# System authorization informationauth --useshadow --passalgo=sha512# Use text mode installtext# System keyboardkeyboard us# System languagelang zh_CN# SELinux configurationselinux --disabled# Do not configure the X Window Systemskipx# Installation logging levellogging --level=info# Reboot after installationreboot# System timezonetimezone --isUtc Asia/Shanghai# Network informationnetwork --bootproto=dhcp --device=eth0 --onboot=on# System bootloader configurationbootloader --location=mbr# Clear the Master Boot Recordzerombr# Partition clearing informationclearpart --all --initlabel# Disk partitioning informationpart /boot --fstype="ext4" --size=200part swap --fstype="swap" --size=1024part / --fstype="ext4" --grow --size=1
## 这是我安装了 system-config-kickstart 在图形界面生成的 ks 文件。
## 看到第一行注释行中有一个汉字了吗?就是这个汉字让我卡了两天...( 文件中不要有汉字 )五、关联 ks 文件
shell > cobbler distro listCentos-6.6-minimal-x86_64
## 有一个镜像
shell > cobbler profile report --name Centos-6.6-minimal-x86_64Name : Centos-6.6-minimal-x86_64TFTP Boot Files : {}Comment :DHCP Tag : defaultDistribution : Centos-6.6-minimal-x86_64Enable gPXE? : 0Enable PXE Menu? : 1Fetchable Files : {}Kernel Options : {}Kernel Options (Post Install) : {}Kickstart : /var/lib/cobbler/kickstarts/sample_end.ksKickstart Metadata : {}Management Classes : []Management Parameters : <>Name Servers : []Name Servers Search Path : []Owners : ['admin']Parent Profile :Proxy :Red Hat Management Key : < >Red Hat Management Server : < >Repos : []Server Override : < >Template Files : {}Virt Auto Boot : 1Virt Bridge : xenbr0Virt CPUs : 1Virt Disk Driver Type : rawVirt File Size(GB) : 5Virt Path :Virt RAM (MB) : 512Virt Type : kvm
## 看到这个镜像默认使用的 ks 文件为 /var/lib/cobbler/kickstarts/sample_end.ks
shell > cobbler profile add --name=Centos-6.6-minimal --distro=Centos-6.6-minimal-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos-6.6_minimal-x86_64.ks
## 关联后,再次查看是否关联成功
shell > cobbler profile report --name Centos-6.6-minimalName : Centos-6.6-minimalTFTP Boot Files : {}Comment :DHCP Tag : defaultDistribution : Centos-6.6-minimal-x86_64Enable gPXE? : 0Enable PXE Menu? : 1Fetchable Files : {}Kernel Options : {}Kernel Options (Post Install) : {}Kickstart : /var/lib/cobbler/kickstarts/Centos-6.6_minimal-x86_64.ksKickstart Metadata : {}Management Classes : []Management Parameters : <>Name Servers : []Name Servers Search Path : []Owners : ['admin']Parent Profile :Proxy :Red Hat Management Key : < >Red Hat Management Server : < >Repos : []Server Override : < >Template Files : {}Virt Auto Boot : 1Virt Bridge : xenbr0Virt CPUs : 1Virt Disk Driver Type : rawVirt File Size(GB) : 5Virt Path :Virt RAM (MB) : 512Virt Type : xenpv
## 已经关联成功 !
shell > cobbler --helpusage=====cobbler...[add|edit|copy|getks*|list|remove|rename|report] [options|--help]cobbler [options|--help]shell > cobbler profile --helpusage=====cobbler profile addcobbler profile copycobbler profile dumpvarscobbler profile editcobbler profile findcobbler profile getkscobbler profile listcobbler profile removecobbler profile renamecobbler profile report
## 它有多种方法,添加、编辑、移除等等( 用到时,请自己琢磨 )。
shell > cobbler sync
## 同步一下配置,客户端开机测试
## 从网络引导进入后,会有一个选择列表,选择要安装 profile ,就可以自动完成安装。
## 修改 ks.cfg 文件后,不需要 sync 就可以直接生效!
## 如果不想关闭防火墙,那么请打开 TCP ( 69、80、25151 ) 端口。
## 遇到问题仔细观察,ks.cfg 中一定不能有中文,注释行也不可以!