Cobbler 自動(dòng)裝機(jī)

基礎(chǔ)環(huán)境

# 使用 more 命令查看基礎(chǔ)系統(tǒng)版本信息
$ more /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core)

# 通過 getenforce 命令查看 selinux 是否禁用了
# 通過 vi /etc/selinux/config 命令進(jìn)行修改,然后重啟才生效
$ getenforce
Disabled

# 修改 hostname 臨時(shí)
$ hostname srv.cobbler.com
# 修改 hostname, 永久生效, 通過 vim /etc/hostname 修改其內(nèi)容即可。 

# 設(shè)置 aliyun 源
$ wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

安裝基礎(chǔ)軟件

  1. 執(zhí)行安裝命令
# 安裝 cobbler 相關(guān)內(nèi)容
$ yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd

# 安裝 django 庫, 實(shí)際版本以 cobbler-web 依賴為主
$ yum -y install python2-pip
$ pip install Django==1.8.9
  1. 查看安裝文件信息
# rpm -ql cobbler  # 查看安裝的文件,下面列出部分。
/etc/cobbler                  # 配置文件目錄
/etc/cobbler/settings         # cobbler主配置文件,這個(gè)文件是YAML格式,Cobbler是python寫的程序。
/etc/cobbler/dhcp.template    # DHCP服務(wù)的配置模板
/etc/cobbler/tftpd.template   # tftp服務(wù)的配置模板
/etc/cobbler/rsync.template   # rsync服務(wù)的配置模板
/etc/cobbler/iso              # iso模板配置文件目錄
/etc/cobbler/pxe              # pxe模板文件目錄
/etc/cobbler/power            # 電源的配置文件目錄
/etc/cobbler/users.conf       # Web服務(wù)授權(quán)配置文件
/etc/cobbler/users.digest     # 用于web訪問的用戶名密碼配置文件
/etc/cobbler/dnsmasq.template # DNS服務(wù)的配置模板
/etc/cobbler/modules.conf     # Cobbler模塊配置文件

# 可以在 /etc/cobbler/settings 中進(jìn)行修改
/var/lib/cobbler              # Cobbler數(shù)據(jù)目錄
/var/lib/cobbler/config       # 配置文件
/var/lib/cobbler/kickstarts   # 默認(rèn)存放kickstart文件
/var/lib/cobbler/loaders      # 存放的各種引導(dǎo)程序

/var/www/cobbler              # 系統(tǒng)安裝鏡像目錄
/var/www/cobbler/ks_mirror    # 導(dǎo)入的系統(tǒng)鏡像列表
/var/www/cobbler/images       # 導(dǎo)入的系統(tǒng)鏡像啟動(dòng)文件
/var/www/cobbler/repo_mirror  # yum源存儲(chǔ)目錄

/var/log/cobbler              # 日志目錄
/var/log/cobbler/install.log  # 客戶端系統(tǒng)安裝日志
/var/log/cobbler/cobbler.log  # cobbler日志
  1. 啟動(dòng)服務(wù)
# 服務(wù)啟動(dòng)并設(shè)置為開機(jī)自啟動(dòng)模式
[root@srv ~]# systemctl start httpd
[root@srv ~]# systemctl enable httpd
[root@srv ~]# systemctl start cobblerd
[root@srv ~]# systemctl enable cobblerd
# 檢查當(dāng)前狀態(tài)
[root@srv ~]# 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.
# 設(shè)置PXE文件
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.
# 設(shè)置tftp
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
# 把網(wǎng)絡(luò)的boot-loaders通過cobbler get-loaders后放在/var/lib/cobbler/loaders
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.
# 啟動(dòng)rsync服務(wù)
5 : enable and start rsyncd.service with systemctl
# 安裝 debmirror 包
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
# 配置裝機(jī)密碼
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
# 安裝 cman 或 fence-agents 工具包
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.

上述問題逐一按如下方式解決:

  • 備份并修改 /etc/cobbler/settings 文件
