Cobbler自動化批量部署CentOS6.5系統

Cobbler做爲一個預備工具,使批量部署Red Hat/Centos/Fedora系統更容易,同時也支持Suse和Debian系統的部署。html

它提供如下服務集成:python

  * PXE服務支持
  * DHCP服務管理
  * DNS服務管理
  * Kickstart服務支持
  * yum倉庫管理
Cobbler客戶端Koan支持虛擬機安裝和操做系統從新安裝功能.linux

1、cobbler安裝準備ios

  系統:CentOS6.5 64位
  IP地址:192.168.132.128git

1.關閉selinuxgithub

[root@localhost ~]#vim /etc/selinux/config
#SELINUX=enforcing            #註釋掉
#SELINUXTYPE=targeted      #註釋掉
SELINUX=disabled                 #增長

:wq!  #保存退出
[root@localhost ~]#setenforce 0 	 #使配置當即生效
[root@localhost ~]#sestatus		 #重啓後查看         

2.關閉iptablesweb

[root@localhost ~]#chkconfig iptables off
[root@localhost ~]#/etc/init.d/iptables stop

3.下載epel源的rpm安裝包並安裝cobbler軟件shell

[root@localhost ~]#wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@localhost ~]#rpm -ivh epel-release-6-8.noarch.rpm
[root@localhost ~]#yum -y install cobbler cobbler-web httpd rsync tftp-server xinetd dhcp python-ctypes debmirror pykickstart fence-agents cman

[root@localhost ~]# /etc/init.d/cobblerd start
Starting cobbler daemon:                                   [  OK  ]
[root@localhost ~]# /etc/init.d/httpd start
Starting httpd: 																					 [  OK  ]
[root@localhost ~]# 

4.檢查配置執行:vim

[root@localhost ~]# 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 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)
  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'">

報錯了
通過網上查找這樣解決以下:centos

[root@localhost ~]# /etc/init.d/cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]
[root@localhost ~]# 
[root@localhost ~]# cobbler get-loaders
task started: 2016-04-07_020452_get_loaders
task started (id=Download Bootloader Content, time=Thu Apr  7 02:04:52 2016)
downloading http://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading http://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading http://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading http://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading http://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading http://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading http://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading http://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading http://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading http://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***

再次檢查配置:

[root@localhost ~]# 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 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : change 'disable' to 'no' in /etc/xinetd.d/rsync
5 : file /etc/xinetd.d/rsync does not exist
6 : comment out 'dists' on /etc/debmirror.conf for proper debian support
7 : comment out 'arches' on /etc/debmirror.conf for proper debian support
8 : ksvalidator was not found, install pykickstart
9 : 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

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

根據cobbler check 檢測所的信息,進行相應配置:

1.配置tftp-server與rsync 設置rsync和tftp服務開機啓動.

編輯/etc/cobbler/settings文件,找到 server選項,修改成適當的ip地址,本實例配置ip爲:192.168.132.128

sed -i 's@manage_dhcp: 0@manage_dhcp: 1@g' /etc/cobbler/settings
sed -i 's@next_server: 127.0.0.1@next_server: '192.168.132.128'@g' /etc/cobbler/settings
sed -i 's@server: 127.0.0.1@server: '192.168.132.128'@g' /etc/cobbler/settings

2.配置tftp-server與rsync.

sed -i 's/disable.*$/disable = no/g' /etc/xinetd.d/tftp
sed -i 's/disable.*$/disable = no/g' /etc/xinetd.d/rsync

3.提示說debmirror沒安裝。若是不是安裝 debian之類的系統,此提示能夠忽略。

4.安裝pykickstart.

[root@localhost ~]# yum install pykickstart -y

5.生成密碼串(設置默認 root 用戶的密碼):

[root@localhost ~]# openssl passwd -1 -salt 'random-phrase-here' 'saneri'
$1$random-p$3a6Zq0MlL6NuutFGzwxGJ.
而後將結果替換 /etc/cobbler/settings 文件中的
default_password_crypted:

根據提示基本配置完成了,OK再來執行檢查.

[root@localhost cobbler]# /etc/init.d/cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]

[root@localhost cobbler]# cobbler check
The following are potential configuration items that you may want to fix:

