Cobbler

1. cobbler簡介

cobbler官網:http://cobbler.github.io/
Cobbler是一個Linux服務器安裝的服務,能夠經過網絡啓動(PXE)的方式來快速安裝、重裝物理服務器和虛擬機,同時還能夠管理DHCP,DNS等。
Cobbler能夠使用命令行方式管理,也提供了基於Web的界面管理工具(cobbler-web),還提供了API接口,能夠方便二次開發使用。
Cobbler是較早前的kickstart的升級版,優勢是比較容易配置,還自帶web界面比較易於管理。
Cobbler內置了一個輕量級配置管理系統,但它也支持和其它配置管理系統集成,如Puppet,暫時不支持SaltStack。



python

二、cobbler集成的服務

  • PXE服務支持
  • DHCP服務管理
  • DNS服務管理(可選bind,dnsmasq)
  • 電源管理
  • Kickstart服務支持
  • YUM倉庫管理
  • TFTP(PXE啓動時須要)
  • Apache(提供kickstart的安裝源,並提供定製化的kickstart配置)

三、cobbler配置文件詳解

cobbler配置文件目錄在/etc/cobblerlinux

配置文件                                                                        做用
/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.templat e              dns服務器的配置模板
/etc/cobbler/tftpd.template                         tftp服務的配置模板
/etc/cobbler/modules.conf                           模塊的配置文件
  • cobbler數據目錄ios

    目錄                                                                               做用
    /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倉庫存儲目錄
  • cobbler的日誌文件git

    日誌文件路徑                                              說明
    /var/log/cobbler/installing             客戶端安裝日誌
    /var/log/cobbler/cobbler.log            cobbler日誌
  • cobbler命令詳解
    cobbler check            //覈對當前設置是否有問題
    cobbler list                //列出全部的cobbler元素
    cobbler report           //列出元素的詳細信息
    cobbler sync            //同步配置到數據目錄,更改配置最好都要執行下
    cobbler reposync     //同步yum倉庫
    cobbler distro          //查看導入的發行版系統信息
    cobbler system        //查看添加的系統信息
    cobbler profile         //查看配置信息

4.cobbler 部署

4.2cobbler 部署github

//關閉防火牆
[root@localhost ~]# systemctl  stop  firewalld
[root@localhost ~]# systemctl  disable  firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim  /etc/selinux/config
 **//將第六行中的 enforcing 改成 disabled**
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled      

[root@localhost ~]# setenforce   0

//配置yum源
//下載以前請確保電腦有網和本地倉庫可用
//163網絡源下載好後請將原來的源移走或刪除
[root@localhost yum.repos.d]# yum  install  -y  wget
[root@server ~]#  curl -o /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@server ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo 
[root@server ~]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo 
[root@server ~]# yum install -y epel-release

//安裝cobbler以及相關的軟件
[root@server ~]#  yum -y install httpd dhcp tftp python-ctypes cobbler xinetd cobbler-web pykickstart

//啓動服務並設置開機自啓
[root@server ~]# systemctl start httpd
[root@server ~]# systemctl start cobblerd
[root@server ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@sever ~]# systemctl enable cobblerd
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.

