天天看點

cobblercobbler介紹Cobbler工作流程Cobbler內建的服務配置檔案相關常用指令Cobbler安裝系統資訊配置yum源安裝相關軟體啟動服務檢查目前配置是否有問題根據提示解決問題配置DHCP導入鏡像導入kickstarts配置檔案

cobbler介紹

Cobbler是一個Linux伺服器快速網絡安裝的服務,由python開發,小巧輕便(15k行python代碼),可以通過PXE的方式來快速安裝、重裝實體伺服器和虛拟機,同時還可以管理DHCP,DNS,TFTP、RSYNC以及yum倉庫、構造系統ISO鏡像。Cobbler可以使用指令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),還提供了API接口,可以友善二次開發使用。

Cobbler工作流程

cobblercobbler介紹Cobbler工作流程Cobbler內建的服務配置檔案相關常用指令Cobbler安裝系統資訊配置yum源安裝相關軟體啟動服務檢查目前配置是否有問題根據提示解決問題配置DHCP導入鏡像導入kickstarts配置檔案

client裸機配置了從網絡啟動後,開機後會廣播包請求DHCP伺服器 (cobbler server)發送其配置設定好的一個IP

DHCP伺服器(cobbler server)收到請求後發送responese,包括其ip位址

client裸機拿到ip後再向cobbler server發送請求OS引導檔案的請求

cobbler server告訴裸機OS引導檔案的名字和TFTP server的ip和 port

client裸機通過上面告知的TFTP server位址通信,下載下傳引導檔案

client裸機執行執行該引導檔案,确定加載資訊,選擇要安裝的os, 期間會再向cobbler server請求kickstart檔案和os image

cobbler server發送請求的kickstart和os image

client裸機加載kickstart檔案

client裸機接收os image,安裝該os image

Cobbler內建的服務

PXE服務支援

DHCP服務管理

DNS服務管理(可選bind,dnsmasq)

電源管理

Kickstart服務支援

YUM倉庫管理

TFTP(PXE啟動時需要)

Apache(提供kickstart的安裝源,并提供定制化的kickstart配置)

配置檔案相關

配置檔案目錄:

/etc/cobbler

/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.template : dns伺服器的配置模闆

/etc/cobbler/tftpd.template : tftp服務的配置模闆

/etc/cobbler/modules.conf : 子產品的配置檔案

資料目錄:

/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 倉庫存儲目錄

日志目錄:

/var/log/cobbler/installing: 用戶端安裝日志

/var/log/cobbler/cobbler.log : cobbler日志

常用指令

cobbler commands 介紹

cobbler check 核對目前設定是否有問題

cobbler list 列出所有的cobbler元素

cobbler report 列出元素的詳細資訊

cobbler sync 同步配置到資料目錄,更改配置最好都要執行下

cobbler reposync 同步yum倉庫

cobbler distro 檢視導入的發行版系統資訊

cobbler system 檢視添加的系統資訊

cobbler profile 檢視配置資訊

Cobbler安裝

systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state
sed -i '/^SELINUX=.*/c SELINUX=disabled' /etc/selinux/config
sed -i 's/^SELINUXTYPE=.*/SELINUXTYPE=disabled/g' /etc/selinux/config
grep --color=auto '^SELINUX' /etc/selinux/config
setenforce 0           

系統資訊

[root@cobbler ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@cobbler ~]# uname -r
3.10.0-693.el7.x86_64
[root@cobbler ~]# getenforce
Permissive
[root@cobbler ~]# ifconfig ens33 | awk -F "[ :]+" 'NR==2 {print $3}'
192.168.26.80
[root@cobbler ~]# hostname
cobbler.example.com           

配置yum源

cd /etc/yum.repos.d/ && rm -rf *
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all && yum makecache           

安裝相關軟體

[root@cobbler ~]# yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web pykickstart           

啟動服務

[root@cobbler ~]# systemctl start httpd.service
[root@cobbler ~]# systemctl enable httpd.service
[root@cobbler ~]# systemctl enable cobblerd.service
[root@cobbler ~]# systemctl start cobblerd.service           

檢查目前配置是否有問題

[root@cobbler ~]# 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.
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.           

根據提示解決問題

問題1: 修改server的ip位址為本機ip

