Cobbler圖文詳解安裝及遇到的問題說明

 1、介紹python

Cobbler是一個使用Python開發的開源項目,經過將部署系統所涉及的全部服務集中在一塊兒,來提供一個全自動批量快速創建linux系統的網絡環境,linux

Cobbler提供了DHCP管理,YUM管理,電源管理等功能,除此以外還支持命令行管理,WEB界面管理,cobbler相關軟件包由EPEL源提供。EPEL(Extra Pavkages for Enterprise Linux,企業版Linux的額外軟件包)是Fedora小組維護的一個軟件倉庫項目。爲RHEL/CentOS提供默認不提供的軟件包,安裝Cobbler除了EPEL源還須要CentOS自帶的網絡yum源以提供相關的依賴包。ios

2、實驗環境web

一、VMware Workstation虛擬機環境redis

二、CentOS7系統的虛擬PC做爲Cobbler服務端,網卡使用NAT鏈接方式apache

3、前期準備django

一、linux能夠上網;bootstrap

ping www.baidu.com

二、修改網卡配置,改成DHCP自動獲取ip;vim

vim /etc/sysconfig/network-scripts/ifcfg-ens33

重啓網絡服務centos

systemctl restart network.service

得到本機IP

ifconfig

4、下載epel源;

方式1,直接安裝

1 yum -y install epel-release    #安裝epel源
#若出現 /var/run/yum.pid已被鎖定 運行以下代碼便可:
rm -f /var/run/yum.pid
2 cd /etc/yum.repos.d/ #檢查該路徑下是否有兩個yum源:epel.repo epel-testing.repo 3 yum clean all && yum makecach #更新yum源,更新後就能夠安裝源

方式2,使用阿里的源

1 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

5、安裝cobbler及所需的服務軟件包

yum install cobbler cobbler-web pykickstart debmirror httpd dhcp tftp-server xinetd syslinux rsync -y

6、啓動apache服務,cobbler服務,關閉防火牆,關閉加強型功能並設置開機自啓

1 systemctl start httpd.service
2 systemctl enable httpd
3 systemctl start cobblerd.service
4 systemctl enable cobblerd
5 systemctl enable dhcpd
6 systemctl stop firewalld.service  #關閉防火牆
7 setenforce 0   #關閉SElinux

7、檢查cobbler配置,然後逐一按提示解決

1 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 : comment out 'dists' on /etc/debmirror.conf for proper debian support
6 : comment out 'arches' on /etc/debmirror.conf for proper debian support
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)編輯/etc/cobbler/settings文件,找到server選項,修改成提供服務的ip地址,即本機ip,不能是127.0.0.1

2)編輯/etc/cobbler/settings文件,找到next_server選項,修改成本機的ip地址,也不能是127.0.0.1

方法1:

1 sed -i 's#^server: 127.0.0.1#server: 192.168.50.101#' /etc/cobbler/settings
2 sed -i 's#^next_server: 127.0.0.1#next_server: 192.168.50.101#' /etc/cobbler/settings

方法2:

1 vim /etc/cobbler/settings

.

3)編輯/etc/xinetd/tftp文件,將文件中的disable字段的配置由yes改成no,並啓動xinetd服務

1 vim /etc/xinetd.d/tftp  #
2 systemctl start xinetd.service  #啓動xinetd服務

4)執行「cobbler get-loaders」命令便可,即下載引導操做系統,須要幾分鐘

1 cobbler get-loaders

5)註釋/etc/debmirror.conf文件中的@dists="sid";一行

1 sed -i 's/@dists="sid";/#@dists="sid";/' /etc/debmirror.conf

6)註釋/etc/debmirror.conf文件中的@arches="i386";一行

1 sed -i 's/@arches="i386";/#@arches="i386";/' /etc/debmirror.conf

7)設置新系統默認的root密碼,執行「openssl passwd -1 -salt $(openssl rand -hex 4)」生成密碼,並用其替換/etc/cobbler/settings文件中default_password_crypted參數的值;

  8)安裝相應的程序包

1 yum install fence-agents

 8、重啓cobbler並同步不檢查

1 systemctl restart cobblerd
2 cobbler sync
3 cobbler check

顯示No configuration problems found. All systems go.(沒有找到配置問題,一切正常)

9、經過cobbler來管理DHCP

1 sed -i 's#manage_dhcp: 0#manage_dhcp: 1#' /etc/cobbler/settings

10、配置DHCP服務

1 vi /etc/cobbler/dhcp.template

重啓cobbler服務並同步配置

systemctl restart cobblerd.service
systemctl restart dhcpd.service  #此服務有可能沒法重啓可忽略
systemctl restart httpd.service
systemctl restart xinetd.service

