1. 程式人生 > >詳解如何在Centos6和Centos7兩個版本上,執行Cobbler無人值守安裝!

詳解如何在Centos6和Centos7兩個版本上,執行Cobbler無人值守安裝!

信息 cgroup 內容 manager 外網 oar 關聯 done 足夠

Cobbler介紹:

Cobbler是一個Linux服務器快速網絡安裝的服務,而且在經過調整也可以支持網絡安裝windows。
該工具使用python開發,小巧輕便(才15k行python代碼),可以通過網絡啟動(PXE)的方式來快速安裝、重裝物理服務器和虛擬機,同時還可以管理DHCP,DNS,TFTP、RSYNC以及yum倉庫、構造系統ISO鏡像。
Cobbler可以使用命令行方式管理,也提供了基於Web的界面管理工具(cobbler-web),還提供了API接口,可以方便二次開發使用。
Cobbler是較早前的kickstart的升級版,優點是比較容易配置,還自帶web界面比較易於管理。
Cobbler內置了一個輕量級配置管理系統,但它也支持和其它配置管理系統集成,如Puppet,暫時不支持SaltStack。

Cobbler客戶端Koan支持虛擬機安裝和操作系統重新安裝,使重裝系統更便捷。

Cobbler可以幹啥:

使用Cobbler,您無需進行人工幹預即可安裝機器。Cobbler設置一個PXE引導環境(它還可以使用yaboot支持PowerPC),並 控制與安裝相關的所有方面,比如網絡引導服務(DHCP和TFTP)與存儲庫鏡像。當希望安裝一臺新機器時,Cobbler可以:
1)使用一個以前定義的模板來配置DHCP服務(如果啟用了管理DHCP)
2)將一個存儲庫(yum或rsync)建立鏡像或解壓縮一個媒介,以註冊一個新操作系統
3)在DHCP配置文件中為需要安裝的機器創建一個條目,並使用指定的參數(IP和MAC)

4)在TFTP服務目錄下創建適當的PXE文件
5)重新啟動DHCP服務來反應新的更改
6)重新啟動機器以開始安裝(如果電源管理已啟動)

Cobbler支持的系統和功能:

Cobbler支持眾多的發行版:RedHat、Fedora、CentOS、Debian、Ubuntu和SUSE。當添加一個操作系統(通常通過使用ISO文件)時,Cobbler知道如何解壓縮合適的文件並調整網絡服務,以正確引導機器。

Cobbler可以使用kickstart模板。基於Red Hat或 Fedora的系統使用kickstart文件來自動化安裝流程。通過使用模板,就會擁有基本的kickstart模板,然後定義如何針對一種配置文件或 機器配置而替換其中的變量。

例如,一個模板可能包含兩個變量$domain和$machine_name.在Cobbler配置中,一個配置文件指定 domain=mydomain.com,並且每臺使用該配置文件的機器在machine_name變量中指定其名稱。該配置文件的所有機器都使用相同的 kickstart安裝且針對domain=mydomain.com進行配置,但每臺機器擁有其自己的機器名稱。您仍然可以使用kickstart模板 在不同的域中安裝其他機器並使用不同的機器名稱。

為了協助管理系統,Cobbler可通過fence scripts連接到各個電源管理環境。Cobbler支持apc_snmp、bladecenter、bullpap、drac、 ether_wake、ilo、integrity、ipmilan、ipmitool、lpar、rsa、virsh和wti。要重新安裝一臺機器,可 運行reboot system foo命令,而且Cobbler會使用必要的 和信息來為您運行恰當的fence scripts(比如機器插槽數)。

除了這些特性,還可以使用一個配置管理系統(CMS)。你有兩種選擇:該工具內的一個內部系統,或者現成的外部CMS,比如Chef或 Puppet。借助內部系統,你可以指定文件模板,這些模板會依據配置參數進行處理(與kickstart模板的處理方式一樣),然後復制到你指定的位 置。如果必須自動將配置文件部署到特定機器,那麽此功能很有用
使用koan客戶端,Cobbler可從客戶端配置虛擬機並重新安裝系統。

主要目的配置網絡接口:
Cobbler的配置結構基於一組註冊的對象。每個對象表示一個與另一個實體相關聯的實體(該對象指向另一個對象,或者另一個對象指向該對象)。當一個對象指向另一個對象時,它就繼承了被指向對象的數據,並可覆蓋或添加更多特定信息。以下對象類型的定義
Distros(發行版):表示一個操作系統,它承載了內核和initrd的信息,以及內核參數等其他數據
Profile(配置文件):包含一個發行版、一個kickstart文件以及可能的存儲庫,還包含更多特定的內核參數等其他數據
Systems(系統):表示要配給的額機器。它包含一個配置文件或一個景象,還包含IP和MAC地址、電源管理(地址、憑據、類型)、(網卡綁定、設置valn等)
Repository(鏡像):保存一個yum或rsync存儲庫的鏡像信息
Image(存儲庫):可替換一個包含不屬於此類比的額文件的發行版對象(例如,無法分為內核和initrd的對象)。
基於註冊的對象以及各個對象之間的關聯,Cobbler知道如何更改文件系統以反應具體配置。因為系統配置的內部是抽象的,所以您可以僅關註想要執行的操作。

1、基礎環境準備

centos6系列:

