cobbler
cobbler服务端部署
说明:虚拟机网卡采用NAT模式或者仅主机模式,不要使用桥接模式,因为后面会搭建DHCP服务器,在同一个局域网多个DHCP服务会有冲突。
//更新yum源,并且安装epel包
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost yum.repos.d]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@localhost yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
//安装cobbler以及相关的软件
[root@localhost ~]# yum module list | grep cobbler
cobbler 3 default [d] Versatile Linux deployment server
cobbler 3.3 default [d] Versatile Linux deployment server
[root@localhost ~]# dnf -y module enable cobbler:3
[root@localhost ~]# dnf -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync rsync-daemon syslinux* yum-utils
//启动服务并设置开机自启
[root@localhost ~]# systemctl enable --now httpd
[root@localhost ~]# systemctl enable --now rsyncd
[root@localhost ~]# systemctl enable --now tftp.socket
[root@localhost ~]# systemctl enable --now cobblerd.service
//关闭防火墙和selinux
[root@localhost ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@localhost ~]# reboot
//cobbler服务,selinux必须得是disabled状态,所以要重启
[root@localhost ~]# getenforce
Disabled
//生成加密的密码
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" 'cobbler123'
$1$29322$v0kv/XMI993dfOV/Cz3tU1
//修改cobbler主配置文件
[root@localhost ~]# vim /etc/cobbler/settings.yaml
next_server: 192.168.26.134
......
server: 192.168.26.134
.....
default_password_crypted: "$1$29322$v0kv/XMI993dfOV/Cz3tU1" //修改密码为新生成的加密密码
.....
manage_dhcp: true //将dhcp功能打开
.....
manage_dns: false //dns服务器为搭建,可以不用开启dns功能
//通过syslinux*包生成引导文件,我们将引导文件复制到/var/lib/cobbler/loaders/目录下
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@localhost ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@localhost ~]# ls /var/lib/cobbler/loaders/
menu.c32 pxelinux.0
//重启cobbler
[root@localhost ~]# systemctl restart cobblerd.service
[root@localhost ~]# ss -anltp |grep 25151
LISTEN 0 5 127.0.0.1:25151 0.0.0.0:* users:(("cobblerd",pid=1888,fd=6))
//通过cobbler check 核对当前设置是否有问题
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:
1: some network boot-loaders are missing from /var/lib/cobbler/loaders. 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, and yaboot.
2: debmirror package is not installed, it will be required to manage debian deployments and repositories
3: 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.
//第一个,我们/var/lib/cobbler/loaders下面有pxelinux.0 和menu.c32俩个引导文件,不需要关心
//第二个和第三个错误,是debian系统需要注意的,这里也没有关系
//配置DHCP模板文件
[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.26.0 netmask 255.255.255.0 {
option routers 192.168.26.2;
option domain-name-servers 114.114.114.114;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.26.150 192.168.26.160;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
[root@localhost ~]# systemctl restart cobblerd.service
//同步cobbler配置
[root@localhost ~]# cobbler sync
......
*** TASK COMPLETE ***
管理distro
//挂载镜像
[root@localhost mnt]# mount /dev/cdrom /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.
//导入镜像(切记勿tab)
[root@localhost ~]# cobbler import --path=/mnt/ --name=zdz arch=x86_64
......
*** TASK COMPLETE ***
//查看cobbler镜像列表
[root@localhost ~]# cobbler list
distros:
zdz-x86_64
profiles:
zdz-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
//查看详细信息 查看指定的--name 接镜像名
[root@localhost ~]# cobbler distro report --name zdz-x86_64
Name : zdz-x86_64
Architecture : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/zdz-x86_64'}
TFTP Boot Files : {}
Boot loader : grub
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/distro_mirror/zdz/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/distro_mirror/zdz/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Management Classes : []
OS Version : rhel8
Owners : ['admin']
Redhat Management Key :
Remote Boot Initrd : ~
Remote Boot Kernel : ~
Template Files : {}
//创建kickstarts自动安装脚本(文件以.ks结尾,勿tab)
[root@localhost ~]# cobbler profile get-autoinstall --name zdz-x86_64 > /var/lib/cobbler/templates/zdz.ks
对脚本进行修改
[root@localhost ~]# vim /var/lib/cobbler/templates/zdz.ks
…………
firewall --disable //防火墙关闭
…………
%packages
@^minimal-environment //设置最小化安装
…………
//如果是生产环境,那么部署就已经完成,如果是虚拟机就还需执行以下步骤
[root@localhost ~]# cd /usr/share/cobbler/bin/
[root@localhost bin]# ls
migrate-data-v2-to-v3.py mkgrub.sh
migrate-settings.sh settings-migration-v1-to-v2.sh
[root@localhost bin]# bash mkgrub.sh
[root@localhost bin]# cd /var/lib/cobbler/loaders/
[root@localhost loaders]# ll
total 72
drwxr-xr-x 2 root root 79 Sep 26 02:31 grub
lrwxrwxrwx 1 root root 31 Sep 26 02:31 ldlinux.c32 -> /usr/share/syslinux/ldlinux.c32
-rw-r--r-- 1 root root 26272 Sep 26 02:11 menu.c32
-rw-r--r-- 1 root root 42376 Sep 26 02:11 pxelinux.0
看见两个引导文件就ok了
//同步
[root@localhost ~]# cobbler sync
//重启服务
[root@localhost loaders]# systemctl restart httpd cobblerd rsyncd
进行测试
安装一个空壳centos8的虚拟机,不需要给镜像
进来后就发现可以自动获取ip选择我们刚才上传的镜像
web页面自动安装
登录
账号密码都是cobbler