cobbler簡介
node
使用PXE批量部署時,有一個缺陷,即只能安裝單一的操做系統(同一個版本,僅用一個kickstart文件)。可是在實際環境中,不一樣功能的服務器須要部署不一樣的環境,而cobbler正好知足了這一需求。cobbler基於python開發,是對PXE的二次封裝,且提供了CLI和Web的管理形式,使得操做和管理更加簡便。cobbler的實現與PXE相似,也須要tftp,httpd,dhcp這些服務。使用yum便可完成cobbler的安裝,在安裝的同時也會自動安裝tftp和httpd服務,dhcp服務須要自行安裝。python
cobbler的部署很是簡單,首先添加distro,或直接導入光盤鏡像,而後爲某一個distro添加kickstart文件,一個distro可有多個kickstart文件,以實現同一版本的操做系統部署多個不同的環境。mysql
實現過程linux
實驗環境:全部的服務均部署在同一臺服務器上(192.168.3.10)web
安裝cobbler
sql
[root@node1 ~]# yum install cobbler
這個過程會自動安裝tftp,httpd。vim
自行安裝dhcp。
centos
[root@node1 ~]# yum install dhcp
tftp,httpd,dhcp,還包括DNS這些服務均可以由cobbler代爲管理,也能夠獨立管理。這裏都將這些服務設置爲單獨管理。瀏覽器
[root@node1 ~]# vim /etc/cobbler/settings manage_dhcp: 0 manage_dns: 0 ..... manage_tftpd: 0 manage_rsync: 0
配置dhcp服務緩存
[root@node1 ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf [root@node1 ~]# vim /etc/dhcp/dhcpd.conf ...... ...... subnet 192.168.3.0 netmask 255.255.255.0 { range 192.168.3.10 192.168.3.254; option routers 192.168.3.1; option broadcast-address 192.168.3.31; default-lease-time 3600; max-lease-time 7200; next-server 192.168.3.10; #指向pxe服務器 filename "pxelinux.0"; }
檢查配置,啓動服務:
[root@node1 ~]# service dhcpd configtest Syntax: OK [root@node1 ~]# service dhcpd start Starting dhcpd: [ OK ] [root@node1 ~]# ss -tunl | grep 67 udp UNCONN 0 0 *:67 *:*
啓動tftp和rsync
[root@node1 ~]# chkconfig tftp on [root@node1 ~]# chkconfig rsync on [root@node1 ~]# service xinetd start [root@node1 ~]# ss -tunl | grep 69 udp UNCONN 0 0 *:69 *:*
啓動cobbler服務
在啓動cobbler以前首先須要啓動httpd服務。
[root@node1 ~]# service httpd start [root@node1 ~]# service cobblerd start
而後使用cobbler check檢查cobbler的運行環境,第一次運行可能會存在以下錯誤():
[root@node1 ~]# 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 : 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)設置server參數爲cobbler服務器的IP地址 # vim /etc/cobbler/settings # server: 192.168.3.10 2)設置next_server爲pxe服務器的IP地址 # vim /etc/cobbler/settings # next_server: 192.168.3.10 3)若僅爲x86/x86_64架構的服務器提供服務,安裝syslinux便可 # yum install syslinux 4)這一項能夠忽略 5)安裝ksvalidator # yum install -y pykickstart 6)爲default_password_crypted參數設置新密碼 # openssl passwd -1 -salt `openssl rand -hex 6` # default_password_crypted: "passwd" 7)install cman or fence-agents(可不裝)
修改完成後,重啓服務:
[root@node1 ~]# cobbler sync [root@node1 ~]# service cobblerd restart
添加distro
掛載光盤鏡像
[root@node3 ~]# mount /dev/cdrom /mnt/flash/
添加一個distro(如有光盤鏡像,推薦直接導入光盤鏡像)
[root@node1 ~]# cobbler import --name=centos-6.5-x86_64 --path=/mnt/flash/ [root@node1 ~]# cobbler distro list centos-6.5-x86_64
若鏡像文件很大,導入過程會很長。導入完成後,在/var/www/cobbler/ks_mirror目錄下會生成一個--name指定的名稱的目錄,這個目錄與掛載在本地的光盤鏡像目錄一致。
製做kickstart文件
kickstart文件的製做很是簡單。
首先安裝system-config-kickstart。
[root@node1 ~]# yum install system-config-kickstart
執行system-config-kickstart啓用圖形界面進行配置(使用xmanager之類的鏈接程序)
[root@node1 ~]# system-config-kickstart
配置的過程與安裝操做系統差很少,按照提示一個一個配置便可。在配置以前須要先掛載光盤鏡像,而且將該光盤鏡像做爲本地的yum源,在Package Selection這一項即會顯示該光盤鏡像中可安裝的軟件包。
若配置的是其餘版本操做系統的ks文件,將對應的光盤鏡像文件做爲本地的yum源便可,例如須要爲centOS7製做ks文件。
換成centOS7的ISO文件。
在/etc/yum.repos.d目錄下添加本地的repo文件,清理以前的緩存,而後掛載。
[root@CentOS-6 ~]# yum clean all Loaded plugins: fastestmirror, security Cleaning repos: Cleaning up Everything Cleaning up list of fastest mirrors [root@CentOS-6 ~]# mount /dev/cdrom /mnt/flash/ mount: block device /dev/sr0 is write-protected, mounting read-only ############################
Package Selection即爲centOS7鏡像光盤上的軟件包。須要注意的是system-config-kickstart不支持LVM,若須要添加LVM還須要在ks文件中手動進行修改。
爲distro添加profile
即爲某個distro提供kickstart文件來生成一個特定的系統安裝配置。例如爲剛纔添加的distro( centos-6.5-x86_64)添加一個kickstart文件。
首先驗證ks文件是否存在語法錯誤,而後複製到指定目錄下添加:
[root@node1 ~]# ksvalidator ks.cfg [root@node1 ~]# cp /root/ks.cfg /var/lib/cobbler/kickstarts/ [root@node1 ~]# cobbler profile add --name=centos-6.5-base --distro=centos-6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks.cfg #####添加第二個profile [root@node1 ~]# cp /root/ks-mysql.cfg /var/lib/cobbler/kickstarts/ [root@node1 ~]# cobbler profile add --name=centos-6.5-mysql --distro=centos-6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks-mysql.cfg
list查看添加的profile:
[root@node1 kickstarts]# cobbler profile list centos-6.5-base centos-6.5-mysql centos-6.5-x86_64
添加完成以後執行cobbler sync,而後就可使用了。
[root@node3 ~]# cobbler sync
測試過程
新添加一臺虛擬機,不安裝操做系統。
選擇須要的版本,開始安裝
cobbler的部署已實現.................^_^
cobbler_web的使用
cobbler_web是經過web界面對cobbler進行管理,在web界面便可實現distro、profile等的添加刪除。下面簡單介紹一下cobbler_web的部署。
安裝cobbler_web
[root@node1 ~]# yum install cobbler-web -y
配置cobbler_web的認證功能
cobbler_web支持多種認證方式,如authn_configfile、authn_ldap或authn_pam等,這裏使用authn_pam模塊實現認證。
[root@node1 ~]# vim /etc/cobbler/modules.conf [authentication] module = authn_pam
添加系統用戶:
[root@node1 ~]# useradd baby [root@node1 ~]# echo "baby" | passwd --stdin baby Changing password for user baby. passwd: all authentication tokens updated successfully.
添加該系統用戶至/etc/cobbler/users.conf文件
[root@node1 ~]# vim /etc/cobbler/users.conf [admins] admin = "baby"
配置完成重啓cobbler服務:
[root@node1 ~]# service cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ]
使用瀏覽器訪問http://192.168.3.10/cobbler_web
登陸,導入centOS7光盤鏡像
正在導入
添加完成後,list查看:
[root@node1 ~]# cobbler distro list centos-6.5-x86_64 centos-7-x86_64
添加profile:
點「save」完成添加。
添加完成。
測試
添加一臺虛擬機,啓動
已經開始安裝
測試完成.................^_^