[root@cobbler ~]# cat /etc/redhat-release    #系統版本               
CentOS release 6.5 (Final)
[root@cobbler ~]# uname -r    #內核版本
2.6.32-431.el6.x86_64
[root@cobbler ~]# getenforce    #檢測selinux是否關閉(必須關閉)                          
Disabled
[root@cobbler ~]# /etc/init.d/iptables status    #檢測防火墻是否關閉(必須關閉)
iptables: Firewall is not running.
[root@cobbler ~]# ifconfig eth0|awk -F ‘[ :]+‘ ‘NR==2 {print $4}‘    #查看IP地址
10.0.0.71
[root@cobbler ~]# hostname    #查看主機名
cobbler
[root@cobbler ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
--2016-05-23 21:10:51--  http://mirrors.aliyun.com/repo/epel-6.repo
Resolving mirrors.aliyun.com... 115.28.122.210, 112.124.140.210
Connecting to mirrors.aliyun.com|115.28.122.210|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1083 (1.1K) [application/octet-stream]
Saving to: “/etc/yum.repos.d/epel.repo”    #cobbler安裝必須使用到epel源

100%[====================================================================================>] 1,083       --.-K/s   in 0s

centos7系列:

[root@cobbler02 ~]# cat /etc/redhat-release     #系統版本
CentOS Linux release 7.2.1511 (Core) 
[root@cobbler02 ~]# uname -r                #內核版本
3.10.0-327.18.2.el7.x86_64
[root@cobbler02 ~]# getenforce              #檢測selinux是否關閉(必須關閉)
Disabled
[root@cobbler02 ~]# systemctl status firewalld    #檢測防火墻是否關閉(必須關閉)
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
[root@cobbler02 ~]# ifconfig eth0|awk -F ‘[ :]+‘ ‘NR==2{print $3}‘
192.168.31.73 
[root@cobbler02 ~]# hostname
cobbler02  
[root@cobbler02 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
--2016-05-30 07:55:52--  http://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 112.124.140.210, 115.28.122.210
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|112.124.140.210|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1084 (1.1K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel.repo’

100%[===============================================================================================>] 1,084       --.-K/s   in 0s      

2016-05-30 07:55:52 (270 MB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [1084/1084]

註意:
虛擬機網卡采用橋接模式,不使用NAT模式,我們會搭建DHCP服務器,在同一局域網多個DHCP服務會有沖突,所以最好把路由器的DHCP服務關閉t_0015.gif我搭建服務只喜歡用橋接模式

2.安裝Cobbler

centos6系列:

[root@cobbler ~]# yum install cobbler cobbler-web pykickstart httpd dhcp tftp-server-y
cobbler            #cobbler程序包
cobbler-web        #cobbler的web服務包
pykickstart        #cobbler檢查kickstart語法錯誤
httpd              #Apache web服務
dhcp               #dhcp服務
tftp-server        #tftp服務

[root@cobbler ~]# 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日誌

centos7系列:

[root@cobbler02 ~]# yum install cobbler cobbler-web pykickstart httpd dhcp tftp-server -y
cobbler            #cobbler程序包
cobbler-web        #cobbler的web服務包
pykickstart        #cobbler檢查kickstart語法錯誤
httpd              #Apache web服務
dhcp               #dhcp服務
tftp-server        #tftp服務
3. 檢測Cobbler

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

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

centos6系列:

[root@cobbler cobbler]# /etc/init.d/httpd restart    #啟動apache服務
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: apr_sockaddr_info_get() failed for cobbler
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
#遇見報錯需要修改apache的配置文件,添加一行
[root@cobbler cobbler]# vim /etc/httpd/conf/httpd.conf  
ServerName localhost:80  
#再重啟服務發現沒有報錯了
[root@cobbler cobbler]# /etc/init.d/httpd restart      
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]                                                        [  OK  ]

[root@cobbler cobbler]# /etc/init.d/cobblerd restart    #啟動cobbler服務
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:

centos7系列:

[root@cobbler02 ~]# systemctl start httpd
[root@cobbler02 ~]# systemctl status httpd    #查看httpd的狀態,看有沒有起來
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2016-05-30 08:06:08 CST; 9s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 2317 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─2317 /usr/sbin/httpd -DFOREGROUND
           ├─2318 (wsgi:cobbler_w -DFOREGROUND
           ├─2319 /usr/sbin/httpd -DFOREGROUND
           ├─2320 /usr/sbin/httpd -DFOREGROUND
           ├─2321 /usr/sbin/httpd -DFOREGROUND
           ├─2322 /usr/sbin/httpd -DFOREGROUND
           └─2323 /usr/sbin/httpd -DFOREGROUND

May 30 08:06:08 cobbler02 systemd[1]: Starting The Apache HTTP Server...
May 30 08:06:08 cobbler02 httpd[2317]: AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, u...message
May 30 08:06:08 cobbler02 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@cobbler02 ~]# systemctl status cobblerd    #查看cobblerd的狀態,看有沒有起來
● cobblerd.service - Cobbler Helper Daemon
   Loaded: loaded (/usr/lib/systemd/system/cobblerd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@cobbler02 ~]# systemctl start cobblerd #開啟cobblerd服務
[root@cobbler02 ~]# systemctl status cobblerd    #再檢查一下,發現確實起來了
● cobblerd.service - Cobbler Helper Daemon
   Loaded: loaded (/usr/lib/systemd/system/cobblerd.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2016-05-30 08:06:39 CST; 1s ago
  Process: 2349 ExecStartPost=/usr/bin/touch /usr/share/cobbler/web/cobbler.wsgi (code=exited, status=0/SUCCESS)
 Main PID: 2348 (cobblerd)
   CGroup: /system.slice/cobblerd.service
           └─2348 /usr/bin/python2 /usr/bin/cobblerd -F

May 30 08:06:39 cobbler02 systemd[1]: Starting Cobbler Helper Daemon...
May 30 08:06:39 cobbler02 systemd[1]: Started Cobbler Helper Daemon.
4、檢查配置文件,需要在cobblerd和httpd啟動的情況下檢查

centos6系列:

[root@cobbler cobbler]# cobbler check    #檢查cobbler配置存在的問題,逐一解決
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 : 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.

5 : change ‘disable‘ to ‘no‘ in /etc/xinetd.d/rsync

6 : file /etc/xinetd.d/rsync does not exist

7 : debmirror package is not installed, it will be required to manage debian deployments and repositories

8 : 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

9 : 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地址或主機名

如server: 192.168.31.71;
#備份原文件
[root@cobbler cobbler]# cp /etc/cobbler/settings{,.ori} 
# server,Cobbler服務器的IP,修改384行server: 127.0.0.1
[root@cobbler cobbler]# sed -i ‘s/server: 127.0.0.1/server: 192.168.31.71/‘ /etc/cobbler/settings

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

如next_server: 192.168.31.71;
# server,pxe服務器的IP,由於這裏使用的是同一臺機器,所以填Cobbler服務器的IP,修改272行next_server: 127.0.0.1

[root@cobbler cobbler]# sed -i ‘s/next_server: 127.0.0.1/next_server: 192.168.31.71/‘ /etc/cobbler/settings
#由於sed的匹配規則的原因,上一步就已經把這裏給修改了,檢查下
[root@cobbler cobbler]# grep "server: 192.168.31.71" settings
next_server: 192.168.31.71
server: 192.168.31.71

3、修改/etc/xinetd.d/tftp文件中的disable參數修改為 disable = no

#備份原文件
[root@cobbler cobbler]# cp /etc/xinetd.d/tftp{,.ori}
#修改替換
[root@cobbler cobbler]# sed -i ‘s/disable.*= yes/disable                 = no/g‘ /etc/xinetd.d/tftp

4、執行 cobbler get-loaders 命令即可;否則,需要安裝syslinux程序包,而後復制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目錄中

[root@cobbler cobbler]# cobbler get-loaders
task started: 2016-05-23_230908_get_loaders
task started (id=Download Bootloader Content, time=Mon May 23 23:09:08 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

5、修改rsync配置文件

[root@cobbler xinetd.d]# sed -i s/"disable.*= yes"/"disable         = no"/g /etc/xinetd.d/rsync 
[root@cobbler xinetd.d]# cat /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it #       allows crc checksumming etc.
service rsync
{
        disable         = no
        flags           = IPv6
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        log_on_failure  += USERID
}

6、安裝debmirror

[root@cobbler cobbler]# yum install -y  debmirror
#安裝後再check下會報如下錯誤
3 : comment out ‘dists‘ on /etc/debmirror.conf for proper debian support4 : comment out ‘arches‘ on /etc/debmirror.conf for proper debian support
#修改配置文件來征服報錯,其實不礙事,但是報錯有礙眼睛,遂除之
[root@cobbler cobbler]# vim /etc/debmirror.conf
 28 #@dists="sid"; 30 #@arches="i386";
 註釋掉這兩行,重新check後沒有報錯了

7、生成密碼來取代默認的密碼,更安全

#try: "openssl passwd -1 -salt ‘random-phrase-here‘ ‘your-password-here‘" to generate new one
#根據提示your-password-here,這裏是自己的密碼,random-phrase-here,這裏是隨機的幹擾碼
[root@cobbler cobbler]# openssl passwd -1 -salt ‘renjunjie‘ ‘123456‘
$1$renjunji$G7LpR5255qFguHrw7E0KP/
[root@cobbler cobbler]# sed -i s/‘default_password_crypted:.*‘/‘default_password_crypted: "$1$renjunji$G7LpR5255qFguHrw7E0KP\/"‘/g /etc/cobbler/settings
[root@cobbler cobbler]# grep -n default_pass /etc/cobbler/settings
101:default_password_crypted: "$1$renjunji$G7LpR5255qFguHrw7E0KP/"

8、安裝cman fence-agents

[root@cobbler cobbler]# yum install -y cman ence-agents

9、其他一些沒有提示報錯的小修改

# 用cobbler管理DHCP,修改242行manage_dhcp: 0
[root@cobbler cobbler]# sed -i ‘s/manage_dhcp: 0/manage_dhcp: 1/g‘ /etc/cobbler/settings
# 防止循環裝系統,適用於服務器第一啟動項是PXE啟動,修改292行pxe_just_once: 0
[root@cobbler cobbler]# sed -i ‘s/pxe_just_once: 0/pxe_just_once: 1/‘ /etc/cobbler/settings

修改完後重啟服務再進行一次檢測,發現剩下這兩個報錯,請往下走

[root@cobbler cobbler]# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@cobbler cobbler]# /etc/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]
[root@cobbler cobbler]# /etc/init.d/cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]
[root@cobbler cobbler]# check
checkmodule  checkpolicy  
[root@cobbler 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

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

centos7系列:

[root@cobbler02 ~]# cobbler check    #檢查cobbler配置存在的問題,逐一解決
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 : 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.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
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地址或主機名

如server: 192.168.31.73;

#備份原文件
[root@cobbler02 ~]# cp /etc/cobbler/settings{,.ori}
# server,Cobbler服務器的IP,修改384行server: 127.0.0.1
[root@cobbler02 ~]# sed -i ‘s/server: 127.0.0.1/server: 192.168.31.73/‘ /etc/cobbler/settings

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

如next_server: 192.168.31.73;
# server,pxe服務器的IP,由於這裏使用的是同一臺機器,所以填Cobbler服務器的IP,修改272行next_server: 127.0.0.1

[root@cobbler02 ~]# sed -i ‘s/next_server: 127.0.0.1/next_server: 192.168.31.73/‘ /etc/cobbler/settings
#由於sed的匹配規則的原因,上一步就已經把這裏給修改了,檢查下
[root@cobbler02 ~]# grep "server: 192.168.31.73" settings
next_server: 192.168.31.713
server: 192.168.31.73

3、修改/etc/xinetd.d/tftp文件中的disable參數修改為 disable = no

#備份原文件
[root@cobbler02 ~]# cp /etc/xinetd.d/tftp{,.ori}
#修改替換
[root@cobbler02 ~r]# sed -i ‘s/disable.*= yes/disable                 = no/g‘ /etc/xinetd.d/tftp

4、執行 cobbler get-loaders 命令即可;否則,需要安裝syslinux程序包,而後復制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目錄中

[root@cobbler02 ~]# cobbler get-loaders
task started: 2016-05-30_082337_get_loaders
task started (id=Download Bootloader Content, time=Mon May 30 08:23:37 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 ***

5、啟動rsyncd服務

[root@cobbler02 ~]# systemctl status rsyncd    #檢查rsyncd服務的狀態,發現是關閉的
● rsyncd.service - fast remote file copy program daemon
   Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@cobbler02 ~]# systemctl enable rsyncd    #開啟rsync的服務開機自啟動
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[root@cobbler02 ~]# systemctl status rsyncd    #檢查rsyncd服務的狀態
● rsyncd.service - fast remote file copy program daemon
   Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
[root@cobbler02 ~]# systemctl start rsyncd     #開啟rsync的服務
[root@cobbler02 ~]# systemctl status rsyncd    #再次檢查rsyncd服務的狀態
● rsyncd.service - fast remote file copy program daemon
   Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2016-05-30 08:27:12 CST; 3s ago
 Main PID: 2455 (rsync)
   CGroup: /system.slice/rsyncd.service
           └─2455 /usr/bin/rsync --daemon --no-detach

May 30 08:27:12 cobbler02 systemd[1]: Started fast remote file copy program daemon.
May 30 08:27:12 cobbler02 systemd[1]: Starting fast remote file copy program daemon...
May 30 08:27:12 cobbler02 rsyncd[2455]: rsyncd version 3.0.9 starting, listening on port 873

6、安裝debmirror

[root@cobbler02 ~]# yum install debmirror
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
No package debmirror available.
Error: Nothing to do 
#這個是提供給debian的管理用的,centos7我沒有這個包

7、生成密碼來取代默認的密碼,更安全

#try: "openssl passwd -1 -salt ‘random-phrase-here‘ ‘your-password-here‘" to generate new one
#根據提示your-password-here,這裏是自己的密碼,random-phrase-here,這裏是隨機的幹擾碼
[root@cobbler02 ~]# openssl passwd -1 -salt ‘renjunjie‘ ‘123456‘
$1$renjunji$G7LpR5255qFguHrw7E0KP/
[root@cobbler02 ~]# sed -i s/‘default_password_crypted:.*‘/‘default_password_crypted: "$1$renjunji$G7LpR5255qFguHrw7E0KP\/"‘/g /etc/cobbler/settings 
[root@cobbler02 ~]# grep -n default_pass /etc/cobbler/settings
101:default_password_crypted: "$1$renjunji$G7LpR5255qFguHrw7E0KP/"

8、安裝cman fence-agents

[root@cobbler02 ~]# yum install -y cman fence-agents

9、其他一些沒有提示報錯的小修改

# 用cobbler管理DHCP,修改242行manage_dhcp: 0
[root@cobbler02 ~]# sed -i ‘s/manage_dhcp: 0/manage_dhcp: 1/g‘ /etc/cobbler/settings
[root@cobbler02 ~]# grep -n manage_dhcp /etc/cobbler/settings
242:manage_dhcp: 1
269:# if using cobbler with manage_dhcp, put the IP address
355:# Note that if manage_dhcp and manage_dns are disabled, the respective
# 防止循環裝系統,適用於服務器第一啟動項是PXE啟動,修改292行pxe_just_once: 0
[root@cobbler02 ~]# sed -i ‘s/pxe_just_once: 0/pxe_just_once: 1/‘ /etc/cobbler/settings
[root@cobbler02 ~]# grep -n pxe_just_once /etc/cobbler/settings
292:pxe_just_once: 1
[root@cobbler02 ~]#
#修改完後重啟服務再進行一次檢測,發現這個報錯,請往下走
[root@cobbler02 ~]# systemctl restart cobblerd.service
[root@cobbler02 ~]# cobbler check                     
The following are potential configuration items that you may want to fix:

1 : debmirror package is not installed, it will be required to manage debian deployments and repositories

Restart cobblerd and then run ‘cobbler sync‘ to apply changes.
[root@cobbler02 ~]# yum install -y debmirror    #再次安裝centos7就是沒得,求適用於centos7的rpm包或者適用於centos7的編譯源碼包
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
No package debmirror available.
Error: Nothing to do
5、配置DHCP

centos6系列:

# 修改cobbler的dhcp模版,這個模板會覆蓋dhcp本身的配置文件。
[root@linux-node1 ~]# vim /etc/cobbler/dhcp.template
#添加如下
subnet 192.168.31.0 netmask 255.255.255.0 {  
option domain-name-servers 223.5.5.5; 
option routers 192.168.31.1;     
range dynamic-bootp 192.168.31.100 192.168.31.250;
option subnet-mask 255.255.255.0;
next-server 192.168.31.71;
filename "/data/sys/kickstart/ks.cfg";
next-server 192.168.31.71;
filename "pxelinux.0";
}
#同步cobbler的配置,可以看到同步幹了哪些事
[root@cobbler cobbler]# cobbler sync
task started: 2016-05-27_145749_sync
task started (id=Sync, time=Fri May 27 14:57:49 2016)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
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 images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
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@cobbler cobbler]# cobbler check
The following are potential configuration items that you may want to fix:

1 : file /etc/xinetd.d/rsync does not exist

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

centos7系列:

# 修改cobbler的dhcp模版,這個模板會覆蓋dhcp本身的配置文件。
[root@cobbler02 ~]# vim /etc/cobbler/dhcp.template
#添加如下
subnet 192.168.31.0 netmask 255.255.255.0 {
option domain-name-servers 223.5.5.5;
option routers 192.168.31.1;
range dynamic-bootp 192.168.31.100 192.168.31.250;
option subnet-mask 255.255.255.0;
next-server $next_server;
default-lease-time 43200;
max-lease-time 86400;
}
#同步cobbler的配置,可以看到同步幹了哪些事
[root@cobbler02 ~]# cobbler sync                  
task started: 2016-05-30_092640_sync
task started (id=Sync, time=Mon May 30 09:26:40 2016)
running pre-sync triggers
cleaning trees
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/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 images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
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: 
received on stderr: Redirecting to /bin/systemctl restart  dhcpd.service

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 ***
6、設置開機自啟動

centos6系列:

方法1:全部寫到rc.local

[root@cobbler cobbler]# echo "/etc/init.d/httpd restart" >>/etc/rc.local 
[root@cobbler cobbler]# echo "/etc/init.d/xinetd restart" >>/etc/rc.local      
[root@cobbler cobbler]# echo "/etc/init.d/cobblerd restart" >>/etc/rc.local       
[root@cobbler cobbler]# echo "/etc/init.d/dhcpd restart" >>/etc/rc.local

方法2:寫一個專門的cobbler開機腳本

cat >>/etc/init.d/cobbler<<EOF
#!/bin/bash
# chkconfig: 345 80 90
# description:cobbler
case \$1 in
 start)
   /etc/init.d/httpd start
   /etc/init.d/xinetd start
   /etc/init.d/dhcpd start
   /etc/init.d/cobblerd start
   ;;
 stop)
   /etc/init.d/httpd stop
   /etc/init.d/xinetd stop
   /etc/init.d/dhcpd stop
   /etc/init.d/cobblerd stop
   ;;
 restart)
   /etc/init.d/httpd restart
   /etc/init.d/xinetd restart
   /etc/init.d/dhcpd restart
   /etc/init.d/cobblerd restart
   ;;
 status)
   /etc/init.d/httpd status
   /etc/init.d/xinetd status
   /etc/init.d/dhcpd status
   /etc/init.d/cobblerd status
   ;;
 sync)
   cobbler sync
   ;;
 *)
   echo "Input error,please in put ‘start|stop|restart|status|sync‘!"
   exit 2
   ;;
