Cobbler無人值守安裝centos6.8系統

Cobbler簡介

Cobbler是通過將DHCP、TFTP、DNS、HTTP等服務進行集成,創建一箇中央管理節點,其可以實現的功能有配置服務,創建存儲庫,解壓縮操作系統媒介,代理或集成一個配置管理系統,控制電源管理等。 Cobbler的最終目的是實現無需進行人工干預即可安裝機器。在進行進一步的操作之前,我們有必要先了解下pxe和kickstart 。

Cobbler是一個快速網絡安裝linux的服務,而且在經過調整也可以支持網絡安裝windows。該工具使用python開發,小巧輕便(才15k行python代碼),使用簡單的命令即可完成PXE網絡安裝環境的配置,同時還可以管理DHCP、DNS、TFTP、RSYNC以及yum倉庫、構造系統ISO鏡像。 Cobbler支持命令行管理,web界面管理,還提供了API接口,可以方便二次開發使用。 Cobbler客戶端Koan支持虛擬機安裝和操作系統重新安裝,同時支持服務器的電源管理,使重裝系統更便捷。更多內容可以查看cobbler官方網站!

cobbler官方網站

Cobbler功能:

pxe支持
dhcp管理
dns服務管理(bind,dnsmasq)
電源管理
kickstart支持
yum倉庫管理
tftp(pxe啓動時需要)
apache,提供ks得安裝源,並提供定製化得ks配置,同時,它和apache做了深度整合,通過cobbler,可以使redhat/centos/fedora系統得快速部署,同時也支持suse、debian(ubuntu)系統,通過配置開可以支持windows

Server端

啓動Cobbler服務
進行Cobbler錯誤檢查,執行cobbler check命令
進行配置同步,執行cobbler sync命令
複製相關啓動文件到TFTP目錄中
啓動DHCP服務,提供地址分配
DHCP服務分配IP地址
TFTP傳輸啓動文件
Server端接收安裝信息
Server端發送ISO鏡像與Kickstart文件

Client端

客戶端以PXE模式啓動
客戶端獲取IP地址
通過TFTP服務器獲取啓動文件
進入Cobbler安裝選擇界面
根據配置信息準備安裝系統
加載Kickstart文件
傳輸系統安裝的其它文件
進行安裝系統

環境部署

centos 7.7-1908 外網10.0.0.44 內網176.16.1.44
說明:虛擬機網卡採用NAT模式或者僅主機模式,不要使用橋接模式,因爲後面會搭建DHCP服務器,在同一個局域網多個DHCP服務會有衝突。VMware的NAT模式的dhcp服務也關閉,避免干擾。

安裝

[root@c7-44 ~]# yum -y install cobbler cobbler-web tftp-server pykickstart httpd dhcp xinetd debmirror
cobbler        #cobbler程序包
cobbler-web     #cobbler的web服務包
pykickstart    #cobbler檢查kickstart語法錯誤
httpd      	#Apache web服務
dhcp       #Dhcp服務
tftp      #tftp服務
xinetd  #諸多服務的超級守護進程

[root@c7-44 ~]# systemctl start httpd cobblerd            #啓動cobbler及httpd並加入開機啓動
[root@c7-44 ~]# systemctl enable httpd cobblerd

配置cobbler

檢查Cobbler的配置,如果看不到下面的結果,再次重啓cobbler。

