歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Cobbler自動批量部署CentOS 6和CentOS 7

Cobbler自動批量部署CentOS 6和CentOS 7

日期:2017/2/28 13:58:04   编辑:Linux教程

Cobbler簡介

使用PXE批量部署時,有一個缺陷,即只能安裝單一的操作系統(同一個版本,僅用一個kickstart文件)。但是在實際環境中,不同功能的服務器需要部署不同的環境,而cobbler正好滿足了這一需求。cobbler基於python開發,是對PXE的二次封裝,且提供了CLI和Web的管理形式,使得操作和管理更加簡便。cobbler的實現與PXE類似,也需要tftp,httpd,dhcp這些服務。使用yum即可完成cobbler的安裝,在安裝的同時也會自動安裝tftp和httpd服務,dhcp服務需要自行安裝。

cobbler的部署非常簡單,首先添加distro,或直接導入光盤鏡像,然後為某一個distro添加kickstart文件,一個distro可有多個kickstart文件,以實現同一版本的操作系統部署多個不一樣的環境。

實現過程

實驗環境:所有的服務均部署在同一台服務器上(192.168.3.10)

安裝cobbler

[root@node1 ~]# yum install cobbler

這個過程會自動安裝tftp,httpd。

自行安裝dhcp。

[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的部署已實現.................^_^

Copyright © Linux教程網 All Rights Reserved