Cobbler+Kickstart自動化批量系統(tǒng)部署

2017年4月10日14:13:50 11 13,070 ℃

Cobbler服務(wù)器系統(tǒng) :Centos 6.8 64位

服務(wù)器IP地址:192.168.159.128

需要安裝部署的Linux系統(tǒng):

系統(tǒng)版本:centos6.8-x86_x64

Eth0 IP地址段:192.168.159.150-192.168.159.250

網(wǎng)關(guān):192.168.159.2

子網(wǎng)掩碼:255.255.255.0

DNS192.168.159.128 114.114.114.114

Cobbler服務(wù)器上操作

一、關(guān)閉selinux

Vim /etc/selinux/config

#SELINUX=enforcing #注釋掉

#SELINUXTYPE=targeted #注釋掉

SELINUX=disabled #增加

:wq!  #保存退出

setenforce 0 #使配置立即生效

二、配置防火墻

Vim /etc/sysconfig/iptables #編輯

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT #ssh服務(wù)需要此端口

-A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT #http服務(wù)需要此端口

-A INPUT -m state --state NEW -m udp -p udp --dport 69 -j ACCEPT #tftp服務(wù)需要此端口

-A INPUT -m state --state NEW -m tcp -p tcp --dport 25151 -j ACCEPT  #cobbler需要此端口

:wq  #保存退出

/etc/init.d/iptables restart #最后重啟防火墻使配置生效

三、安裝cobbler

wget -O /etc/yum.repos.d/aliyunepel.repo http://mirrors.aliyun.com/repo/epel-6.repo #下載aliyun yum

yum  install  -y cobbler tftp tftp-server xinetd  dhcp  httpd  rsync cobbler-web #安裝cobbler

yum  install  -y  pykickstart  debmirror  python-ctypes   cman   #安裝運行cobbler需要的軟件包

四、配置Cobbler

1、設(shè)置http服務(wù)

Vim  /etc/httpd/conf.d/wsgi.conf

LoadModule wsgi_module modules/mod_wsgi.so  #取消前面的注釋

:wq! #保存退出

chkconfig httpd on  #設(shè)置開機啟動

service httpd start   #啟動

2、設(shè)置tftp服務(wù)開機啟動

vim  /etc/cobbler/tftpd.template  #編輯

service tftp

{

        disable                     = no  #修改為no

        socket_type                  = dgram

        protocol                = udp

        wait                        = yes

        user                        = $user

        server                  = $binary

        server_args                    = -B 1380 -v -s $args

        per_source                     = 11

        cps                          = 100 2

        flags                   = IPv4

}

:wq! #保存退出

3、設(shè)置rsync服務(wù)開機啟動

vim /etc/xinetd.d/rsync  #編輯配置文件,設(shè)置開機啟動rsync

service rsync

{

         disable     = no  #修改為no

         flags         = IPv6

         socket_type     = stream

         wait            = no

         user            = root

         server          = /usr/bin/rsync

         server_args     = --daemon

         log_on_failure  += USERID

}

:wq! #保存退出

/etc/init.d/xinetd start  #啟動(CentOS中是以xinetd 來管理Rsynctftp服務(wù)的)

4、配置cobbler相關(guān)參數(shù)

vi /etc/debmirror.conf  #注釋掉 @dists @arches 兩行

#@dists="sid";

#@arches="i386";

:wq! #保存退出

openssl passwd -1 -salt 'myredhat''12344321' #生成默認模板下系統(tǒng)安裝完成之后root賬號登錄密碼

$1$myredhat$2LHloV2OJhLZQO.b1/yg9/  #記錄下這行,下面會用到

vim /etc/cobbler/settings  #編輯,修改

default_password_crypted: "$1$myredhat$2LHloV2OJhLZQO.b1/yg9/"

next_server: 192.168.159.128

server: 192.168.159.128

manage_dhcp: 1

default_kickstart: /var/lib/cobbler/kickstarts/default.ks

:wq! #保存退出

5、配置dhcp服務(wù)器

vim /etc/cobbler/dhcp.template #編輯,修改

