Cobbler部署与配置

Cobbler

Cobbler简介

  • Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
  • Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
  • Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
  • Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
  • Cobbler官网

Cobbler集成的服务

  • PXE服务支持
  • DHCP服务管理
  • DNS服务管理(可选bind,dnsmasq)
  • 电源管理
  • Kickstart服务支持
  • YUM仓库管理
  • TFTP(PXE启动时需要)
  • Apache(提供kickstart的安装源,并提供定制化的kickstart配置)

Cobbler配置文件详解

  • cobbler配置文件目录在/etc/cobbler
配置文件作用
/etc/cobbler/settingscobbler 主配置文件
/etc/cobbler/iso/iso模板配置文件
/etc/cobbler/pxepxe模板配置文件
/etc/cobbler/power电源配置文件
/etc/cobbler/user.confweb服务授权配置文件
/etc/cobbler/users.digestweb访问的用户名密码配置文件
/etc/cobbler/dhcp.templatedhcp服务器的的配置模板
/etc/cobbler/dnsmasq.templatedns服务器的配置模板
/etc/cobbler/tftpd.templatetftp服务的配置模板
/etc/cobbler/modules.conf模块的配置文件
  • cobbler数据目录
目录作用
/var/lib/cobbler/config/用于存放distros,system,profiles等信息配置文件
/var/lib/cobbler/triggers/用于存放用户定义的cobbler命令
/var/lib/cobbler/kickstart/默认存放kickstart文件
/var/lib/cobbler/loaders/存放各种引导程序以及镜像目录
/var/www/cobbler/ks_mirror/导入的发行版系统的所有数据
/var/www/cobbler/images/导入发行版的kernel和initrd镜像用于远程网络启动
/var/www/cobbler/repo_mirror/yum仓库存储目录
  • cobbler日志文件
路径说明
/var/log/cobbler/installing客户端安装日志
/var/log/cobbler/cobbler.logcobbler日志

Cobbler命令详解

命令含义
cobbler check核对当前设置是否有问题
cobbler list列出所有的cobbler元素
cobbler report列出元素的详细信息
cobbler sync同步配置到数据目录,更改配置后建议执行一下,以防配置不生效。
cobbler reposync同步yum仓库
cobbler distro查看导入的发行版系统信息
cobbler system查看添加的系统信息
cobbler profile查看配置信息

Cobbler服务端部署

  • 环境说明
系统版本IP地址
Redaht8192.168.192.135
//关闭防火墙
[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 ~]# setenforce 0
[root@localhost ~]# reboot

//配置yum源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo


//配置epel源
[root@localhost ~]# yum -y install epel-release vim 

//安装依赖包
[root@php ~]# dnf module enable cobbler
[root@php ~]# dnf -y install httpd dhcp-* tftp xinetd pykickstart cobbler cobbler-web rsync-daemon

//启动
[root@localhost ~]# systemctl enable --now httpd cobblerd

