CentOS6.9上安裝cobbler2.6實現自動化安裝Linux系統
CentOS6.9上安裝cobbler2.6實現自動化安裝Linux系統
cobbler可以批量部署Linux系統,並實現無人值守安裝。
cobbler依賴的服務:dhcp,tftp,http,pxe,kickstart
服務對應的端口號為dhcp--67,68;tftp--69;http--80;cobbler--25151
1.環境準備:最小化安裝centos6.9mini,配置固定IP和本地yum源,關閉防火墻和selinux
iptables -F
setenforce 0
chkconfig iptables off
vi /etc/selinux/config 更改為permissive
2.設置yum源和epel源
這裏使用本地光盤作為yum源,也可以使用阿裏源,如下
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
cobbler安裝需要使用epel源,這裏使用阿裏的epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
3.安裝對應上述服務的軟件包
yum install -y cobbler cobbler-web pykickstart httpd dhcp tftp-server syslinux
cobbler #cobbler程序包
cobbler-web #cobbler的web服務包
pykickstart #cobbler檢查kickstart語法錯誤
httpd #Apache web服務
dhcp #dhcp服務
tftp-server #tftp服務
syslinux#pxe相關文件,如pxelinux.0
4.編輯cobbler的配置文件
vi /etc/cobbler/settings 更改如下參數:
default_kickstart: /var/lib/cobbler/kickstarts/default.ks
default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."
manage_dhcp: 1
manage_tftpd: 1
next_server: 192.168.10.24
server: 192.168.10.24
更改default_password默認密碼,即設置root密碼,格式為$1即md5加密,可以通過OpenSSL命令生成,如下:
openssl passwd -1 –salt centos
輸入密碼,如redhat
5.cobbler配置檢查,根據說明逐步更改設置,設置過的選項可以忽略
[[email protected] ~]# cobbler check
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 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
https://github.com/cobbler/cobbler/wiki/Selinux
4 : change ‘disable‘ to ‘no‘ in /etc/xinetd.d/tftp
5 : 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.
6 : change ‘disable‘ to ‘no‘ in /etc/xinetd.d/rsync
7 : file /etc/xinetd.d/rsync does not exist
8 : since iptables may be running, ensure 69, 80/443, and 25151 are unblocked
9 : debmirror package is not installed, it will be required to manage debian deployments and repositories
10 : 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
11 : 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.
如果不安裝Debian系統也可以忽略9.debmirror...錯誤;
由於網絡問題無法通過cobbler get-loaders命令下載文件的話,可以直接復制本機的文件。(這一步也可以省略,使用cobbler sync命令會自動執行如下的復制操作)
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
重啟cobblerd服務並執行同步操作
service cobblerd restart
cobbler sync
提示錯誤:2.service dhcpd is not running
6.配置dhcp服務,更改cobbler自帶的dhcp模板文件,更改subnet地址網段和地址範圍
vi /etc/cobbler/dhcp.template
subnet 192.168.10.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.10.100 192.168.10.254;
再次重啟cobbler服務並執行sync同步操作,cobbler會自動同步dhcp配置
重啟dhcpd服務,啟動xinetd服務
service dhcpd restart
service xinetd start
7.設置服務開機啟動
cobbler默認已設置開機啟動,需設置httpd和dhcpd服務開機啟動
chkconfig dhcpd on
chkconfig httpd on
檢查所有服務是否正常啟動,端口67,69,80,25151
netstat -tuanlp
或ss -tunlp
8.導入安裝文件
導入安裝光盤文件,因為要完全復制光盤文件,需要等待一段時間
cobbler import --path=/mnt/cdrom --name=centos6.9mini --arch=x86_64
ll /var/www/cobbler/ks_mirror/centos6.9mini-x86_64
更換光盤,導入centos6.9的安裝光盤文件
cobbler import --path=/mnt/cdrom --name=centos7.3mini --arch=x86_64
ll /var/www/cobbler/ks_mirror/centos7.3mini-x86_64
導入成功後查詢名稱
cobbler list
distros:
centos6.9mini-x86_64
centos7.3mini-x86_64
profiles:
centos6.9mini-x86_64
centos7.3mini-x86_64
查看詳細信息
cobbler distro report --name centos6.9mini-x86_64
cobbler profile report --name centos6.9mini-x86_64
導入成功後cobbler會自動生成ks文件和menu啟動菜單文件,默認最小化安裝系統。
/var/lib/cobbler/kickstarts/sample_end.ks
/var/lib/tftpboot/pxelinux.cfg/default
如果導入的是mini安裝光盤,則需要更改ks文件一個參數,即%packages後邊添加--nobase
vi /var/lib/cobbler/kickstarts/sample_end.ks
%packages --nobase
9.添加自定義的ks配置文件
更改自己的ks配置文件參數,更改url --url=$tree
增加配置文件,即啟動菜單項,並指定自定義的ks文件
cobbler profile add --name=centos6.9-custom --kickstart=/var/lib/cobbler/kickstarts/ks-69mini.ks --distro=centos6.9mini-x86_64
查看新增菜單項
cobbler profile list
centos6.9-custom
centos6.9mini-x86_64
centos7.3mini-x86_64
刪除啟動菜單項
cobbler profile remove --name=centos7.3-x86_64
至此所有cobbler配置已完成,可以新建一個虛擬機測試網絡無人值守安裝Linux系統。
本文出自 “rackie” 博客,請務必保留此出處http://rackie386.blog.51cto.com/11279229/1950307
CentOS6.9上安裝cobbler2.6實現自動化安裝Linux系統