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


 一、介紹

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

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

二、實驗環境

1、VMware Workstation虛擬機環境

2、CentOS7系統的虛擬PC作為Cobbler服務端,網卡使用NAT連接方式

三、前期准備

1、linux可以上網;

ping www.baidu.com

2、修改網卡配置,改為DHCP自動獲取ip;

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

重啟網絡服務

systemctl restart network.service

獲得本機IP

ifconfig

四、下載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

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

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

六、啟動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

七、檢查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

 八、重啟cobbler並同步不檢查

1 systemctl restart cobblerd
2 cobbler sync
3 cobbler check

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

九、通過cobbler來管理DHCP

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

十、配置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

十一、掛載導入鏡像

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

方法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命令查看(系統默認沒有這個命令,需要單獨安裝相應軟件包)

十二、驗證cobbler自動裝機

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

如果是物理機需要保證和服務器網絡暢通

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

十三、自定義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的方法:

方法1、 每安裝好一台Centos機器,Centos安裝程序都會創建一個kickstart配置文件,記錄你的真實安裝配置。如果你希望實現和某系統類似的安裝,可以基於該系統的kickstart配置文件來生成你自己的kickstart配置文件。(生成的文件名字叫anaconda-ks.cfg位於/root/anaconda-ks.cfg)

方法2、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更改都要執行同步

 

十四、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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM