linux下pxe+cobber自動化安裝系統


使用cobbler批量安裝linux系統

第一 cobber 簡介

Cobbler 可使用 kickstart 模板。基於 Red Hat 或 Fedora 的系統使用 kickstart 文件來自動化安裝流程。通過使用模板,您就會擁有基本的 kickstart 模板,然后定義如何針對一種配置文件或機器配置而替換其中的變量。例如,一個模板可能包含兩個變量 $domain和 $machine_name。在 Cobbler 配置中,一個配置文件指定 domain=mydomain.com,並且每台使用該配置文件的機器在machine_name 變量中指定其名稱。該配置文件中的所有機器都使用相同的 kickstart 安裝且針對 domain=mydomain.com 進行配置,但每台機器擁有其自己的機器名稱。您仍然可以使用 kickstart 模板在不同的域中安裝其他機器並使用不同的機器名稱。

工作原理:

Server端:

 

    第一步,啟動Cobbler服務

 

    第二步,進行Cobbler錯誤檢查,執行cobbler check命令

 

    第三步,進行配置同步,執行cobbler sync命令

 

    第四步,復制相關啟動文件文件到TFTP目錄中

 

    第五步,啟動DHCP服務,提供地址分配

 

    第六步,DHCP服務分配IP地址

 

    第七步,TFTP傳輸啟動文件

 

    第八步,Server端接收安裝信息

 

    第九步,Server端發送ISO鏡像與Kickstart文件

 

Client端:

 

    第一步,客戶端以PXE模式啟動

 

    第二步,客戶端獲取IP地址

 

    第三步,通過TFTP服務器獲取啟動文件

 

    第四步,進入Cobbler安裝選擇界面

 

    第五步,客戶端確定加載信息

 

    第六步,根據配置信息准備安裝系統

 

    第七步,加載Kickstart文件

 

    第八步,傳輸系統安裝的其它文件

 

    第九步,進行安裝系統

 

第二選擇yum源

2.1 選擇 epel源

Centos5 32位: rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/5/i386/epel-release-5-4.noarch.rpm

Centos5 64位: rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/5/x86_64/epel-release-5-4.noarch.rpm

Centos6 32位: rpm -Uvh 'http://mirrors.ustc.edu.cn/fedora/epel/6/i386/epel-release-6-7.noarch.rpm'

Centos6 64位: rpm -Uvh 'http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-7.noarch.rpm       

2.2 下載安裝yum源

 [root@localhost src]# wget http://mirrors.ustc.edu.cn/fedora/epel/5/x86_64/epel-release-5-4.noarch.rpm

--2015-06-29 10:13:48--  http://mirrors.ustc.edu.cn/fedora/epel/5/x86_64/epel-release-5-4.noarch.rpm

Resolving mirrors.ustc.edu.cn... 202.141.176.110, 2001:da8:d800:95::110

Connecting to mirrors.ustc.edu.cn|202.141.176.110|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 12232 (12K) [application/x-redhat-package-manager]

Saving to: `epel-release-5-4.noarch.rpm'

 

100%[====================================================================================================>] 12,232      --.-K/s   in 0.02s  

 

2015-06-29 10:13:52 (484 KB/s) - `epel-release-5-4.noarch.rpm' saved [12232/12232]

 

[root@localhost src]# ls

epel-release-5-4.noarch.rpm

[root@localhost src]# rpm -ivh epel-release-5-4.noarch.rpm

warning: epel-release-5-4.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6

Preparing...                ########################################### [100%]

   1:epel-release           ########################################### [100%]

[root@localhost src]#

2.3 安裝cobber

安裝軟件 yum  install cobbler tftp tftp-server xinetd  dhcp  httpd  rsync 安裝cobbler

[root@localhost src]# yum  install  pykickstart  debmirror  python-ctypes   cman  -y  安裝cobbler所需的軟件包

2.4 配置cobbler

2.4.1  設置httpd服務

[root@localhost src]# cat   /etc/httpd/conf.d/wsgi.conf   

# NOTE: mod_wsgi can not coexist in the same apache process as

# mod_wsgi_python3.  Only load if mod_wsgi_python3 is not

# already loaded.

 

<IfModule !wsgi_module>

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

</IfModule>

[root@localhost src]# /etc/init.d/httpd restart

Stopping httpd:                                            [FAILED]

Starting httpd:                                            [  OK  ]

[root@localhost src]# chkconfig httpd on

2.4.2  設置tftp

[root@localhost src]# cat  /etc/cobbler/tftpd.template   

# default: off

# description: The tftp server serves files using the trivial file transfer \

#       protocol.  The tftp protocol is often used to boot diskless \

#       workstations, download configuration files to network-aware printers, \

#       and to start the installation process for some operating systems.

service tftp

{

        disable                 = no  ##將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

}

[root@localhost src]# 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   ##將yes改為no

        socket_type     = stream

        wait            = no

        user            = root

        server          = /usr/bin/rsync

        server_args     = --daemon

        log_on_failure  += USERID

}

[root@localhost src]# /etc/init.d/xinetd start

[root@localhost src]# vim /etc/debmirror.conf

注釋

#@dists="sid";

#@arches="i386";

2.4.3  創建用戶密碼

[root@localhost src]# openssl passwd -1 -salt 'osyunwei' '123456'

$1$osyunwei$sEV8iwXXuR4CqzLXyLnzm

修改 vim /etc/cobber/settings

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

default_password_crypted: "$1$osyunwei$sEV8iwXXuR4CqzLXyLnzm0"

