1. 程式人生 > >Cobbler——無人值守安裝多種版本多種配置操作系統

Cobbler——無人值守安裝多種版本多種配置操作系統

for root HERE 用法 安裝源 path match sde reposync

Cobbler

1、Cobbler是一個linux安裝服務器,他能實現網絡安裝環境下的快速安裝
基於Python開發的

2、適用於大規模安裝linux操作系統,不同版本的操作系統,同一版本又不同的配置
Cobber基於DHCP、PXE、TFTP、HTTP、Kickstart的技術,來提供統一的對外服務,另外還有Cobbler Web界面,不過Cobbler CLI已經滿足大部分人需求,本節Cobbler Web不做研究,下節有個簡單的Web實際用法。

3、另外Cobbler還可以作為一個本地yum倉庫,利用reposync

Cobbler工作機制

  1. client客戶端配置了從網絡啟動後,開機會廣播請求DHCP服務器(cobbler server)發送其分配好的一個IP
  2. DHCP服務器接收到請求後發送responese,包括其IP地址
  3. clinet裸機拿到ip後,再向cobbler server 發送請求,OS引導文件的請求
  4. cobbler server 返回給客戶端OS引導文件的名字和TFTP服務器的ip和port
  5. 客戶端通過cobbler返回的信息,通過地址找到TFTP服務器,下載引導文件
  6. 客戶端通過該引導文件,確定加載信息,選擇要安裝的系統,期間會再向cobbler server請求應答文件
  7. 客戶端加載應答文件,通過應答文件的配置來完成相關操作

    Cobbler 服務集成

    PXE服務支持
    rsync服務
    DHCP服務管理
    DNS服務管理(可選bind,dnsmasq)

    IPMI電源管理
    Kickstart服務支持
    YUM倉庫管理
    TFTP(PXE啟動時需要)
    HTTPD(提供kickstart的安裝源,並提供定制化的kickstart配置)

    Cobbler 配置目錄說明

    配置文件目錄:/etc/cobbler

    /etc/cobbler/settings : cobbler 主配置文件
    /etc/cobbler/iso/: iso模板配置文件
    /etc/cobbler/pxe: pxe模板文件
    /etc/cobbler/power: 電源配置文件
    /etc/cobbler/user.conf: web服務授權配置文件
    /etc/cobbler/users.digest: web訪問的用戶名密碼配置文件
    /etc/cobbler/dhcp.template : dhcp服務器的的配置末班

    /etc/cobbler/dnsmasq.template : dns服務器的配置模板
    /etc/cobbler/tftpd.template : tftp服務的配置模板
    /etc/cobbler/modules.conf : 模塊的配置文件

    數據目錄:

    /var/lib/cobbler/config/: 用於存放distros,system,profiles 等信 息配置文件
    /var/lib/cobbler/triggers/: 用於存放用戶定義的cobbler命令
    /var/lib/cobbler/kickstart/: 默認存放kickstart文件
    /var/lib/cobbler/loaders/: 存放各種引導程序 ? 鏡像目錄
    /var/www/cobbler/ks_mirror/: 導入的發行版系統的所有數據
    /var/www/cobbler/images/ : 導入發行版的kernel和initrd鏡像用於 遠程網絡啟動
    /var/www/cobbler/repo_mirror/: yum 倉庫存儲目錄

    日誌目錄:

    /var/log/cobbler/installing: 客戶端安裝日誌
    /var/log/cobbler/cobbler.log : cobbler日誌

    Cobber 命令

    cobbler commands    介紹 
    cobbler check       核對當前設置是否有問題 
    cobbler list        列出所有的cobbler元素 
    cobbler report      列出元素的詳細信息 
    cobbler sync        同步配置到數據目錄,更改配置最好都要執行下 
    cobbler reposync    同步yum倉庫 
    cobbler distro      查看導入的發行版系統信息 
    cobbler system      查看添加的系統信息 
    cobbler profile     查看配置信息 

    實驗:Cobbler 自動化部署系統

    主機信息

    服務器:centos7
    網卡: 僅主機,192.168.146.10
    橋接: dhcp
    安裝服務:cobbler dhcp tftp-server pykickstart httpd

    準備工作

    systemctl disable firewalld       centos7開機不自啟防火墻
    systemctl stop firewalld          centos7停止防火墻
    service iptables stop             centos6關閉iptables
    service iptables enable           centos6開機不自啟iptables
    sed -i "s/SELINUX=SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config  修改selinux配置文件
    reboot                      重啟生效
    關閉虛擬機VM本地dhcp服務,防止和我們安裝的dhcp發生沖突
    yum install cobbler dhcp tftp-server pykickstart httpd -y 安裝本實驗需要的軟件包

    安裝Cobbler

    yum install cobbler -y
    systemctl start cobbler
    systemctl enable cobbler

    修改配置文件

    cobbler check 檢查cobbler配置文件
    當我們執行這條命令後,通常會報以下8條錯誤,我們一條條修改即可

    會出現如下錯誤:

    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.

