cobbler的部署

cobbler部署

//配置yum源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0  10800      0 --:--:-- --:--:-- --:--:-- 10800
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]# dnf clean all
[root@localhost ~]# dnf list all
[root@localhost ~]# dnf -y install epel-release

//安装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 module enable cobbler:3 -y

[root@localhost ~]# dnf -y install httpd dhcp* tftp tftp-server cobbler cobbler-web pykickstart rsync rsync-daemon 

//启动服务并设置开机自启
[root@localhost ~]# systemctl enable --now httpd
[root@localhost ~]# systemctl enable --now rsyncd
[root@localhost ~]# systemctl enable --now tftp
[root@localhost ~]# systemctl enable --now cobblerd


//关闭防火墙和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 '/^SELINUX=/s/(SELINUX=).*/\1disabled/g' /etc/selinux/config 
//重启系统
[root@localhost ~]# reboot

//修改cobbler 主配置文件
[root@localhost ~]# vim /etc/cobbler/settings.yaml
server: 192.168.169.139			//改为服务器的IP地址
next_server: 192.168.169.139

//生成加密的密码
[root@localhost ~]# openssl passwd -1 -salt  "$RANDOM" "zzd123!"
$1$23$FmphinVlvQL8Lck6CsOIN.
[root@localhost ~]# vim /etc/cobbler/settings.yaml
default_password_crypted: "$1$23$FmphinVlvQL8Lck6CsOIN."	//刚才生成的密码

//将cobbler的dhcp功能打开
[root@localhost ~]# vim /etc/cobbler/settings.yaml
manage_dhcp: true

//解决cobbler check命令可能会报错的问题
[root@localhost ~]# dnf -y install syslinux* yum-utils
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/    
[root@localhost ~]# cp /usr/share/syslinux/menu.c32  /var/lib/cobbler/loaders/


//重启cobbler
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart cobblerd.service 


//通过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.
//第一个问题我们已经解决过了,第二第三个问题是在Debian系统上面需要注意的,解决办法是在Debian系统上面安装fence-agents,可以忽略


//配置DHCP模板文件
[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.169.0 netmask 255.255.255.0 {
     option routers             192.168.169.2;
     option domain-name-servers 8.8.8.8;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.169.143 192.168.169.153;		//地址池,视情况而定
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;


//同步cobbler配置
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart cobblerd.service 
[root@localhost ~]# cobbler sync
task started: 2022-09-23_170758_sync
task started (id=Sync, time=Fri Sep 23 17:07:58 2022)
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/lib/tftpboot/grub/system
removing: /var/lib/tftpboot/grub/system_link
removing: /var/lib/tftpboot/grub/images
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 images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
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 ***


管理distro
//挂载镜像
[root@localhost ~]# mount /dev/cdrom /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.

//导入镜像
[root@localhost ~]# cobbler import --path=/mnt --name=zzd arch=x86_64  //--name可以自定义
task started: 2022-09-23_183222_import
task started (id=Media import, time=Fri Sep 23 18:32:22 2022)
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
…………
*** TASK COMPLETE ***

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

profiles:
   zzd-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

//查看详细信息  查看指定的--name 接镜像名
[root@localhost ~]# cobbler distro report --name zzd-x86_64
Name                           : zzd-x86_64
Architecture                   : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/zzd-x86_64'}
TFTP Boot Files                : {}
Boot loader                    : grub
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/distro_mirror/zzd/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/distro_mirror/zzd/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自动安装脚本
[root@localhost ~]# cobbler profile get-autoinstall --name zzd-x86_64  > /var/lib/cobbler/templates/centos8.ks	//存放位置可以自定义

//修改脚本文件
[root@localhost ~]# vim /var/lib/cobbler/templates/centos8.ks
firewall --disable		//关闭防火墙

%packages
@^minimal-environment //在这两行中间加上这一行,设置最小换安装
%end

//如果是在生产环境中,那么cobbler的部署已经完成了,但是在VMware虚拟机中还需要做如下操作
[root@localhost ~]# cd /usr/share/cobbler/bin/
[root@localhost bin]# ls
migrate-data-v2-to-v3.py  migrate-settings.sh  mkgrub.sh  settings-migration-v1-to-v2.sh
[root@localhost bin]# bash mkgrub.sh
[root@localhost bin]# cd /var/lib/cobbler/loaders/
[root@localhost loaders]# ls
grub  ldlinux.c32  menu.c32  pxelinux.0
[root@localhost loaders]# cobbler sync
[root@localhost loaders]# systemctl restart httpd cobblerd rsyncd dhcpd

手动安装

创建一个虚拟机,然后打开虚拟机,等待dhcp分配完毕,选择想要使用的镜像

密码就是上面执行命令所用的密码

自动安装

通过web管理界面进行自动安装,先新建一个虚拟机

在浏览器输入:https:// + ip地址/cobbler_web

用户名和密码都为:cobbler

将生成出来的mac地址复制保存下来点击左上角的save保存

同步,右上角有同步日志

这里也可以查看日志

将刚才保存下来的Mac地址复制到即将安装的虚拟机上

打开虚拟机,进行安装,等待安装完成后,进行验证

posted @ 2022-09-25 12:58  Zic师傅  阅读(44)  评论(0编辑  收藏  举报