系統自動化安裝部署工具——cobbler

本節我們來講一講系統自動化安裝工具,大家應該還記得我在在前面的內容中曾經有講過一個跟這個類似的PXE安裝環境,而本節我們要講的這個cobbler其實就是PEX的加強版,那麼下面我們就來學習下如何部署安裝吧。

 

cobbler的介紹

cobbler是一個部署和創建系統的工具,他的主要功能就是通過一些自動化的操作來簡化系統管理員的操作,他也可以使虛擬化操作變的簡化;其組成部分主要包括cobbler和cobbler_web兩部分。

 

cobbler所依賴的服務

想要組件一個cobbler環境,還得有以下幾個服務

?TFTP (在安裝cobbler時會自動裝上一個)      
?rsync(一般系統自帶,只需設置開機啓動)      
?DHCP(可以單獨安裝,也可以使用dnsmasq包安裝,該包同時安裝了DHCP以及DNS)      
?DNS(這個其實也可以不用)

 

cobbler框架

clipboard

大多數情況不需要system,只需要distribution,repository,profile

 

cobbler的命令

clipboard[8]

 

cobbler的安裝配置

注意:cobbler由epel源提供,因此安裝之前必須配置好yum源

需要安裝的包有:cobbler  pykickstart   debmirror

[root@www ~]# yum install cobbler

可以看到安裝過程中tftp也會自動安裝

clipboard[10]

 

安裝完成之後可以看到在下面路徑下會產生cobbler目錄

[root@www ~]#ls /var/www/    
cgi-bin  cobbler  error  html  icons

可以使用tree命令看下這個目錄

[root@www ~]# tree /var/www/cobbler

image

 

啓動服務

[root@www ~]# service httpd start

[root@www ~]# service cobblerd start

啓動cobblerd後監聽在25151

clipboard[12]

 

檢查存在的問題

root@www ~]# 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 : some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.    
4 : change 'disable' to 'no' in /etc/xinetd.d/rsync    
5 : comment 'dists' on /etc/debmirror.conf for proper debian support    
6 : comment 'arches' on /etc/debmirror.conf for proper debian support    
7 : 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    
8 : 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參數的值爲提供cobbler服務的主機相應的IP地址或主機名;        
2、修改/etc/cobbler/settings文件中的next_server參數的值爲提供PXE服務的主機相應的IP地址;        
3、如果當前節點可以訪問互聯網,執行“cobbler get-loaders”命令即可;否則,需要安裝syslinux程序包,而後複製/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目錄中;        
4、執行“chkconfig rsync on”命令即可;        
5、註釋/etc/debmirror.conf文件中的“@dists="sid";”一行;        
6、註釋/etc/debmirror.conf文件中的“@arches="i386";”一行;        
7、執行“openssl passwd -1 -salt $(openssl rand -hex 4)”生成密碼,並用其替換/etc/cobbler/settings文件中default_password_crypted參數的值;        
8、執行“yum install cman fence-agents”命令安裝相應的程序包即可;

接着重啓cobblerd,而後執行“cobbler sync”同步新的配置至cobbler。

 

由於有些問題是可以忽略的,因此我們這裏就給出了其中一些步驟

修改配置文件/etc/cobbler/settings

[root@www ~]# vim /etc/cobbler/settings

     server參數

     image

     next_server參數

     image

     default_password_crypted參數

     image

     密碼生成命令:openssl passwd -1 -salt 'openssl rand -hex 4'

安裝syslinux包以及複製相應文件

由於syslinux以及安裝所有這裏我只需複製相應文件即可,是否安裝的查看命令

[root@www ~]# yum list syslinux    
Loaded plugins: fastestmirror, refresh-packagekit, security    
Loading mirror speeds from cached hostfile    
Installed Packages    
syslinux.x86_64                                                                                4.02-8.el6                                                                                 @base

[root@www ~]#  cd /usr/share/syslinux/

[root@www syslinux]# ls    
altmbr.bin    cmd.c32        dmitest.c32   gptmbr.bin    hdt.c32      int18.com       isohdppx_c.bin      linux.c32  mbr_c.bin    menu.c32      pxechain.com  sdi.c32         vesainfo.c32    
altmbr_c.bin  config.c32     dosutil       gptmbr_c.bin  host.c32     isohdpfx.bin    isohdppx_f.bin      ls.c32     mbr_f.bin    pcitest.c32   pxelinux.0    sysdump.c32     vesamenu.c32    
altmbr_f.bin  cpuid.c32      elf.c32       gptmbr_f.bin  ifcpu64.c32  isohdpfx_c.bin  isolinux.bin        lua.c32    memdisk      pmload.c32    reboot.c32    syslinux64.exe  vpdtest.c32    
cat.c32       cpuidtest.c32  ethersel.c32  gpxecmd.c32   ifcpu.c32    isohdpfx_f.bin  isolinux-debug.bin  mboot.c32  memdump.com  poweroff.com  rosh.c32      syslinux.com    whichsys.c32    
chain.c32     disk.c32       gfxboot.c32   gpxelinux.0   ifplop.c32   isohdppx.bin    kbdmap.c32          mbr.bin    meminfo.c32  pwd.c32       sanboot.c32   syslinux.exe

[root@www syslinux]# cp -r * /var/lib/cobbler/loaders/                      複製文件

 

開機啓動rsync

[root@www ~]#chkconfig rsync on

ok,其他幾項暫時忽略,重啓服務並同步

