一下內容是我根據其他博主的博客,和自己的實驗總結的cobbler批量部署的步驟。
1 關閉防火牆,關閉selinux
2 yum安裝相應的工具
yum install -y httpd dhcp tftp cobbler cobbler-web pykickstart xinetd
3 啓動tftp rsync xinetd
[root@bogon ~]# chkconfig tftp on
[root@bogon ~]# chkconfig rsync on
[root@bogon ~]# service xinetd start
4、 配置Cobbler主配置文件
在啓動Cobbler服務之前,你需要修改一些配置文件。在修改每一個文件之前最好先備份下當前的文件。
Cobblerd的配置文件爲/etc/cobbler/settings ,這個文件是YAML信息的格式文件。
根據需要修改 cobbler主配置文件: /etc/cobbler/settings
Server 和 Next_Server
server 選項用於爲cobbler 服務器指定ip地址,請不要使用0.0.0.0,設置一個你希望和cobbler服務器通過http和tftp等協議鏈接的IP。
# sed -i 's/server: 127.0.0.1/server: 192.168.200.1/g' /etc/cobbler/settings
next_server選項是DHCP/PXE網絡引導文件被下載的TFTP服務器的IP,在本例中它將和server設置爲同一個IP
# sed -i 's/next_server: 127.0.0.1/next_server: 192.168.200.1/g' /etc/cobbler/settings
防止誤重裝系統
pxe安裝只允許一次,防止誤操作 ( 在正式環境有用。實際測試來看,這個功能可以屏蔽掉 )
# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/g' /etc/cobbler/settings
生成root隨機密碼
命令格式 openssl passwd -1 -salt ‘隨機字符’ ‘密碼’
這個命令的用法,-salt後面跟隨機字符可以隨便寫,-1 代表用MD5加密,這個密碼就是安裝完系統root的密碼了
[root@bogon ~]# openssl passwd -1 -salt '12345678' 121121
$1$12345678$herNBEwHp2fzlPGLG.RXj1
將上面的加密串加入cobbler配置文件中。
# vi /etc/cobbler/settings
default_password_crypted: "$1$12345678$fEDuDQ4Xt2vqatvip.4XR0"
Cobbler管理rsync
默認爲0,不對rsync進行管理,可以修改爲1 進行管理
# sed -i 's/manage_rsync: 0/manage_rsync: 1/g' /etc/cobbler/settings
Cobbler管理dhcp
爲了pxe的啓動,需要一個DHCP服務器地址,並直接引導系統,它可以在網絡中下載引導文件到TFTP的服務器,cobbler可以通過manage_dhcp的設置來進行管理
配置dhcp服務
首先修改cobbler配置,讓cobbler來管理dhcp服務,在做自定義配置時,需要修改dhcp相關配置,以配合PXE啓動用,編輯文件/etc/cobbler/settings
manage_dhcp: 1 (注:默認爲0 ,表示不進行管理dhcp服務,可以修改爲1,對其進行管理。此爲使cobbler管理dhcp也就是後面用於同步更新配置信息[cobbler sync])
也可用命令修改:
# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/g' /etc/cobbler/settings
關閉cobbler管理dns
修改配置文件爲 manage_dns 0
5 修改cobbler管理DHCP的模板
/etc/cobbler/dhcp.template,此文件是cobbler管理dhcp的模板,確保DHCP分配的地址和Cobbler在同一網段
修改爲自己需要的配置
subnet 192.168.21.0 netmask 255.255.255.0 {
option routers 192.168.21.1;
option domain-name-servers 114.114.114.114;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.21.40 192.168.21.49;
如果是多網卡需要指定DHCP服務的網絡接口
#vi /etc/sysconfig/dhcpd
修改內容如下:
#Command line options here DHCPDARGS=eth0
DHCPDARGS=eth0
修改後要執行
cobbler sync
service dhcpd start
6 下載cobbler所需的引導文件
cobbler get-loaders
7 重啓cobbler服務
service cobblerd restart
8 執行下發配置命令
cobbler sync
9 執行檢查cobbler配置命令
cobbler check
根據報錯提示處理那些必須解決的問題
10 掛載鏡像文件(也可以掛載光驅)
[root@bogon ~]# mount -o loop -t iso9660 CentOS-6.8-x86_64-bin-DVD1.iso /mnt/centos6
[root@bogon ~]# mount -o loop -t iso9660 CentOS-7-x86_64-DVD-1611.iso /mnt/centos7
11 給cobbler導入系統鏡像
cobbler import --path=/mnt/centos6 --name=centos6.8 --arch=x86_64
cobbler import --path=/mnt/centos7 --name=centos7 --arch=x86_64
根據設備性能不同,時間長短也不同
主要有以下幾個參數--path 指定導入鏡像的路徑,--name 指定導入鏡像的名稱,--arch 指定導入鏡像的架構(32位還是64位)。這個安裝源的唯一標示就是根據--name和--arch這兩個參數來定義
12 查看導入的鏡像文件
[root@bogon ~]# cobbler profile list
centos6.8-x86_64
centos7-x86_64
13 查看cobbler倉庫中的系統版本信息
[root@bogon ~]# cobbler profile report
Name : centos7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : centos7-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks #這裏顯示此係統版本使用的是系統自帶的kickstart文件
14 編輯kcikstart.ks文件
最好在傳統安裝方式成功的操作系統中找到anaconda-ks.cfg文件,這個文件就是本機安裝時的ks文件,這個文件是不能直接用在網絡安裝中的,需要做對應更改
ks文件不能有中文
安裝方式使用http協議(這也是爲什麼要安裝httpd服務的一個原因),在制定url路徑的時候,要保證在瀏覽器端可以訪問系統鏡像所在的目錄。
虛擬機半成品的ks文件-cents6.5
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
url --url=http://192.168.21.19/mnt/centos6.5 //根據實際情況更改
lang zh_CN.UTF-8
keyboard us
network --onboot no --device eth0 --bootproto dhcp --noipv6
rootpw 121121 // root的加密密碼怎麼設置還不知道
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
reboot //這個位置必須要加reboot,否則安裝完會等待人工重啓
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# 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 --none
clearpart --all --initlabel //這個位置必須這麼寫,否則會讓你交互式的選擇安裝的磁盤
part /boot --fstype=ext4 --size=200 //分區還沒有按照預想的設置成功
part / --fstype=ext4 --grow --asprimary --size=10000
part swap --size=2000
repo --name="CentOS" --baseurl=http://192.168.21.19/mnt/centos6.5 --cost=100 //這個位置也必須按照實際情況修改
%packages //安裝包的安裝應該還可以簡化
@chinese-support
@console-internet
@core
@debugging
@hardware-monitoring
@network-tools
@performance
@server-policy
@workstation-policy
%end
dell服務器上安裝centos7的ks文件
#version=RHEL7
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
url --url=http://192.168.10.11/centos7
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
#Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8
# Network information
network --bootproto=dhcp --device=eno16777736 --ipv6=auto
network --hostname=localhost.localdomain
# Root password
rootpw 121121
reboot
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="xfs" --ondisk=sda --size=30720
part /boot --fstype="xfs" --ondisk=sda --size=500
part /usr --fstype="xfs" --ondisk=sda --size=48648
part swap --fstype="swap" --ondisk=sda --size=2048
part /home --fstype="xfs" --ondisk=sda --size=20480
part /var --fstype="xfs" --ondisk=sda --size=20480
repo --name="CentOS" --baseurl=http://192.168.10.11/centos7 --cost=100
%packages
@core
@debugging
@development
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
15 給鏡像文件指定ks文件
[root@zabbixandsvn kickstarts]# cobbler profile edit --name=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.kc.cfg