運維工具之Cobbler

what is Cobbler?

Cobbler是一個Linux安裝服務器,可以快速設置網絡安裝環境。它粘合並可以自動化執行很多關聯的linux任務。因此,在部署新系統或在某些情況下更開現有系統時,你不必在許多不同的命令和應用程序之間跳轉。 Cobbler可以幫助配置,管理DNS和DHCP,軟件包更新,電源管理,配置管理編排等等。

Cobbler特點

Cobbler是一個Linux服務器安裝的服務,可以通過網絡啓動(PXE)的方式來快速安裝、重裝物理服務器和虛擬機,同時還可以管理DHCP,DNS等。

Cobbler可以使用命令行方式管理,也提供了基於Web的界面管理工具(cobbler-web),還提供了API接口,可以方便二次開發使用。

Cobbler是較早前的kickstart的升級版,優點是比較容易配置,還自帶web界面比較易於管理。

Cobbler內置了一個輕量級配置管理系統,但它也支持和其它配置管理系統集成,如Puppet,暫時不支持SaltStack。

Cobbler集成的服務

  • PXE服務支持

  • DHCP服務管理

  • DNS服務管理(可選bind,dnsmasq)

  • 電源管理

  • Kickstart服務支持

  • YUM倉庫管理

  • TFTP(PXE啓動時需要)

  • Apache(提供kickstart的安裝源,並提供定製化的kickstart配置)


一、Cobbler的安裝

前提:cobbler由epel源提供,故此需要事先配置指向epel的yum源方可進行類似下面的安裝過程。 可以通過以下鏈接進行下載:wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

# yum install cobbler cobbler-web pykickstart debmirror
# service httpd start
# service cobblerd start

cobbler目錄:

  1. [root@Centos ~]# rpm -ql cobbler  # 查看安裝的文件,下面列出部分。
    /etc/cobbler                  # 配置文件目錄
    /etc/cobbler/settings         # cobbler主配置文件,這個文件是YAML格式,Cobbler是python寫的程序。
    /etc/cobbler/dhcp.template    # DHCP服務的配置模板
    /etc/cobbler/tftpd.template   # tftp服務的配置模板
    /etc/cobbler/rsync.template   # rsync服務的配置模板
    /etc/cobbler/iso              # iso模板配置文件目錄
    /etc/cobbler/pxe              # pxe模板文件目錄
    /etc/cobbler/power            # 電源的配置文件目錄
    /etc/cobbler/users.conf       # Web服務授權配置文件
    /etc/cobbler/users.digest     # 用於web訪問的用戶名密碼配置文件
    /etc/cobbler/dnsmasq.template # DNS服務的配置模板
    /etc/cobbler/modules.conf     # Cobbler模塊配置文件
    /var/lib/cobbler              # Cobbler數據目錄
    /var/lib/cobbler/config       # 配置文件
    /var/lib/cobbler/kickstarts   # 默認存放kickstart文件
    /var/lib/cobbler/loaders      # 存放的各種引導程序
    /var/www/cobbler              # 系統安裝鏡像目錄
    /var/www/cobbler/ks_mirror    # 導入的系統鏡像列表
    /var/www/cobbler/images       # 導入的系統鏡像啓動文件
    /var/www/cobbler/repo_mirror  # yum源存儲目錄
    /var/log/cobbler              # 日誌目錄
    /var/log/cobbler/install.log  # 客戶端系統安裝日誌
    /var/log/cobbler/cobbler.log  # cobbler日誌

執行“cobbler check命令檢查存的問題,而後逐一按提示解決之。常見的問題如下所示:

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地址或主機名,如172.16.100.15;

2、修改/etc/cobbler/settings文件中的next_server參數的值爲提供PXE服務的主機相應的IP地址,如172.16.100.16;

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”命令安裝相應的程序包即可;

9、在安裝cobbler-web時,需要解決依賴關係。問題如下:

錯誤:Package: cobbler-web-2.6.11-1.el6.noarch (epel)
          Requires: Django >= 1.4

解決:http://cbs.centos.org/koji/buildinfo?buildID=1027下載Django14-doc-1.4.20-1.el6.noarch.rpm 並安裝。

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


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

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

