Cobbler無人值守

Cobbler介紹

Cobbler是一個Linux服務器安裝的服務,可以通過網絡啓動(PXE)的方式來快速安裝、重裝物理服務器和虛擬機,同時還可以管理DHCP,DNS等。

Cobbler可以使用命令行方式管理,也提供了基於Web的界面管理工具(cobbler-web),還提供了API接口,可以方便二次開發使用。

Cobbler是較早前的kickstart的升級版,優點是比較容易配置,還自帶web界面比較易於管理。

Cobbler內置了一個輕量級配置管理系統,但它也支持和其它配置管理系統集成,如Puppet,暫時不支持SaltStack。

Cobbler集成的服務

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

注意:
虛擬機網卡採用NAT模式,不要使用橋接模式,因爲稍後我們會搭建DHCP服務器,在同一局域網多個DHCP服務會有衝突。
VMware的NAT模式的dhcp服務也關閉,避免干擾。

cobbler功能介紹

  • 使用一個以前定義的模板來配置DHCP服務(如果啓用了管理DHCP)
  • 將一個存儲庫(yum或rsync)建立鏡像或解壓縮一個媒介,以註冊一個新操作系統
  • 在DHCP配置文件中爲需要安裝的機器創建一個條目,並使用您指定的參數(ip和mac地址)
  • 在TFTP服務目錄下創建適當的PXE文件
  • 重新啓動DHCP服務以反映更改 重新啓動機器以開始安裝(如果電源管理已啓用)

cobbler官網:http://cobbler.github.io/

環境

centos7
ip:10.0.0.43

Cobbler安裝配置

