1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Centos7.x实现Cobbler无人值守安装

Centos7.x实现Cobbler无人值守安装

时间:2021-12-03 02:46:08

相关推荐

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:1manage_tftpd:1pxe_just_once:1next_server:< tftp服务器的 IP 地址>server:<Cobbler服务器IP地址>

Cobble安装:

系统信息:

[root@c7-42 ~]# cat /etc/redhat-releaseCentOS Linux release 7.7.1908 (Core)

关闭防火墙

1.[root@c7-42 ~]# systemctl status firewalld● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset:enabled)Active: inactive (dead)Docs: man:firewalld(1)2.[root@c7-42 ~]# systemctl stop firewalld3.[root@c7-42 ~]# systemctl enable firewalld# 加入开机自启

关闭selinux

vim /etc/selinux/config或getenforce # 必须关闭selinux

注:getenforce是暂时性关闭

查看本机IP

[root@c7-42 ~]# ifconfig ens33 | awk -F "[ :]+" 'NR==2 {print $3}'10.0.0.42

配置yum源:

[root@c7-42 ~]# yum -y install wget # 下载wget

epel 配置方法(扩展源)

1.备份(如有配置其他epel源)

1.[root@c7-42 ~]# mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup2.[root@c7-42 ~]# mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup

2.下载新repo 到/etc/yum.repos.d/

[root@c7-42 ~]# wget -O /etc/yum.repos.d/epel.repo /repo/epel-7.repo

开始安装Cobbler,下载相关服务:

[root@c7-42 ~]# yum -y install cobbler dhcp httpd xinetd tftp-server syslinux pykickstart rsync cobbler-web

启动相关服务

1.[root@c7-42 ~]# systemctl start httpd2.[root@c7-42 ~]# systemctl enable httpd3.[root@c7-42 ~]# systemctl start cobblerd4.[root@c7-42 ~]# systemctl enable cobblerd

通过cobbler check 核对当前设置是否有问题

[root@c7-42 ~]# cobbler checkThe 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/tftp4 : 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 systemctl6 : debmirror package is not installed, it will be required to manage debian deployments and repositories7 : 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 one8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use themRestart cobblerd and then run 'cobbler sync' to apply changes.

一般都有8到9个问题需要修复。 按照提示一个一个的解决问题:

问题1:

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

问题2:

