cobbler原理知識介紹
distribution:指定發行版本,pxe隻能為一個發行版提供一個安裝場景(使用kickstart的情況下)
這是cobbler的最核心元件
定義distribution是為指明某個發行版的核心(kernel)和ramdisk檔案(initrd),進而确定是哪個版本,安裝啟動之後,能找到後面的倉庫repository,下載下傳後面要完成安裝的各個元件
通過distribution和repository定義profile,指明系統的版本,指定安裝需要的包的URL,然後,通過kickstart檔案,實作自動化安裝,每個kickstart不同,安裝的包都是不同的
注意:kickstart一變化,我們的profile就是一個新的樣式
安裝cobbler程式
[root@localhost ~]# yum install cobbler
如果是幹淨的CentOS6.5作業系統,它會自動解決依賴關系,包括syslinux,createrepo,tftp,xinetd還有一些系列的python包,因為系統自帶httpd了,httpd也是其依賴包
啟動cobbler服務,并進行初始化
[root@localhost ~]# service httpd start
[root@localhost ~]# service cobblerd start
此時安裝的cobbler還有一些問題,我們可以使用cobbler的check指令檢視,并且修改一些選項
[root@localhost ~]# 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.
#cobbler中的server不能指定localhost,要指定目前主機的IP位址
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.
#需要将next_server的位址該為網絡中的位址,而不是目前主機(127.0.0.1)
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.
#缺少啟動的選項,如果在能連接配接到網際網路的狀況下,可以使用cobbler
get-loaders解決,如果不能聯網,則可以将syslinux生成的包中的檔案拷貝過來
4 : change 'disable' to 'no' in /etc/xinetd.d/rsync
#確定rsync服務能夠啟動
5 : debmirror package is not installed, it will be required to manage
debian deployments and repositories
#在CentOS上,可以忽略這點
6 : ksvalidator was not found, install pykickstart
#關于kickstart的python包沒有安裝
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
#使用者的密碼預設是沒有加密的,要使用openssl工具加密一個字元串,然後填到配置檔案中
8 : fencing tools were not found, and are required to use the
(optional) power management features. install cman or fence-agents to use
them
#fecing工具沒有找到,要安裝cman和fence-agentbs工具包
Restart cobblerd and then run 'cobbler sync' to apply changes.
對應上面的問題,解決如下:
1、[root@localhost ~]# vim /etc/cobbler/settings
server: 192.168.81.132
2、[root@localhost ~]# vim /etc/cobbler/settings
next_server: 192.168.81.132
3、[root@localhost ~]# cp -a /usr/share/syslinux/*
/var/lib/cobbler/loaders/
4、[root@localhost ~]# chkconfig rsync on
6、[root@localhost ~]# yum install pykickstart
7、[root@localhost ~]# openssl passwd -1 -salt `openssl rand -hex 4`
Password: #輸入12345
$1$53f481cf$GTTafWaZfepR7NI966y4n.
[root@localhost ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$53f481cf$GTTafWaZfepR7NI966y4n."
8、[root@localhost ~]# yum install cman fence-agents
解決所有的問題之後,重新開機cobbler服務,再同步一下
[root@localhost ~]# service cobblerd restart
[root@localhost ~]# cobbler sync
此時,在check一次,檢視是否還有問題
下面安裝cobbler所依賴的服務
包括tftp、dns、dhcp、rsync
rsync這裡采用cobbler管理的包
dhcp我們自行安裝
[root@localhost ~]# yum install dhcp
配置dhcp服務,定義域,IP位址範圍資訊
[root@localhost ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample
/etc/dhcp/dhcpd.conf #提供配置檔案
#覆寫原來的配置檔案
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf #更改配置檔案
option domain-name "365lsy.com";
option domain-name-servers
ns.365lsy.com;
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.81.0 netmask 255.255.255.0 {
range 192.168.81.10
192.168.81.30;
option domain-name-servers ns.365lsy.com
option routers
192.168.81.132
}
next-server 192.168.81.132; #指定tftp的位址
filename "pxelinux.0";
檢查一下配置檔案,沒有問題的話,啟動dhcp服務
[root@localhost ~]# service dhcpd configtest
Syntax: OK
[root@localhost ~]# service dhcpd start
tftp服務在安裝cobbler服務時被作為依賴包已經安裝了,下面我們要啟動tftp服務
[root@localhost ~]# chkconfig tftp on
[root@localhost ~]# service xinetd
start
定義distro,其實是提供kernel和initrd的過程(可以使用distro或import指令)
使用import指令導入CD光牒鏡像檔案
[root@localhost ~]# mount /dev/cdrom /mnt/ #先挂着一個系統CD光牒
[root@localhost ~]# cobbler import --name=CentOS-6.5-x86_64
--path=/mnt/
可以在import導入時指定kickstart檔案,但是,此處不指定,在profile中指定
導入的時候,會在httpd的目錄下生成我們定義的distro
[root@localhost ~]# ls
/var/www/cobbler/ks_mirror/
CentOS-6.5-x86_64 config
其實,就是建立一個yum源了,把CD光牒内的檔案都拷貝過來了
檢視我們剛剛定義好的distr
[root@localhost ~]# cobbler distro list
CentOS-6.5-x86_64
建立定義profile,提供kickstart檔案(可以利用安裝系統生成的anaconda.cfg)
稍作修改
[root@localhost ~]# vim anaconda-ks.cfg
# Kickstart file automatically generated by
anaconda.
#version=DEVEL
install
url
--url=http://192.168.81.132/cobbler/ks_mirror/CentOS-6.5-x86_64/
#指定repository的URL路徑
lang en_US.UTF-8
keyboard us
network --onboot yes
--device eth0 --bootproto dhcp --noipv6
# Reboot after
installation
reboot
firewall --disabled
authconfig --useshadow
--passalgo=sha512
# The following is the partition information you
requested
# Note that any partitions you deleted are not expressed
# here
so unless you clear all partitions first, this is
# not guaranteed to
work
zerombr #添加此選項
clearpart --all
part /boot --fstype=ext4
--size=200
part pv.008002 --size=61440
volgroup vg0 --pesize=8192
pv.008002
logvol / --fstype=ext4 --name=root --vgname=vg0
--size=20480
logvol swap --name=swap --vgname=vg0 --size=2048
logvol /usr
--fstype=ext4 --name=usr --vgname=vg0 --size=10240
logvol /var --fstype=ext4
--name=var --vgname=vg0
%packages
@Base
@Core
@base
@basic-desktop
@chinese-support
@client-mgmt-tools
@core
@desktop-platform
@fonts
@general-desktop
@graphical-admin-tools
@legacy-x
@network-file-system-client
@perl-runtime
@remote-desktop-clients
@x11
ibus-table-cangjie
ibus-table-erbi
ibus-table-wubi
lftp
%end
驗證ks檔案是否有文法錯誤
[root@localhost ~]# ksvalidator anaconda-ks.cfg
将anaconda.cfg更名為CentOS6.5.cfg
定義一個名為CentOS-6.5-x86_64-basic的prifile
[root@localhost ~]# cobbler profile add --name=CentOS-6.5-x86_64-basic
--distro=CentOS-6.5-x86_64 --kickstart=/root/CentOS6.5.cfg
檢視我們建立的profile
[root@localhost ~]# cobbler profile list
CentOS-6.5-x86_64
#預設生成的
CentOS-6.5-x86_64-basic
對于上面的資訊,同步一下
測試階段:
建立一個空的虛拟機,并将cobbler的伺服器與空白虛拟機放在同一個網段中
[root@60sec /]# vim /etc/cobbler/settings
next_server: 192.168.83.137
server: 192.168.83.137
manage_tftpd: 0
[root@60sec /]# yum -y install syslinux
[root@60sec /]# chkconfig rsync on
[root@60sec /]# yum -y install pykickstart
[root@60sec /]# openssl passwd -1 -salt'openssl rand -hex 4'
Password:
$1$openssl $.oduSwbhLj6jqAwVsLo/H1
default_password_crypted: "penssl$.oduSwbhLj6jqAwVsLo/H1"
[root@60sec /]# cd /usr/share/syslinux/
[root@60sec syslinux]# cp -r ./*/var/lib/cobbler/loaders/
安裝dhcp服務
[root@60sec /]# yum -y install dhcp
[root@60sec /]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample/etc/dhcp/dhcpd.conf
[root@60sec /]# vim /etc/dhcp/dhcpd.conf
option domain-name "60sec.com";
option domain-name-servers172.16.0.1,192.168.83.137;
default-lease-time 43300;
max-lease-time 86500;
subnet 192.168.83.0 netmask 255.255.255.0 {
range 192.168.83.50 192.168.83.100;
option routers 192.168.83.137;
next-server 192.168.83.137;
filename="pxelinux.0";
[root@60sec /]# service dhcpd start
Starting dhcpd: [ OK ]
開啟tftp服務
[root@60sec /]# chkconfig tftp on
[root@60sec /]# service xinetd start
Starting xinetd: [ OK ]
定義distro,挂載CD光牒并導入
[root@60sec /]# mount -r /dev/cdrom /media/
[root@60sec /]# cobbler import --name=centos-6.5-x86_64 --path=/media
如果有kickstart檔案,使用“--kickstart=/path/to/kickstart_file”進行導入,也可使用以下指令
[root@60sec mnt]# ksvalidatorcentos6.x86_64.cfg
cobbler使用profile來為特定的需求類别提供所需要安裝配置,即在distro的基礎上通過提供kickstart檔案來生成一個特定的系統安裝配置。distro的profile可以出現在PXE的引導菜單中作為安裝的選擇之一。
[root@60sec mnt]# cobbler profile add--name=CenTos-6.5-x86_64-basic --distro=centos-6.5-x86_64 --kickstart=/mnt/centos6.x86_64.cfg
[root@60sec mnt]# cobbler profile list
CenTos-6.5-x86_64-basic
Centos-6.5-x86_64
[root@60sec mnt]# cobbler sync
[root@60sec mnt]# service cobblerd restart
可修改相關資訊