[root@www syslinux]# service cobblerd restart    
Stopping cobbler daemon:                                   [  OK  ]    
Starting cobbler daemon:                                   [  OK  ]

[root@www syslinux]# cobbler sync

image

配置及啓動cobbler所依賴的各服務

cobbler的運行依賴於dhcp、tftp、rsync及dns服務。其中dhcp可由dhcpd(isc)提供,也可由dnsmasq提供;tftp可由tftp-server程序包提供,也可由cobbler自帶的tftp功能提供;rsync由rsync程序包提供;dns可由bind提供,也可由dnsmasq提供。

安裝配置dhcp

這裏直接使用yum單獨安裝

[root@www ~]# yum install dhcp

安裝好之後可以看下生成的文件

[root@www syslinux]# rpm -ql dhcp

image

其中/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample是一個配置示例,可以複製過來

[root@www syslinux]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

 

 

 

修改配置文件

[root@www syslinux]# vim  /etc/dhcp/dhcpd.conf

image

# dhcpd.conf    
#    
# Sample configuration file for ISC dhcpd    
#

# option definitions common to all supported networks...    
option domain-name "mwj.com";    
option domain-name-servers 172.16.6.20;

default-lease-time 600;    
max-lease-time 7200;    

log-facility local7;


subnet 172.16.0.0 netmask 255.255.0.0 {    
    range 172.16.6.100 172.16.6.120;             # dhcp給定的地址段    
    option routers 172.16.6.20;                      # 路由器地址    
}

next-server 172.16.6.20;                              # 指向tftp    
filename="pxelinux.0";

 

配置好之後啓動服務

[root@www ~]# service dhcpd start

Starting dhcpd:                                            [  OK  ]

dhcp監聽在udp67號端口

[root@www syslinux]# ss -unl|grep 67    
UNCONN     0      0                         *:67                       *:* 

配置tftp服務

這裏只須直接啓動xinetd守護進程即可

[root@www ~]# chkconfig tftp on                       開機啓動    
[root@www ~]# service xinetd start                 啓動下xinetd

tftp監聽在udp69好端口

[root@www ~]# ss -unl|grep 69    
UNCONN     0      0                         *:69                       *:*

配置cobbler

配置distro

這裏我們使用cobbler import命令導入

來看下這個命令的使用格式

[root@www ~]# cobbler import --help

Usage: cobbler [options]

Options:    
  -h, –help                   show this help message and exit    
  --arch=ARCH             OS architecture being imported    
  --breed=BREED         the breed being imported    
  --os-version=OS_VERSION    
                                  the version being imported    
  --path=PATH             local path or rsync location    
  --name=NAME           name, ex 'RHEL-5'    
  --available-as=AVAILABLE_AS    
                                  tree is here, don't mirror    
  --kickstart=KICKSTART_FILE    
                                  assign this kickstart file    
  --rsync-flags=RSYNC_FLAGS    
                                  pass additional flags to rsync

這裏的導入前提是光盤已經掛載

[root@www ~]# cobbler import --name=centos-6.5-x86_64 --path=/media/cdrom                  後面的路徑是光盤掛載的路徑

創建的過程就是將光盤中的文件複製到這個目錄下的過程,可能會比較慢需要等部件長的時間

image

創建好之後路徑是在下面路徑中

image

查看生成的distro

[root@www ks_mirror]# cobbler distro list

image

 

配置profile

我這裏已經準備好了一個kickstart文件,你也可以根據自己的anaconda文件(anaconda-ks.cfg)進行修改

[root@www tmp]# ls    
  centos6.x86_64.cfg

編輯該文件

image

  

驗證下是否有錯誤

[root@www tmp]# ksvalidator centos6.x86_64.cfg            

       沒有出現錯誤就是最好的消息

 

創建profile

[root@www tmp]# cobbler profile add --name=centos-6.5-x86_64-basic --distro=centos-6.5-x86_64 --kickstart=/tmp/centos6.x86_64.cfg

[root@www tmp]# cobbler profile list    
   centos-6.5-x86_64                                                      這個是創建distro的時候默認生成的    
   centos-6.5-x86_64-basic

 

創建好之後執行cobbler sync命令

image

 

ok,都好了之後我們就可以創建一個新的虛擬機進行測試了

image

 

 

cobbler_web

cobbler_web是一個可以配置的網絡接口,通過網絡遠程來進行配置

直接yum安裝

[root@www ~]# yum install cobbler-web

  配置支持認證功能

[root@www ~]# vim /etc/cobbler/modules.conf

image 驗證模式修改爲pam

 

先創建一個測試用戶

[root@www ~]# useradd cobadm    
[root@www ~]# passwd cobadm    
Changing password for user cobadm.    
New password:    
BAD PASSWORD: it is based on a dictionary word    
BAD PASSWORD: is too simple    
Retype new password:    
passwd: all authentication tokens updated successfully.

 

修改配置文件將用戶加進行

[root@www ~]# vim /etc/cobbler/users.conf

image

重啓服務

[root@www ~]# service cobblerd restart    
Stopping cobbler daemon:                                   [  OK  ]    
Starting cobbler daemon:                                   [  OK  ]    
[root@www ~]# service httpd restart    
Stopping httpd:                                            [  OK  ]    
Starting httpd:                                            [  OK  ]

 

然後看看是否能夠訪問了

clipboard[16]

clipboard[17]

 

 

 

 

   OK,具體的配置希望大家自己去摸索吧,這裏我就不再闡述了!

 

那麼本節的內容就講到這裏,歡迎大家的批評指正,謝謝!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章