一、Cobbler簡介linux
Cobbler是一個免費開源系統安裝部署軟件,用於自動化網絡安裝操做系統。Cobbler 集成了 DNS, DHCP, 軟件包更新,帶外管理以及配置管理,方便操做系統安裝自動化。Cobbler 能夠支持PXE啓動, 操做系統從新安裝,以及虛擬化客戶機建立,包括Xen, KVM or VMware. Cobbler透過koan程序以支持虛擬化客戶機安 裝。Cobbler能夠支持管理複雜網路環境,如創建在鏈路聚合以太網的橋接環境。Cobbler能夠用來快速創建 Linux 網絡安裝環境,它已將 Linux 網絡安裝的技術門檻,從大專以上文化水平,成功下降到初中如下,連補鞋匠都能學會。在生產環境中,常常批量部署幾十甚至上百臺服務器時,實現自動化安裝操做系統尤其重要,按照傳統的光盤引導安裝工做量是不可預估的;此前咱們經過pxe+kickstart簡單實現了自動化安裝,但只能實現單一版本安裝,當須要部署不一樣版本或不一樣引導模式(BIOS、EFI)時,此種方式就不夠靈活。而Cobbler正是爲了解決此問題而設計的。ios
二、Cobbler的組織架構:web
三、Cobbler安裝及配置
3.一、基本配置vim
[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.二、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.三、安裝Cobbler架構
yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd
systemctl start httpd.service
systemctl start cobbled.service
cobbler check
check以後會出現如下問題,逐步解決就能夠:app
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.dom
3.4解決以上問題:
一、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/"
六、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.
四、掛載操做系統,進行批量安裝(主要採用圖形化操做)
4.一、掛載操做系統
mount /dev/cdrom /mnt/ df -h|grep mnt
導入成功的標誌:
ls /var/www/cobbler/ks_mirror
CentOS-7.4-x86_64 config
因爲CentOS7的網卡名稱不是默認的eth0,因此修改網卡名稱,操做過程以下:
4.2編輯kickstart Templates模板
具體內容爲:
cd /var/lib/cobbler/kickstarts/
vim CentOS-7.4-x86_64.cfgCobbler 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-librariesbr/>@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.三、自定義操做系統:
a、==============================
b、==============================
c、==============================
d、==============================
上述d、的圖中mac地址是建立空白虛擬機生成的:
上述配置完成以後,要建立空白虛擬機,只要對應mac地址的虛擬機啓動就會自動安裝了。
建立空白虛擬機時要注意:紅框對應的√要去掉
=================================================================
安裝畫面:
=================================================================
以上都是基於圖形化的安裝,手動安裝以下:
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 reportcobbler sync
vim /etc/cobbler/pxe/pxedefault.templateMENU TITLE Cobbler|Welcome to Cobbleer(安裝界面,可自行選擇更改與否)cobbler synccobbler 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地址虛擬機啓動就能夠安裝了。