1. 程式人生 > >【親測可用】Cobbler自動批量部署Linux系統

【親測可用】Cobbler自動批量部署Linux系統

Cobbler web Cobbler 自動裝機 批量裝機 linux批量安裝

Cobbler是一個快速網絡安裝linux的服務,而且在經過調整也可以支持網絡安裝windows。該工具使用python開發,小巧輕便,使用簡單的命令即可完成PXE網絡安裝環境的配置,同時還可以管理DHCP、DNS、TFTP、RSYNC以及yum倉庫、構造系統ISO鏡像。

Cobbler支持命令行管理,web界面管理,還提供了API接口,可以方便二次開發使用。

Cobbler客戶端Koan支持虛擬機安裝和操作系統重新安裝,使重裝系統更便捷。

環境準備

  1. VMware 12 虛擬機
  2. Centos 7 操作系統(網卡模式:NAT模式;IP地址為:192.168.96.129)
  3. 軟件包: epel-release-latest-7.noarch.rpm 密 碼:fqw7

服務部署

  1. 安裝 epel-release-latest-7.noarch.rpm 軟件包(cobbler相關軟件包是由EPEL源提供的)

    rpm -ivh /mnt/epel-release-latest-7.noarch.rpm
  2. 安裝cobbler cobbler-web dhcp tftp-server pykickstart httpd rsync xinetd軟件包
yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd rsync xinetd -y
  1. 修改cobbler主配置文件:
    vim /etc/cobbler/settings

next-server:192.168.96.129 #tftp服務器的ip地址
server:192.168.96.129 #服務器的ip地址
manage_dhcp:1 #開啟dhcp功能

  1. 使用cobbler check對cobbler做檢查設置
    cobbler check 

---------------------提示內容:需要優化-----------------------------------
The following are potential configuration items that you may want to fix:

1 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
https:#github.com/cobbler/cobbler/wiki/Selinux

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

3 : 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 haveinstalled 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.

4 : enable and start rsyncd.service with systemctl

5 : debmirror package is not installed, it will be required to manage debian deployments and repositories

6 : 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

7 : 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.

  1. 修改cobbler用戶的初始密碼,可以使用以下命令生成密碼
    openssl passwd -1 -salt ‘abc123‘ ‘abc123‘    #鹽值加密

$1$abc123$9v8z2./E/PZihXrVcy3II0 #加密後的密碼

將此密碼替換到settings文件中

default_password_crypted: "$1$abner$kDle2KnwbPHdm1UZEE79V." #替換密碼,此為root用戶密碼
:wq! #保存退出

  1. 下載引導操作系統文件

    cobbler get-loaders 
  2. 啟動rsyncd服務

    systemctl start rsyncd.service
  3. 開啟tftp服務
    vim /etc/xinetd.d/tftp

    disable = no #將yes修改為no,啟用tftp

重啟xinetd服務

systemctl restart xinetd.service

  1. 編輯dhcp模板文件
    vim /etc/cobbler/dhcp.template       

    #cobbler控制的dhcp服務模板

subnet 192.168.96.0 netmask 255.255.255.0 {
option routers 192.168.96.1; #修改網關
option domain-name-servers 192.168.96.2; #修改DNS
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.96.100 192.168.96.200; #修改地址池
:wq! #保存退出

  1. 同步生成DHCP配置文件
    cobbler sync      
  2. 啟動dhcpd服務

    systemctl restart dhcpd.service    
  3. 加載系統光盤鏡像
    mount /dev/sr0 /mnt

    #導入iso鏡像

    cobbler import --path=/mnt/ --name=CentOS-7-x86_64 --arch=x86_64 

    #默認導入存放位置

    /var/www/cobbler/ks_mirror/CentOS-7-x86_64        

    技術分享圖片

#查看導入結果

cobbler list    

distros:
Centos-7-x86_64
profiles:
Centos-7-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:

#查看發行版本

cobbler distro list   

技術分享圖片

#安裝tree軟件包

yum install tree -y

tree /var/lib/tftpboot/images #查看內核和初始化文件在tftp server 共享目錄
└── Centos-7-x86_64
├── initrd.img
└── vmlinuz

cobbler profile report

Name : Centos-7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : Centos-7-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

#ks默認文件存放位置

/var/lib/cobbler/kickstarts/sample_end.ks 

#cobbler日誌文件所在位置

/var/log/cobbler/cobbler.log

關閉防火墻及安全功能

setenforce 0
systemctl stop firewalld.service

客戶端安裝完成後只具備字符界面
登錄賬戶名:root 密碼:abc123

Cobbler Web用戶設置

vim /etc/cobbler/modules.conf     

authn_configfile #默認就是模塊認證

htdigest -c /etc/cobbler/users.digest Cobbler maaiqiang
輸入兩次確認密碼(123123)

#重新啟動cobblerd、httpd服務

systemctl restart cobblerd.service
systemctl restart httpd.service


自動裝機

技術分享圖片
技術分享圖片
技術分享圖片
技術分享圖片
技術分享圖片
技術分享圖片
技術分享圖片

以下為Cobbler web管理平臺

技術分享圖片
技術分享圖片
技術分享圖片
技術分享圖片

【親測可用】Cobbler自動批量部署Linux系統