esac
EOF

centos7系列:

#設置開機自動啟動,避免白辛苦一場
[root@cobbler02 multi-user.target.wants]# systemctl enable dhcpd.service
[root@cobbler02 multi-user.target.wants]# systemctl enable rsyncd.service
[root@cobbler02 multi-user.target.wants]# systemctl enable tftp.service 
[root@cobbler02 multi-user.target.wants]# systemctl enable httpd.service 
[root@cobbler02 multi-user.target.wants]# systemctl enable cobblerd.service
#將所有的服務重啟一遍,避免有服務忘了開啟
[root@cobbler02 multi-user.target.wants]# systemctl restart dhcpd.service
[root@cobbler02 multi-user.target.wants]# systemctl restart rsyncd.service
[root@cobbler02 multi-user.target.wants]# systemctl restart tftp.service 
[root@cobbler02 multi-user.target.wants]# systemctl restart httpd.service 
[root@cobbler02 multi-user.target.wants]# systemctl restart cobblerd.service
7、Cobbler的命令行管理(6和7的命令是一致的)
[root@cobbler ~]# cobbler
usage
=====
cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... 
        [add|edit|copy|getks*|list|remove|rename|report] [options|--help]
cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help]
cobbler check    核對當前設置是否有問題
cobbler list     列出所有的cobbler元素cobbler 
report               列出元素的詳細信息
cobbler sync     同步配置到數據目錄,更改配置最好都要執行下
cobbler reposync    同步yum倉庫
cobbler distro   查看導入的發行版系統信息
cobbler system   查看添加的系統信息cobbler 
profile  查看配置信息
8、導入鏡像
#掛載centos光盤鏡像
[root@cobbler ~]# mount /dev/cdrom /mnt/
mount: block device /dev/sr0 is write-protected, mounting read-only
#導入鏡像
[root@cobbler ~]# cobbler import --path=/mnt/ --name=CentOS-6.6-x86_64 --arch=x86_64
task started: 2016-05-27_153110_import
task started (id=Media import, time=Fri May 27 15:31:10 2016)
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/CentOS-6.6-x86_64:
creating new distro: CentOS-6.6-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS-6.6-x86_64 -> /var/www/cobbler/links/CentOS-6.6-x86_64
creating new profile: CentOS-6.6-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/CentOS-6.6-x86_64 for CentOS-6.6-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS-6.6-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-6.6-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS-6.6-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-6.6-x86_64/repodata
*** TASK COMPLETE ***
# --path 鏡像路徑
# --name 為安裝源定義一個名字
# --arch 指定安裝源是32位、64位、ia64, 目前支持的選項有: x86│x86_64│ia64
# 安裝源的唯一標示就是根據name參數來定義,本例導入成功後,安裝源的唯一標示就是:CentOS-6.6-x86_64,如果重復,系統會提示導入失敗。

