使用Cobbler無人值守安裝CentOS6.5(一)


Cobbler是一個快速網絡安裝linux的服務,而且在經過調整也可以支持網絡安裝windows。該工具使用python開發,小巧輕便(才15k行代碼),使用簡單的命令即可完成PXE網絡安裝環境的配置,同時還可以管理DHCP,DNS,以及yum包鏡像。

我用的系統是Centos6.5 64 位

配置epel  yum源

我這用阿里雲的epel

1
2
mv /etc/yum .repos.d /epel .repo /etc/yum .repos.d /epel .repo.backup
wget -O /etc/yum .repos.d /epel .repo http: //mirrors .aliyun.com /repo/epel-6 .repo

安裝cobbler需要的服務


 
1
yum install dhcp tftp rsync xinetd httpd

關閉selinux和防火牆自己做測試為了不影響就關了


 
1
2
[root@i51 upimg] # setenforce 0
[root@i51 upimg] # service  iptables stop

安裝cobbler並啟動


 
1
2
3
4
5
[root@i51 yum.repos.d] # yum install cobbler -y
[root@i51 yum.repos.d] # /etc/init.d/cobblerd start
Starting cobbler daemon:                                   [  OK  ]
[root@i51 yum.repos.d] # /etc/init.d/httpd start
Starting httpd:

檢查配置執行


 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@i51 ~] # 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'" >

報錯了

經過網上查找這樣解決如下:

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@i51 ~] # service cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]
[root@i51 ~] # cobbler get-loaders
task started: 2014-10-23_131316_get_loaders
task started ( id =Download Bootloader Content, time =Thu Oct 23 13:13:16 2014)
downloading http: //www .cobblerd.org /loaders/README to /var/lib/cobbler/loaders/README
downloading http: //www .cobblerd.org /loaders/COPYING .elilo to /var/lib/cobbler/loaders/COPYING .elilo
downloading http: //www .cobblerd.org /loaders/COPYING .yaboot to /var/lib/cobbler/loaders/COPYING .yaboot
downloading http: //www .cobblerd.org /loaders/COPYING .syslinux to /var/lib/cobbler/loaders/COPYING .syslinux
downloading http: //www .cobblerd.org /loaders/elilo-3 .8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64 .efi
downloading http: //www .cobblerd.org /loaders/yaboot-1 .3.14-12 to /var/lib/cobbler/loaders/yaboot
downloading http: //www .cobblerd.org /loaders/pxelinux .0-3.86 to /var/lib/cobbler/loaders/pxelinux .0
downloading http: //www .cobblerd.org /loaders/menu .c32-3.86 to /var/lib/cobbler/loaders/menu .c32
downloading http: //www .cobblerd.org /loaders/grub-0 .97-x86.efi to /var/lib/cobbler/loaders/grub-x86 .efi
downloading http: //www .cobblerd.org /loaders/grub-0 .97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64 .efi
*** TASK COMPLETE ***

在檢查配置

 

1
2
3
4
5
6
7
8
9
10
11
12
[root@i51 ~] # 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 /rsync
4 : debmirror package is not installed, it will be required to manage debian deployments and repositories
5 : ksvalidator was not found, install pykickstart
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.

上面這段信息大意就是:

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

2,編輯/etc/cobbler/settings文件,找到 next_server選項,修改為適當的ip地址,本實例配置ip為:192.168.1.243

3,編輯/etc/xinetd.d/rsync文件,將文件中的disable字段的配置由yes改為no

4,提示說debmirror沒安裝。如果不是安裝 debian之類的系統,此提示可以忽略,如果需要安裝,下載地址為:

http://rpmfind.net/linux/rpm2html/search.php?query=debmirror


5,ksvalidator沒有被發現,安裝pykickstart


?
1
[root@i51 ~] # yum install pykickstart


6,修改cobbler用戶的默認密碼,可以使用如下命令生成密碼,並使用生成后的密碼替換/etc/cobbler/settings中的密碼。生成密碼命令: 其中“random-phrase-here”為干擾碼

openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'

7,fencing tools為找到安裝

 
1
[root@i51 ~] # yum install fence-agents

OK再來執行檢查

 
1
2
3
4
5
6
7
8
9
[root@i51 ~] # 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 : debmirror package is not installed, it will be required to manage debian deployments and repositories
4 : 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

 
1
2
3
[root@i51 ~] # /etc/init.d/cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]

cobbler使用  導入安裝文件

總體來說,在RHT/Centos 系列版本下,Cobbler的使用上不會遇到很大問題
Cobbler 主要的作用是,把DHCP 、Kickstart 的修改都集成在一個平台下做了管理
 
Cobbler 的精華 其實是 它啟用了 Kickstart 配置模板,其中可以內嵌python代碼
這部分技術,Cobbler叫做:snippets 
在RHT/Centos 系列中,官方已經提供了不少這些代碼,基本上調用一下就可以了,而Ubuntu下就非常的痛苦,必須自己開發(這部分的配置 暫且不表,后續有專門篇幅來介紹 )
 
以下是相關配置路徑(默認安裝) :
Cobbler 配置主要位置:/var/lib/cobbler/ (實際操作和配置的目錄 )
snippets 代碼  位置:/var/lib/cobbler/snippets/
Kickstart 模板  位置 : /var/lib/cobbler/kickstarts/
安裝源鏡像       位置 : /var/www/cobbler/ks_mirror/ (把它link到apache的發布目錄,方便kickstart 工作時通過http下載安裝鏡像文件 )

導入安裝源

 准備好安裝光盤 (ISO)我的服務器上有這么多

 