1 : service dhcpd is not running
2 : file /etc/xinetd.d/rsync does not exist
3 : comment out 'dists' on /etc/debmirror.conf for proper debian support
4 : comment out 'arches' on /etc/debmirror.conf for proper debian support

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

配置dhcp服務 

修改/etc/cobbler/dhcp.template,此文件是cobbler管理dhcp的模板和/etc/dhcp/dhcpd.conf文件,兩個配置內容同樣
cat > /etc/cobbler/dhcp.template <<EOF

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

option pxe-system-type code 93 = unsigned integer 16;

subnet 192.168.132.0 netmask 255.255.255.0 {         #設置網段
		 option routers 192.168.132.1;        #設置網關
		 option subnet-mask      255.255.255.0;   #子網掩碼
     range dynamic-bootp 192.168.132.30 192.168.132.35;    #動態IP範圍
     option domain-name-servers 8.8.8.8,8.8.4.4;   #DNS地址
     default-lease-time 43200;             #缺省租約時間
		 max-lease-time 86400;        #最大租約時間
		 log-facility local7;         #
		 filename="pxelinux.0";
		 next-server $next-server;      #指定引導服務器
}		

EOF

從新啓動相關服務

[root@localhost cobbler]# /etc/init.d/dhcpd restart
Starting dhcpd:                                            [  OK  ]

[root@localhost dhcp]# /etc/init.d/cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]

[root@localhost dhcp]# /etc/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]

同步配置模板

[root@localhost dhcp]# cobbler sync										#同步配置模板
task started: 2016-04-07_052540_sync
task started (id=Sync, time=Thu Apr  7 05:25:40 2016)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/CentOS6.5-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/images/CentOS6.5-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
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 files for distro: CentOS6.5-x86_64
trying hardlink /var/www/cobbler/ks_mirror/CentOS6.5-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/CentOS6.5-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/CentOS6.5-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/CentOS6.5-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: CentOS6.5-x86_64
trying hardlink /var/www/cobbler/ks_mirror/CentOS6.5-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/CentOS6.5-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/CentOS6.5-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/CentOS6.5-x86_64/initrd.img
Writing template files for CentOS6.5-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: CentOS6.5-x86_64
cleaning link caches
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: Starting dhcpd: [  OK  ]

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 ***

掛載系統鏡像並導入鏡像:

[root@localhost ~]#mkdir /mnt/ios/
[root@localhost ~]#mount -t iso9660 -o loop /dev/cdrom /mnt/ios/
[root@localhost ~]#cobbler import --path=/mnt/ios --name=CentOS6.5 --arch=x86_64

#命令格式:cobbler import --path=鏡像路徑 -- name=安裝引導名 --arch=32位或64位

查看導入源庫列表:

[root@localhost dhcp]# cobbler distro list 
   CentOS6.5-x86_64
################################################  至此cobbler已經能夠使用了################################################

Cobbler經常使用命令詳解:

cobbler check     #檢查cobbler配置(主要用於檢查cobbler配置是否有錯.)
cobbler sync       #同步配置到dhcp/pxe和數據目錄(注,同步cobbler配置到數據目錄中,更改某些配置後得執行一下,同步一下配置)
cobbler list         #列出全部的cobbler元素
cobbler import    #導入安裝的系統鏡像
cobbler report        #列出各元素的詳細信息
cobbler distro         #查看導入的發行版系統信息
cobbler profile        #查看配置信息
cobbler system       #查看添加的系統信息
cobbler reposync     #同步yum倉庫到本地   

cobbler profile remove --name=CentOS6.5x86_64-x86_64                    #移除profile
cobbler distro remove --name=CentOS6.5x86_64-x86_64			      #移除distro
 
cobbler profile report --name  CentOS6.5-x86_64 				 #查看profile設置
cobbler profile report --name  CentOS6.5-x86_64					 #查看安裝鏡像文件信息
 
cobbler profile add --name=centos-6.5-x86_64 --distro=centos-6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos-6.5-x86_64.ks    #添加

.

.

參閱文檔:http://www.osyunwei.com/archives/7606.html

       http://blog.oldboyedu.com/autoinstall-cobbler/

相關文章
相關標籤/搜索