#查看鏡像列表
[root@cobbler ~]# cobbler distro list
   CentOS-6.6-x86_64

## 鏡像存放目錄,cobbler會將鏡像中的所有安裝文件拷貝到本地一份,放在/var/www/cobbler/ks_mirror下的CentOS-6.6-x86_64目錄下。因此/var/www/cobbler目錄必須具有足夠容納安裝文件的空間   
[root@cobbler ~]# cd /var/www/cobbler/ks_mirror/
[root@cobbler ks_mirror]# ls
CentOS-6.6-x86_64  config
[root@cobbler ks_mirror]# ls CentOS-6.6-x86_64/
CentOS_BuildTag  EULA  images    Packages                  repodata              RPM-GPG-KEY-CentOS-Debug-6     RPM-GPG-KEY-CentOS-Testing-6
EFI              GPL   isolinux  RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-6  RPM-GPG-KEY-CentOS-Security-6  TRANS.TBL
9、配置ks.cfg(使用centos7的鏡像的時候,註意下方的ks.cfg要在安裝包那裏刪除掉@server-policy,這玩意在7沒有)
[root@cobbler ks_mirror]# cd /var/lib/cobbler/kickstarts/
[root@cobbler kickstarts]# ls
default.ks    esxi5-ks.cfg      legacy.ks     sample_autoyast.xml  sample_esx4.ks   sample_esxi5.ks  sample_old.seed
esxi4-ks.cfg  install_profiles  pxerescue.ks  sample_end.ks(默認使用的ks文件)
        sample_esxi4.ks  sample.ks        sample.seed