1、關閉防火牆和seliunx
[root@ c7-43 ~]# systemctl stop firewalld
[root@ c7-43 ~]# systemctl disable firewalld
[root@ c7-43 ~]# setenforce 0
[root@ c7-43 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

2、安裝cobbler

首先安裝 epel-release,Cobbler 和 tftp-server 在 base 源中是沒有的

[root@ c7-43 ~]# yum -y install epel-release

安裝 Cobbler 其實有一部分軟件會被當做依賴進行安裝上去,比如 tftp 和 httpd 服務,我們這裏爲了方便可以一併安裝,避免後續出現相關問題。

[root@ c7-43 ~]# yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd rsync xinetd

#cobbler #Cobbler 程序包
#cobbler-web #Cobbler 的 Web 服務包
#pykickstart #Cobbler 檢查 kickstart 語法錯誤
#httpd #Apache Web 服務

[root@ c7-41 ~]# rpm -ql cobbler  ##查看安裝的文件
/etc/cobbler                  # 配置文件目錄
/etc/cobbler/settings         # cobbler主配置文件,這個文件是YAML格式,Cobbler是python寫的程序。
/etc/cobbler/dhcp.template    # DHCP服務的配置模板
/etc/cobbler/tftpd.template   # tftp服務的配置模板
/etc/cobbler/rsync.template   # rsync服務的配置模板
/etc/cobbler/iso              # iso模板配置文件目錄
/etc/cobbler/pxe              # pxe模板文件目錄
/etc/cobbler/power            # 電源的配置文件目錄
/etc/cobbler/users.conf       # Web服務授權配置文件
/etc/cobbler/users.digest     # 用於web訪問的用戶名密碼配置文件
/etc/cobbler/dnsmasq.template # DNS服務的配置模板
/etc/cobbler/modules.conf     # Cobbler模塊配置文件
/var/lib/cobbler              # Cobbler數據目錄
/var/lib/cobbler/config       # 配置文件
/var/lib/cobbler/kickstarts   # 默認存放kickstart文件
/var/lib/cobbler/loaders      # 存放的各種引導程序
/var/www/cobbler              # 系統安裝鏡像目錄
/var/www/cobbler/ks_mirror    # 導入的系統鏡像列表
/var/www/cobbler/images       # 導入的系統鏡像啓動文件
/var/www/cobbler/repo_mirror  # yum源存儲目錄
/var/log/cobbler              # 日誌目錄
/var/log/cobbler/install.log  # 客戶端系統安裝日誌
/var/log/cobbler/cobbler.log  # cobbler日誌

###cobbler的配置文件
[root@ c7-41 ~]# cd /etc/httpd/conf.d/
[root@ c7-41 conf.d]# ls
autoindex.conf  cobbler.conf  cobbler_web.conf  README  ssl.conf  userdir.conf  welcome.conf
###如cobbler.conf、cobbler_web.conf

3、檢查配置Cobbler

[root@ c7-41 ~]# systemctl start httpd     ##啓動apache
[root@ c7-41 ~]# netstat -ntlp  | grep httpd   ##查看開啓服務
tcp6       0      0 :::443                  :::*                    LISTEN      2904/httpd
tcp6       0      0 :::80                   :::*                    LISTEN      2904/httpd
[root@ c7-41 ~]# systemctl start cobblerd         ##啓動cobbler
[root@ c7-41 ~]# cobbler check         ##檢查cobbler
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 kickstartingfeatures will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
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.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
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.
5 : enable and start rsyncd.service with systemctl
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
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.
##根據上圖可以看到,使用cobbler需要完成的9個步驟,一個一個解決。

現在開始解決

問題 1:修改 server 地址爲 10.0.0.43

# server,Cobbler服務器的IP。
[root@ c7-43 ~]# vim /etc/cobbler/settings
390行改: server: 10.0.0.43        
#或者sed -i 's/server: 127.0.0.1/server: 10.0.0.43/' /etc/cobbler/settings

問題 2:修改 next_server 地址爲 10.0.0.43

# next_server,如果用Cobbler管理DHCP,修改本項,作用不解釋,看kickstart。
[root@ c7-43 ~]# vim /etc/cobbler/settings
278行改:next_server: 10.0.0.43
###或者sed -i 's/next_server: 127.0.0.1/next_server: 10.0.0.43/' /etc/cobbler/settings

298行改:pxe_just_once: 1 #防止循環安裝

問題 3:修改 tftp 服務被 xinetd 服務管理

[root@ c7-41 ~]# vim /etc/xinetd.d/tftp
disable                 = no
###或者sed -i '14s/= yes/= no/'  /etc/xinetd.d/tftp

xinetd 和 tftpd 服務開機啓動

[root@ c7-43 ~]# systemctl start xinetd tftp && systemctl enable xinetd tftp

問題 4:下載操作系統引導文件

[root@ c7-43 ~]# cobbler get-loaders
task started: 2020-05-06_140250_get_loaders
task started (id=Download Bootloader Content, time=Wed May  6 14:02:50 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 ***

問題 5: rsyncd 服務爲開機自啓動狀態並啓用它

[root@ c7-43 ~]# systemctl start rsyncd && systemctl enable rsyncd

問題 6:關於 debian 相關部署管理配置,忽略。
debmirror package is not installed, it will be required to manage debian
deployments and repositories # debmirror 包尚未安裝,需要它來管理 debian 部署和存儲庫

問題 7:修改操作系統默認密碼

# 設置新裝系統的默認root密碼123456。 將生成的密碼寫入default_password_crypted
[root@ c7-43 ~]# openssl passwd -1 -salt 'cobbler' '123456'
$1$cobbler$sqDDOBeLKJVmxTCZr52/11
[root@ c7-43 ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$cobbler$sqDDOBeLKJVmxTCZr52/11"

問題 8:電源管理相關服務,忽略

4、配置DHCP

修改完以上配置就可以檢查 DHCP 配置了,由於 Cobbler 自動管理 DHCP 服務,我們只需要修改 Cobbler 中的模板配置文件即可

# 修改cobbler的dhcp模版,不要直接修改dhcp本身的配置文件,因爲cobbler會覆蓋。
[root@ c7-43 ~]# vim /etc/cobbler/dhcp.template
ssubnet 192.168.1.0 netmask 255.255.255.0 {
     option routers             10.0.0.254;
     option domain-name-servers 223.5.5.5,223.6.6.6;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.100 10.0.0.200;

修改 Cobbler 管理 dhcp 服務

[root@ c7-43 ~]# vim /etc/cobbler/settings
manage_dhcp: 1

同步cobbler配置

[root@ c7-43 ~]# systemctl restart cobblerd.service
# 同步最新cobbler配置,它會根據配置自動修改dhcp等服務。
[root@ c7-41 loaders]# cobbler sync       # 同步所有配置,可以仔細看一下sync做了什麼。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章