systemctl restart rsync.service
cobbler sync

11、掛載導入鏡像

將鏡像文件掛載到服務器上

方法1:直接將鏡像文件拷貝至root目錄下

1 mount -r CentOS-7-x86_64-Minimal-1804.iso /mnt/CentOS-7-x86_64/

方法2:將光驅中的內容進行掛載

1)設置CD/DVD設備狀態勾選已鏈接

2)使用df -h命令查看光盤是否掛載,便是否有/dev/sr*的盤符

1 umount  /dev/sr1 #先卸載
2 mkdir /mnt/ #建立cdrom掛載點
3 mount  /dev/sr1  /mnt/  #將光盤掛載到剛纔建立的cdrom
4 df-h    #查看當前掛載

導入ISO鏡像文件

使用cobbler的import命令從ISO安裝鏡像中導入安裝所須要的程序包。數據文件較大,需等待。

命令格式;cobbler import --path=鏡像路徑 --name=安裝引導名 --arch=32位或64位

--path表示鏡像所掛載的目錄

--name表示爲安裝源定義的名字

--arch表示指定安裝源是32位仍是64位,目前支持的選項:x86,x86_64,ia64.

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

cobbler會將鏡像中的全部安裝文件拷貝到本地一份,放在/var/www/cobbler/ks_mirrors下。所以/var/www/cobbler目錄必須具備足夠容納安裝文件的空間,若是空間不夠,能夠對/var/www/cobbler目錄進行移動,建軟連接來修改文件存儲位置。

導入鏡像後可經過cobbler list來查看導入的結果,

其中distro表示一個發行版,

profile表示kickstart配置文件

此時tftp服務器的共享目錄也有了啓動linux所需的文件,由於從OS安裝光盤導入時,同時會把內核vmlinuz和初始化鏡像文件initrd.img複製到tftp共享目錄下,

可使用tree命令查看(系統默認沒有這個命令,須要單獨安裝相應軟件包)

12、驗證cobbler自動裝機

新建一臺虛擬機PC進行驗證,不使用鏡像,網絡鏈接方式選擇NAT,注意內存選擇2G以上(不然會因內存不夠而安裝失敗)。而後開啓新建的虛擬機會出現cobbler畫面,選擇第二種回車繼續等待。

若是是物理機須要保證和服務器網絡暢通

等待一會系統就會自動安裝好了,案後輸入root用戶和以前設好的密碼進行登陸

十3、自定義KickStart文件

在上面的實驗中,咱們沒有進行任何的安裝配置,所有都是Cobbler幫助咱們完成的。但是在實際生產中,咱們對每臺主機的硬盤分區,安裝的軟件都有相應的要求,因此咱們須要本身來定製KickStart文件,這樣咱們就可以定製地批量安裝操做系統了。
咱們就利用實驗環境(CentOS 7.3)中的KickStart文件來定製咱們本身的KickStart文件。

1)Cobbler的ks.cfg文件存放位置

cd /var/lib/cobbler/kickstarts/ && ls #自帶不少
default.ks    install_profiles  sample_autoyast.xml  sample_esxi4.ks  sample_old.seed
esxi4-ks.cfg  legacy.ks         sample_end.ks(默認使用的ks文件)        sample_esxi5.ks  sample.seed
esxi5-ks.cfg  pxerescue.ks      sample_esx4.ks       sample.ks

提供兩種配置ks的方法:

方法一、 每安裝好一臺Centos機器,Centos安裝程序都會建立一個kickstart配置文件,記錄你的真實安裝配置。若是你但願實現和某系統相似的安裝,能夠基於該系統的kickstart配置文件來生成你本身的kickstart配置文件。(生成的文件名字叫anaconda-ks.cfg位於/root/anaconda-ks.cfg)

方法二、Centos提供了一個圖形化的kickstart配置工具。在任何一個安裝好的Linux系統上運行該工具,就能夠很容易地建立你本身的kickstart配置文件。kickstart配置工具命令爲redhat-config-kickstart(RHEL3)或system-config-kickstart(RHEL5/6/7)

# yum install system-config-kickstart #安裝

# yum groupinstall "X Window System" #安裝X Window圖形界面

# system-config-kickstart #運行kickstart配置

#筆者不喜歡使用Linux運行圖形化界面,浪費資源,有興趣的夥伴能夠研究一下

實例一(CentOS7.4 ks)

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymap=us --xlayouts='us'
# Root password
rootpw --iscrypted $1$ljohn$yBMDpKkntQ9jfV1ZAWKpU1
# Use network installation
url --url="http://192.168.137.38/cobbler/ks_mirror/CentOS-7.4-x86_64/"
# System language
lang en_US.UTF-8
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System services
services --disabled="chronyd"
ignoredisk --only-use=sda
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
#network  --bootproto=static --device=eth0 --gateway=192.168.137.1 --ip=192.168.137.40 --nameserver=8.8.8.8 --netmask=255.255.255.0  --activate
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --asprimary --fstype="xfs" --size=1024
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --grow --size=1
%packages
@^minimal
@core
%end

