日常筆記-Centos7安裝cobbler-2.8

Cobbler安裝部署指南(Centos 7.2)

1. Cobbler介紹

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

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

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

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

Cobbler官網

1.1 Cobbler集成的服務

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

1.2 系統環境準備

[root@cobbler1 ~]# cat /etc/redhat-release     //系統版本
CentOS Linux release 7.2.1511 (Core) 
[root@cobbler1 ~]# uname -r                    //內核版本
3.10.0-327.18.2.el7.x86_64
[root@cobbler1 ~]# getenforce                  //檢測selinux是否關閉(必須關閉)
Disabled
[root@cobbler1 ~]# systemctl status firewalld    //檢測防火牆是否關閉(必須關閉)
● firewalld.service - firewalld - dynamic firewall daemon
     Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
     Active: inactive (dead)
[root@cobbler1 ~]# ifconfig eno16777736 | awk -F '[ :]+' 'NR==2{print $3}'
192.168.145.200
[root@cobbler1 ~]# hostname
cobbler1  

配置阿里雲的epel源

[root@cobbler1 ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

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

##2. Cobbler安裝配置

2.1 安裝Cobbler

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

2.2 配置Cobbler

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

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

第1、2、6問題的處理

  • 首先備份cobbler的配置文件
    [root@cobbler1 ~]# cp /etc/cobbler/settings{,.ori} # 備份

  • server,Cobbler服務器的IP。
  • next_server,如果用Cobbler管理DHCP,修改本項,作用不解釋,看kickstart。
  • 用Cobbler管理DHCP
  • 防止循環裝系統,適用於服務器第一啓動項是PXE啓動。
    [root@cobbler1 ~]# vim /etc/cobbler/settings 編輯配置文件
    272 next_server:192.168.145.200
    384 server: 192.168.145.200
    242:manage_dhcp: 1
    292:pxe_just_once: 1

    [root@cobbler1 ~]# vim /etc/xinetd.d/tftp
    disable = no

    [root@cobbler1 ~]# systemctl start rsyncd
    [root@cobbler1 ~]# cobbler get-loaders

  • 設置新裝系統的默認root密碼cobbler。下面的命令來源於提示6。random-phrase-here爲干擾碼,可以自行設定。

    [root@cobbler1 ~]# openssl passwd -1 -salt 'cobbler' 'cobbler'
    $1$cobbler$M6SE55xZodWc9.vAKLJs6.

    [root@cobbler1 ~]# vim /etc/cobbler/settings
    default_password_crypted: "$1$oldboy$Npg9Pt9k98Mlg0ZeqHAuN1"

第3個問題

[root@cobbler1 ~]# cobbler get-loaders  # 會自動從官網下載
[root@cobbler1 ~]# cd /var/lib/cobbler/loaders/  # 下載的內容
[root@cobbler1 loaders]# ls
COPYING.elilo     COPYING.yaboot  grub-x86_64.efi  menu.c32    README
COPYING.syslinux  elilo-ia64.efi  grub-x86.efi     pxelinux.0  yaboot

第4個問題

[root@cobbler1 ~]# vim /etc/xinetd.d/rsync
disable = no
[root@cobbler1 ~]# systemctl restart xinetd

[root@cobbler1 ~]# systemctl restart cobblerd

[root@cobbler1 ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : debmirror package is not installed, it will be required to manage debian deployments and repositories  # 和debian系統相關,不需要
2 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them # fence設備相關,不需要
Restart cobblerd and then run 'cobbler sync' to apply changes.

2.3 配置DHCP

  • 修改cobbler的dhcp模版,不要直接修改dhcp本身的配置文件,因爲cobbler會覆蓋。

[root@cobbler1 ~]# vim /etc/cobbler/dhcp.template

僅列出修改過的字段

subnet 192.168.145.0 netmask 255.255.255.0 {
 option routers             192.168.145.2;
 option domain-name-servers 192.168.145.2;
 option subnet-mask         255.255.255.0;
 range dynamic-bootp        192.168.145.210 192.168.145.220;
 default-lease-time         21600;
 max-lease-time             43200;
 next-server                $next_server;

2.4 同步cobbler配置

同步最新cobbler配置,它會根據配置自動修改dhcp等服務。
[root@cobbler1 ~]# cobbler sync   // 同步所有配置,可以仔細看一下sync做了什麼。
task started: 2018-12-11_133547_sync

task started (id=Sync, time=Tue Dec 11 13:35:47 2018)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/CentOS-7.1-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/CentOS-7.1-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying files for distro: CentOS-7.1-x86_64
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.1-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/CentOS-7.1-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.1-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/CentOS-7.1-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: CentOS-7.1-x86_64
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.1-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/CentOS-7.1-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/CentOS-7.1-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/CentOS-7.1-x86_64/initrd.img
Writing template files for CentOS-7.1-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: CentOS-7.1-x86_64
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.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
TASK COMPLETE

2.5 設置開機啓動

設置開機自動啓動,避免白辛苦一場
[root@cobbler1 ~]# systemctl enable dhcpd.service
[root@cobbler1 ~]# systemctl enable rsyncd.service
[root@cobbler1 ~]# systemctl enable tftp.service 
[root@cobbler1 ~]# systemctl enable httpd.service 
[root@cobbler1 ~]# systemctl enable cobblerd.service
[root@cobbler1 ~]# systemctl enable xinetd

將所有的服務重啓一遍,避免有服務忘了開啓
[root@cobbler1 ~]# systemctl restart dhcpd.service
[root@cobbler1 ~]# systemctl restart rsyncd.service
[root@cobbler1 ~]# systemctl restart tftp.service 
[root@cobbler1 ~]# systemctl restart httpd.service 
[root@cobbler1 ~]# systemctl restart cobblerd.service
[root@cobbler1 ~]# systemctl start xinetd

3. Cobbler的命令行管理

3.1 查看命令幫助

    [root@cobbler1 ~]# cobbler
    usage
    ======
        cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... 
            [add|edit|copy|getks*|list|remove|rename|report] [options|--help]
    cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help]
    [root@cobbler1 ~]# cobbler import --help  // 導入鏡像
    Usage: cobbler [options]

    Options:
      -h, --help            show this help message and exit
      --arch=ARCH           OS architecture being imported
      --breed=BREED         the breed being imported
      --os-version=OS_VERSION
                            the version being imported
      --path=PATH           local path or rsync location
      --name=NAME           name, ex 'RHEL-5'
      --available-as=AVAILABLE_AS
                            tree is here, don't mirror
      --kickstart=KICKSTART_FILE
                            assign this kickstart file
      --rsync-flags=RSYNC_FLAGS
                            pass additional flags to rsync

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

3.2 導入鏡像

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

[root@cobbler1 ~]# cobbler distro list # 查看鏡像列表
CentOS-7.1-x86_64

鏡像存放目錄,cobbler會將鏡像中的所有安裝文件拷貝到本地一份,放在/var/www/cobbler/ks_mirror下的CentOS-7.1-x86_64目錄下。因此/var/www/cobbler目錄必須具有足夠容納安裝文件的空間。

[root@cobbler1 ~]# cd /var/www/cobbler/ks_mirror/
[root@cobbler1 ks_mirror]# ll
total 4
dr-xr-xr-x 8 root root 4096 Dec 10  2015 CentOS-7.1-x86_64

drwxr-xr-x 2 root root 35 Dec 11 09:40 config

[root@cobbler1 ks_mirror]# ll CentOS-7.1-x86_64/
total 296
-r--r--r-- 1 root root     14 Dec 10  2015 CentOS_BuildTag
dr-xr-xr-x 3 root root     33 Dec 10  2015 EFI
-r--r--r-- 1 root root    215 Dec 10  2015 EULA
-r--r--r-- 1 root root  18009 Dec 10  2015 GPL
dr-xr-xr-x 3 root root     54 Dec 10  2015 images
dr-xr-xr-x 2 root root   4096 Dec 10  2015 isolinux
dr-xr-xr-x 2 root root     41 Dec 10  2015 LiveOS
dr-xr-xr-x 2 root root 204800 Dec 10  2015 Packages
dr-xr-xr-x 2 root root   4096 Dec 10  2015 repodata
-r--r--r-- 1 root root   1690 Dec 10  2015 RPM-GPG-KEY-CentOS-7
-r--r--r-- 1 root root   1690 Dec 10  2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root   2883 Dec 10  2015 TRANS.TBL

3.3 指定ks.cfg文件及調整內核參數

Cobbler的ks.cfg文件存放位置
[root@cobbler1 ks_mirror]# cd /var/lib/cobbler/kickstarts/
[root@cobbler1 kickstarts]# ll
total 56
-rw-r--r-- 1 root root  115 May  4  2018 default.ks
-rw-r--r-- 1 root root   22 May  4  2018 esxi4-ks.cfg
-rw-r--r-- 1 root root   22 May  4  2018 esxi5-ks.cfg
drwxr-xr-x 2 root root   54 Dec 10 21:41 install_profiles
-rw-r--r-- 1 root root 1424 May  4  2018 legacy.ks
-rw-r--r-- 1 root root  292 May  4  2018 pxerescue.ks
-rw-r--r-- 1 root root 2825 May  4  2018 sample_autoyast.xml
-rw-r--r-- 1 root root 1856 May  4  2018 sample_end.ks
-rw-r--r-- 1 root root    0 May  4  2018 sample_esx4.ks
-rw-r--r-- 1 root root  324 May  4  2018 sample_esxi4.ks
-rw-r--r-- 1 root root  386 May  4  2018 sample_esxi5.ks
-rw-r--r-- 1 root root  386 May  4  2018 sample_esxi6.ks
-rw-r--r-- 1 root root 1913 May  4  2018 sample.ks
-rw-r--r-- 1 root root 3419 May  4  2018 sample_old.seed
-rw-r--r-- 1 root root 6658 May  4  2018 sample.seed

在第一次導入系統鏡像後,Cobbler會給鏡像指定一個默認的kickstart自動安裝文件在/var/lib/cobbler/kickstarts下的sample_end.ks。
[root@cobbler1 ~]# cobbler list
distros:
CentOS-7.1-x86_64

profiles:
   CentOS-7.1-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

3.4 ks.cfg文件內容(參考)

[root@cobbler1 kickstarts]# vim CentOS-7.1-x86_64.cfg

[root@cobbler1 kickstarts]# cat CentOS-7.1-x86_64.cfg 
# kickstart template for Fedora 8 and later.
# (includes %end blocks)
# do not use with earlier distros

#platform=x86, AMD64, or Intel EM64T
# System authorization information
#auth  --useshadow  --enablemd5
authconfig --enableshadow --passalgo=sha512
# System bootloader configuration
bootloader --location=mbr --driveorder=sda --append="nomodeset crashkernel=auto rhgb quiet"
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot
logging --level=info

#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone  Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
#autopart
part /boot --fstype=ext4 --asprimary --size=200
part swap --asprimary --size=1024
part / --fstype=ext4 --grow --asprimary --size=200

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

%packages
@base
@compat-libraries
@core
@debugging
@development
@dial-up
@hardware-monitoring
@performance
@server-policy
sgpio
device-mapper-persistent-data
systemtap-client
tree
lrzsz
telnet
nmap
dos2unix
%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
%end

%post
systemctl disable postfix.service

$yum_config_stanza
%end

查看安裝鏡像文件信息

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

查看所有的profile設置

[root@cobbler1 ~]# cobbler profile report

查看指定的profile設置

[root@cobbler1 ~]# cobbler profile report --name=CentOS-7.1-x86_64
Name                           : CentOS-7.1-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : CentOS-7.1-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文件
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

編輯profile,修改關聯的ks文件

[root@cobbler1 ~]# cobbler profile edit --name=CentOS-7.1-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.1-x86_64.cfg

修改安裝系統的內核參數,在CentOS7系統有一個地方變了,就是網卡名變成eno16777736這種形式,但是爲了運維標準化,我們需要將它變成我們常用的eth0,因此使用下面的參數。但要注意是CentOS7才需要下面的步驟,CentOS6不需要。

[root@cobbler1 ~]# cobbler profile edit --name=CentOS-7.1-x86_64 --kopts='net.ifnames=0 biosdevname=0'

[root@cobbler1 ~]# cobbler profile report CentOS-7.1-x86_64
Name                           : CentOS-7.1-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : CentOS-7.1-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {'biosdevname': '0', 'net.ifnames': '0'}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/CentOS-7.1-x86_64.cfg
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

每次修改完都要同步一次

[root@cobbler1 ~]# cobbler sync

3.4 安裝系統

進行到這裏就可以安裝系統了!


日常筆記-Centos7安裝cobbler-2.8
日常筆記-Centos7安裝cobbler-2.8

4 Cobbler的Web管理界面的安裝與配置

    已經安裝cobbler-web軟件。
    訪問網址:https://192.168.145.200/cobbler_web
    默認用戶名:cobbler 默認密碼 :cobbler
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章