384    # of the manpage for how that works 
server  192.168.146.10`` 

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.

272   # if you do not set this correctly, this will be manifested in TFTP open timeouts. 
next_server 192.168.146.10

3 : change ‘disable‘ to ‘no‘ in /etc/xinetd.d/tftp

vim /etc/xinetd.d/tftp
disable     =disable改為no 

技術分享圖片
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.

如果當前節點可以訪問互聯網,執行“cobbler get-loaders”命令即可;
cobbler get-loaders    下載bootloader 加載程序
否則,需要安裝syslinux程序包,而後復制
/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至
/var/lib/cobbler/loaders/目錄中 

技術分享圖片
5 : enable and start rsyncd.service with systemctl

systemctl enable rsyncd
systemctl start rsyncd

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

--這個配置文件在101行 
-- openssl passwd -1
#and put the output between the "" below.
必須要修改這個文件,cobbler check 會報錯
default_password_crypted: "$1$3pHPXQL8$VxaAapUajtxI0X610meBl/"

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.

修改完以上6個配置後,可執行 cobbler sync 命令
技術分享圖片

配置cobbler-DHCP

修改cobbler配置

vim /etc/cobbler/settings 將dhcp服務由cobbler托管

僅修改以下配置文件
技術分享圖片

導入安裝源文件

首先掛載光盤

mount /dev/sr0 /mnt/centos7/        掛載CentOS7鏡像文件
mount /dev/sr1 /mnt/centos6/        掛載CentOS6鏡像文件

導入光盤

cobbler import --name=CentOS6.10 --path=/mnt/centos6 --arch=x86_64
cobbler import --name=CentOS7.6  --path=/mnt/centos7 --arch=x86_64
    --name  為安裝源定義一個名字
    --path  鏡像文件路徑
    --arch  安裝源的架構

centos7
技術分享圖片

cneots6
技術分享圖片

安裝源的唯一標識就是name參數定義的,以上面為例。導入後唯一標識就是
技術分享圖片

生成kickstart文件

制作kickstart

基於epel源,安裝system-config-kickstart程序包

    yum install system-config-kickstart  

基於圖形化界面來制作kickstart文件

也可以參考當前主機上的應答模板文件 /root/anaconda-ks.cfg
制作完kickstart文件後,建議檢查一下語法錯誤

    cobbler validateks

修改kickstart

將原來的配置修改文 url --url="$tree"

導入kickstart文件

將制作好的kickstart文件導入到/var/lib/cobbler/kickstarts/(默認存放kickstart文件) 目錄下

cp /data/ks7_mini.cfg /var/lib/cobbler/kickstart/
cp /data/ks6_mini.cfg /var/lib/cobbler/kickstart/

將ks文件和系統關聯,生成啟動菜單

cobbler profile edit --name Centos7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7_mini.cfg
cobbler profile edit --name Centos6.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks6_mini.cfg
我們還可以修改CentOS7的默認網卡名稱
cobbler profile edit --name Centos7.6-x86_64 --kopts=‘net.ifnames=0 biosdevname=0‘ 

同步cobbler
cobbler sync

結尾工作

systemctl restart httpd
systemctl restart dhcpd
systemctl restart tftp
systemctl restart cobblerd
systemctl restart xinetd.service

技術分享圖片


如有錯誤或不清晰的地方,請各位指正。

Cobbler——無人值守安裝多種版本多種配置操作系統