實例二(CentOS6.8 ks):

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.137.38/cobbler/ks_mirror/CentOS-6.8-x86_64/"
#repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100
# Root password
rootpw --iscrypted $1$ljohn$yBMDpKkntQ9jfV1ZAWKpU1
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
# System keyboard
keyboard us
# System language
lang en_US.UTF-8
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
#logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
#network  --bootproto=dhcp --device=eth1 --onboot=on
# System bootloader configuration
bootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda"
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=2048
part / --fstype="ext4" --grow --size=1
%packages --nobase
@core
%end

這兩個實例安裝包都使用了core的最小化版本安裝,能夠大大縮短系統部署時間,畢竟時間就是金錢。若是有須要的,能夠在packages後面添加一些經常使用的工具,這裏再也不贅述。

2)關聯鏡像與kickstart 文件,修改kickstart文件爲自定義的CentOS-7.5-x86_64.cfg

 # --name 咱們須要添加的啓動菜單的名字
 # --distro  咱們自定製的ks文件關聯的yum庫
 # --kickstart 咱們自定製的ks文件的路徑
cobbler profile edit --name=CentOS-7.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.5-x86_64.cfg
# 查看Cobbler中如今還有多少個啓動項
[root@localhost kickstarts]cobbler profile list
   centos6.9-x86_64
    centos7.3-x86_64
    centos7.3-x86_64-desktop

 

cobbler profile report --name CentOS-7.4-x86_64#查看鏡像是否存在,
cobbler profile report --name CentOS-6.8-x86_64
cobbler profile edit --name=CentOS-7.4-x86_64 --kopts='net.ifnames=0 biosdevname=0'#這裏還原centos7網卡名爲「eth0」
cobbler profile edit --name=CentOS-7.4-x86_64 --distro=CentOS-7.4-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.4-x86_64.cfg #關聯ks文件與對應的CentOS7.4鏡像
cobbler profile edit --name=CentOS-6.8-x86_64 --distro=CentOS-6.8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.8-x86_64.cfg
service cobbler sync #與cobbler sync做用相同,同步配置,每次對cobbler更改都要執行同步

 

十4、Cobbler的Web管理

cobbler web支持多種認證方式,下面介紹兩種用戶認證登陸cobbler web的方式

1)使用cobbler默認的authn_configfile模塊認證方式

cobbler web界面的身份認證和受權配置位於文件/etc/cobbler/modules.conf中,cobbler默認這種方式的認證

能夠直接使用htdigest命令添加cobbler用戶和密碼

而後重啓cobbler服務,apache服務便可

2)使用authn_pam模塊認證方式

首先須要在配置文件/etc/cobbler/modules.conf裏修改認證方式

而後添加系統用戶

以後在文件/etc/cobbler/users.conf中,將新添加的webuser用戶添加到admins組中,該組具備完整訪問權限

配置完成後重啓cobbler,apache服務,就能夠用webuser的身份登陸到cobbler web頁面了。

使用https://192.168.195.128/cobbler_web地址訪問cobbler web頁面,使用設定的用戶和密碼就能夠進行登陸,在web頁面進行相關配置。

附錄1:錯誤彙總

1)Cobbler 登陸web界面提示報錯「Internal Server Error」

有多是pythone-django版本問題

#下載pip.py
wget https://bootstrap.pypa.io/get-pip.py

#調用本地python運行pip.py腳本
python get-pip.py

#安裝pip
pip install Django==1.8.9

#查看pip版本號
python -c "import django; print(django.get_version())"

#重啓httpd
systemctl restart httpd

完美解決

附錄2:cobbler命令

# 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]
Cobbler 命令介紹:
cobbler get-loaders  #加載部分缺失的網絡boot-loaders
cobbler check          #檢查cobbler配置
cobbler sync            #同步配置到dhcp pxe和數據目錄
cobbler list              #列出全部的cobbler元素
cobbler import          #導入安裝的系統光盤鏡像
cobbler report          #列出各元素的詳細信息
cobbler distro          #查看導入的發行版系統信息
cobbler profile         #查看配置信息
cobbler system         #查看添加的系統信息
cobbler reposync       #同步yum倉庫到本地
cobbler signature update
cobbler --help           #得到cobbler的幫助
cobbler distro --help  #得到cobbler子命令的幫助
獲取幫助:
#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
相關文章
相關標籤/搜索