manage_dhcp: 1

next_server: 192.168.209.128

server: 192.168.209.128

2.4.4  搭建dhcp服務

[root@localhost ~]# grep -v "#" /etc/cobbler/dhcp.template

ddns-update-style interim;

allow booting;

allow bootp;

 

ignore client-updates;

set vendorclass = option vendor-class-identifier;

 

option pxe-system-type code 93 = unsigned integer 16;

 

subnet 192.168.209.0 netmask 255.255.255.0 {

     option routers             192.168.209.1;

     option domain-name-servers 8.8.8.8,8.8.4.4; 注: 這里多個ip時 使用逗號分開 ,已陷坑多時

     option subnet-mask         255.255.255.0;

     range dynamic-bootp        192.168.209.100 192.168.209.254;

     filename                   "/pxelinux.0";

     default-lease-time         21600;

     max-lease-time             43200;

     next-server                $next_server;

     }

[root@localhost ks_mirror]# cat  /etc/sysconfig/dhcpd

# Command line options here

DHCPDARGS=eth0

啟動dhcp 使用cobber sync  就可以啟動dhcp

同步cobber sync 就可以加載dhcp服務啟動了

 

cobbler check  檢查cobbler 配置是否錯誤

注:如果提示'cobbler get-loaders' 的一些錯誤  可以忽略,暫時沒發現有什么影響

          以為執行cobbler get-loaders 這個命令 回包HTTP 404  也不知是不是網站倒閉了怎樣

          或許換centos6 可以試試

 

確保這些服務都開啟就可以進行測試安裝了,

/etc/init.d/xinted  start

/etc/init.d/httpd  start

/etc/init.d/cobber start

2.4.5  創建鏡像站點

掛載映像文件到httpd的站點目錄

mkdir -p /var/www/html/os/centos_x64_x86

mount /dev/cdrom /media/

rsync -avP  /media/* /var/www/html/os/centos_x64_x86/

使用rsync或者scp

cobbler import --path=/var/www/html/os/centos_x64_x86/  --name=centos_x64_x86  --arch=x86_64

導入鏡像的命令參數

命令格式:cobbler import --path=鏡像路徑 -- name=安裝引導名 --arch=32位或64位, 重復上面的操作,把其他的系統鏡像文件導入到cobber中,

cobbler distro list 列出已經安裝鏡像

 

注: 1. 原以為不用新建/var/www/html/os/centos_x64_x86/ 網站目錄  直接講httpd目錄改成/var/www/cobbler/images/  這個 cobbler 已經自動導入鏡像的路徑,  結果報錯, 暫不清楚為何cobbler導入鏡像后 為何還需要http服務

             2. cobbler import --path=/var/www/html/os/centos_x64_x86/  --name=qing  --arch=x86_64

                   導入的鏡像后的命名規則 name+arch   (cobbler distro list 查看 不使用qing-xen-x86_64)

                   在創建profile 時 會調用這個distro名字

qing-x86_64

      qing-xen-x86_64

2.4.6  創建自動化安裝腳本

創建自動化安裝腳本

進入到kickstarts 模板目錄(默認)

cd /var/lib/cobbler/kickstarts 

[root@localhost kickstarts]# ls

default.ks    legacy.ks            sample_end.ks    sample_esxi5.ks  sample.seed

esxi4-ks.cfg  pxerescue.ks         sample_esx4.ks   sample.ks

esxi5-ks.cfg  sample_autoyast.xml  sample_esxi4.ks  sample_old.seed

注: 此目錄為模板的默認存放目錄, 新添加profile時需指定默認的模板文件, 否則就會使用默認的sample.ks的文件, 造成裝機錯誤(因為沒有正確使用kistart文件)

安裝kickstart

yum  install system-config-kickstart

yum groupinstall "X Window System"

startx 進入到圖形界面

system-config-kickstart 運行生成ks.cf 文件

具體修改內容請參考下面注釋

 

修改文件名稱添加到cobber 中

[root@localhost ~]# cobbler profile add --name=centos_x64-x86_64 --distro=centos_x64-x86_64 --kickstart=/var/lib/cobbler/kickstarts/cenots5.8_x86_64.cfg

添加文件的命令參數

命令:cobbler profile add|edit|remove --name=安裝引導名 --distro=系統鏡像名 --kickstart=kickstart自動安裝文件路徑

--name:自定義的安裝引導名,在客戶端(被裝的機器上)顯示的就是這個名字

--distro:系統安裝鏡像名,用cobbler distro list可以查看

--kickstart:與系統鏡像文件相關聯的kickstart自動安裝文件

 

2.3  測試

測試之前將bios 調整為pxe啟動,

在這里就可以測試pxe引導安裝了(選擇centos_x64-x86_64 這個選項)

 

                              

 

 

2.4  cobbler 幫助

 [root@localhost ~]# man cobbler   查看cobbler幫助

cobbler list

cobbler report     常用

cobbler profile report

cobbler distro list

 

[root@localhost ~]# cobbler list

distros:

   centos_x64-x86_64

   centos_x64-xen-x86_64

 

profiles:

   centos_x64-x86_64

   centos_x64-xen-x86_64

 

systems:

 

repos:

 

images:

 

mgmtclasses:

 

packages:

 

files:

[root@localhost ~]# cobbler distro list

   centos_x64-x86_64

   centos_x64-xen-x86_64

[root@localhost ~]#

 

 

 

Kickstart圖解:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM