1. 先安装cobbler和dhcp包
[root@centos ~]#yum install -y cobbler dhcp
2. 启动 cobbler httpd tftp 服务
[root@centos ~]#systemctl start cobblerd httpd tftp
3. 命令行输入cobbler check 会提示你修改哪些配置文件,我们只需要修改 1,2,4,8 选项即可
[root@centos ~]#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 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : ksvalidator was not found, install pykickstart
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.
4. 打开配置文件vim /etc/cobbler/settings 进行修改
第278行 next_server: 192.168.8.100 #修改为本机的IP地址
第390行 server: 92.168.8.100 #修改为本机的IP地址
第242行 manage_dhcp: 1 #修改为1
第101行 default_password_crypted: "$1$GRNAdUcK$q2bSFPQ/iEcKKx3NZXaTk/" 将密码替换为自己的
密码生成方式:
[root@centos ~]#openssl passwd -1
5. 修改好后重启 cobbler 服务
[root@centos ~]#systemctl restart cobblerd
6. 修改 vim /etc/cobbler/dhcp.template 文件 ,利用cobbler自动生成DHCP配置文件
21 subnet 192.168.8.0 netmask 255.255.255.0 { #将IP地址修改为自己的范围
22 option routers 192.168.8.2; #修改为路由
23 option domain-name-servers 192.168.8.2; #修改域名
24 option subnet-mask 255.255.255.0;
25 range dynamic-bootp 192.168.8.100 192.168.8.254; #修改DHCP获取地址范围
7. 下载cobbler需要的文件
[root@centos ~]#cobbler get-loaders
task started: 2020-05-05_132356_get_loaders
task started (id=Download Bootloader Content, time=Tue May 5 13:23:56 2020)
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 ***
8. 同步cobbler的配置文件
[root@centos ~]#cobbler sync
#查看同步的文件在tftp的共享目录里/var/lib/tftpboot/
[root@centos ~]#tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot
│ └── grub
│ └── menu.lst
├── etc
├── grub
│ ├── efidefault
│ ├── grub-x86_64.efi
│ ├── grub-x86.efi
│ └── images -> ../images
├── images
├── images2
├── memdisk
├── menu.c32
├── ppc
├── pxelinux.0
├── pxelinux.cfg
│ └── default
├── s390x
│ └── profile_list
└── yaboot
10 directories, 10 files
9. 导入光盘yum源文件
[root@centos ~]#cobbler import --path=/misc/cd --name=Centos7.6-x86_64 --arch=x86_64
--path= #自己光盘挂载的路径
--name= #这个名字自定义
--arch= #是什么架构的
#查看是否成功
[root@centos ~]#ls /var/www/cobbler/ks_mirror/
Centos7.6-x86_64 config
#完成之后就可以启动电脑了
10. 启动电脑或虚拟机后可以看到以下界面就证明我们的自动化安装系统配置已经成功了
如果自带的应答文件不满意可以自定义
1. 以下文件是我自己制作好的,如果不满足需求可自行更改
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext centos
# Use network installation
url --url=$tree
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part / --fstype="xfs" --size=100000
part /boot --fstype="xfs" --size=1000
part swap --fstype="swap" --size=2000
%packages
@^minimal
@core
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
2. 需要把上面做好的应答文件做关联
把应答文件复制到/var/lib/cobbler/kickstarts/这个目录下
[root@centos ~]#cp ks-mini.cfg /var/lib/cobbler/kickstarts/
[root@centos ~]#cd /var/lib/cobbler/kickstarts/
[root@centos kickstarts]#ls
default.ks install_profiles pxerescue.ks sample_esx4.ks sample_esxi6.ks sample.seed
esxi4-ks.cfg ks-mini.cfg sample_autoyast.xml sample_esxi4.ks sample.ks sample.seed.28
esxi5-ks.cfg legacy.ks sample_end.ks sample_esxi5.ks sample_old.seed
3. 添加我们自己的 ks-mini.cfg 文件
[root@centos kickstarts]#cobbler profile add --name Centos7.6-x86_64_Mini --distro=Centos7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks-mini.cfg
--name #名字自定义
--distro= #添加好的Centos7的源文件 #如何查看添加好的Centos7的源文件[root@centos ~]#cobbler distro list
[root@centos kickstarts]#cobbler profile list
Centos7.6-x86_64 #这是自带的
Centos7.6-x86_64_Mini #这是我们自己添加的
4. 可以看见我们添加好的ks-mini.cfg文件菜单
5. 如果不想要自带的菜单可以删除
[root@centos kickstarts]#cobbler profile remove --name=Centos7.6-x86_64
[root@centos kickstarts]#cobbler profile list
Centos7.6-x86_64_Mini #就剩我们自己制作的ks-mini.cfg文件了