運維自動化工具 Cobbler


from http://www.cnblogs.com/wangxiaoqiangs/p/5354846.html

簡介:

關於操作系統安裝方面的自動化,早前我們使用 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 之類的系統,可以忽略此提示。 (如需安裝,下載地址為:http://rpmfind.net/linux/rpm2html/search.php?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:[確定] 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_track running shell triggers from /var/lib/cobbler/triggers/change/* *** TASK COMPLETE *** shell > service xinetd restart 停止 xinetd: [確定] 正在啟動 xinetd: [確定] shell > service cobblerd restart Stopping 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 list
distros:
Centos-6.6-minimal-x86_64 profiles: Centos-6.6-minimal-x86_64 systems: 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 configuration firewall --disabled # Install OS instead of upgrade install # Use network installation url --url="http://192.168.214.10/cobbler/ks_mirror/Centos-6.6-minimal-x84_64/" # Root password rootpw --iscrypted $1$hk0MvN4A$Dz.sYvyDjac1.cMVTk9270 # System authorization information auth --useshadow --passalgo=sha512 # Use text mode install text # System keyboard keyboard us # System language lang zh_CN # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # Installation logging level logging --level=info # Reboot after installation reboot # System timezone timezone --isUtc Asia/Shanghai # Network information network --bootproto=dhcp --device=eth0 --onboot=on # System bootloader configuration bootloader --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part /boot --fstype="ext4" --size=200 part swap --fstype="swap" --size=1024 part / --fstype="ext4" --grow --size=1
復制代碼

## 這是我安裝了 system-config-kickstart 在圖形界面生成的 ks 文件。
## 看到第一行注釋行中有一個漢字了嗎?就是這個漢字讓我卡了兩天...( 文件中不要有漢字 )

五、關聯 ks 文件

shell > cobbler distro list
Centos-6.6-minimal-x86_64

## 有一個鏡像

復制代碼
shell > cobbler profile report --name Centos-6.6-minimal-x86_64 Name : Centos-6.6-minimal-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : Centos-6.6-minimal-x86_64 Enable gPXE? : 0 Enable PXE Menu? : 1 Fetchable Files : {} Kernel Options : {} Kernel Options (Post Install) : {} Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks Kickstart Metadata : {} Management Classes : [] Management Parameters : <<inherit>> Name Servers : [] Name Servers Search Path : [] Owners : ['admin'] Parent Profile : Proxy : Red Hat Management Key : <<inherit>> Red Hat Management Server : <<inherit>> Repos : [] Server Override : <<inherit>> Template Files : {} Virt Auto Boot : 1 Virt Bridge : xenbr0 Virt CPUs : 1 Virt Disk Driver Type : raw Virt File Size(GB) : 5 Virt Path : Virt RAM (MB) : 512 Virt 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-minimal Name : Centos-6.6-minimal TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : Centos-6.6-minimal-x86_64 Enable gPXE? : 0 Enable PXE Menu? : 1 Fetchable Files : {} Kernel Options : {} Kernel Options (Post Install) : {} Kickstart : /var/lib/cobbler/kickstarts/Centos-6.6_minimal-x86_64.ks Kickstart Metadata : {} Management Classes : [] Management Parameters : <<inherit>> Name Servers : [] Name Servers Search Path : [] Owners : ['admin'] Parent Profile : Proxy : Red Hat Management Key : <<inherit>> Red Hat Management Server : <<inherit>> Repos : [] Server Override : <<inherit>> Template Files : {} Virt Auto Boot : 1 Virt Bridge : xenbr0 Virt CPUs : 1 Virt Disk Driver Type : raw Virt File Size(GB) : 5 Virt Path : Virt RAM (MB) : 512 Virt Type : xenpv
復制代碼

## 已經關聯成功 !

復制代碼
shell > cobbler --help
usage
===== cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... [add|edit|copy|getks*|list|remove|rename|report] [options|--help] cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help] shell > cobbler profile --help usage ===== cobbler profile add cobbler profile copy cobbler profile dumpvars cobbler profile edit cobbler profile find cobbler profile getks cobbler profile list cobbler profile remove cobbler profile rename cobbler profile report
復制代碼

## 它有多種方法,添加、編輯、移除等等( 用到時,請自己琢磨 )。

shell > cobbler sync

## 同步一下配置,客戶端開機測試

## 從網絡引導進入后,會有一個選擇列表,選擇要安裝 profile ,就可以自動完成安裝。

## 修改 ks.cfg 文件后,不需要 sync 就可以直接生效!

## 如果不想關閉防火牆,那么請打開 TCP ( 69、80、25151 ) 端口。

## 遇到問題仔細觀察,ks.cfg 中一定不能有中文,注釋行也不可以!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM