安装之前需要关闭防火墙、Selinux和更新安装epel源。
一、安装Cobbler以及其相关服务软件包
yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd rsync xinetd
二、启动相关服务
systemctl start httpd
systemctl enable httpd
systemctl start cobblerd
systemctl enable cobblerd
systemctl start xinetd
systemctl enable xinetd
三、检查cobbler环境
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 : enable and start rsyncd.service with systemctl
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
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.
解决上面问题步骤:
cp /etc/cobbler/settings{,.ori} # 备份cobbler配置文件
问题1: ip修改为cobber本机ip
sed -i 's/server: 127.0.0.1/server: 自己的IP地址/' /etc/cobbler/settings
问题2: next-server修改为tftp-server
sed -i 's/next_server: 127.0.0.1/next_server: 自己的IP地址/' /etc/cobbler/settings
问题 3:可忽略
问题4: 修改tftp配置文件
# 备份tftp配置文件
cp /etc/xinetd.d/tftp{,.ori}
sed -i '14c disable = no' /etc/xinetd.d/tftp
问题5: 准备bootloader
cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/cobbler/loaders/
cobbler get-loaders
问题6: 启动rsyncd
systemctl start rsyncd
systemctl enable rsyncd
问题7: 非Debain系统可以忽略,可忽略
问题8: 为系统设置复杂密码
openssl passwd -1 -salt 'hhm' 'hm0406120201'
$1$hhm$C5IaP23HRgRnAKcdBrKFp0
sed -i 's#$1$mF86/UHC$WvcIcX2t6crBz2onWxyac.# $1$hhm$C5IaP23HRgRnAKcdBrKFp0#g' /etc/cobbler/settings
问题9: 非Debain系统可以忽略,可忽略
sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
#防止系统被多次安装
sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
#修改cobbler修改dhcp配置文件选项设置
sed -i 's/ manage_dhcp: 0/ manage_dhcp: 1/' /etc/cobbler/settings
重启cobblerd
systemctl restart cobblerd
四、修改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; #对应的dns
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.1.100 192.168.1.254; #自己划分的IP段
default-lease-time 21600;
max-lease-time 43200;
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 if option pxe-system-type = 00:09 {
filename "grub/grub-x86_64.efi";
} else {
filename "pxelinux.0";
.........
五、sync服务同步生成DHCP配置文件
cobbler sync
六、导入ISO镜像文件
mkdir /mnt/sr0/
mount /dev/sr0 /mnt/sr0/
cobbler import --path=/mnt/sr0 --name=CentOS7-x86_64 --arch=x86_64
七、自定义ks文件(根据实际情况)
vim /var/lib/cobbler/kickstarts/CentOS7-x86_64.cfg
下面是一个ks模板,自己可以根据情况修改
install
url --url=$tree
text
lang en_US.UTF-8
keyboard us
zerombr
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
#Network information
$SNIPPET('network_config')
#network --bootproto=dhcp --device=eth0 --onboot=yes --noipv6 --hostname=CentOS7
timezone --utc Asia/Shanghai
authconfig --enableshadow --passalgo=sha512
rootpw --iscrypted $default_password_crypted
clearpart --all --initlabel
part /boot --fstype xfs --size 1024
part swap --size 1024
part / --fstype xfs --size 1 --grow
firstboot --disable
selinux --disabled
firewall --disabled
logging --level=info
reboot
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
@^minimal
@compat-libraries
@core
@debugging
@development
bash-completion
chrony
dos2unix
kexec-tools
lrzsz
nmap
sysstat
telnet
tree
vim
wget
%end
%post
systemctl disable postfix.service
%end
cobbler profile edit --name=CentOS7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS7-x86_64.cfg
cobbler sync
八、重启相关服务
systemctl restart cobblerd
systemctl restart dhcpd
systemctl restart xinetd
systemctl restart httpd