cobbler介绍
Cobbler是一个Linux服务器快速网络安装的服务,由python开发,小巧轻便(15k行python代码),可以通过PXE的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS,TFTP、RSYNC以及yum仓库、构造系统ISO镜像。Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler工作流程
client裸机配置了从网络启动后,开机后会广播包请求DHCP服务器 (cobbler server)发送其分配好的一个IP
DHCP服务器(cobbler server)收到请求后发送responese,包括其ip地址
client裸机拿到ip后再向cobbler server发送请求OS引导文件的请求
cobbler server告诉裸机OS引导文件的名字和TFTP server的ip和 port
client裸机通过上面告知的TFTP server地址通信,下载引导文件
client裸机执行执行该引导文件,确定加载信息,选择要安装的os, 期间会再向cobbler server请求kickstart文件和os image
cobbler server发送请求的kickstart和os image
client裸机加载kickstart文件
client裸机接收os image,安装该os image
Cobbler集成的服务
PXE服务支持
DHCP服务管理
DNS服务管理(可选bind,dnsmasq)
电源管理
Kickstart服务支持
YUM仓库管理
TFTP(PXE启动时需要)
Apache(提供kickstart的安装源,并提供定制化的kickstart配置)
配置文件相关
配置文件目录:
/etc/cobbler
/etc/cobbler/settings : cobbler 主配置文件
/etc/cobbler/iso/: iso模板配置文件
/etc/cobbler/pxe: pxe模板文件
/etc/cobbler/power: 电源配置文件
/etc/cobbler/user.conf: web服务授权配置文件
/etc/cobbler/users.digest: web访问的用户名密码配置文件
/etc/cobbler/dhcp.template : dhcp服务器的的配置模板
/etc/cobbler/dnsmasq.template : dns服务器的配置模板
/etc/cobbler/tftpd.template : tftp服务的配置模板
/etc/cobbler/modules.conf : 模块的配置文件
数据目录:
/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 仓库存储目录
日志目录:
/var/log/cobbler/installing: 客户端安装日志
/var/log/cobbler/cobbler.log : cobbler日志
常用命令
cobbler commands 介绍
cobbler check 核对当前设置是否有问题
cobbler list 列出所有的cobbler元素
cobbler report 列出元素的详细信息
cobbler sync 同步配置到数据目录,更改配置最好都要执行下
cobbler reposync 同步yum仓库
cobbler distro 查看导入的发行版系统信息
cobbler system 查看添加的系统信息
cobbler profile 查看配置信息
Cobbler安装
systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state
sed -i '/^SELINUX=.*/c SELINUX=disabled' /etc/selinux/config
sed -i 's/^SELINUXTYPE=.*/SELINUXTYPE=disabled/g' /etc/selinux/config
grep --color=auto '^SELINUX' /etc/selinux/config
setenforce 0
系统信息
[root@cobbler ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@cobbler ~]# uname -r
3.10.0-693.el7.x86_64
[root@cobbler ~]# getenforce
Permissive
[root@cobbler ~]# ifconfig ens33 | awk -F "[ :]+" 'NR==2 {print $3}'
192.168.26.80
[root@cobbler ~]# hostname
cobbler.example.com
配置yum源
cd /etc/yum.repos.d/ && rm -rf *
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all && yum makecache
安装相关软件
[root@cobbler ~]# yum -y install httpd dhcp tftp python-ctypes cobbler xinetd cobbler-web pykickstart
启动服务
[root@cobbler ~]# systemctl start httpd.service
[root@cobbler ~]# systemctl enable httpd.service
[root@cobbler ~]# systemctl enable cobblerd.service
[root@cobbler ~]# systemctl start cobblerd.service
检查当前配置是否有问题
[root@cobbler ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work. This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, 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, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
8 : 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: 修改server的ip地址为本机ip
[root@cobbler ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.26.80/' /etc/cobbler/settings
问题2:修改TFTP Server 的IP地址
[root@cobbler ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.26.80/' /etc/cobbler/settings
问题3:启用tftp
[root@cobbler ~]# sed -i 's#yes#no#g' /etc/xinetd.d/tftp
问题4:下载缺失的文件
[root@cobbler ~]# cobbler get-loaders
task started: 2019-08-20_035058_get_loaders
task started (id=Download Bootloader Content, time=Tue Aug 20 03:50:58 2019)
path /var/lib/cobbler/loaders/README already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.elilo already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.yaboot already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.syslinux already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/elilo-ia64.efi already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/yaboot already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/pxelinux.0 already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/menu.c32 already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/grub-x86.efi already exists, not overwriting existing content, use --force if you wish to update
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***
问题5:启动rsync服务
[root@cobbler ~]# systemctl enable rsyncd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[root@cobbler ~]# systemctl start rsyncd.service
问题6:跟debian 相关,可以忽略
问题7:
[root@cobbler ~]# openssl passwd -1 -salt 'root' 'redhat'
$1$root$M1uN9dLHipbORRwJW/xR3/
[root@cobbler ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$root$M1uN9dLHipbORRwJW/xR3/"
[root@cobbler ~]# systemctl restart cobblerd
配置DHCP
[root@cobbler ~]# vim /etc/cobbler/settings
manage_dhcp: 1
[root@cobbler ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
修改dhcp模板
[root@cobbler ~]# 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 192.168.26.2;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.26.100 192.168.26.254;
重启所有服务,同步
[root@cobbler ~]# systemctl restart httpd.service
[root@cobbler ~]# systemctl restart cobblerd.service
[root@cobbler ~]# systemctl restart dhcpd.service
[root@cobbler ~]# systemctl restart rsyncd.service
[root@cobbler ~]# systemctl restart tftp.socket
[root@cobbler ~]# cobbler sync
导入镜像
[root@cobbler ~]# mount /dev/cdrom /mnt
[root@cobbler ~]# cobbler import --path=/mnt --name=Centos-7.4 --arch=x86_64
[root@cobbler ~]# cobbler list
distros:
Centos-7.4-x86_64
profiles:
Centos-7.4-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
导入kickstarts配置文件
[root@cobbler ~]# cd /var/lib/cobbler/kickstarts/
[root@cobbler kickstarts]# ls
default.ks install_profiles sample_autoyast.xml sample_esxi4.ks sample.ks
esxi4-ks.cfg legacy.ks sample_end.ks sample_esxi5.ks sample_old.seed
esxi5-ks.cfg pxerescue.ks sample_esx4.ks sample_esxi6.ks sample.seed
[root@cobbler kickstarts]# pwd
/var/lib/cobbler/kickstarts
在电脑桌面创建一个Centos-7.4-x86_64.cfg文本添加以下内容
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$m1pE0DG6$vALBphGGynqvUzfJaWZ6U1
# Use network installation
url --url="$tree"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
# Network information
network --bootproto=dhcp --device=eth0
network --bootproto=dhcp --device=eth1
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --asprimary --fstype="ext4" --size=200
part swap --fstype="swap" --size=1024
part / --fstype="ext4" --grow --size=1
%packages
@base
@core
@compat-libraries
@debugging
@development
@gnome-desktop
@X Window System
%end
使用rz工具导入配置文件,也可使用xftp进行导入
[root@cobbler kickstarts]# rz -E
rz waiting to receive.
[root@cobbler kickstarts]# ls
Centos-7.4-x86_64.cfg install_profiles sample_end.ks sample_esxi6.ks sample.seed.28
default.ks legacy.ks sample_esx4.ks sample.ks
esxi4-ks.cfg pxerescue.ks sample_esxi4.ks sample_old.seed
esxi5-ks.cfg sample_autoyast.xml sample_esxi5.ks sample.seed
查看导入信息及默认ks文件
[root@cobbler kickstarts]# cobbler report
distros:
==========
Name : Centos-7.4-x86_64
Architecture : x86_64
TFTP Boot Files : {}
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/ks_mirror/Centos-7.4-x86_64/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/ks_mirror/Centos-7.4-x86_64/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/Centos-7.4-x86_64'}
Management Classes : []
OS Version : rhel7
Owners : ['admin']
Red Hat Management Key : <>
Red Hat Management Server : <>
Template Files : {}
profiles:
==========
Name : Centos-7.4-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : Centos-7.4-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks #默认的ks文件,这里需要修改为我们自己配置好的ks文件
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <>
Red Hat Management Server : <>
Repos : []
Server Override : <>
Template Files : {}
Virt Auto Boot : 1
Virt Bridge : xenbr0
Virt CPUs : 1
Virt Disk Driver Type : raw
Virt File Size(GB) : 5
Virt Path :
Virt RAM (MB) : 512
Virt Type : kvm
systems:
==========
repos:
==========
images:
==========
mgmtclasses:
==========
packages:
==========
files:
==========
写完 ks 文件之后,先通过 validateks 测试一下有没有语法错误
[root@cobbler kickstarts]# cobbler validateks
编辑修改指定KS文件为我们刚刚上传的KS文件Centos-7.4-x86_64.cfg
[root@cobbler kickstarts]# cobbler profile edit --name Centos-7.4-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos-7.4-x86_64.cfg
修改安装系统的内核参数,在CentOS7系统有一个地方变了,就是网卡名变成eno16777736这种形式,但是为了运维标准化,我们需要将它变成我们常用的eth0,因此使用上面的参数。但要注意是CentOS7才需要上面的步骤,CentOS6不需要。
[root@cobbler kickstarts]# cobbler profile edit --name Centos-7.4-x86_64 --kopts='net.ifnames=0 biosdevname=0'
重启服务,同步
[root@cobbler ~]# systemctl restart cobblerd
[root@cobbler ~]# cobbler sync
新建虚拟机测试
注意:本实验网卡配置的模式为NAT模式