cobbler+pxe實機部署
- 需求場景
- 網絡環境
- cobbler所需元件介紹
-
- 基本環境部署
- DHCP配置
- 部署Centos7
需求場景
實驗室有多台伺服器在機櫃裡,如果一台一台裝,會十分麻煩。給出解決方案。cobbler+pxe
網絡環境
伺服器由一台三層交換機管理,分2個vlan.
如有使用路由器,記得關閉路由器dhcp功能
位址段為,192.168.1.0/24和192.168.2.0/24
伺服器有2張網卡,預設使用第一張。
在部署前需關閉交換機DHCP功能。
cobbler所需元件介紹
需部署的服務
cobbler (cobbler 的核心)
httpd (提供 cobbler 的 web 界面)
dhcpd (為自動安裝系統配置設定 IP 位址)
epel-release(為之提供yum源)
rsync (cobbler 需要同步資訊)
cobbler-web (cobbler 的一個 web 插件)
xinetd (為 rsync 和 tftp 的守護程序)
tftp (傳送安裝的一些檔案的 類似ftp)
基本環境部署
1.關閉防火牆和 selinux
systemctl stop firewalld
systemctl disable firewalld
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
2.cobbler 安裝
3.加入開機自啟并啟動
systemctl enable httpd cobblerd
systemctl start httpd cobblerd
4.滿足部署要求
如下:
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 : ksvalidator was not found, install pykickstart
8 : 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
9 : 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.</font>
這裡我們設定為可以動态配置
sed -ri '/allow_dynamic_settings:/c\allow_dynamic_settings: 1' /etc/cobbler/settings
grep allow_dynamic_settings /etc/cobbler/settings
systemctl restart cobblerd
開始解決問題
1.`cobbler setting edit --name=server --value=你目前伺服器ip位址`
2.`cobbler setting edit --name=next_server --value=你目前伺服器ip位址`
3.sed -ri '/disable/c\disable = no' /etc/xinetd.d/tftp
systemctl enable xinetd
systemctl restart xinetd
4. cobbler get-loaders
5. systemctl start rsyncd
systemctl enable rsyncd
6.可選
7.yum -y install pykickstart
8.重裝後系統的預設密碼配置
openssl passwd -1 -salt `openssl rand -hex 4` '000000'(密碼6個0)
$1$5b2b9b6c$jS20zul6Vx0eoeu.ejFKo0(複制這個)
cobbler setting edit --name=default_password_crypted --value=''$1$5b2b9b6c$jS20zul6Vx0eoeu.ejFKo0"
9.yum -y install fence-agents
DHCP配置
cobbler setting edit --name=manage_dhcp --value=1
vim /etc/cobbler/dhcp.template
直接修改cobbler的dhcp配置,他會直接覆寫
同步cobbler配置,它會根據配置自動修改dhcp等
這個時候可以建立一個虛拟機,橋接模式測試下是否出現如下頁面,注意不要挂載光驅
(此頁面為成功頁面)
部署Centos7
首先你需要上傳鏡像
我這裡的鏡像為: Centos7-2009-x86_64
挂載到任意目錄
鏡像導入cobbler指令
檢視鏡像
寫入安裝腳本
如下:
# Install OS instead of upgrade
install
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# System timezone
timezone Asia/ShangHai
#Root password
rootpw --iscrypted $default_password_crypted
# System authorization information
auth --useshadow --enablemd5
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Use network installation
url --url=$tree
# Clear the Master Boot Record
zerombr
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
#建議自行修改分區
clearpart --all --initlabel
part /boot --fstype=xfs --size=1000
part swap --fstype=swap --size=2048
part / --fstype=xfs --grow --size=20000
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Do not configure the X Window System
skipx
# Run the Setup Agent on first boot
firstboot --disable
# Reboot after installation
reboot
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
$SNIPPET('func_install_if_enabled')
@core
@base
tree
nmap
wget
lftp
lrzsz
telnet
%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
sed -ri "/^#UseDNS/c\UseDNS no" /etc/ssh/sshd_config
sed -ri "/^GSSAPIAuthentication/c\GSSAPIAuthentication no" /etc/ssh/sshd_config
%end
指定配置檔案
同步cobbler
伺服器重新開機BIOS開啟pxe(測試機最低配置雙核2G運)顯示如下界面,回車,開始安裝。