Cobbler自動化安裝(linux)服務器

1、Cobbler簡介

Cobbler是一個免費開源系統安裝部署軟件,用於自動化網絡安裝操作系統。Cobbler 集成了 DNS, DHCP, 軟件包更新,帶外管理以及配置管理,方便操作系統安裝自動化。Cobbler 可以支持PXE啓動, 操作系統重新安裝,以及虛擬化客戶機創建,包括Xen, KVM or VMware. Cobbler透過koan程序以支持虛擬化客戶機安 裝。Cobbler可以支持管理複雜網路環境,如建立在鏈路聚合以太網的橋接環境。Cobbler可以用來快速建立 Linux 網絡安裝環境,它已將 Linux 網絡安裝的技術門檻,從大專以上文化水平,成功降低到初中以下,連補鞋匠都能學會。在生產環境中,經常批量部署幾十甚至上百臺服務器時,實現自動化安裝操作系統尤爲重要,按照傳統的光盤引導安裝工作量是不可預估的;此前我們通過pxe+kickstart簡單實現了自動化安裝,但只能實現單一版本安裝,當需要部署不同版本或不同引導模式(BIOS、EFI)時,此種方式就不夠靈活。而Cobbler正是爲了解決此問題而設計的。

2、Cobbler的組織架構:
Cobbler自動化安裝(linux)服務器

3、Cobbler安裝及配置
3.1、基本配置

[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
Disabled
[root@Cobbler ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor
preset: enabled)
[root@Cobbler ~]# hostname -I
10.0.0.10

3.2、yum源以及eple源

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

3.3、安裝Cobbler

yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd
systemctl start httpd.service
systemctl start cobbled.service
cobbler check
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.

3.4解決以上問題:

1、2問題的解決:
cp /etc/cobbler/settings{,.ori}
sed -i 's/server: 127.0.0.1/server: 10.0.0.10/' /etc/cobbler/settings
sed -i 's/next_server: 127.0.0.1/next_server: 10.0.0.10/' /etc/cobbler/settings
3問題的解決:
sed -i 's#yes#no#g' /etc/xinetd.d/tftp
4問題的解決:
cobbler get-loaders
5問題的解決
systemctl start rsyncd.service
systemctl enable rsyncd.service
7問題的解決
openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'
random-phrase-here 隨機字符串
your-password-here 密碼
openssl passwd -1 -salt 'zbjt' '123456'
$1$zbjt$LpJk4x1cplibx3q/O4O/K/
vim /etc/cobbler/settings
default_password_crypted: "$1$zbjt$LpJk4x1cplibx3q/O4O/K/"
6、8兩個暫時不用處理

後面要批量安裝服務器,所以還要對以下幾處內容進行修改:

管理dhcp
sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
防止重裝
sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
修改dhcp模板(以下展示的是修改後的內容,注意比對)
vim /etc/cobbler/settings
subnet 10.0.0.0 netmask 255.255.255.0 {
option routers 10.0.0.2;
option domain-name-servers 223.5.5.5;
option subnet-mask 255.255.255.0;
range dynamic-bootp 10.0.0.100 10.0.0.200;

注意:修改完成之後要用cobbler sync進行同步!

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
2 : 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.
將所有的服務重啓(啓動)
systemctl restart httpd.service
systemctl restart cobblerd.service
systemctl start dhcpd.service
systemctl restart rsyncd.service
systemctl start tftp.socket

注意:CentOS7使用https進行登錄
瀏覽器中輸入:https://10.0.0.10/cobbler_web登錄進入圖形化操作界面:用戶名密碼都是cobbler.
Cobbler自動化安裝(linux)服務器

4、掛載操作系統,進行批量安裝(主要採用圖形化操作)
4.1、掛載操作系統

      mount /dev/cdrom /mnt/
      df -h|grep mnt

Cobbler自動化安裝(linux)服務器

導入成功的標誌:

ls /var/www/cobbler/ks_mirror
CentOS-7.4-x86_64 config
由於CentOS7的網卡名稱不是默認的eth0,所以修改網卡名稱,操作過程如下:
Cobbler自動化安裝(linux)服務器Cobbler自動化安裝(linux)服務器

4.2編輯kickstart Templates模板
Cobbler自動化安裝(linux)服務器

具體內容爲:

cd /var/lib/cobbler/kickstarts/
vim CentOS-7.4-x86_64.cfg

Cobbler for Kickstart Configurator for CentOS 7.4 by wyyue

install
url --url=$tree
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
$SNIPPET('network_config')
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw --iscrypted $default_password_crypted
clearpart --all --initlabel
part /boot --fstype xfs --size 1024 --ondisk sda
part swap --size 1024 --ondisk sda
part / --fstype xfs --size 1 --grow --ondisk sda
firstboot --disable
selinux --disabled
firewall --disabled
logging --level=info
reboot

%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
$SNIPPET('pre_anamon')
%end

%packagesbr/>@base
@compat-libraries
br/>@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
iptraf
ncurses-devel
openssl-devel
zlib-devel
OpenIPMI-tools
screen
%end

%post
systemctl disable postfix.service
%end

注意:上述配置文件中不能有中文,不能有中文,不能有中文,註釋也不行!

4.3、自定義操作系統:
a、==============================
Cobbler自動化安裝(linux)服務器
b、==============================
Cobbler自動化安裝(linux)服務器
c、==============================
Cobbler自動化安裝(linux)服務器
d、==============================
Cobbler自動化安裝(linux)服務器

上述d、的圖中mac地址是創建空白虛擬機生成的:
Cobbler自動化安裝(linux)服務器

上述配置完成之後,要創建空白虛擬機,只要對應mac地址的虛擬機啓動就會自動安裝了。
創建空白虛擬機時要注意:紅框對應的√要去掉
Cobbler自動化安裝(linux)服務器

=================================================================
安裝畫面:
Cobbler自動化安裝(linux)服務器

=================================================================

以上都是基於圖形化的安裝,手動安裝如下:

mount /dev/cdrom /mnt/
df -h|grep mnt
cobbler import --path=/mnt/ --name=CentOS-7.4-x86_64 --arch=x86_64
cobbler distro list
CentOS-7.4-x86_64
kickstart的配置文件是一樣的
cobbler profile edit --name=CentOS-7.4-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.4-x86_64.cfg
cobbler profile edit --name=CentOS-7.4-x86_64 --kopts='net.ifnames=0 biosdevname=0'
cobbler profile report

cobbler sync

vim /etc/cobbler/pxe/pxedefault.template
MENU TITLE Cobbler|Welcome to Cobbleer(安裝界面,可自行選擇更改與否)
cobbler sync
cobbler system add --name=zbjt3 --mac=00:50:56:29:12:9A --profile=CentOS-7.4-x86_64 --interface=eth0 --static=1 --hostname=zbjt3.com --name-servers="8.8.8.8"
對應的mac地址虛擬機啓動就可以安裝了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章