注意:CentOS8没有cobbler,只能使用CentOS7安装cobbler做服务器
安装软件包
[root@localhost ~]# yum install cobbler cobbler-web dhcp pykickstart -y
开机启动
[root@localhost ~]# systemctl enable --now cobblerd httpd tftp dhcpd
关闭防火墙
[root@localhost ~]# systemctl disable --now firewalld
关闭selinux
[root@localhost ~]# sed -ri 's/^(SELINUX=).*/\1disabled/' /etc/selinux/config
#记得改完要重启生效
[root@localhost ~]# reboot
改tftp配置
[root@localhost ~]# vim /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
disable = no # 原来的yes 改成no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -B 1380 -v -s /var/lib/tftpboot
per_source = 11
cps = 100 2
flags = IPv4
}
重启服务
[root@localhost ~]# systemctl restart xinetd
去网络拉
[root@localhost ~]# cobbler get-loaders
如果没有网络情况下拷贝启动文件到TFTP服务文件夹
[root@localhost ~]# cp -a /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot
命令生成passwd添加到配置文件的password
[root@localhost ~]# openssl passwd -1 -salt `openssl rand -hex 4`
Password:
$1$3615869d$.n6qC68e6B05ibbdQaU1L/
改cobbler配置
[root@localhost ~]# vim /etc/cobbler/settings
manage_dhcp: 1
default_password_crypted: "$1$3615869d$.n6qC68e6B05ibbdQaU1L/"
manage_tftpd: 1
# 自己虚拟机本机ip地址
next_server: 172.31.0.37
server: 172.31.0.37
重启服务
[root@localhost ~]# systemctl restart cobblerd
挂载镜像
[root@localhost ~]# mount /dev/cdrom /mnt
cobbler命令
[root@localhost ~]# cobbler
usage
=====
cobbler ...
[add|edit|copy|getks*|list|remove|rename|report] [options|--help]
cobbler [options|--help]
可以使用下面的方式得到使用帮助
[root@localhost ~]# cobbler distro --help
usage
=====
cobbler distro add
cobbler distro copy
cobbler distro edit
cobbler distro find
cobbler distro list
cobbler distro remove
cobbler distro rename
cobbler distro report
常见用法:
#列出当前导入的linux发行版条目
cobbler distro list
#报告当前所有的linux发行版详细信息
cobbler distro report
#导入系统源文件生成仓库
cobbler import --name=centos-8.0-x86_64 --path=/mnt --arch=x86_64
cobbler import --name=centos7-x86_64 --path=/mnt --arch=x86_64
#将linux发行版系统镜像与其对应的ks文件建立关联
cobbler profile add --name=centos7 --distro=centos7-x86_64 --
kickstart=/var/lib/cobbler/kickstarts/ks7.cfg
#删除默认的
[root@localhost kickstarts]# cobbler profile remove --name=centos-7.6-x86_64
导入镜像
[root@localhost ~]# cobbler import --name=CentOS-7.6-x86_64 --path=/mnt
拷贝本地的制作应答文件
[root@localhost ~]# cp anaconda-ks.cfg centos7-cobbler.cfg
定制的应答文件如下:
[root@localhost kickstarts]# cat centos7-cobbler.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext 123456
# 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=static --device=eth0 --ip=10.0.0.123 --netmask=255.255.255.0
network --bootproto=dhcp --device=eth0 --activate
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
# cobbler应答文件路径 :/var/www/cobbler/ks_mirror/CentOS-7.6-x86_64
url --url="http://172.31.0.37/cobbler/ks_mirror/CentOS-7.6-x86_64"
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
# Partition clearing information
clearpart --all
# Disk partitioning information 50G
part / --fstype="xfs" --size=45000
part /boot --fstype="xfs" --size=1024
part swap --fstype="swap" --size=2048
%post
useradd longwang
echo 123456 |passwd --stdin longwang
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/base.repo <> /etc/profile.d/env.sh <
存放cobbler应答文件路径
[root@localhost ~]# cd /var/lib/cobbler/kickstarts/
拷贝应答文件到当前目录
[root@localhost kickstarts]# pwd
/var/lib/cobbler/kickstarts
[root@localhost kickstarts]# cp /root/centos7-cobbler.cfg .
将kickstart文件,关联指定的YUM源和生成菜单列表
[root@localhost kickstarts]# cobbler profile add --name=CentOS-7.6 --distro=CentOS-7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7-cobbler.cfg
删除原生的
[root@localhost kickstarts]# cobbler profile remove --name=centos-7.6-x86_64
优化系统启动界面
[root@localhost ~]# cat /etc/cobbler/pxe/pxedefault.template
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.longxuan.vip/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
$pxe_menu_items
MENU end
#启动并同步
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler sync
制作系统启动界面
[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.longxuan.vip/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
LABEL CentOS-7.6-x86_64
kernel /images/CentOS-7.6-x86_64/vmlinuz
MENU LABEL CentOS-7.6-x86_64
append initrd=/images/CentOS-7.6-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://172.31.0.37/cblr/svc/op/ks/profile/CentOS-7.6-x86_64
ipappend 2
MENU end
改dhcp配置
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
ddns-update-style interim;
allow booting;
allow bootp;
ignore client-updates;
set vendorclass = option vendor-class-identifier;
option pxe-system-type code 93 = unsigned integer 16;
subnet 172.31.0.0 netmask 255.255.0.0 {
option routers 172.31.0.254;
option domain-name-servers 172.31.0.254;
option subnet-mask 255.255.0.0;
range dynamic-bootp 172.31.0.180 172.31.0.200;
default-lease-time 21600;
max-lease-time 43200;
next-server 172.31.0.37;
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";
}
}
}
重启
[root@localhost ~]# systemctl restart dhcpd
一、最后验证cobbler自动装机
然后新建一台虚拟机PC进行验证,不使用镜像,网络连接方式选择NAT,注意内存选择2G以上(否则会因内存不够而安装失败)。然后开启新建的虚拟机会出现cobbler画面,选择第二种回车继续等待
[root@localhost ~]# yum install cobbler-web -y
改配置文件
[root@localhost ~]# vim /etc/cobbler/modules.conf
[authentication]
#module=authn_configfile
module = authn_pam
创建用户并设置密码
[root@localhost ~]# useradd webuser
[root@localhost ~]# passwd webuser
配置文件添加用户
[root@localhost ~]# vim /etc/cobbler/users.conf
[admins]
admin = ""
cobbler = ""
webuser = "" # 添加这行