subnet 192.168.159.0 netmask 255.255.255.0 { #設(shè)置網(wǎng)段

option routers             192.168.159.2;   #設(shè)置網(wǎng)關(guān)

option domain-name-servers 192.168.159.128,114.114.114.114 #設(shè)置dns服務(wù)器地址

option subnet-mask         255.255.255.0; #設(shè)置子網(wǎng)掩碼

range dynamic-bootp        192.168.159.150 192.168.159.250;  #設(shè)置dhcp服務(wù)器IP地址租用的范圍

default-lease-time         21600;  #默認租約時間

max-lease-time              43200;  #最大租約時間

next-server                $next_server;

class "pxeclients" {

match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";

if option pxe-system-type = 00:02 {

filename "ia64/elilo.efi";

} else if option pxe-system-type = 00:06 {

filename "grub/grub-x86.efi";

} else if option pxe-system-type = 00:07 {

filename "grub/grub-x86_64.efi";

} else {

filename "pxelinux.0";

}

}

}

:wq! #保存退出

vim /etc/sysconfig/dhcpd   #指定DHCP服務(wù)的網(wǎng)絡(luò)接口

DHCPDARGS=eth0

:wq!  #保存退出

dhcpd  #測試dhcp服務(wù)器配置是否正確

chkconfig dhcpd on   #設(shè)置開機啟動

chkconfig cobblerd on   #設(shè)置開機啟動

cobbler get-loaders  #安裝cobbler相關(guān)工具包,否則檢查cobbler配置會報錯

service cobblerd start  #啟動cobbler

cobbler sync  #同步配置文件到dhcp服務(wù)器

service dhcpd start    #啟動dhcp服務(wù)

五、掛載系統(tǒng)安裝鏡像到http服務(wù)器站點目錄

由于我使用的是虛擬機環(huán)境、直接掛載的ISO文件,所以直接掛載光盤

mkdir -p /var/www/html/os/Centos6.8  #創(chuàng)建掛載目錄

mount /dev/sr0 /var/www/html/os/Centos6.8 #掛載光盤

如果是下載到服務(wù)器的iso文件,掛載方法:

Mount -t iso9660 -o loop /usr/local/src/CentOS-6.8-x86_64-bin-DVD-1of2.iso  /var/www/html/os/CentOS6.8  #掛載系統(tǒng)鏡像

vim /etc/fstab   #添加以下代碼。實現(xiàn)開機自動掛載

/usr/local/src/CentOS-6.8-x86_64-bin-DVD-1of2.iso   /var/www/html/os/CentOS6.8   iso9660    defaults,ro,loop  0 0

:wq! #保存退出

備注:重復(fù)上面的操作,把自己需要安裝的CentOS系統(tǒng)鏡像文件都掛載到/var/www/html/os/目錄下

六、創(chuàng)建kickstarts自動安裝腳本

cd /var/lib/cobbler/kickstarts  #進入默認Kickstart模板目錄

vim /var/lib/cobbler/kickstarts/centos-6.8-x86_64.ks  #創(chuàng)建centos-6.8-x86_64.ks安裝腳本

# Kickstart file automatically generated by anaconda.

install

url --url=http://192.168.159.128/cobbler/ks_mirror/centos6.8-x86_64/

lang en_US.UTF-8

zerombr  yes

key --skip

keyboard us

network --device eth0 --bootproto dhcp  --onboot on

#network --device eth0 --bootproto static --ip 192.168.159.250 --netmask 255.255.255.0 --gateway 192.168.159.2 --nameserver 192.168.159.128 --hostname CentOS

rootpw --iscrypted $1$myredhat$2LHloV2OJhLZQO.b1/yg9/

firewall --enabled --port=22:tcp

authconfig --enableshadow --enablemd5

selinux --disabled

timezone Asia/Shanghai

bootloader --location=mbr --driveorder=sda

# 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

#clearpart --linux

clearpart --all --initlabel

part / --bytes-per-inode=4096 --fstype="ext4" --size=2048

part /boot --bytes-per-inode=4096 --fstype="ext4" --size=128

part swap --bytes-per-inode=4096 --fstype="swap" --size=500

part /data --bytes-per-inode=4096 --fstype="ext4" --grow --size=1

reboot

%packages

ntp

@base

@core

@dialup

@editors

@text-internet

keyutils

trousers

fipscheck

device-mapper-multipath

%post

七、導(dǎo)入系統(tǒng)鏡像到cobbler

cobbler import --path=/var/www/html/os/CentOS6.8  --name=CentOS-6.8-x86_64  --arch=x86_64  #導(dǎo)入系統(tǒng)鏡像文件,需要一段時間

cd /var/www/cobbler/ks_mirror  #進入系統(tǒng)鏡像導(dǎo)入目錄