[root@cobbler kickstarts]# vim CentOS-6.6-x86_64.cfg
#修改成以下內容
[root@cobbler kickstarts]# cat CentOS-6.6-x86_64.cfg 
# kickstart template for Fedora 8 and later.
# (includes %end blocks)
# do not use with earlier distros

#platform=x86, AMD64, or Intel EM64T
# System authorization information
#auth  --useshadow  --enablemd5
authconfig --enableshadow --passalgo=sha512
# System bootloader configuration
bootloader --location=mbr --driveorder=sda --append="nomodeset crashkernel=auto rhgb quiet"
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET(‘network_config‘)
# Reboot after installation
reboot
logging --level=info

#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone  Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
#autopart
part /boot --fstype=ext4 --asprimary --size=200
part swap --asprimary --size=1024
part / --fstype=ext4 --grow --asprimary --size=200

%pre
$SNIPPET(‘log_ks_pre‘)
$SNIPPET(‘kickstart_start‘)
$SNIPPET(‘pre_install_network_config‘)
# Enable installation monitoring
$SNIPPET(‘pre_anamon‘)
%end

%packages
@base
@compat-libraries
@core
@debugging
@development
@dial-up
@hardware-monitoring
@performance
@server-policy
sgpio
device-mapper-persistent-data
systemtap-client
tree
lrzsz
telnet
nmap
dos2unix
%end

