当前环境介绍:
当前系统Centos7.5,关闭selinux,关闭firewalld(或自行设置相应规则),关闭当前路由dhcp功能,如果是虚拟机安装则网络适配器要选择NAT模式(因为同一局域网多个DHCP服务会有冲突),本机IP地址192.168.50.101
前提:cobbler由epel源提供,所以需要事先配置epel的yum源。
一、安装epel源
1 |
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo |
我这里使用的是阿里的epel源,你也可以直接yum install epel-release
二、安装cobbler
1 |
yum install cobbler cobbler-web pykickstart debmirror httpd dhcp tftp-server xinetd syslinux |
三、启动相关服务并设置开机自启
1 2 3 4 5 6 7 |
systemctl start httpd systemctl enable httpd systemctl start cobblerd systemctl enable cobblerd systemctl start rsyncd systemctl enable rsyncd systemctl enable dhcpd |
四、检查cobbler配置
通过cobbler自带的命令检查,而后逐一按提示解决。
1 |
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 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : 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.
5 : comment out 'dists' on /etc/debmirror.conf for proper debian support
6 : comment out 'arches' on /etc/debmirror.conf for proper debian support
7 : 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
8: 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.
如上各问题的解决方法如下所示:
1、修改/etc/cobbler/settings文件,将默认server的127.0.0.1替换为本机IP地址
1 |
sed -i 's#^server: 127.0.0.1#server: 192.168.50.101#' /etc/cobbler/settings |
2、修改/etc/cobbler/settings文件,将默认next_server的127.0.0.1替换为本机IP地址
1 |
sed -i 's#^next_server: 127.0.0.1#next_server: 192.168.50.101#' /etc/cobbler/settings |
3、将/etc/xinetd.d/tftp中disable改为no
1 |
disable = no |
4、执行“cobbler get-loaders”命令即可
1 |
cobbler get-loaders |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
task started: 2018-11-04_103455_get_loaders task started (id=Download Bootloader Content, time=Sat Nov 4 10:34:55 2018) downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0 downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32 downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi *** TASK COMPLETE *** |
5、注释/etc/debmirror.conf文件中的@dists="sid";一行
1 |
sed -i 's/@dists="sid";/#@dists="sid";/' /etc/debmirror.conf |
6、注释/etc/debmirror.conf文件中的@arches="i386";一行
1 |
sed -i 's/@arches="i386";/#@arches="i386";/' /etc/debmirror.conf |
7、设置新系统默认的root密码,执行“openssl passwd -1 -salt $(openssl rand -hex 4)”生成密码,并用其替换/etc/cobbler/settings文件中default_password_crypted参数的值;
1 2 3 |
openssl passwd -1 -salt $(openssl rand -hex 4) Password:whsir $1$7cbbc3f6$NDKbP8HqfR4/p6S6g9Mzd/ |
1 |
vi /etc/cobbler/settings |
1 |
default_password_crypted: "$1$7cbbc3f6$NDKbP8HqfR4/p6S6g9Mzd/" |
8、安装相应的程序包
1 |
yum install fence-agents |
五、重启cobblerd并同步检查
1 2 3 |
systemctl restart cobblerd cobbler sync cobbler check |
显示No configuration problems found. All systems go.(没有找到配置问题,一切正常)
六、通过cobbler来管理dhcp
1 |
sed -i 's#manage_dhcp: 0#manage_dhcp: 1#' /etc/cobbler/settings |
七、配置dhcp服务
1 |
vi /etc/cobbler/dhcp.template |
1 2 3 4 5 6 7 |
... subnet 192.168.50.0 netmask 255.255.255.0 { option routers 192.168.50.1; #网关地址 option domain-name-servers 114.114.114.114; #DNS option subnet-mask 255.255.255.0; #掩码 range dynamic-bootp 192.168.50.120 192.168.50.130; #网段 ... |
重启cobbler服务并同步配置
1 2 |
systemctl restart cobblerd cobbler sync |
八、挂载导入镜像
我这里已经上传好了一个镜像在root目录下
1 |
mount -r CentOS-7-x86_64-Minimal-1804.iso /mnt/ |
导入镜像,cobbler会将镜像中所有安装文件拷贝到/var/www/cobbler/ks_mirror/NAME目录下,因此/var/www/cobbler目录必须具有足够的空间
1 |
cobbler import --path=/mnt/ --name=CentOS-7.5-x86_64 --arch=x86_64 |
导入镜像完成后,可用下面命令查看到刚才导入的镜像
1 |
cobbler distro list |
九、编辑kickstart文件
我这里已经提前准备好了一份kickstart文件,文件内容如下
1 |
vi /var/lib/cobbler/kickstarts/CentOS-7.5-x86_64.cfg |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# Centos7 # This kickstart file should only be used with EL > 5 and/or Fedora > 7. # For older versions please use the sample.ks kickstart file. #platform=x86, AMD64, or Intel EM64T # System authorization information auth --useshadow --passalgo=sha512 # System bootloader configuration bootloader --location=mbr # Partition clearing information clearpart --all --initlabel # Use text mode install text # Firewall configuration firewall --disable # Run the Setup Agent on first boot firstboot --disable ignoredisk --only-use=sda # 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 # Network information $SNIPPET('network_config') # Reboot after installation reboot #Root password rootpw --iscrypted $default_password_crypted # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # System timezone timezone Asia/Shanghai # Install OS instead of upgrade install # Clear the Master Boot Record zerombr # Allow anaconda to partition the system as needed part /boot --fstype="xfs" --size=300 --ondisk=sda part swap --fstype="swap" --size=2048 --ondisk=sda part / --fstype="xfs" --grow --size=1 --ondisk=sda %pre $SNIPPET('log_ks_pre') $SNIPPET('kickstart_start') $SNIPPET('pre_install_network_config') # Enable installation monitoring $SNIPPET('pre_anamon') %end %packages @^minimal @core kexec-tools %end %post systemctl disable postfix.service %end |
十、修改kickstart文件为自定义的CentOS-7.5-x86_64.cfg
1 |
cobbler profile edit --name=CentOS-7.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.5-x86_64.cfg |
用cobbler profile report查看,Kickstart已经改变
十一、重启xinetd服务
1 |
systemctl restart xinetd |
至此为止配置完成,部分参数可根据情况自行进行修改
PS:
后续安装系统时如果提示TFTP timeout,请检查xinetd服务是否启动,netstat -lntpu是否可以看到69端口
如果出现/sbin/dmsquash-live-root: line 286: printf: write error: No space left on device因为内存不足2G的原因
完
原文链接:Cobbler部署详细教程基于Centos7.5,转载请注明来源!