//修改server的ip地址爲本機ip
[root@server ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.66.130/' /etc/cobbler/settings

//設置tftp的ip地址爲本機ip
[root@server ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.66.130/' /etc/cobbler/settings 

//開啓tftp
[root@server ~]# sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp

//下載缺失文件
[root@server ~]# cobbler get-loaders
task started: 2020-05-28_172454_get_loaders
task started (id=Download Bootloader Content, time=Thu May 28 17:24:54 2020)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***

//啓動rsync並設置開機自啓
[root@server ~]# systemctl start rsyncd
[root@server ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

//生成加密的密碼
[root@server ~]#  openssl passwd -1 -salt "$RANDOM" 'wlw123!'
$1$30214$snHY66HJF6ZeMh8ul1eW..//這是密碼加密後的形式

//將新生成的加密密碼加入到配置文件
[root@server ~]# vim /etc/cobbler/settings
//修改密碼
default_password_crypted: "$1$30214$snHY66HJF6ZeMh8ul1eW.."

//重啓cobbler
[root@server ~]# systemctl restart cobblerd
[root@server ~]# ss -antl
State      Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
LISTEN     0      128                           *:22                                        *:*                  
LISTEN     0      100                   127.0.0.1:25                                        *:*                  
LISTEN     0      5                     127.0.0.1:25151                                     *:*                  
LISTEN     0      5                             *:873                                       *:*                  
LISTEN     0      128                          :::80                                       :::*                  
LISTEN     0      128                          :::22                                       :::*                  
LISTEN     0      100                         ::1:25                                       :::*                  
LISTEN     0      128                          :::443                                      :::*                  
LISTEN     0      5                            :::873                                      :::*    

//經過cobbler check 覈對當前設置是否有問題
//要是有Seliux錯誤要重啓虛擬機
[root@wan ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
2 : 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.
//以上兩個是關於debian系統的錯誤,請忽略

//配置cobbler dhcp
//修改cobbler配置文件,讓cobbler控制dhcp
[root@wan ~]# sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
[root@wan ~]# sed -n '/^manage_dhcp/p' /etc/cobbler/settings
manage_dhcp: 1

//配置dhcp
[root@wan ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.66.0 netmask 255.255.255.0 {
     option routers             192.168.66.2;   // 指定網關
     option domain-name-servers 192.168.66.2;   // 此處爲系統安裝好後指定的dns地址
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.66.100 192.168.66.200;    // 分配的ip地址範圍(批量安裝機子,最多252,253臺)
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;

//重啓服務並同步配置,改完dhcp必需要sync同步配置
[root@wan ~]# systemctl restart cobblerd
[root@wan ~]# cobbler sync
.......
*** TASK COMPLETE ***       #最後出現這個表示正常

//檢查dhcp是否正常
[root@wan ~]# netstat -anulp | grep dhcp
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1392/dhcpd          
//導入redhat7鏡像
[root@wan ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@wan ~]# cobbler import --path=/mnt --name=rhel-7 --arch=x86_64
.......
*** TASK COMPLETE ***       #最後出現這個表示正常

# 說明:
    --path      //鏡像路徑
    --name      //爲安裝源定義一個名字
    --arch      //指定安裝源平臺
//安裝源的惟一標示就是根據name參數來定義,本例導入成功後,安裝源的惟一標示就是CentOS-7-x86_64,若是重複,系統會提示導入失敗

//查看cobbler鏡像列表
[root@wan ~]# cobbler list
distros:
   rhel-7-x86_64

profiles:
   rhel-7-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

//建立kickstarts自動安裝腳本
[root@wan ~]# cat > /var/lib/cobbler/kickstarts/rhel-7-x86_64.ks <<'EOF'
auth --enableshadow --passalgo=sha512
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.66.130/cobbler/ks_mirror/rhel-7-x86_64
$yum_repo_stanza
reboot

## 此處密碼應爲本機系統anaconda-ks.cfg文件裏的 # Root password
rootpw --iscrypted $6$2WTFvfNvAMgCUPuC$MJgWGzhakgxrRObcEbAwSe8vkz0s//xyiTllGwxRsHHruQhcskO69u2LVTU9u0eemHXH2pzcGawyAJ54R2E/x0

selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr

%packages
@^minimal
@core
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
EOF
# 檢查ks文件語法是否有誤
[root@localhost ~]# cobbler validateks
task started: 2018-08-21_171616_validateks
task started (id=Kickstart Validation, time=Tue Aug 21 17:16:16 2018)
----------------------------
osversion: rhel7
checking url: http://192.168.100.96/cblr/svc/op/ks/profile/rhel-7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.100.96/cblr/svc/op/ks/profile/rhel-7-x86_64"
received on stdout:
received on stderr:
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***

# 查看當前cobbler有哪些配置文件
[root@localhost ~]# cobbler profile list
   rhel-7-x86_64

# 修改profile,將咱們新建的ks文件設爲默認的kickstarts安裝文件
[root@localhost ~]# cobbler profile edit --name rhel-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/rhel-7-x86_64.ks

# 配置網卡名稱爲傳統網卡名稱eth0
[root@localhost ~]# cobbler profile edit --name rhel-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'

# 檢查當前系統cobbler配置文件信息
[root@localhost ~]# cobbler profile report
Name                           : rhel-7-x86_64
TFTP Boot Files                : {}
Comment                        :
DHCP Tag                       : default
Distribution                   : rhel-7-x86_64        //倉庫名字
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {'biosdevname': '0', 'net.ifnames': '0'}       //網卡設爲傳統命名方式
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/rhel-7-x86_64.ks     //使用的kickstarts配置文件的路徑,必須爲咱們新建的ks文件的路徑
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 :
Internal proxy                 :
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      :
Virt RAM (MB)                  : 512
Virt Type                      : kvm

# 同步cobbler
[root@localhost ~]# cobbler sync
.......
*** TASK COMPLETE ***       ##出現此表示成功

# 爲避免發生未知問題,先把服務端全部服務重啓
[root@localhost ~]# systemctl restart xinetd
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port
LISTEN     0      128            *:22                         *:*
LISTEN     0      100    127.0.0.1:25                         *:*
LISTEN     0      5      127.0.0.1:25151                      *:*
LISTEN     0      5              *:873                        *:*
LISTEN     0      128           :::80                        :::*
LISTEN     0      128           :::22                        :::*
LISTEN     0      100          ::1:25                        :::*
LISTEN     0      128           :::443                       :::*
LISTEN     0      5             :::873                       :::*

5.客戶端安裝系統

手動驗證:
建立一個虛擬機,模式和服務端模式同樣,(這裏我使用的是nat,因此要安裝的虛擬機模式也是nat),而後設置虛擬機
Cobbler
而後,直接開啓虛擬機,看到如下界面,選擇第二個,回車,而後等待系統自動安裝完成便可。
Cobbler
由於這種方式須要手動選擇,若是機器太多,每臺服務器都要選擇,仍是很麻煩,因此採用web界面配置定製安裝




web

# 配置完成後可能致使訪問不了web頁面,猜想python-django版本有問題
[root@localhost ~]# yum -y install python2-pip
[root@localhost ~]#  pip install --upgrade pip
[root@localhost ~]# pip install Django==1.9.13
#用pip安裝指定版本的Django

重啓httpd服務 ,再次訪問https://192.168.100.96/cobbler_web出現登陸頁面
Cobbler
django

6.定製安裝

定製安裝步驟:vim

  • 統計服務器mac地址
  • 配置cobbler
  • 安裝

    6.1 獲取mac地址

    mac地址在:虛擬機—編輯此虛擬機—網路適配器—高級—MAC地址(點擊生成而後複製便可)
    CobblerCobblerCobblerCobbler
    瀏覽器

    6.2 配置cobbler

  • 直接在瀏覽器上搜索:https://本機ip+/cobbler_web
  • 用戶名與密碼都是cobbler
    CobblerCobblerCobblerCobblerCobbler

6.3 安裝

直接開啓此虛擬機,它就會自動安裝
Cobbler
CobblerCobbler

bash

編寫腳本部署cobbler服務端

#!/bin/bash
#配置yum源
curl -o /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
yum install -y epel-release

#安裝cobbler以及相關的軟件
yum -y install httpd dhcp tftp python-ctypes cobbler xinetd cobbler-web pykickstart

#啓動服務並設置開機自啓
systemctl start httpd
systemctl start cobblerd
systemctl enable httpd
systemctl enable cobblerd

#關閉防火牆
firewall()
{
systemctl stop firewalld
systemctl disable firewalld
systemctl mask firewalld
setenforce 0
}

#修改server的ip地址爲本機ip
sed -i 's/^server: 127.0.0.1/server: 192.168.66.130/' /etc/cobbler/settings

#設置tftp的ip地址爲本機ip
sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.66.130/' /etc/cobbler/settings

#開啓tftp
sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp
#下載缺失文件
cobbler get-loaders

#啓動rsync並設置開機自啓
systemctl start rsyncd
systemctl enable rsyncd

#生成加密密碼並添加到配置文件
configure_passwd()
{
if [$? -eq 0];then
passwd=`openssl passwd -1 -salt "$RANDOM" 'wlw123!'`
sed -i "101idefault_password_crypted: \"$pass\"" /etc/cobbler/settings
sed -i '102d' /etc/cobbler/settings
fi
}
#重啓cobbler
systemctl restart cobblerd
#配置cobbler dhcp
#修改cobbler配置文件,讓cobbler控制dhcp
sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
sed -n '/^manage_dhcp/p' /etc/cobbler/settings

#配置cobbler dhcp
configure_dhcp()
{
if [$? -eq 0];then
sed -i '21s/192.168.1/192.168.66/g' /etc/cobbler/dhcp.template
sed -i '22s/192.168.1.5/192.168.66.2/g' /etc/cobbler/dhcp.template
sed -i '23s/192.168.1.1/192.168.66.2/g' /etc/cobbler/dhcp.template
sed -i '25s/192.168.1.100 192.168.1.254/192.168.66.100 192.168.66.200/' /etc/cobbler/dhcp.template
fi
}

#重啓服務並同步配置,改完dhcp必需要sync同步配置
systemctl restart cobblerd
cobbler sync
main()
{
    firewall&&configure_cobbler&&configure_passwd&&configure_dhcp
}
#導入redhat7鏡像
mount /dev/cdrom /mnt/
cobbler import --path=/mnt --name=rhel-7 --arch=x86_64

#提取root密碼
root=`awk 'NR==23{print}' anaconda-ks.cfg`

#建立kickstarts自動安裝腳本
cat > /var/lib/cobbler/kickstarts/rhel-7-x86_64.ks <<'EOF'
auth --enableshadow --passalgo=sha512
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.66.130/cobbler/ks_mirror/rhel-7-x86_64
$yum_repo_stanza
reboot

## 此處密碼應爲本機系統anaconda-ks.cfg文件裏的 # Root password
rootpw --iscrypted $6$2WTFvfNvAMgCUPuC$MJgWGzhakgxrRObcEbAwSe8vkz0s//xyiTllGwxRsHHruQhcskO69u2LVTU9u0eemHXH2pzcGawyAJ54R2E/x0

selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr

%packages
@^minimal
@core
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
EOF

# 修改profile,將咱們新建的ks文件設爲默認的kickstarts安裝文件
cobbler profile edit --name rhel-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/rhel-7-x86_64.ks

# 配置網卡名稱爲傳統網卡名稱eth0
cobbler profile edit --name rhel-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'

# 同步cobbler
cobbler sync

# 爲避免發生未知問題,先把服務端全部服務重啓
systemctl restart xinetd
systemctl restart cobblerd
systemctl restart httpd
相關文章
相關標籤/搜索