Centos7.x实现Cobbler无人值守安装
Cobbler
技术原理解析:
Client向PXE Server上的DHCP发送IP地址请求消息,DHCP检测Client是否合法(主要是检测Client的网卡MAC地址),如果合法则返回Client的IP地址,同时将启动文件pxelinux.0的位置信息一并传送给Client
Client向PXE Server上的TFTP发送获取pxelinux.0请求消息,TFTP接收到消息之后再向Client发送pxelinux.0大小信息,试探Client是否满意,当TFTP收到Client发回的同意大小信息之后,正式向Client发送pxelinux.0
Client执行接收到的pxelinux.0文件
Client向TFTP Server发送针对本机的配置信息文件(在TFTP服务的pxelinux.cfg目录下,这是系统菜单文件,格式和isolinux.cfg格式一样,功能也是类似),TFTP将配置文件发回Client,继而Client根据配置文件执行后续操作。
Client向TFTP发送Linux内核请求信息,TFTP接收到消息之后将内核文件发送给Client
Client向TFTP发送根文件请求信息,TFTP接收到消息之后返回Linux根文件系统
Client启动Linux内核
Client下载安装源文件,读取自动化安装脚本
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 iamge
Client裸机加载kickstart文件
Client裸机接收os image,安装该OS image
Cobbler集成的服务:
PXE服务支持
DHCP服务管理
DNS服务管理(可选bind,dnsmasq)
电源管理
Kickstart服务支持
YUM仓库管理
TFTP(PXE启动时需要)
Apache(提供kickstart的安装源,并提供定制化的kickstart配置)
Cobbler 设计方式:
发行版(distro) :表示一个操作系统,它承载了内核和initrd的信息,以及内核等其他数据 存储库
(repository):保存了一个yum或者rsync存储库的镜像信息
配置文件(profile):包含了一个发行版(distro),一个kickstart文件以及可能的存储库(repository),还包含了更多的内核参数等其他数据
系统(system):表示要配给的机器,它包含了一个配置文件或一个镜像,还包含了ip和mac地址,电源管理(地址,凭据,类型)以及更为专业的数据信息
镜像(image):可替换一个包含不属于此类别的文件的发行版对象(eg: 无法作为内核和initrd的对象)
以上各个组件中, 发行版,存储库, 配置文件为必须配置项,只有在虚拟环境中,必须要用cobbler来引导虚拟机启动时候,才会用到系统组件但事实上,在生产环境中需要大量的虚拟机实例的话,通常利用openstack等来实现虚拟机节点
Cobbler配置目录文件说明:
> /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 # 模块的配置文件
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/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.log # cobbler日志
Cobbler命令介绍:
cobbler check # 核对当前设置是否有问题
cobbler list # 列出所有的cobbler元素
cobbler report # 列出元素的详细信息
cobbler sync # 同步配置到数据目录,更改配置最好都要执行下
cobbler reposync # 同步yum仓库
cobbler distro # 查看导入的发行版系统信息
cobbler system # 查看添加的系统信息
cobbler profile # 查看配置信息
/etc/cobbler/settings中重要的参数设置:
default_password_crypted: "1gEc7ilpP$pg5iSOj/mlxTxEslhRvyp/"
manage_dhcp:1
manage_tftpd:1
pxe_just_once:1
next_server:< tftp服务器的 IP 地址>
server:<Cobbler服务器IP地址>
Cobble安装:
系统信息:
[aaa@qq.com-42 ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
关闭防火墙
1.[aaa@qq.com-42 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset:enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
2.[aaa@qq.com-42 ~]# systemctl stop firewalld
3.[aaa@qq.com-42 ~]# systemctl enable firewalld
# 加入开机自启
关闭selinux
vim /etc/selinux/config或getenforce # 必须关闭selinux
注:getenforce是暂时性关闭
查看本机IP
[aaa@qq.com-42 ~]# ifconfig ens33 | awk -F "[ :]+" 'NR==2 {print $3}'
10.0.0.42
配置yum源:
[aaa@qq.com-42 ~]# yum -y install wget # 下载wget
epel 配置方法(扩展源)
1.备份(如有配置其他epel源)
1.[aaa@qq.com-42 ~]# mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
2.[aaa@qq.com-42 ~]# mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
2.下载新repo 到/etc/yum.repos.d/
[aaa@qq.com-42 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
开始安装Cobbler,下载相关服务:
[aaa@qq.com-42 ~]# yum -y install cobbler dhcp httpd xinetd tftp-server syslinux pykickstart rsync cobbler-web
启动相关服务
1.[aaa@qq.com-42 ~]# systemctl start httpd
2.[aaa@qq.com-42 ~]# systemctl enable httpd
3.[aaa@qq.com-42 ~]# systemctl start cobblerd
4.[aaa@qq.com-42 ~]# systemctl enable cobblerd
通过cobbler check 核对当前设置是否有问题
[aaa@qq.com-42 ~]# 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 beset 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 packageinstalled 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.
一般都有8到9个问题需要修复。 按照提示一个一个的解决问题:
问题1:
[aaa@qq.com-42 ~]# sed -i 's/^server: 127.0.0.1/server: 10.0.0.42/' /etc/cobbler/settings # 修改server的ip地址为本机ip
问题2:
[aaa@qq.com-42 ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 10.0.0.42/' /etc/cobbler/settings # TFTP Server 的IP地址
问题3:
[aaa@qq.com-42 ~]# vim /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no # 修改为No
per_source = 11
cps = 100 2
flags = IPv4
}
问题4:
[aaa@qq.com-42 ~]# cobbler get-loaders # 下载缺失的文件
task started: 2020-05-01_095847_get_loaders
task started (id=Download Bootloader Content, time=Fri May 1 09:58:47 2020)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
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/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
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 ***
报错
解决办法
[aaa@qq.com-42 ~]# vim /etc/cobbler/settings # 找到第390行(我这里是390看一下自己的时是否是不是找server就行)
390 server: 10.0.0.42 ####改为自己的IP地址(我这里是已经修改过的)
问题5:
# 添加rsync到自启动并启动rsync
1.[aaa@qq.com-42 ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
2.[aaa@qq.com-42 ~]# systemctl start rsyncd
问题6:
1.[aaa@qq.com-42 ~]# yum install debmirror -y # 安装debian
2.[aaa@qq.com-42 ~]# vim /etc/debmirror.conf
28 #@dists="sid";
30 #@arches="i386";
注释掉这两行,重新check后没有报错了
问题7:
# 修改密码为123456 ,salt后面是常用的加密方式加密
1.[aaa@qq.com-42 ~]# openssl passwd -1 -salt '123456' '123456'
$1$123456$wOSEtcyiP2N/IfIl15W6Z0
2.default_password_crypted: "$1$123456$wOSEtcyiP2N/IfIl15W6Z0 # 修改settings配置文件中下面位置,把新生成的密码加进去
问题8:
[aaa@qq.com-42 ~]# yum -y install fence-agents # fence设备相关,电源管理模块
重启cobbler
[aaa@qq.com-42 ~]# systemctl restart cobblerd.service
再次执行cobbler check
[aaa@qq.com-42 ~]# cobbler check
dhcp利用cobbler管理
[aaa@qq.com-42 ~]# vim /etc/cobbler/settings # 修改settings中参数,由cobbler控制dhcp
manage_dhcp: 1
修改dhcp.templates配置文件(仅列出修改部分)
[aaa@qq.com-42 ~]# vim /etc/cobbler/dhcp.template
21 subnet 10.0.0.0 netmask 255.255.255.0 { #网段 这个可以是10网段,也可以是172网段
22 option routers 10.0.0.254; #网关
23 option domain-name-servers 10.0.0.254; #MDS
24 option subnet-mask 255.255.255.0; #子网掩码
25 range dynamic-bootp 10.0.0.200 10.0.0.210; #分配的地址段
26 default-lease-time 21600;
27 max-lease-time 43200;
28 next-server $next_server; #这个是cobbler配置文件里面的变量
重启服务并同步配置,改完dhcp必须要sync同步配置
1.[aaa@qq.com-42 ~]# systemctl restart cobblerd.service
2.[aaa@qq.com-42 ~]# cobbler sync
检查dhcp
[aaa@qq.com-42 ~]# netstat -tulp | grep dhcp
现在开始一键装机
1.首先挂载镜像
Linux 上是需要挂载光盘,我们进行挂载
[aaa@qq.com-42 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
制作镜像,用于安装操作系统,使cobbler导入镜像
[aaa@qq.com-42 ~]# cobbler import --path=/mnt --name=CentOS7.7
还未完成尽情见谅
上一篇: 高...高精度!!!