# 備份配置文件
[root@srv ~]# cp /etc/cobbler/settings{,.ori}
# 查看ip
[root@srv ~]# ip addr
[root@srv ~]# sed -i 's/server: 127.0.0.1/server: 172.19.114.130/' /etc/cobbler/settings
# tftp 服務(wù)位置
[root@srv ~]# sed -i 's/next_server: 127.0.0.1/next_server: 172.19.114.130/' /etc/cobbler/settings
# 是否開啟 dhcp 服務(wù)
[root@srv ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
# 預(yù)防將機(jī)器中的安裝循環(huán)配置為始終從網(wǎng)絡(luò)引導(dǎo)
[root@srv ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings

# 構(gòu)建裝機(jī)密碼
[root@srv ~]# openssl passwd -1 -salt 'cobboy' 'cobbler'
$1$cobboy$nm7lnHQbrcuc5J4z0Df2a/

# 修改裝機(jī)后默認(rèn)密碼
[root@srv ~]# cat /etc/cobbler/settings | grep "default_password_crypted"
default_password_crypted: "$1$cobboy$nm7lnHQbrcuc5J4z0Df2a/"
  • 修改 dhcp 配置

/etc/cobbler/dhcp.template 文件中如下內(nèi)容進(jìn)行修改:

# 修改為子網(wǎng)網(wǎng)段
subnet 172.xxx.xxx.0 netmask 255.255.255.0 {
     # 網(wǎng)關(guān)信息
     option routers             172.xxx.xxx.254;
     # DNS 服務(wù)
     option domain-name-servers 114.114.114.114;
     option subnet-mask         255.255.255.0;
     # 可分配的網(wǎng)段
     range dynamic-bootp        172.xxx.xxx.130 172.xxx.xxx.140;

多網(wǎng)卡主機(jī)配置如下:

$ cp /usr/lib/systemd/system/dhcpd.service /etc/systemd/system/
$ vi /etc/systemd/system/dhcpd.service
 ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid <your_interface_name(s)>
$ systemctl --system daemon-reload
$ systemctl restart dhcpd.service
  • 安裝周邊設(shè)施
# 下載網(wǎng)絡(luò)引導(dǎo)文件
$ cobbler get-loaders

# 安裝  fence-agents
yum install fence-agents -y
  • 安裝 debmirror
$ yum install debmirror -y

注釋掉 /etc/debmirror.conf 文件中的 'dists' 及 'arches', 如下:

# @dists="sid";
@sections="main,main/debian-installer,contrib,non-free";
# @arches="i386";
  • 檢測狀態(tài),同步配置
# 檢查配置內(nèi)容
[root@repo ~]# cobbler check
No configuration problems found.  All systems go.
# 同步配置相關(guān)的修改,并生成相應(yīng)的配置文件
[root@repo ~]# cobbler sync
task started: 2019-05-08_111445_sync
task started (id=Sync, time=Wed May  8 11:14:45 2019)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout: 
received on stderr: 
running: service dhcpd restart
received on stdout: 
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service

running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***
  • 關(guān)閉防火墻及使能cobblerd服務(wù)
systemctl stop firewalld
systemctl disable firewalld

systemctl restart rsyncd
systemctl enable rsyncd

systemctl start  dhcpd
systemctl enable dhcpd

systemctl restart  cobblerd
systemctl enable cobblerd

systemctl start  httpd
systemctl enable httpd

systemctl start  tftp
systemctl enable tftp
  1. WebUI 使用
  • WebUI 訪問出現(xiàn) 403 問題

僅支持 https 方式訪問,因此 https://<ip>/cobbler_web

  • WebUI 出現(xiàn) 500 Internal Server Error

通過查看 httpd 運(yùn)行日志,可知新安裝機(jī)器中不包含 django 包,安裝即可

# 安裝 django 包
yum -y install python2-pip
pip install Django==1.8.9
# 重啟 httpd
[root@web ~]# systemctl restart httpd
[root@web ~]# systemctl status httpd
  • WebUI 用戶密碼
# 查看用戶信息
$ cat /etc/cobbler/users.conf
[admins]
admin = ""
cobbler = ""

# 修改密碼為 cobbler
$ htdigest /etc/cobbler/users.digest "Cobbler" cobbler

重新登錄 https://<ip>/cobbler_web 用戶為 cobbler/cobbler 即可登錄。

鏡像管理

  1. 定制 PXE 顯示內(nèi)容

通過 vim /etc/cobbler/pxe/pxedefault.template 修改 MENU TITLE Cobbler | ... 內(nèi)容即可。

  1. 添加鏡像
[root@srv data]# mount -t iso9660 -o loop,ro  ./CentOS-7-x86_64-Minimal-1804.iso /mnt/
# 上述也可之間簡單 `mount -o loop CentOS-7-x86_64-Minimal-1804.iso /mnt`
[root@srv data]# cobbler import --path=/mnt/ --arch=x86_64 --name=centos7-mini --breed=redhat

導(dǎo)入成功后,會(huì)輸出:*** TASK COMPLETE *** 。

  1. 查看鏡像列表及其信息
# 鏡像列表
[root@srv data]# cobbler list
distros:
   centos7-mini-x86_64
profiles:
   centos7-mini-x86_64
...省略...

# 僅查看 profile 列表
[root@srv data]# cobbler profile list
   centos7-mini-x86_64

# 查看詳細(xì)信息
[root@srv data]# cobbler report
distros:
==========
Name                           : centos7-mini-x86_64
Architecture                   : x86_64
...省略...
Initrd                         : /var/www/cobbler/ks_mirror/centos7-mini-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/centos7-mini-x86_64/images/pxeboot/vmlinuz
...省略...

profiles:
==========
Name                           : centos7-mini-x86_64
...省略...
DHCP Tag                       : default
Distribution                   : centos7-mini-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
...省略...
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks
...省略...

# 僅查看 profile 列表
[root@srv data]# cobbler profile report centos7-mini-x86_64 | grep Kickstart
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks
Kickstart Metadata             : {}

從上述內(nèi)容可以才看到,導(dǎo)入的系統(tǒng)相關(guān)配置文件路徑為 /var/lib/cobbler/kickstarts/sample_end.ks 在該文件中進(jìn)行修改。

  1. 重裝系統(tǒng)
# 安裝 koan 客戶端
[root@srv data]# yum install koan

# 查看系統(tǒng)列表
[root@srv data]# koan --server=bootserver.example.com --list=profiles

# 重新替換安裝
[root@srv data]# koan --replace-self --server=bootserver.example.com --profile=centos7-mini-x86_64

# 重啟安裝系統(tǒng)
[root@srv data]# reboot

這時(shí),在啟動(dòng)項(xiàng)中會(huì)增加 kickXXXXXXXX 該項(xiàng)即為剛加入的啟動(dòng)項(xiàng)目。具體內(nèi)容可以查看 /boot/grub2/grub.cfg 文件。

  1. 定制啟動(dòng)流程
  • 創(chuàng)建 kickstart 文件
#Kickstart Configurator for cobbler by Jason Zhao
#platform=x86, AMD64, or Intel EM64T
#System  language
lang en_US
#System keyboard
keyboard us
#Sytem timezone
timezone Asia/Shanghai
#Root password
rootpw --iscrypted $default_password_crypted
#Use text mode install
text
#Install OS instead of upgrade
install
#Use NFS installation Media
url --url=$tree

#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr
#Partition clearing information
clearpart --all --initlabel
#Disk partitioning information
part /boot --fstype xfs --size 1024 --ondisk sda
part swap --size 16384 --ondisk sda
part / --fstype xfs --size 1 --grow --ondisk sda

#System authorization infomation
auth  --useshadow  --enablemd5
#Network information
$SNIPPET('network_config')
#network --bootproto=dhcp --device=em1 --onboot=on
# Reboot after installation
reboot
#Firewall configuration
firewall --disabled
#SELinux configuration
selinux --disabled
#Do not configure XWindows
skipx
#Package install information
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
 
%packages
@ base
@ core
#@chinese-support
wget
# sysstat
# iptraf
# ntp
# lrzsz
# ncurses-devel
# openssl-devel
# zlib-devel
# mysql
# nmap
# screen
%end
 
%post
# adds the yum repositories to the installed system
$yum_config_stanza
systemctl disable postfix.service
systemctl disable firewalld.service

# 執(zhí)行初始化腳本
rpm -ihv https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

# cobbler final steps
$SNIPPET('kickstart_done')
%end
  1. 內(nèi)網(wǎng) Yum 倉庫
  • 增加倉庫源
[root@srv ~]# cobbler repo add --name=Centos6-UPDATES --mirror=http://mirrors.aliyun.com/centos/6/updates/x86_64/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=Centos6-salt201611 --mirror=https://repo.saltstack.com/yum/redhat/6/x86_64/2016.11/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=Centos7-Base --mirror= https://mirrors.aliyun.com/centos/7/os/x86_64/ --arch=x86_64 --breed=rsync
[root@srv ~]# cobbler repo add --name=Centos7-extras  --mirror=https://mirrors.aliyun.com/centos/7/extras/x86_64/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=epel6-x86_64-testing --mirror=http://mirrors.aliyun.com/epel/testing/6/x86_64/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=Centos7-salt201707  --mirror=https://repo.saltstack.com/yum/redhat/7Server/x86_64/2017.7/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=Centos6-Base --mirror=http://mirrors.aliyun.com/centos/6/os/x86_64/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=epel6-x86_64 --mirror=http://mirrors.aliyun.com/epel/6/x86_64/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=Centos7-epel --mirror=https://mirrors.aliyun.com/epel/7Server/x86_64/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=Centos6-webtatic --mirror=http://sp.repo.webtatic.com/yum/el6/x86_64/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=Centos7-webtatic --mirror=https://sp.repo.webtatic.com/yum/el7/x86_64/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=Centos6-percona  --mirror=http://repo.percona.com/release/6Server/os/x86_64/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=Centos7-salt201611 --mirror=https://repo.saltstack.com/yum/redhat/7/x86_64/2016.11/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=Centos7-zabbix3 --mirror=http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=Centos6-extras  --mirror=http://mirrors.aliyun.com/centos/6/extras/x86_64/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=Centos6-zabbix3 --mirror=http://repo.zabbix.com/zabbix/3.4/rhel/6/x86_64/ --arch=x86_64 --breed=yum
[root@srv ~]# cobbler repo add --name=Centos7-percona --mirror=http://repo.percona.com/release/7Server/os/x86_64/ --arch=x86_64 --breed=yum

上述增加源的內(nèi)容可以通過 cobbler repo list 進(jìn)行查看。

  • 同步源鏡像
[root@srv ~]# cobbler reposync --only=Centos7-zabbix3
  1. 指定mac安裝
# 查看啟動(dòng)腳本
[root@srv ~]# ls /var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
# 添加新機(jī)器及其基礎(chǔ)網(wǎng)絡(luò)配置
[root@srv ~]# cobbler system add --name=n1.cobbler.com --mac=00:0c:29:f6:4a:00 --profile=centos7-mini-x86_64 --ip-address=172.xxx.xxx.131 --subnet=255.255.255.0 --gateway=172.xxx.xxx.254 --interface=eth0 --static=1 --hostname=n1.cobbler.com --name-servers="172.xxx.xxx.201" --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
# 查看機(jī)器名
[root@srv ~]# cobbler system list
   n1.cobbler.com

然后開機(jī)網(wǎng)絡(luò)啟動(dòng)即可。上述修改后通過 cobbler sync 命令進(jìn)行同步,

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容