//修改server的ip地址为本机ip
[root@localhost ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.129.135/' /etc/cobbler/settings.yaml

//设置tftp的ip地址为本机ip
[root@localhost ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.129.135/' /etc/cobbler/settings.yaml

//下载缺失文件
[root@localhost ~]# cobbler get-loaders
task started: 2021-10-13_123854_get_loaders
task started (id=Download Bootloader Content, time=Wed Oct 13 12:38:54 2021)
running python triggers from /var/lib/cobbler/triggers/task/get_loaders/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/get_loaders/pre/*
shell triggers finished successfully
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
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/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 ***
注意:此处显示 TASK COMPLETE 则表示没有问题

//启动rsync并设置开机自启
[root@localhost ~]# systemctl enable --now rsyncd
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.service → /usr/lib/systemd/system/rsyncd.service.

//生成加密的密码
[root@localhost ~]# openssl passwd -1
Password: 
Verifying - Password: 
$1$VbNNoYL9$UtmeEV9aGp3VCtdWH.7f21     //加密后的密码

//将新生成的加密密码加入到配置文件
[root@localhost ~]# vim /etc/cobbler/settings.yaml 
....
default_password_crypted: "$1$VbNNoYL9$UtmeEV9aGp3VCtdWH.7f21"
....

//修改cobbler配置文件,让cobbler控制dhcp
[root@localhost ~]# sed -i 's/^manage_dhcp: false/manage_dhcp: true/g' /etc/cobbler/settings.yaml		#修改此处的值为true,表示让cobbler控制dhcp

[root@localhost ~]# sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
[root@localhost ~]# sed -n '/^manage_dhcp/p' /etc/cobbler/settings
manage_dhcp: 1

//配置dhcp
[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.129.0 netmask 255.255.255.0 {						#本地主机网段
     option routers             192.168.129.135;					#本机IP
     option domain-name-servers 192.168.129.2;						#DNS地址
     option subnet-mask         255.255.255.0;						#子网掩码
     range dynamic-bootp        192.168.129.10 192.168.129.20;		#dhcp服务器分配的IP地址范围
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
     class "pxeclients" {
....

//重启cobbler
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# ss -antl
State       Recv-Q       Send-Q             Local Address:Port              Peer Address:Port      
LISTEN      0            5                      127.0.0.1:25151                  0.0.0.0:*         
LISTEN      0            5                        0.0.0.0:873                    0.0.0.0:*         
LISTEN      0            128                      0.0.0.0:22                     0.0.0.0:*         
LISTEN      0            128                            *:443                          *:*         
LISTEN      0            5                           [::]:873                       [::]:*         
LISTEN      0            128                            *:80                           *:*         
LISTEN      0            128                         [::]:22                        [::]:*   

//通过cobbler check 核对当前设置是否有问题
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:

1: reposync is not installed, install yum-utils or dnf-plugins-core
2: yumdownloader is not installed, install yum-utils or dnf-plugins-core
3: debmirror package is not installed, it will be required to manage debian deployments and repositories
4: 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.
#以上3、4是关于debian系统的错误,请忽略

解决方法:
1、yum install fence-agents 
2、yum -y install yum-utils
3、执行cobbler get-loaders命令
4、wget -P /etc/yum.repos.d/ https://copr.fedoraproject.org/coprs/jkastner/dnf-plugins-core/repo/epel-7/jkastner-dnf-plugins-core-epel-7.repo && yum install dnf-plugins-core 


//再次查看
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:

1: debmirror package is not installed, it will be required to manage debian deployments and repositories
2: 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、2忽略

//最后一个问题
[root@php kickstarts]#  yum  -y install debmirror
[root@php kickstarts]# sed -i 's/@dists="sid";/#@dists="sid";/' /etc/debmirror.conf
[root@php kickstarts]# sed -i 's/@arches="i386";/#@arches="i386";/' /etc/debmirror.conf

//检查就没有问题了
[root@php kickstarts]# cobbler check
No configuration problems found.  All systems go.

//重启服务并同步配置,改完dhcp必须要sync同步配置
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler sync
task started: 2021-10-13_032729_sync
task started (id=Sync, time=Wed Oct 13 22:45:29 2021)
running python triggers from /var/lib/cobbler/triggers/task/sync/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/sync/pre/*
shell triggers finished successfully
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/redhat-8-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/system
removing: /var/lib/tftpboot/grub/system_link
removing: /var/lib/tftpboot/grub/grub.cfg
removing: /var/lib/tftpboot/grub/local_efi.cfg
removing: /var/lib/tftpboot/grub/local_legacy.cfg
removing: /var/lib/tftpboot/grub/local_powerpc-ieee1275.cfg
removing: /var/lib/tftpboot/images/redhat-8-x86_64
copying bootloaders
running: ['rsync', '-rpt', '--copy-links', '--exclude=.cobbler_postun_cleanup', '/var/lib/cobbler/loaders/', '/var/lib/tftpboot']
received on stdout: 
received on stderr: 
running: ['rsync', '-rpt', '--copy-links', '--exclude=README.grubconfig', '/var/lib/cobbler/grub_config/', '/var/lib/tftpboot']
received on stdout: 
received on stderr: 
copying distros to tftpboot
copying files for distro: redhat-8-x86_64
trying hardlink /var/www/cobbler/distro_mirror/redhat-8-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/redhat-8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/redhat-8-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/redhat-8-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: redhat-8-x86_64
trying hardlink /var/www/cobbler/distro_mirror/redhat-8-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/redhat-8-x86_64/vmlinuz
trying hardlink /var/www/cobbler/distro_mirror/redhat-8-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/redhat-8-x86_64/initrd.img
Writing template files for redhat-8-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
processing boot_files for distro: redhat-8-x86_64
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout: 
received on stderr: 
running: service dhcpd restart
received on stdout: 
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service

running shell triggers from /var/lib/cobbler/triggers/sync/post/*
shell triggers finished successfully
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running python trigger cobbler.modules.managers.genders
running shell triggers from /var/lib/cobbler/triggers/change/*
shell triggers finished successfully
*** TASK COMPLETE ***

//检查dhcp是否正常
[root@localhost ~]# ss -anulp| grep dhcp
UNCONN    0         0                            *:67                  *:*       users:(("dhcpd",pid=108719,fd=7))
UNCONN    0         0                   0.0.0.0:40348            0.0.0.0:*       users:(("dhcpd",pid=146845,fd=20))                                             
UNCONN    0         0                      [::]:52014               [::]:*       users:(("dhcpd",pid=146845,fd=21))                                             

//导入安装镜像
[root@localhost ~]# mount /dev/cdrom  /mnt 
mount: /mnt: /dev/sr0 already mounted on /mnt/cdrom.

[root@localhost ~]# df -h
文件系统               容量  已用  可用 已用% 挂载点
devtmpfs               1.9G     0  1.9G    0% /dev
tmpfs                  1.9G     0  1.9G    0% /dev/shm
tmpfs                  1.9G  9.0M  1.9G    1% /run
tmpfs                  1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/mapper/rhel-root   36G  1.9G   34G    6% /
/dev/nvme0n1p1        1014M  179M  836M   18% /boot
tmpfs                  376M     0  376M    0% /run/user/0
/dev/sr0               7.9G  7.9G     0  100% /mnt

[root@localhost ~]# cobbler import --name=redhat-8.2 --arch=x86_64 --path=/mnt
task started: 2021-10-12_125827_import
task started (id=Media import, time=Wed Oct 13 23:8:27 2021)
running python triggers from /var/lib/cobbler/triggers/task/import/pre/*
running shell triggers from /var/lib/cobbler/triggers/task/import/pre/*
shell triggers finished successfully
Found a candidate signature: breed=redhat, version=rhel8
Found a matching signature: breed=redhat, version=rhel8
Adding distros from path /var/www/cobbler/distro_mirror/redhat-8.2-x86_64:
creating new distro: redhat-8.2-x86_64
trying symlink: /var/www/cobbler/distro_mirror/redhat-8.2-x86_64 -> /var/www/cobbler/links/redhat-8.2-x86_64
creating new profile: redhat-8.2-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/distro_mirror/redhat-8.2-x86_64 for redhat-8.2-x86_64
processing repo at : /var/www/cobbler/distro_mirror/redhat-8.2-x86_64/AppStream			
need to process repo/comps: /var/www/cobbler/distro_mirror/redhat-8.2-x86_64/AppStream
looking for /var/www/cobbler/distro_mirror/redhat-8.2-x86_64/AppStream/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/redhat-8.2-x86_64/AppStream/repodata
processing repo at : /var/www/cobbler/distro_mirror/redhat-8.2-x86_64/BaseOS
need to process repo/comps: /var/www/cobbler/distro_mirror/redhat-8.2-x86_64/BaseOS
looking for /var/www/cobbler/distro_mirror/redhat-8.2-x86_64/BaseOS/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/distro_mirror/redhat-8.2-x86_64/BaseOS/repodata
*** TASK COMPLETE ***
#参数说明
		--path      //镜像路径
        --name      //为安装源定义一个名字
        --arch      //指定安装源平台
#安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7-x86_64,如果重复,系统会提示导入失败

//查看cobbler镜像列表
[root@localhost ~]# cobbler list
distros:
   redhat-8.2-x86_64

profiles:
   redhat-8.2-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

//创建kickstarts自动安装脚本
[root@localhost ~]# cat > /var/lib/cobbler/kickstarts/redhat-8.2-x86_64.ks<<'EOF'
auth --enableshadow --passalgo=sha512
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.129.135/cobbler/ks_mirror/redhat-8.2-x86_64/			#本机ip
$yum_repo_stanza
reboot

rootpw --iscrypted $6$dsDSjBlVZrhKDfMG$XO2VJHSWQRVzkTCy0FUHeFUSX5YwtAdQ4rw5haeo2JpjzW6bvzG2OfZa2pB283ckYLmT5VYnn5BnWyJc6sLPE/		#修改为自己的密码

selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr

%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
EOF
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值