剛進公司,聽同事提到cobbler,之前只知道有個PXE,後來在網上查找了一些資料,自己找了臺服務器測試了一下
Cobbler
部署環境 :
cobbler-server dell PowerEdge C6220
cobbler-server OS Centos6.4
cobbler_server ip : 192.168.1.100
cobbler安裝環境:
1、安裝epel
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh epel-release-6*.rpm
2、服務安裝
yum -y install cobbler httpd rsync tftp xinetd dhcp cman pykickstart
3、修改cobbler配置文件 /etc/cobbler/settings
sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings #開啓dhcp功能
sed -i 's/manage_rsync: 0/manage_rsync: 1/' /etc/cobbler/settings #開啓rsync功能
sed -i 's/next_server: 127.0.0.1/next_server: 192.168.1.100/' /etc/cobbler/settings #設置你的 tftp server 地址
sed -i 's/server: 127.0.0.1/server: 192.168.1.100/' /etc/cobbler/settings #cobbler_server 地址
4、開啓cobbler服務前需要做
service iptables stop #關閉防火牆
setenforce 0 #關閉selinux
/etc/xinetd.d/tftp
disable = no #開啓tftp服務
/etc/xinetd.d/rsync
disable = no #開啓 rsync 服務
openssl passwd -1 -salt 'cocosoa' '00001234' 生成系統安裝後的 root 密碼,cocosoa是干擾密碼,00001234是系統登錄密碼
vim /etc/cobbler/settings 編輯配置文件,將默認的密碼替換爲新生成的
default_password_crypted: "$1$cocosoa$oAeSzE7VLKwhMPiBEOJD81"
cobbler get-loaders #下載引導操作系統文件
yum install debmirror -y
vim /etc/debmirror.conf
#@dists="sid"; // 註銷
#@arches="i386"; // 註銷
配置dhcp服務,只需要修改cobbler的dhcp模板文件即可
vim /etc/cobbler/dhcp.template
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.5;
option domain-name-servers 192.168.1.1;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.1.100 192.168.1.254;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.1.122;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
if option pxe-system-type = 00:02 {
filename "ia64/elilo.efi";
} else if option pxe-system-type = 00:06 {
filename "grub/grub-x86.efi";
} else if option pxe-system-type = 00:07 {
filename "grub/grub-x86_64.efi";
} else {
filename "pxelinux.0";
}
}
}
注意修改之後,使用cobbler sync 同步下配置文件,不然dhcp無法啓動,會報錯
5、啓動服務
service httpd start 在配置文件中加入ServerName localhost:80
service cobbler start
chkconfig httpd on
chkconfig cobblerd on
chkconfig dhcpd on
chkconfig xinetd on
chkconfig tftp on
chkconfig iptables off
6、導入鏡像
cobbler import --path=/media --name=CentOS6.4 --arch=x86_64
touch /var/lib/cobbler/kickstarts/CentOS6.4.ks
cobbler profile add --name=centos6.4 --distro=CentOS6.4-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS6.4.ks
添加一個profile文件,並使用CentOS6.4-x86_64這個distro,並指定相應的ks文件,ks文件是事先準備好的
vim /etc/cobbler/pxe/pxedefault.template #編輯pxe模板
ONTIMEOUT centos6.4 #修改默認安裝的profile爲centos6.4,也就是說當你沒有選擇,超時操作後自動安裝此profile
7、編輯kickstarts文件 #可以自己寫
vim /var/lib/cobbler/kickstarts/CentOS6.4.ks
install
auth --useshadow --enablemd5
key --skip
bootloader --location=mbr
clearpart --all --initlabel
text
firewall --disabled
keyboard us
lang en_US
url --url=$tree
reboot
rootpw --iscrypted $1$cocosoa$oAeSzE7VLKwhMPiBEOJD81
selinux --disabled
timezone --isUtc Asia/Shanghai
zerombr
autopart
%packages
$SNIPPET('package')
cat /var/lib/cobbler/snippets/package
此文件裏寫入需要安裝的包
下面是擴展目錄,可以自己添加單獨的配置文件,方便管理
/var/lib/cobbler/snippets
$SNIPPET (文件名) 該文件要到/var/lib/cobbler/snippets下創建編輯。
# System authorization information
auth --useshadow --enablemd #用戶登錄認證
# System bootloader configuration
bootloader --location=mbr #mbr引導
# Partition clearing information
clearpart --all --initlabel #默認清除所以分區
# Use text mode install
text #默認以文本模式安裝
# Firewall configuration
firewall --enabled #防火牆默認開啓
# Run the Setup Agent on first boot
firstboot --disable #禁用啓動代理
# System keyboard
keyboard us #默認英文鍵盤
# System language
lang en_US #默認語言英文
# Use network installation
url --url=$tree #網絡安裝路徑
# If any cobbler repo definitions were referenced in the kickstart profile, include them here
$yum_repo_stanza #默認的yum倉庫
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot #安裝完成後重啓
#Root password
rootpw --iscrypted $default_password_crypted #密碼是我們/etc/cobbler/settings設置密碼
# SELinux configuration
selinux --disabled #默認關閉selinux
# Do not configure the X Window System
skipx #默認沒有安裝圖形界面
# System timezone
timezone America/New_York #默認時區是美國/紐約
# Install OS instead of upgrade
install #定義的是安裝系統而不是升級系統
# Clear the Master Boot Record
zerombr #默認清空所有的mbr
# Allow anaconda to partition the system as needed
autopart #默認自動分區
IT交流羣144486234