%post --nochroot
$SNIPPET(‘log_ks_post_nochroot‘)
%end

%post
$SNIPPET(‘log_ks_post‘)
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET(‘post_install_kernel_options‘)
$SNIPPET(‘post_install_network_config‘)
$SNIPPET(‘func_register_if_enabled‘)
$SNIPPET(‘download_config_files‘)
$SNIPPET(‘koan_environment‘)
$SNIPPET(‘redhat_register‘)
$SNIPPET(‘cobbler_register‘)
# Enable post-install boot notification
$SNIPPET(‘post_anamon‘)
# Start final steps
$SNIPPET(‘kickstart_done‘)
# End final steps
%end

在第一次導入系統鏡像後,Cobbler會給鏡像指定一個默認的kickstart自動安裝文件在/var/lib/cobbler/kickstarts下的sample_end.ks

[root@cobbler kickstarts]# cobbler list
distros:
   CentOS-6.6-x86_64

profiles:
   CentOS-6.6-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files

:

查看安裝鏡像文件信息

[root@cobbler kickstarts]# cobbler distro report --name=CentOS-6.6-x86_64
Name                           : CentOS-6.6-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/CentOS-6.6-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/CentOS-6.6-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {‘tree‘: ‘http://@@http_server@@/cblr/links/CentOS-6.6-x86_64‘}
Management Classes             : []
OS Version                     : rhel6
Owners                         : [‘admin‘]
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

查看所有的profile設置

cobbler profile report

查看指定的profile設置

cobbler profile report --name=CentOS-6.6-x86_64 
[root@cobbler kickstarts]# cobbler profile report
Name                           : CentOS-6.6-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : CentOS-6.6-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : [‘admin‘]
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm

編輯profile,修改關聯的ks文件

[root@cobbler kickstarts]# cobbler profile edit --name=CentOS-6.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.6-x86_64.cfg

修改安裝系統的內核參數,在CentOS7系統有一個地方變了,就是網卡名變成eno*****這種形式,但是為了運維標準化,我們需要將它變成我們常用的eth0,因此使用下面的參數。但要註意是CentOS7才需要下面的步驟,CentOS6不需要。

#下次做centos7版本的cobbler的時候再續寫

cobbler profile edit --name=CentOS-7.0-x86_64 --kopts=‘net.ifnames=0 biosdevname=0‘

#可以看到下面Kickstart那裏的配置cfg文件地址被改變了

[root@cobbler kickstarts]# cobbler profile report --name=CentOS-6.6-x86_64                                                            
Name                           : CentOS-6.6-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : CentOS-6.6-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/CentOS-6.6-x86_64.cfg
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : [‘admin‘]
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm

#同步下cobbler數據,每次修改完都要鏡像同步

[root@cobbler kickstarts]# cobbler sync
task started: 2016-05-27_162048_sync
task started (id=Sync, time=Fri May 27 16:20:48 2016)
running pre-sync triggers
cleaning trees

#修改這裏,開機畫面顯示,有問題自己去查看之前的操作文本解決

[root@cobbler kickstarts]# vim /etc/cobbler/pxe/pxedefault.template
MENU TITLE Cobbler | QQ:315420700 
[root@cobbler kickstarts]# cobbler sync # 修改配置都要同步

技術分享圖片

這裏是如果方向鍵不選擇第二項就無法裝機,不算自動化,我們需要進行手動指定才可以完全自動化

定制化安裝

kickstart實現某臺服務器使用指定ks文件可能比較復雜,但是Cobbler就很簡單了,區分一臺服務器的最簡單的方法就是物理MAC地址。

VMware查看物理MAC地址
技術分享圖片

[root@cobbler kickstarts]# cobbler system add --name=ren --mac=00:0C:29:4E:73:7F  --profile=CentOS-6.6-x86_64 --ip-address=192.168.31.120 --subnet=255.255.255.0 --gateway=192.168.31.1 --interface=eth0 --static=1 --hostname=linux_node --name-servers="223.5.5.5"

[root@cobbler kickstarts]# cobbler system list
ren
[root@cobbler kickstarts]# cobbler sync
###特此說明下
如果你有幾塊網卡的話,只自定義第二塊網卡為外網,第一塊網卡不一起配置,就會還是出現在那個選擇界面。

[root@cobbler kickstarts]# cobbler system add --name=ren --mac=00:0C:29:4E:73:7F --profile=CentOS-6.6-x86_64 --ip-address=192.168.31.120 --subnet=255.255.255.0 --gateway=192.168.31.1 --interface=eth0 --static=1 --hostname=linux_node --name-servers="223.5.5.5"
[root@cobbler kickstarts]# cobbler system list
ren
[root@cobbler kickstarts]# cobbler sync
###特此說明下
如果你有幾塊網卡的話,只自定義第二塊網卡為外網,第一塊網卡不一起配置,就會還是出現在那個選擇界面。

#補充!多網卡像這樣指定IP和網卡
[root@cobbler02 cobbler]# cobbler system add --name=zabbix02 --mac=00:0C:29:3E:E6:FF  --profile=CentOS-7.2-x86_64 --ip-address=10.0.0.82 --subnet=255.255.255.0 --interface=eth0 --static=1
[root@cobbler02 cobbler]# cobbler system edit --name=zabbix02 --mac=00:0C:29:3E:E6:09  --profile=CentOS-7.2-x86_64 --ip-address=192.168.31.82 --subnet=255.255.255.0 --gateway=192.168.31.1 --interface=eth1 --static=1 --hostname=zabbix --name-servers="223.5.5.5"

技術分享圖片

Cobbler的Web管理界面的安裝與配置
新版 Cobbler 的 Web 界面使用的是 https

登錄URL: https://192.168.31.71/cobbler_web

技術分享圖片

默認用戶名:cobbler
默認密碼 :cobbler
/etc/cobbler/users.conf # Web服務授權配置文件
/etc/cobbler/users.digest # 用於web訪問的用戶名密碼配置文件
#在Cobbler組添加ren用戶,提示輸入2遍密碼確認

[root@cobbler kickstarts]# htdigest /etc/cobbler/users.digest "Cobbler" ren
Adding user ren in realm Cobbler
New password: 
Re-type new password:

同步下

[root@cobbler kickstarts]# cobbler sync
附錄:添加repos源
1.添加repo源
#舉個例子,centos7.2版本的openstack的repo源
[root@cobbler02 ~]# cobbler repo add --name=centos7.2-openstack-mitaka --mirror=http://mirrors.aliyun.com/centos/7.2.1511/cloud/x86_64/openstack-mitaka/ --arch=x86_64 --breed=yum    
#添加repo源,舉個栗子,centos7版本的epel源
[root@cobbler02 ~]# cobbler repo add --name=centos7-x86_64-epel --mirror=http://mirrors.aliyun.com/epel/7/x86_64/ --arch=x86_64 --breed=yum
2.同步repo
[root@cobbler02 ~]# cobbler reposync
3.添加repo到對應的profile
cobbler profile edit --name=Centos-7-x86_64  --repos=
4.修改kickstart文件。添加。(些到%post %end中間)
%post
systemctl disable postfix.service

$yum_config_stanza
%end

5.添加定時任務,定期同步repo

客戶機重裝系統教程:

centos7系列:

1)不指定詳細system模板,讓cobbler自己裝一臺centos7的鏡像