命令格式:cobbler import --path=鏡像路徑 -- name=安裝引導(dǎo)名 --arch=32位或64

重復(fù)上面的操作,把其他的系統(tǒng)鏡像文件導(dǎo)入到cobbler

八、設(shè)置profile,按照操作系統(tǒng)版本分別關(guān)聯(lián)系統(tǒng)鏡像文件和kickstart自動安裝文件

在第一次導(dǎo)入系統(tǒng)鏡像時,cobbler會給安裝鏡像指定一個默認的kickstart自動安裝文件

如:CentOS-6.8-x86_64版本的kickstart自動安裝文件為:/var/lib/cobbler/kickstarts/sample.ks

cobbler profile report --name  centos-6.8-x86_64  #查看profile設(shè)置

cobbler distro report --name centos-6.8-x86_64  #查看安裝鏡像文件信息

cobbler profile remove --name= centos-6.8-x86_64   #移除profile

cobbler profile add --name=centos-6.8-x86_64  --distro= centos-6.8-x86_64  --kickstart=/var/lib/cobbler/kickstarts/ centos-6.8-x86_64 .ks  #添加

cobbler profile edit --name=centos-6.8-x86_64  --distro=CentOS-6.8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.8-x86_64.ks  #編輯

命令:cobbler profile add|edit|remove --name=安裝引導(dǎo)名 --distro=系統(tǒng)鏡像名 --kickstart=kickstart自動安裝文件路徑

--name:自定義的安裝引導(dǎo)名,注意不能重復(fù)

--distro:系統(tǒng)安裝鏡像名,用cobbler distro list可以查看

--kickstart:與系統(tǒng)鏡像文件相關(guān)聯(lián)的kickstart自動安裝文件

#查看Cobbler列表

cobbler list

cobbler report

cobbler profile report

cobbler distro list

也可以圖形界面操作,訪問http://192.168.159.128/cobbler_web/賬號密碼都是cobbler

登錄以后點擊Importer DVD (先掛載鏡像ISO),然后再Importer,點擊run。

Cobbler+Kickstart自動化批量系統(tǒng)部署                 

導(dǎo)入完成后可以看到:

Cobbler+Kickstart自動化批量系統(tǒng)部署

選擇左側(cè)profile配置ks文件

Cobbler+Kickstart自動化批量系統(tǒng)部署

輸入你所需要的ks文件路徑

Cobbler+Kickstart自動化批量系統(tǒng)部署

自動化部署系統(tǒng)

九、客戶端從網(wǎng)絡(luò)啟動后選擇對應(yīng)的文件開始自動部署

開機之后,如下圖所示,根據(jù)需要選擇相應(yīng)的系統(tǒng)版本進行安裝,安裝完成之后,系統(tǒng)會自動重啟

Cobbler+Kickstart自動化批量系統(tǒng)部署

Cobbler+Kickstart自動化批量系統(tǒng)部署

安裝成功重啟以后,輸入設(shè)置的密碼,用戶名root

Cobbler+Kickstart自動化批量系統(tǒng)部署

至此,Cobbler全自動批量安裝部署Linux系統(tǒng)完成。

【騰訊云】云服務(wù)器、云數(shù)據(jù)庫、COS、CDN、短信等云產(chǎn)品特惠熱賣中

發(fā)表評論取消回復(fù)

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前評論:11   其中:訪客  0   博主  0

    • avatar 衣皇后 0

      很榮幸來訪您的博客,留言只是證明我來過!

      • avatar 練習(xí) 1

        世事無常,但這個博客定能永保輝煌!

        • avatar 暗你著迷 1

          時間飛快,轉(zhuǎn)眼年中就要到來,祝你天天愉快!

          • avatar 菲德爾 0

            我只想默默的拜讀您的博客!

            • avatar 疾如風(fēng) 2

              你的博客讓人流連忘返!

              • avatar 肺司水道 1

                閑著沒事,隨便逛逛,心靜自然涼。

                • avatar 人鬼狐 1

                  受教了!呵呵!

                  • avatar 聚劃算 1

                    古人日三省其身,我從博客里吸收養(yǎng)分!

                    • avatar 衣皇后 0

                      很榮幸來到這里參觀!

                      • avatar 增達網(wǎng) 0

                        學(xué)習(xí)是人前進的助力,認真拜讀咯!

                        • avatar 衣皇后 1

                          相當精彩的博客!