Cobbler服務(wù)器系統(tǒng) :Centos 6.8 64位
服務(wù)器IP地址:192.168.159.128
需要安裝部署的Linux系統(tǒng):
系統(tǒng)版本:centos6.8-x86_x64
Eth0 IP地址段:192.168.159.150-192.168.159.250
網(wǎng)關(guān):192.168.159.2
子網(wǎng)掩碼:255.255.255.0
DNS:192.168.159.128 114.114.114.114
在Cobbler服務(wù)器上操作
一、關(guān)閉selinux
Vim /etc/selinux/config
#SELINUX=enforcing #注釋掉
#SELINUXTYPE=targeted #注釋掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效
二、配置防火墻
Vim /etc/sysconfig/iptables #編輯
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT #ssh服務(wù)需要此端口
-A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT #http服務(wù)需要此端口
-A INPUT -m state --state NEW -m udp -p udp --dport 69 -j ACCEPT #tftp服務(wù)需要此端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 25151 -j ACCEPT #cobbler需要此端口
:wq #保存退出
/etc/init.d/iptables restart #最后重啟防火墻使配置生效
三、安裝cobbler
wget -O /etc/yum.repos.d/aliyunepel.repo http://mirrors.aliyun.com/repo/epel-6.repo #下載aliyun yum源
yum install -y cobbler tftp tftp-server xinetd dhcp httpd rsync cobbler-web #安裝cobbler
yum install -y pykickstart debmirror python-ctypes cman #安裝運(yùn)行cobbler需要的軟件包
四、配置Cobbler
1、設(shè)置http服務(wù)
Vim /etc/httpd/conf.d/wsgi.conf
LoadModule wsgi_module modules/mod_wsgi.so #取消前面的注釋
:wq! #保存退出
chkconfig httpd on #設(shè)置開(kāi)機(jī)啟動(dòng)
service httpd start #啟動(dòng)
2、設(shè)置tftp服務(wù)開(kāi)機(jī)啟動(dòng)
vim /etc/cobbler/tftpd.template #編輯
service tftp
{
disable = no #修改為no
socket_type = dgram
protocol = udp
wait = yes
user = $user
server = $binary
server_args = -B 1380 -v -s $args
per_source = 11
cps = 100 2
flags = IPv4
}
:wq! #保存退出
3、設(shè)置rsync服務(wù)開(kāi)機(jī)啟動(dòng)
vim /etc/xinetd.d/rsync #編輯配置文件,設(shè)置開(kāi)機(jī)啟動(dòng)rsync
service rsync
{
disable = no #修改為no
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
:wq! #保存退出
/etc/init.d/xinetd start #啟動(dòng)(CentOS中是以xinetd 來(lái)管理Rsync和tftp服務(wù)的)
4、配置cobbler相關(guān)參數(shù)
vi /etc/debmirror.conf #注釋掉 @dists 和 @arches 兩行
#@dists="sid";
#@arches="i386";
:wq! #保存退出
openssl passwd -1 -salt 'myredhat''12344321' #生成默認(rèn)模板下系統(tǒng)安裝完成之后root賬號(hào)登錄密碼
$1$myredhat$2LHloV2OJhLZQO.b1/yg9/ #記錄下這行,下面會(huì)用到
vim /etc/cobbler/settings #編輯,修改
default_password_crypted: "$1$myredhat$2LHloV2OJhLZQO.b1/yg9/"
next_server: 192.168.159.128
server: 192.168.159.128
manage_dhcp: 1
default_kickstart: /var/lib/cobbler/kickstarts/default.ks
:wq! #保存退出
5、配置dhcp服務(wù)器
vim /etc/cobbler/dhcp.template #編輯,修改
subnet 192.168.159.0 netmask 255.255.255.0 { #設(shè)置網(wǎng)段
option routers 192.168.159.2; #設(shè)置網(wǎng)關(guān)
option domain-name-servers 192.168.159.128,114.114.114.114 #設(shè)置dns服務(wù)器地址
option subnet-mask 255.255.255.0; #設(shè)置子網(wǎng)掩碼
range dynamic-bootp 192.168.159.150 192.168.159.250; #設(shè)置dhcp服務(wù)器IP地址租用的范圍
default-lease-time 21600; #默認(rèn)租約時(shí)間
max-lease-time 43200; #最大租約時(shí)間
next-server $next_server;
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";
}
}
}
:wq! #保存退出
vim /etc/sysconfig/dhcpd #指定DHCP服務(wù)的網(wǎng)絡(luò)接口
DHCPDARGS=eth0
:wq! #保存退出
dhcpd #測(cè)試dhcp服務(wù)器配置是否正確
chkconfig dhcpd on #設(shè)置開(kāi)機(jī)啟動(dòng)
chkconfig cobblerd on #設(shè)置開(kāi)機(jī)啟動(dòng)
cobbler get-loaders #安裝cobbler相關(guān)工具包,否則檢查cobbler配置會(huì)報(bào)錯(cuò)
service cobblerd start #啟動(dòng)cobbler
cobbler sync #同步配置文件到dhcp服務(wù)器
service dhcpd start #啟動(dòng)dhcp服務(wù)
五、掛載系統(tǒng)安裝鏡像到http服務(wù)器站點(diǎn)目錄
由于我使用的是虛擬機(jī)環(huán)境、直接掛載的ISO文件,所以直接掛載光盤(pán)
mkdir -p /var/www/html/os/Centos6.8 #創(chuàng)建掛載目錄
mount /dev/sr0 /var/www/html/os/Centos6.8 #掛載光盤(pán)
如果是下載到服務(wù)器的iso文件,掛載方法:
Mount -t iso9660 -o loop /usr/local/src/CentOS-6.8-x86_64-bin-DVD-1of2.iso /var/www/html/os/CentOS6.8 #掛載系統(tǒng)鏡像
vim /etc/fstab #添加以下代碼。實(shí)現(xiàn)開(kāi)機(jī)自動(dòng)掛載
/usr/local/src/CentOS-6.8-x86_64-bin-DVD-1of2.iso /var/www/html/os/CentOS6.8 iso9660 defaults,ro,loop 0 0
:wq! #保存退出
備注:重復(fù)上面的操作,把自己需要安裝的CentOS系統(tǒng)鏡像文件都掛載到/var/www/html/os/目錄下
六、創(chuàng)建kickstarts自動(dòng)安裝腳本
cd /var/lib/cobbler/kickstarts #進(jìn)入默認(rèn)Kickstart模板目錄
vim /var/lib/cobbler/kickstarts/centos-6.8-x86_64.ks #創(chuàng)建centos-6.8-x86_64.ks安裝腳本
# Kickstart file automatically generated by anaconda.
install
url --url=http://192.168.159.128/cobbler/ks_mirror/centos6.8-x86_64/
lang en_US.UTF-8
zerombr yes
key --skip
keyboard us
network --device eth0 --bootproto dhcp --onboot on
#network --device eth0 --bootproto static --ip 192.168.159.250 --netmask 255.255.255.0 --gateway 192.168.159.2 --nameserver 192.168.159.128 --hostname CentOS
rootpw --iscrypted $1$myredhat$2LHloV2OJhLZQO.b1/yg9/
firewall --enabled --port=22:tcp
authconfig --enableshadow --enablemd5
selinux --disabled
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --linux
clearpart --all --initlabel
part / --bytes-per-inode=4096 --fstype="ext4" --size=2048
part /boot --bytes-per-inode=4096 --fstype="ext4" --size=128
part swap --bytes-per-inode=4096 --fstype="swap" --size=500
part /data --bytes-per-inode=4096 --fstype="ext4" --grow --size=1
reboot
%packages
ntp
@base
@core
@dialup
@editors
@text-internet
keyutils
trousers
fipscheck
device-mapper-multipath
%post
七、導(dǎo)入系統(tǒng)鏡像到cobbler
cobbler import --path=/var/www/html/os/CentOS6.8 --name=CentOS-6.8-x86_64 --arch=x86_64 #導(dǎo)入系統(tǒng)鏡像文件,需要一段時(shí)間
cd /var/www/cobbler/ks_mirror #進(jìn)入系統(tǒng)鏡像導(dǎo)入目錄
命令格式:cobbler import --path=鏡像路徑 -- name=安裝引導(dǎo)名 --arch=32位或64位
重復(fù)上面的操作,把其他的系統(tǒng)鏡像文件導(dǎo)入到cobbler
八、設(shè)置profile,按照操作系統(tǒng)版本分別關(guān)聯(lián)系統(tǒng)鏡像文件和kickstart自動(dòng)安裝文件
在第一次導(dǎo)入系統(tǒng)鏡像時(shí),cobbler會(huì)給安裝鏡像指定一個(gè)默認(rèn)的kickstart自動(dòng)安裝文件
如:CentOS-6.8-x86_64版本的kickstart自動(dòng)安裝文件為:/var/lib/cobbler/kickstarts/sample.ks
cobbler profile report --name centos-6.8-x86_64 #查看profile設(shè)置
cobbler distro report --name centos-6.8-x86_64 #查看安裝鏡像文件信息
cobbler profile remove --name= centos-6.8-x86_64 #移除profile
cobbler profile add --name=centos-6.8-x86_64 --distro= centos-6.8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ centos-6.8-x86_64 .ks #添加
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.ks #編輯
命令:cobbler profile add|edit|remove --name=安裝引導(dǎo)名 --distro=系統(tǒng)鏡像名 --kickstart=kickstart自動(dòng)安裝文件路徑
--name:自定義的安裝引導(dǎo)名,注意不能重復(fù)
--distro:系統(tǒng)安裝鏡像名,用cobbler distro list可以查看
--kickstart:與系統(tǒng)鏡像文件相關(guān)聯(lián)的kickstart自動(dòng)安裝文件
#查看Cobbler列表
cobbler list
cobbler report
cobbler profile report
cobbler distro list
也可以圖形界面操作,訪問(wèn)http://192.168.159.128/cobbler_web/賬號(hào)密碼都是cobbler
登錄以后點(diǎn)擊Importer DVD (先掛載鏡像ISO),然后再Importer,點(diǎn)擊run。
導(dǎo)入完成后可以看到:
選擇左側(cè)profile配置ks文件
輸入你所需要的ks文件路徑
自動(dòng)化部署系統(tǒng)
九、客戶端從網(wǎng)絡(luò)啟動(dòng)后選擇對(duì)應(yīng)的文件開(kāi)始自動(dòng)部署
開(kāi)機(jī)之后,如下圖所示,根據(jù)需要選擇相應(yīng)的系統(tǒng)版本進(jìn)行安裝,安裝完成之后,系統(tǒng)會(huì)自動(dòng)重啟
安裝成功重啟以后,輸入設(shè)置的密碼,用戶名root
至此,Cobbler全自動(dòng)批量安裝部署Linux系統(tǒng)完成。
2017年4月13日 上午8:38 沙發(fā)
很榮幸來(lái)訪您的博客,留言只是證明我來(lái)過(guò)!
2017年4月17日 下午4:26 板凳
世事無(wú)常,但這個(gè)博客定能永保輝煌!
2017年4月21日 下午5:07 地板
時(shí)間飛快,轉(zhuǎn)眼年中就要到來(lái),祝你天天愉快!
我只想默默的拜讀您的博客!
2017年4月27日 下午3:52 5樓
你的博客讓人流連忘返!
2017年4月30日 上午7:32 6樓
閑著沒(méi)事,隨便逛逛,心靜自然涼。
2017年5月15日 上午10:02 7樓
受教了!呵呵!
2017年5月19日 下午5:20 8樓
古人日三省其身,我從博客里吸收養(yǎng)分!
2017年5月31日 下午5:20 9樓
很榮幸來(lái)到這里參觀!
2017年6月3日 下午4:02 10樓
學(xué)習(xí)是人前進(jìn)的助力,認(rèn)真拜讀咯!
2017年6月5日 下午4:14 11樓
相當(dāng)精彩的博客!