cobbler可自行管理這些服務中的部分甚至是全部,但需要配置/etc/cobbler/settings文件中的“manage_dhcp”、“manage_tftpd”、“manage_rsync”和“manage_dns”分別進行定義。另外,由於每種服務都有着不同的實現方式,如若需要進行自定義,需要通過修改/etc/cobbler/modules.conf配置文件中各服務的模塊參數的值來實現。

本文采用了獨立管理的方式,即不通過cobbler來管理這些服務。

2.1 配置dhcp服務

定義好所需的“subnet”及其它參數或選項,而後啓動dhcpd守護進程即可。本示例中所用的dhcpd的配置如下所示: 

option domain-name "shine.com";
option domain-name-servers 192.168.10.254,172.16.0.1;
default-lease-time 43200;
max-lease-time 86400; 
log-facility local7;
subnet 192.168.10.0 netmask 255.255.255.0 {
    range 192.168.10.21 192.168.10.100;
    option routers 192.168.10.254;
} 
next-server 192.168.10.254;
filename="pxelinux.0";

接着使用“service dhcpd start”啓動服務即可。

2.2 配置tftp服務

# chkconfig tftp on
# service xinetd restart


三、配置cobbler

cobbler的各主要組件間的關係如下圖所示。

wKioL1dCyxTAinKaAAH0I6yzrL8642.jpg

3.1 管理distro
使cobbler變得可用的第一步爲定義distro,其可以通過爲其指定外部的安裝引導內核及ramdisk文件的方式實現。而如果已經有完整的系統安裝樹(如CentOS6的安裝鏡像)則推薦使用import直接導入的方式進行。
例如,對於已經掛載至/media/cdrom目錄的CentOS 6.5 x86_64的安裝鏡像,則可以使用類似如下命令進行導入。
# cobbler import --name=centos-6.5-x86_64 --path=/media/cdrom
可使用“cobbler distro list”列出所有的distro。
如果有kickstart文件,也可以使用“--kickstart=/path/to/kickstart_file”進行導入,因此import會自動爲導入的distro生成一個profile。
3.2 管理profile
cobbler使用profile來爲特定的需求類別提供所需要安裝配置,即在distro的基礎上通過提供kickstart文件來生成一個特定的系統安裝配置。distro的profile可以出現在PXE的引導菜單中作爲安裝的選擇之一。
因此,如果需要爲前面創建的centos-6.5-x86_64這個distro提供一個可引導安裝條目,其用到的kickstart文件爲/tmp/centos-6.5-x86_64.cfg(只提供了最基本的程序包),則可通過如下命令實現。
# cobbler profile add --name=centos-6.5-x86_64-basic --distro=centos-6.5-x86_64 --kickstart=/tmp/centos-6.5-x86_64.cfg

可使用“cobbler profile list”查看已經創建的profile。


四、使用cobbler_web
4.1 配置cobbler_web的認證功能
cobbler_web支持多種認證方式,如authn_configfile、authn_ldap或authn_pam等,默認爲authn_denyall,即拒絕所有用戶登錄。下面說明兩種能認證用戶登錄cobbler_web的方式。
4.1.1 使用authn_pam模塊認證cobbler_web用戶
首先修改modules中[authentication]段的module參數的值爲authn_pam。
接着添加系統用戶,用戶名和密碼按需設定即可,例如下面的命令所示。
# useradd cblradmin
# echo 'cblrpass' | passwd --stdin cblradmi
而後將cblradmin用戶添加至cobbler_web的admin組中。修改/etc/cobbler/users.conf文件,將cblradmin用戶名添加爲admin參數的值即可,如下所示。
[admins]
admin = "cblradmin
最後重啓cobblerd服務,通過http://YOUR_COBBLERD_IP/cobbler_web訪問即可。
4.1.2 使用authn_configfile模塊認證cobbler_web用戶
首先修改modules中[authentication]段的module參數的值爲authn_configfile。
接着創建其認證文件/etc/cobbler/users.digest,並添加所需的用戶即可。需要注意的是,添加第一個用戶時,需要爲htdigest命令使用“-c”選項,後續添加其他用戶時不能再使用;另外,cobbler_web的realm只能爲Cobbler。如下所示。
# htdigest -c /etc/cobbler/users.digest Cobbler cblradmin
最後重啓cobblerd服務,通過http://YOUR_COBBLERD_IP/cobbler_web訪問即可。


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