#註意上面如果沒有指定epel源的是無法裝koan包的
#執行這個命令:wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@zabbix ~]# yum install -y koan
#指定cobbler的服務器
[root@zabbix ~]# koan --server=192.168.31.73 --list=profiles
- looking for Cobbler at http://192.168.31.73:80/cobbler_api
CentOS-7.2-x86_64
#指定從哪個鏡像進行安裝
[root@zabbix ~]# koan --replace-self --server=192.168.31.73 --profile=CentOS-7.2-x86_64
- looking for Cobbler at http://192.168.31.73:80/cobbler_api
- reading URL: http://192.168.31.73/cblr/svc/op/ks/profile/CentOS-7.2-x86_64
install_tree: http://192.168.31.73/cblr/links/CentOS-7.2-x86_64
downloading initrd initrd.img to /boot/initrd.img_koan
url=http://192.168.31.73/cobbler/images/CentOS-7.2-x86_64/initrd.img
- reading URL: http://192.168.31.73/cobbler/images/CentOS-7.2-x86_64/initrd.img
downloading kernel vmlinuz to /boot/vmlinuz_koan
url=http://192.168.31.73/cobbler/images/CentOS-7.2-x86_64/vmlinuz
- reading URL: http://192.168.31.73/cobbler/images/CentOS-7.2-x86_64/vmlinuz
- [‘/sbin/grubby‘, ‘--add-kernel‘, ‘/boot/vmlinuz_koan‘, ‘--initrd‘, ‘/boot/initrd.img_koan‘, ‘--args‘, ‘"ksdevice=link lang= text net.ifnames=0 ks=http://192.168.31.73/cblr/svc/op/ks/profile/CentOS-7.2-x86_64 biosdevname=0 kssendmac "‘, ‘--copy-default‘, ‘--make-default‘, ‘--title=kick1464687061‘]
- [‘/sbin/grubby‘, ‘--update-kernel‘, ‘/boot/vmlinuz_koan‘, ‘--remove-args=root‘]
- reboot to apply changes
#重啟系統
[root@zabbix ~]# reboot

