部署cobbler和镜像手动安装和自动安装方法
文章目录
- 部署cobbler和镜像手动安装和自动安装方法
- @[toc]
- 一、cobbler简介
- 二、cobbler功能
- 三、cobbler集成的服务
- 四、cobbler命令
- 五、部署
- 1. 配置
- 2. 手动安装
- 3. 自动安装
一、cobbler简介
Cobbler
可以用来快速建立 Linux
网络安装环境。
Cobbler
是一个快速网络安装linux
的服务,而且在经过调整也可以支持网络安装windows
。
使用简单的命令即可完成PXE
网络安装环境的配置,同时还可以管理DHCP
、DNS
、TFTP
、RSYNC
以及yum
仓库、构造系统ISO镜像。 Cobbler
支持命令行管理,web
界面管理,还提供了API接口,可以方便二次开发使用,Cobbler
客户端Koan支持虚拟机安装和操作系统重新安装。
1、Cobbler
是一个Linux
服务器安装的服务,可以通过网络启动(PXE
)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP
,DNS
等。
2、Cobbler
可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web
),还提供了API
接口,可以方便二次开发使用。
3、Cobbler
是较早前的kickstart
的升级版,优点是比较容易配置,还自带web界面比较易于管理。
4、Cobbler
内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet
。
二、cobbler功能
1、服务器上架后,可以手动选择需要安装的系统(如:Centos6.8 或 Centos 7.3)
2、服务器上架后,能够根据需求,安装配置操作系统(如:修改IP地址、主机名、选择安装包)
3、系统安装后,可以自定义的执行脚本,完成系统基础软件初始化(如:Zabbix安装配置、SaltStack安装配置)
4、可以当内部YUM源,并在系统安装时进行初始化
5、可以重装系统
6、Cobbler支持API,可以无缝融合到自建运维平台中
7、Cobbler支持网卡的路由配置、DNS配置、bonding
三、cobbler集成的服务
1、PXE服务支持
2、DHCP服务管理
3、DNS服务管理(可选bind,dnsmasq)
4、电源管理
5、Kickstart服务支持
6、YUM仓库管理
7、TFTP(PXE启动时需要)
8、Apache(提供kickstart的安装源,并提供定制化的kickstart配置)
四、cobbler命令
cobbler check //核对当前设置是否有问题
cobbler list //列出所有的cobbler元素
cobbler report //列出元素的详细信息
cobbler sync //同步配置到数据目录,更改配置最好都要执行下
cobbler reposync //同步yum仓库
cobbler distro //查看导入的发行版系统信息
cobbler system //查看添加的系统信息
cobbler profile //查看配置信息
五、部署
环境说明:
主机 | IP地址 | 网关 | 系统 |
cobbler | 192.168.183.141 | 192.168.183.2 | centos |
1. 配置
//关闭防火墙和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
//重启生效
[root@localhost ~]# getenforce
Disabled
//配置yum源,并安装epel源
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@localhost ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
//安装cobbler及相关软件
[root@localhost ~]# yum module list | grep cobbler
Failed to set locale, defaulting to C.UTF-8
Repository extras is listed more than once in the configuration
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
······
//启动服务并设置开机自启
[root@localhost ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[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 ~]# systemctl enable --now tftp.socket
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.
[root@localhost ~]# systemctl enable --now cobblerd.service
Created symlink /etc/systemd/system/multi-user.target.wants/cobblerd.service → /usr/lib/systemd/system/cobblerd.service.
//生成加密的密码
[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" "lishuai123"
$1$685$s67bZ5GeP2U3bEIlTMMs1.
//修改cobbler主配置文件
[root@localhost ~]# dnf install vim -y
[root@localhost ~]# vim /etc/cobbler/settings.yaml
103 default_password_crypted: "$1$685$s67bZ5GeP2U3bEIlTMMs1." //修改密码为新生成的加密密码
······
220 manage_dhcp: true //将dhcp功能打开
······
255 next_server: 192.168.183.141 tftp的ip地址,为本机ip
······
353 server: 192.168.183.141 //server的ip地址,为本机ip
······
[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: reposync is not installed, install yum-utils or dnf-plugins-core
3: yumdownloader is not installed, install yum-utils or dnf-plugins-core
4: debmirror package is not installed, it will be required to manage debian deployments and repositories
5: 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.
[root@localhost ~]#
//问题1解决办法:
[root@rhel8 ~]# yum -y install syslinux*
[root@rhel8 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@rhel8 ~]# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@rhel8 ~]# ls /var/lib/cobbler/loaders/
menu.c32 pxelinux.0
问题2和问题3解决办法
[root@rhel8 ~]# yum -y install yum-utils
问题4和问题5可以忽略,
因为是debian系统才需要解决,显示使用的是centos8
Debian系统解决办法安装fence-agents
//配置DHCP模板文件
[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.183.0 netmask 255.255.255.0 { //网段
option routers 192.168.183.2; //网关
option domain-name-servers 8.8.8.8; //dns服务器
option subnet-mask 255.255.255.0; //子网掩码
range dynamic-bootp 192.168.183.150 192.168.183.160; //IP地址池
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
[root@localhost ~]# systemctl restart cobblerd.service httpd
//同步cobbler配置
[root@localhost ~]# cobbler sync
······
shell triggers finished successfully
管理distro
//挂载镜像
[root@localhost ~]# mount /dev/cdrom /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.
//导入镜像
[root@localhost ~]# cobbler import --path=/mnt/ --name=lishuai arch=x86_64
······
//查看cobbler镜像列表
[root@localhost ~]# cobbler list
distros:
lishuai-x86_64
profiles:
lishuai-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
//查看详细信息 查看指定的--name 接镜像名
[root@localhost ~]# cobbler distro report --name lishuai-x86_64
Name : lishuai-x86_64
Architecture : x86_64
Automatic Installation Template Metadata : {'tree': 'http://@@http_server@@/cblr/links/lishuai-x86_64'}
TFTP Boot Files : {}
Boot loader : grub
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/distro_mirror/lishuai/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/distro_mirror/lishuai/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 lishuai-x86_64 > /var/lib/cobbler/templates/lishuai.ks
[root@localhost ~]# vim /var/lib/cobbler/templates/lishuai.ks
······
# Firewall configuration
firewall --disabled //关闭防火墙
······
%packageso
@^minimal-environment //设置最小化安装
······
[root@localhost ~]# cat /var/lib/cobbler/templates/lishuai.ks
# Sample kickstart file for current EL, Fedora based distributions.
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=http://192.168.183.141/cblr/links/lishuai-x86_64
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
repo --name=source-1 --baseurl=http://192.168.183.141/cobbler/distro_mirror/lishuai/AppStream
repo --name=source-2 --baseurl=http://192.168.183.141/cobbler/distro_mirror/lishuai/BaseOS
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $1$30275$/guecEG04ZaM.46rVU9Bb1
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone America/New_York
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
autopart
%pre
set -x -v
exec 1>/tmp/ks-pre.log 2>&1
# Once root's homedir is there, copy over the log.
while : ; do
sleep 10
if [ -d /mnt/sysimage/root ]; then
cp /tmp/ks-pre.log /mnt/sysimage/root/
logger "Copied %pre section log to system"
break
fi
done &
# Enable installation monitoring
%end
%packageso
@^minimal-environment
%end
%post --nochroot
set -x -v
exec 1>/mnt/sysimage/root/ks-post-nochroot.log 2>&1
%end
%post
set -x -v
exec 1>/root/ks-post.log 2>&1
# Start yum configuration
curl "http://192.168.183.141/cblr/svc/op/yum/profile/lishuai-x86_64" --output /etc/yum.repos.d/cobbler-config.repo
# End yum configuration
# Start post_install_network_config generated code
# End post_install_network_config generated code
# Start download cobbler managed config files (if applicable)
# End download cobbler managed config files (if applicable)
# Start koan environment setup
echo "export COBBLER_SERVER=192.168.183.141" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.183.141" > /etc/profile.d/cobbler.csh
# End koan environment setup
$SNIPPET('redhat_register')
# Begin cobbler registration
# cobbler registration is disabled in /etc/cobbler/settings.yaml
# End cobbler registration
# Enable post-install boot notification
# Start final steps
curl "http://192.168.183.141/cblr/svc/op/autoinstall/profile/lishuai-x86_64" -o /root/cobbler.ks
# End final steps
%end
[root@localhost ~]#
//如果是生产环境,那么部署就已经完成,如果是虚拟机就还需执行以下步骤
[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 24 10:12 grub
lrwxrwxrwx 1 root root 31 Sep 24 10:12 ldlinux.c32 -> /usr/share/syslinux/ldlinux.c32
-rw-r--r-- 1 root root 26272 Sep 24 09:42 menu.c32
-rw-r--r-- 1 root root 42376 Sep 24 09:41 pxelinux.0
[root@localhost ~]# cobbler sync
[root@localhost ~]# systemctl restart httpd cobblerd rsyncd dhcpd
2. 手动安装
3. 自动安装
开启创建的虚拟机就会自动安装了无需手动操作。