1
2
3
4
5
6
7
8
9
10
[root@i51 Soft] # cd 鏡像
像[root@i51 鏡像] # ls
CentOS-5.10-x86_64-bin-DVD-1of2.iso  CentOS-6.5-x86_64-bin-DVD1.iso                       oracle_10201_for_linux32.iso
CentOS-5.10-x86_64-bin-DVD-2of2.iso  CentOS-7.0-1406-x86_64-DVD.iso                       redhat5_32
CentOS-5.5-i386-bin-DVD.iso          cn_windows_7_ultimate_with_sp1_x86_dvd_u_677486.iso  rhel-client-7.0-x86_64-dvd.iso
CentOS-6.4-i386-bin-DVD1.iso         kali-linux-1.0.9a-amd64.iso                          rhel-server-5.8-x86_64-dvd.iso
CentOS-6.4-i386-bin-DVD2.iso         Office_Professional_Plus_2013.1403512018.img         rhel-server-6.4-x86_64-dvd.iso
centOS-6.4-x86_64-bin-DVD1.iso       openfiler-2.3-x86-disc1.iso                          ubuntu-14.04-desktop-amd64.iso
像[root@i51 鏡像] # pwd
/var/ftp/pub/Soft/ 鏡像

掛載 ISO

 
1
2
[root@i51 鏡像] # mkdir /mnt/Centos6.5
像[root@i51 鏡像] # mount -o loop CentOS-6.5-x86_64-bin-DVD1.iso /mnt/Centos6.5/

導入安裝源 到Cobbler中

通過這個環節, Cobbler 會把安裝的鏡像ISO 拷貝到 源安裝鏡像目錄下: /var/www/cobbler/ks_mirror/
操作命令如下:
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@i51 鏡像] # cobbler import --path=/mnt/Centos6.5 --name=CentOS6.5 --arch=x86_64
task started: 2014-10-23_134307_import
task started ( id =Media import , time =Thu Oct 23 13:43:07 2014)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/CentOS6 .5-x86_64:
creating new distro: CentOS6.5-x86_64
trying symlink : /var/www/cobbler/ks_mirror/CentOS6 .5-x86_64 -> /var/www/cobbler/links/CentOS6 .5-x86_64
creating new profile: CentOS6.5-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/CentOS6 .5-x86_64 for CentOS6.5-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS6 .5-x86_64
need to process repo /comps : /var/www/cobbler/ks_mirror/CentOS6 .5-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS6 .5-x86_64 /repodata/ *comps*.xml
Keeping repodata as-is : /var/www/cobbler/ks_mirror/CentOS6 .5-x86_64 /repodata
*** TASK COMPLETE ***
參數說明: 
--name  為安裝源定義一個名字
--arch    指定安裝源是32位還是64位、ia64, 目前支持的選項有: x86│x86_64│ia64
注意: 這個安裝源的唯一標示 就是根據這兩個參數來定義
本例導入成功后,安裝源的唯一標示就是:centos6.3-x86_64 ,如果重復,系統會提示導入失敗
更多用法,可以查看官方文檔: man cobbler ,然后查找 import 的配置
相關管理命令:
//查看導入源庫列表
 
1
2
[root@i51 鏡像] # cobbler distro list
    CentOS6.5-x86_64

配置dhcp服務

首先修改cobbler配置,讓cobbler來管理dhcp服務,編輯文件/etc/cobbler/settings

manage_dhcp: 1

接下來修改/etc/cobbler/dhcp.template,此文件是cobbler管理dhcp的模板

本例中只需要修改如下部分

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
subnet 192.168.1.0 netmask 255.255.255.0 {
      option routers             192.168.1.1;
      option domain-name-servers 192.168.1.1;
      option subnet-mask         255.255.255.0;
      range dynamic-bootp        192.168.1.30 192.168.1.80;
      default-lease- time         21600;
      max-lease- time             43200;
      next-server                $next_server;
      class "pxeclients" {
           match if substring (option vendor-class-identifier, 0, 9) = "PXEClient" ;
           if option pxe-system- type = 00:02 {
                   filename "ia64/elilo.efi" ;
           } else if option pxe-system- type = 00:06 {
                   filename "grub/grub-x86.efi" ;
           } else if option pxe-system- type = 00:07 {
                   filename "grub/grub-x86_64.efi" ;
           } else {
                   filename "/pxelinux.0" ;
           }
      }
 
}

IP地址段根據你實際環境中的給定

其他可以不用改

重啟xinetd

 
1
2
3
[root@i51 鏡像] # /etc/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]

同步cobbler配置

cobbler sync

輸出如下

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[root@i51 鏡像]cobbler syncrt
task started: 2014-10-23_141019_sync
task started ( id =Sync, time =Thu Oct 23 14:10:19 2014)
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/grub-x86_64 .efi
removing: /var/lib/tftpboot/grub/efidefault
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 ***

cobbler會自動進行初始化工作,移除已經存在的啟動項,然后根據模板拷貝loader文件。之后再生成pxe的配置文件,生成dhcp的配置文件,最后再重啟dhcp服務。
至此,就可以使用虛擬機來測試cobbler安裝了。

OK開啟真機或者虛擬機來測試注意開啟網絡引導 網卡要開啟PXE  引導程序

測試如下

登陸后如下默認root密碼為cobbler

 

 

1
2
3
4
5
6
7
# 在要重裝的機器安裝koan 
yum install koan 
#查看cobbler服務器有哪些安裝盤 
koan --list-profiles --server=192.168.1.243 
#選擇要重裝的系統並重啟 
koan --replace-self --server=192.168.1.243 --profile=CentOS-5-4-x86-64 
reboot

轉載自:http://my.oschina.net/kcw/blog/336630


免責聲明!

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



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