[root@c7-42 ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 10.0.0.42/' /etc/cobbler/settings # TFTP Server 的IP地址

问题3:

[root@c7-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 = dgramprotocol= udpwait= yesuser= rootserver = /usr/sbin/in.tftpdserver_args = -s /var/lib/tftpbootdisable = no # 修改为Noper_source = 11cps = 100 2flags = IPv4}

问题4:

[root@c7-42 ~]# cobbler get-loaders # 下载缺失的文件task started: -05-01_095847_get_loaderstask started (id=Download Bootloader Content, time=Fri May 1 09:58:47 )downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/READMEdownloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilodownloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yabootdownloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinuxdownloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efidownloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yabootdownloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efidownloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi*** TASK COMPLETE ***

报错

解决办法

[root@c7-42 ~]# vim /etc/cobbler/settings # 找到第390行(我这里是390看一下自己的时是否是不是找server就行)390 server: 10.0.0.42 ####改为自己的IP地址(我这里是已经修改过的)

问题5:

# 添加rsync到自启动并启动rsync1.[root@c7-42 ~]# systemctl enable rsyncdCreated symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.2.[root@c7-42 ~]# systemctl start rsyncd

问题6:

1.[root@c7-42 ~]# yum install debmirror -y # 安装debian2.[root@c7-42 ~]# vim /etc/debmirror.conf28 #@dists="sid";30 #@arches="i386";注释掉这两行,重新check后没有报错了

问题7:

# 修改密码为123456 ,salt后面是常用的加密方式加密1.[root@c7-42 ~]# openssl passwd -1 -salt '123456' '123456'$1$123456$wOSEtcyiP2N/IfIl15W6Z02.default_password_crypted: "$1$123456$wOSEtcyiP2N/IfIl15W6Z0 # 修改settings配置文件中下面位置,把新生成的密码加进去

问题8:

[root@c7-42 ~]# yum -y install fence-agents # fence设备相关,电源管理模块

重启cobbler

[root@c7-42 ~]# systemctl restart cobblerd.service

再次执行cobbler check

[root@c7-42 ~]# cobbler check

dhcp利用cobbler管理

[root@c7-42 ~]# vim /etc/cobbler/settings # 修改settings中参数,由cobbler控制dhcpmanage_dhcp: 1

修改dhcp.templates配置文件(仅列出修改部分)

[root@c7-42 ~]# vim /etc/cobbler/dhcp.template21 subnet 10.0.0.0 netmask 255.255.255.0 {#网段 这个可以是10网段,也可以是172网段22option routers 10.0.0.254; #网关23option domain-name-servers 10.0.0.254; #MDS24option subnet-mask 255.255.255.0; #子网掩码25range dynamic-bootp 10.0.0.200 10.0.0.210; #分配的地址段26default-lease-time 21600;27max-lease-time 43200;28next-server$next_server; #这个是cobbler配置文件里面的变量

重启服务并同步配置,改完dhcp必须要sync同步配置

1.[root@c7-42 ~]# systemctl restart cobblerd.service2.[root@c7-42 ~]# cobbler sync

检查dhcp

[root@c7-42 ~]# netstat -tulp | grep dhcp

现在开始一键装机

1.首先挂载镜像

Linux 上是需要挂载光盘,我们进行挂载

[root@c7-42 ~]# mount /dev/cdrom /mnt/mount: /dev/sr0 is write-protected, mounting read-only

制作镜像,用于安装操作系统,使cobbler导入镜像

[root@c7-42 ~]# cobbler import --path=/mnt --name=CentOS7.7

查看镜像,上面是镜像名称,下面是启动菜单

[root@c7-42 ~]# cobbler listdistros:CentOS-7.7.1908-x86_64profiles:CentOS-7.7.1908-x86_64systems:repos:images:mgmtclasses:packages:files:

同步 Cobbler 配置

[root@c7-42 ~]# systemctl restart cobblerd.service[root@c7-42 ~]# cobbler synctask started: -05-07_143942_synctask started (id=Sync, time=Thu May 7 14:39:42 )running pre-sync triggerscleaning treesremoving: /var/www/cobbler/images/CentOS-7.7.1908-x86_64removing: /var/lib/tftpboot/pxelinux.cfg/defaultremoving: /var/lib/tftpboot/grub/imagesremoving: /var/lib/tftpboot/grub/grub-x86.efiremoving: /var/lib/tftpboot/grub/grub-x86_64.efiremoving: /var/lib/tftpboot/grub/efidefaultremoving: /var/lib/tftpboot/images/CentOS-7.7.1908-x86_64removing: /var/lib/tftpboot/s390x/profile_listcopying bootloaders

测试

创建一台 CentOS 系统(不需要选择镜像)

保证相同私有网络,并且最好2G内存,内存小的话会在安装时报空间不够出现下图的错误

耐心等待安装时间较长,出现下图代表已经安装完成

全自动无人值守

修改pxe默认启动顺序:var/lib/tftpboot/pxelinux.cfg/default(客户端获取IP地址之后在准备安装之前默认从本地启动)

[root@c7-42 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default6 ONTIMEOUT CentOS-7.7.1908-x86_64 #修改第六行local[root@c7-42 ~]# systemctl restart cobblerd.service

将ONTIMEOUT 修改成想要安装的系统名称(自己制作好的那个),否则客户端在启动安装的过程中会选择localhost导致安装失败。

注意:这时修改之后重启客户端即可,切记重启之后一定不要执行cobbler sync,否则修改的配置文件将失效。如果想要其永久性生效

需要修改:vim /etc/cobbler/pxe/pxedefault.template,把上面的字段改为安装系统的名称:ONTIMEOUT CentOS-7.7.1908-x86_64

测试:

默认的20秒过后就可以自动安装了 全自动无人值守!

定制ks文件

定制ks文件,系统默认的ks文件为/var/lib/cobbler/kickstarts/sample_end.ks,但是默认不符合我们需要,所以得去定制。

可以拷贝默认模板进行修改,也可上传ks文件到此目录下

[root@c7-42 ~]# cd /var/lib/cobbler/kickstarts/[root@c7-42 kickstarts]# cp sample_end.ks mylinux.ks[root@c7-42 kickstarts]# vim mylinux.ks

修改完成后一定要通过: cobbler profile edit --name=CentOS-7.7.1908-x86_64 --distro=CentOS-7.7.1908-x86_64 --kickstart=/var/lib/cobbler/kickstarts/mylinux.ks

命令指定.ks文件,否则系统会找默认的ks文件。可以用cobbler report检查。

补充

如果有多块网卡,需要监听其中一块的话,配置如下:

vim /etc/sysconfig/dhcpd# $ cp /usr/lib/systemd/system/dhcpd.service /etc/systemd/system/# $ vi /etc/systemd/system/dhcpd.service# $ ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid <your_interface_name(s)># 注意上面一步,写的时候没有不带"<>"这个符号,否则会报错!# $ systemctl --system daemon-reload# $ systemctl restart dhcpd.service

cobbler命令详解

# cobblerusage=====cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... [add|edit|copy|getks*|list|remove|rename|report] [options|--help]cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help]# cobbler import --help # 导入镜像帮助Usage: cobbler [options]Options:-h, --help show this help message and exit--arch=ARCH OS architecture being imported--breed=BREED the breed being imported--os-version=OS_VERSIONthe version being imported--path=PATH local path or rsync location--name=NAME name, ex 'RHEL-5'--available-as=AVAILABLE_AStree is here, don't mirror--kickstart=KICKSTART_FILEassign this kickstart file--rsync-flags=RSYNC_FLAGSpass additional flags to rsync#其它命令cobbler check 核对当前设置是否有问题cobbler list列出所有的cobbler元素cobbler report 列出元素的详细信息cobbler sync同步配置到数据目录,更改配置最好都要执行下cobbler reposync 同步yum仓库cobbler distro 查看导入的发行版系统信息cobbler system 查看添加的系统信息cobbler profile 查看配置信息

Cobbler的web管理界面

https://10.0.0.42/cobbler_web

默认用户名:cobbler

默认密码 :cobbler

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。