2)指定設定好的系統配置,讓系統生成一個指定的mac地址綁定的ip和其他你指定的東西

[root@zabbix ~]# yum install -y koan
#指定cobbler的服務器選擇system模板
[root@MiWiFi-R2D-srv ~]# koan --server=192.168.31.73 --list=system
- looking for Cobbler at http://192.168.31.73:80/cobbler_api
koan does not know how
[root@MiWiFi-R2D-srv ~]# koan --replace-self --server=192.168.31.73 --system=zabbix02
- looking for Cobbler at http://192.168.31.73:80/cobbler_api
- reading URL: http://192.168.31.73/cblr/svc/op/ks/system/zabbix02
install_tree: http://192.168.31.73/cblr/links/CentOS-7.2-x86_64
downloading initrd initrd.img to /boot/initrd.img_koan
url=http://192.168.31.73/cobbler/images/CentOS-7.2-x86_64/initrd.img
- reading URL: http://192.168.31.73/cobbler/images/CentOS-7.2-x86_64/initrd.img
downloading kernel vmlinuz to /boot/vmlinuz_koan
url=http://192.168.31.73/cobbler/images/CentOS-7.2-x86_64/vmlinuz
- reading URL: http://192.168.31.73/cobbler/images/CentOS-7.2-x86_64/vmlinuz
- [‘/sbin/grubby‘, ‘--add-kernel‘, ‘/boot/vmlinuz_koan‘, ‘--initrd‘, ‘/boot/initrd.img_koan‘, ‘--args‘, ‘"ksdevice=link lang= text net.ifnames=0 ks=http://192.168.31.73/cblr/svc/op/ks/system/zabbix02 biosdevname=0 kssendmac "‘, ‘--copy-default‘, ‘--make-default‘, ‘--title=kick1464688081‘]
- [‘/sbin/grubby‘, ‘--update-kernel‘, ‘/boot/vmlinuz_koan‘, ‘--remove-args=root‘]
- reboot to apply changes to list that
[root@MiWiFi-R2D-srv ~]# reboot

技術分享圖片技術分享圖片

技術分享圖片

配置就是這樣,前路漫漫,多學多練!

詳解如何在Centos6和Centos7兩個版本上,執行Cobbler無人值守安裝!