[root@cobbler ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.26.80/' /etc/cobbler/settings           

問題2:修改TFTP Server 的IP位址

[root@cobbler ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.26.80/' /etc/cobbler/settings           

問題3:啟用tftp

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

問題4:下載下傳缺失的檔案

[root@cobbler ~]# cobbler get-loaders     
task started: 2019-08-20_035058_get_loaders
task started (id=Download Bootloader Content, time=Tue Aug 20 03:50:58 2019)
path /var/lib/cobbler/loaders/README already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.elilo already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.yaboot already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.syslinux already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/elilo-ia64.efi already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/yaboot already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/pxelinux.0 already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/menu.c32 already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/grub-x86.efi already exists, not overwriting existing content, use --force if you wish to update
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***           

問題5:啟動rsync服務

[root@cobbler ~]#  systemctl enable rsyncd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[root@cobbler ~]# systemctl start rsyncd.service           

問題6:跟debian 相關,可以忽略

問題7:

[root@cobbler ~]# openssl passwd -1 -salt 'root' 'redhat'
$1$root$M1uN9dLHipbORRwJW/xR3/

[root@cobbler ~]# vim /etc/cobbler/settings 
default_password_crypted: "$1$root$M1uN9dLHipbORRwJW/xR3/" 
[root@cobbler ~]# systemctl restart cobblerd           

配置DHCP

[root@cobbler ~]# vim /etc/cobbler/settings
manage_dhcp: 1
[root@cobbler ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings           

修改dhcp模闆

[root@cobbler ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.26.0 netmask 255.255.255.0 {
     option routers             192.168.26.2;
     option domain-name-servers 192.168.26.2;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.26.100 192.168.26.254;           

重新開機所有服務,同步

[root@cobbler ~]# systemctl restart httpd.service
[root@cobbler ~]# systemctl restart cobblerd.service
[root@cobbler ~]# systemctl restart dhcpd.service
[root@cobbler ~]# systemctl restart rsyncd.service
[root@cobbler ~]# systemctl restart tftp.socket
[root@cobbler ~]# cobbler sync           

導入鏡像

[root@cobbler ~]# mount /dev/cdrom /mnt         
[root@cobbler ~]# cobbler import --path=/mnt --name=Centos-7.4 --arch=x86_64
[root@cobbler ~]# cobbler list
distros:
   Centos-7.4-x86_64

profiles:
   Centos-7.4-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:           

導入kickstarts配置檔案

[root@cobbler ~]# cd /var/lib/cobbler/kickstarts/
[root@cobbler kickstarts]# ls
default.ks    install_profiles  sample_autoyast.xml  sample_esxi4.ks  sample.ks
esxi4-ks.cfg  legacy.ks         sample_end.ks        sample_esxi5.ks  sample_old.seed
esxi5-ks.cfg  pxerescue.ks      sample_esx4.ks       sample_esxi6.ks  sample.seed
[root@cobbler kickstarts]# pwd
/var/lib/cobbler/kickstarts           

在電腦桌面建立一個Centos-7.4-x86_64.cfg文本添加以下内容

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$m1pE0DG6$vALBphGGynqvUzfJaWZ6U1
# Use network installation
url --url="$tree"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
# Network information
network  --bootproto=dhcp --device=eth0
network  --bootproto=dhcp --device=eth1
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --asprimary --fstype="ext4" --size=200
part swap --fstype="swap" --size=1024
part / --fstype="ext4" --grow --size=1
%packages
@base
@core
@compat-libraries
@debugging
@development
@gnome-desktop
@X Window System
%end           

使用rz工具導入配置檔案,也可使用xftp進行導入

[root@cobbler kickstarts]# rz -E             
rz waiting to receive.
[root@cobbler kickstarts]# ls
Centos-7.4-x86_64.cfg  install_profiles     sample_end.ks    sample_esxi6.ks  sample.seed.28
default.ks             legacy.ks            sample_esx4.ks   sample.ks
esxi4-ks.cfg           pxerescue.ks         sample_esxi4.ks  sample_old.seed
esxi5-ks.cfg           sample_autoyast.xml  sample_esxi5.ks  sample.seed           

檢視導入資訊及預設ks檔案

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

profiles:
==========
Name                           : Centos-7.4-x86_64
TFTP Boot Files                : {}
Comment                        :
DHCP Tag                       : default
Distribution                   : Centos-7.4-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              #預設的ks檔案,這裡需要修改為我們自己配置好的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

systems:
==========

repos:
==========

images:
==========

mgmtclasses:
==========

packages:
==========

files:
==========           

寫完 ks 檔案之後,先通過 validateks 測試一下有沒有文法錯誤

[root@cobbler kickstarts]# cobbler validateks           

編輯修改指定KS檔案為我們剛剛上傳的KS檔案Centos-7.4-x86_64.cfg

[root@cobbler kickstarts]# cobbler profile edit --name Centos-7.4-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos-7.4-x86_64.cfg           
[root@cobbler kickstarts]# cobbler profile edit --name Centos-7.4-x86_64 --kopts='net.ifnames=0 biosdevname=0'           
[root@cobbler ~]# systemctl restart cobblerd
[root@cobbler ~]# cobbler sync           
上一篇: cobbler
下一篇: Cobbler