[root@c7-44 ~]# 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 fe will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines thatuse it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other tha0.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 dowthem, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* verf the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want port all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' coms the easiest way to resolve these requirements.
5 : enable and start rsyncd.service with systemctl
6 : comment out 'dists' on /etc/debmirror.conf for proper debian support
7 : comment out 'arches' on /etc/debmirror.conf for proper debian support
8 : The default password used by the sample templates for newly installed machines (default_password_crypted in /bbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-herur-password-here'" to generate new one
9 : fencing tools were not found, and are required to use the (optional) power management features. install cman ce-agents to use them

Restart cobblerd and then run 'cobbler sync' to apply changes.

看到上面出現的問題,然後一個一個的進行解決,先進行設置爲可以動態配置,也可以直接更改配置文件

[root@c7-44 ~]# sed -ri '/allow_dynamic_settings:/c\allow_dynamic_settings: 1' /etc/cobbler/settings
[root@c7-44 ~]# grep allow_dynamic_settings /etc/cobbler/settings
allow_dynamic_settings: 1
[root@c7-44 ~]# systemctl restart cobblerd

逐個解決上面的問題

[root@c7-44 ~]# cobbler setting edit --name=server --value=10.0.0.44      #1.配置server地址
[root@c7-44 ~]# cobbler setting edit --name=next_server --value=10.0.0.44    #2,配置next_server地址
[root@c7-44 ~]# sed -ri '/disable/c\disable = no' /etc/xinetd.d/tftp           #3.配置xinetd管理tftp
[root@c7-44 ~]# systemctl enable xinetd    
[root@c7-44 ~]# systemctl restart xinetd
[root@c7-44 ~]# cobbler get-loaders                # 4.boot-loaders 
[root@c7-44 ~]# systemctl start rsyncd           #5.啓動sync
[root@c7-44 ~]# systemctl enable rsyncd
[root@c7-44 ~]# sed -i 's#@dists="sid";#\#@dists="sid";#gp' /etc/debmirror.conf        #6和7.debian support
[root@c7-44 ~]# sed -i 's#@arches="i386";#\#@arches="i386";#g' /etc/debmirror.conf   
   #8.default_password_crypted
# 注意:這裏設置的密碼是clbbler安裝完系統後,默認root用戶初始化登錄密碼,用 openssl 生成一串密碼後加入到 cobbler 的配置文件(/etc/cobbler/settings)裏,替換 default_password_crypted 字段 
[root@c7-44 ~]# openssl passwd -1 -salt `openssl rand -hex 4` '123456'
$1$2a939c66$8/OJHSFoQfA86pRhHpt2j1
[root@c7-44 ~]# cobbler setting edit --name=default_password_crypted --value='$1$2a939c66$8/OJHSFoQfA86pRhHpt2j1'
[root@c7-44 ~]# yum -y install fence-agents           #9.安裝fencing tools
[root@c7-44 ~]# systemctl restart cobblerd
[root@c7-44 ~]# cobbler sync
[root@c7-44 ~]# cobbler check
No configuration problems found.  All systems go.

配置DHCP

[root@c7-44 ~]# cobbler setting edit --name=manage_dhcp --value=1
[root@c7-44 ~]# vim /etc/cobbler/dhcp.template
#修改一下幾處
subnet 10.0.0.0 netmask 255.255.255.0 {   #這裏改爲分配的網段和掩碼
     option routers             10.0.0.254;  #如果有網關,這裏改爲網關地址
     option domain-name-servers 223.5.5.5;   #如果有DNS,這裏改爲DNS地址
     option subnet-mask         255.255.255.0;  #改爲分配的IP的掩碼
     range dynamic-bootp        10.0.0.100 10.0.0.200;  #改爲分配的IP的範圍

同步cobbler配置

[root@c7-44 ~]# cobbler sync

查看一下dhcp,查看cobbler是否可以管理dhcp

[root@c7-44 ~]# cat /etc/dhcp/dhcpd.conf
# ******************************************************************
# Cobbler managed dhcpd.conf file
# generated from cobbler dhcp.conf template (Fri Apr 24 08:34:20 2020)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
# ******************************************************************

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 10.0.0.0 netmask 255.255.255.0 {
     option routers             10.0.0.254;
     option domain-name-servers 223.5.5.5;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.100 10.0.0.200;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                10.0.0.44;
     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 {
                  filename "ia64/elilo.efi";
          } else if option pxe-system-type = 00:06 {
                  filename "grub/grub-x86.efi";
          } else if option pxe-system-type = 00:07 {
                  filename "grub/grub-x86_64.efi";
          } else if option pxe-system-type = 00:09 {
                  filename "grub/grub-x86_64.efi";
          } else {
                  filename "pxelinux.0";
          }
     }

}

# group for Cobbler DHCP tag: default
group {
}

cobbler命令幫助

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

這時候創建一個新虛擬機可以獲取到如下信息,沒有鏡像選擇,只能從本地啓動。
在這裏插入圖片描述

Cobbler安裝centos6.8

注意:由於我這臺是在centos7系統上面配置的cobbler,並沒有centos6.8鏡像,所以需要上傳了一個centos6.8的鏡像並進行掛載。

創建掛載點並掛載

[root@cobbler ~]# ll
total 3824644
-rw-------. 1 root root       1273 Apr 17 14:41 anaconda-ks.cfg
-rw-r--r--  1 root root 3916431360 Apr 24 16:44 CentOS-6.8-x86_64-bin-DVD1.iso
[root@cobbler ~]# mkdir /centos6.8/
[root@cobbler ~]# mount -o loop CentOS-6.8-x86_64-bin-DVD1.iso /centos6.8

查看掛載後的目錄

[root@cobbler ~]# ls /centos6.8/
CentOS_BuildTag  isolinux                  RPM-GPG-KEY-CentOS-Debug-6
EFI              Packages                  RPM-GPG-KEY-CentOS-Security-6
EULA             RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Testing-6
GPL              repodata                  TRANS.TBL
images           RPM-GPG-KEY-CentOS-6

導入鏡像

[root@cobbler ~]# cobbler import --path=/centos6.8 --name=centos6.8 --arch=x86_64
# --path 鏡像路徑
# --name 爲安裝源定義一個名字
# --arch 指定安裝源是32位、64位、ia64, 目前支持的選項有: x86│x86_64│ia64
# 安裝源的唯一標示就是根據name參數來定義,本例導入成功後,安裝源的唯一標示就是:centos6.8,如果重複,系統會提示導入失敗。

查看導入後鏡像信息

[root@cobbler ~]# cobbler distro report --name=centos6.8-x86_64
Name                           : centos6.8-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/centos6.8-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/centos6.8-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/centos6.8-x86_64'}
Management Classes             : []
OS Version                     : rhel6
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

查看profile信息

[root@cobbler ~]# cobbler profile report --name=centos6.8-x86_64
Name                           : centos6.8-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : centos6.8-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.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

編輯centos6.8鏡像的kickstart文件

[root@cobbler ~]# cd /var/lib/cobbler/kickstarts/
[root@cobbler kickstarts]# cp sample_end.ks centos6.8.ks
[root@cobbler kickstarts]# vim centos6.8.ks
# This kickstart file should only be used with EL > 5 and/or Fedora > 7.
# For older versions please use the sample.ks kickstart file.
# Install OS instead of upgrade
install
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# System timezone
timezone  Asia/ShangHai
#Root password
rootpw --iscrypted $default_password_crypted
# System authorization information
auth  --useshadow  --enablemd5
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Use network installation
url --url=$tree

# Clear the Master Boot Record
zerombr
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
part /boot --fstype=ext4 --size=200
part swap --fstype=swap --size=2048
part / --fstype=ext4 --grow --size=200 --asprimary

# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Do not configure the X Window System
skipx
# Run the Setup Agent on first boot
firstboot --disable
# Reboot after installation
reboot


%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end

%packages
$SNIPPET('func_install_if_enabled')
@core
@base
tree
nmap
wget
lftp
lrzsz
telnet
%end

%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end

%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps

sed -ri "/^#UseDNS/c\UseDNS no" /etc/ssh/sshd_config
sed -ri "/^GSSAPIAuthentication/c\GSSAPIAuthentication no" /etc/ssh/sshd_config
%end

# 動態編輯指定使用新的kickstart文件
[root@cobbler kickstarts]# cobbler profile edit --name=centos6.8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.8.ks
[root@cobbler kickstarts]# cobbler profile report --name=centos6.8-x86_64 |grep Kickstart   # 驗證是否更改成功
Kickstart                      : /var/lib/cobbler/kickstarts/centos6.8.ks
Kickstart Metadata             : {}

同步cobbler配置

[root@cobbler kickstarts]# cobbler sync

新建虛擬機進行測試

在這裏插入圖片描述
用鍵盤方向鍵選擇安裝的系統,如果超時未選擇,默認不安裝,安裝完後即可登錄系統。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章