CentOS 7下cobbler安装及配置

本文介绍了Cobbler自动化部署系统的方法,包括PEX原理、Cobbler的工作流程、Cobbler的配置和命令使用,以及Cobbler安装、DHCP配置和镜像导入等步骤。通过Cobbler,可以实现服务器和虚拟机的网络无人值守安装,提高部署效率。
摘要由CSDN通过智能技术生成

目录

1.背景介绍

2. PEX 原理介绍

2.1 PEX 原理与概念

2.2 PEX 工作原理示意图​

 3. Cobbler 简介

3.1 Cobbler 概述

3.2 Cobbler

3.3 Cobbler 工作原理 

 3.4 Cobbler 相关目录说明

3.5 Cobbler 命令介绍

4. Cobbler 安装

4.1 系统信息

4.2 配置 yum 源 

 4.3 关闭SELinux

4.4 安装Cobbler

 4.5 启动Cobbler

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

4.7 配置Cobbler-DHCP 

 4.8 导入CentOs-7的镜像

 4.9 Ks文件配置

5.验证

5.1 将服务端所有服务重启

5.2 新建一台虚拟机


1.背景介绍

服务器系统的部署是一件单一且重复性较高的事,那么该怎样避免“重复造轮子”?本节主要介绍Cobbler及其部署实践,通过配置Kickstart的无人值守安装方式,服务器通过PXE启动方式,实现通过网络就可以在服务器上自动部署系统的目的。

2. PEX 原理介绍

2.1 PEX 原理与概念

PEX是预启动执行环境(preboot execution environment)的简称,也被称为预执行环境,是让计算机通过网卡独立地使用数据设备(如硬盘)或者安装操作系统的环境。它是基于TCP/IP、DHCP、TFTP等Internet协议之上的扩展网络协议,提供了一种从网络启动的新技术。严格来说,PXE并不是一种安装方式,而是一种引导方式。进行PXE安装的必要条件是在要安装的计算机中必须包含一个PXE支持的网卡(NIC),即网卡中必须要有PXE client。PXE协议可以使计算机通过网络启动。此协议分为client端和server端,而PXE client则在网卡的ROM中。当计算机引导时,BIOS把PXE client调入内存中执行,然后由PXE client将放置在远端的文件通过网络下载到本地运行。运行PXE协议需要设置DHCP server和TFTP server。 DHCP server会给PXE client(将要安装系统的主机)分配一个IP地址,由于是给PXEclient分配IP地址,所以在配置DHCP server时需要增加相应的PXE设置。此外,在PXE client的ROM中,已经存在了TFTP client,那么它就可以通过TFTP协议到TFTPserver上下载所需的文件了。

2.2 PEX 工作原理示意图
watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA54ix55Cz5YWI55Sf,size_20,color_FFFFFF,t_70,g_se,x_16

 3. Cobbler 简介

3.1 Cobbler 概述

Cobbler 由Python语言开发,是对PXE、Kickstart和DHCP的封装。它融合了很多特性,提供了CLI和Web的管理形式,更加方便地实行网络安装。同时,Cobbler也提供了API接法田甘他语言也很容易做护展。匕个仪可以女农物埋机,同时也支持KVM.XEN
和GuestOS的安装。

3.2 Cobbler

Cobbler的配置结构基于一组注册的对象,每个对象表示一个与另一个实体相关联的实体(该对象指向另一个对象,或者另一个对象指向该对象)。当一个对象指向另一个对象时,它就继承了被指向对象的数据,并可覆盖或添加更多特定信息。对象类型的定义如下。
        发行版:表示一个操作系统。它承载了内核和initrd的信息,以及内核参数等其他数据。
        配置文件:包含一个发行版、一个Kickstart文件以及可能的存储库,还包含更多特定的内核参数等其他数据。
        系统:表示要配给的机器。它包含一个配置文件或一个镜像,还包含IP和MAC地址、电源管理(地址、凭据、类型)以及更为专业的数据等信息。
        存储库:保存一个yum或Rsync存储库的镜像信息。
        镜像:可替换一个包含不属于此类别的文件的发行版对象(例如,无法分为内核和initrd的对象)。
基于注册的对象以及各个对象之间的关联,Cobbler知道如何更改文件系统以反映具体配置。因为系统配置的内部是抽象的,所以我们可以仅关注想要执行的操作。Cobbler对象关系如下图所示。

3.3 Cobbler 工作原理 

Cobbler 工作原理如下图所示:

图中server端的工作步骤如下:
第一步,启动Cobbler服务;
第二步,进行Cobbler错误检查,执行Cobbler check命令;
第三步,进行配置同步,执行Cobbler sync命令;
第四步,复制相关启动文件到TFTP目录中;
第五步,启动DHCP服务,提供地址分配;
第六步,DHCP服务分配IP地址;
第七步,TFTP传输启动文件;
第八步,server端接收安装信息;
第九步,server端发送ISO镜像与Kickstart 文件。

client端的工作步骤如下:
第一步,客户端以PXE模式启动;
第二步,客户端获取IP地址;
第三步,通过TFTP服务器获取启动文件;
第四步,进人Cobbler安装选择界面;
第五步,客户端确定加载信息;
第六步,根据配置信息准备安装系统;
第七步,加载Kickstart文件;
第八步,传输系统安装的其他文件;
第九步,进行安装系统。
 

 3.4 Cobbler 相关目录说明

(1)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模块的配置文件

   (2)Cobbler 数据目录 /var/lib/cobbler 说明:

/var/lib/cobbler/config/  : 用于存放 distros、system、profiles 等信息配置文件
/var/lib/cobbler/triggers/  : 用于存放用户定义的Cobbler命令
/var/lib/cobbler/kickstart/  : 默认存放Kickstart文件
/var/lib/cobbler/loaders/  : 存放各种引导程序

(3)镜像数据目录 /var/www/cobbler 说明:

/var/www/cobbler/ks_mirror/  : 导入的发行版系统的所有数据
/var/www/cobbler/images/  : 导入发行版的 kernel 和 initrd 镜像用于 远程网络启动
/var/www/cobbler/repo_mirror/  : yum 仓库存储目录

(4)日志目录 /var/log/cobbler/说明:

/var/log/cobbler/install.log  : 客户端的安装系统日志
/var/log/cobbler/cobbler.log  : Cobbler 日志

3.5 Cobbler 命令介绍

(1)查看 Cobbler 命令

[root@cobbler svr-]# cobbler
       usage

       =====
       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>
[options|--help]
        在上面的显示中,我们可以看到,Cobbler命令有很多的选项,想获得相关选项的帮助只需
要加--help即可:
[root@cobbler ~]# cobbler profile --help

(2)Cobbler常用命令

 cobbler check       检查Cobbler配置
cobbler sync          同步配置到DHCP/PXE和数据目录
cobbler list             列出所有的Cobbler元素
cobbler import       导入安装的系统镜像
cobbler report        列出各元素的详细信息
cobbler distro         查看导入的发行版系统信息
cobbler profile        查看配置信息
cobbler system      查看添加的系统信息
cobbler reposync   同步yum仓库到本地

4. Cobbler 安装

4.1 系统信息

4.2 配置 yum 源 

[root@localhost ~]# rpm -ql epel-release >> /dev/nul || yum install -y epel-release

 4.3 关闭SELinux

sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux setenforce 0

4.4 安装Cobbler

yum -y install cobbler cobbler-web tftp-server dhcp httpd xinetd

 4.5 启动Cobbler

systemctl enable --now httpd cobblerd

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

[root@localhost ~]# 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 resol vable 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 : SELinux is enabled. Please review the following wiki page for details on en suring cobbler works correctly in your SELinux environment:
    https://github.com/cobbler/cobbler/wiki/Selinux
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
5 : 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 insta lled a *recent* version of the syslinux package installed and can ignore this message entirely.  Files this directory, should you want to support all archi tectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot.
6 : enable and start rsyncd.service with systemctl
7 : debmirror package is not installed, it will be required to manage debian de ployments and repositories
8 : ksvalidator was not found, install pykickstart
9 : The default password used by the sample templates for newly installed machi nes (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
10 : 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.

从上面的执行结果来看,存在10处错误,下面我们来一一解决:

问题1:

#修改后面server的ip地址为本机ip

sed -i 's/^server: 127.0.0.1/server: 192.168.139.62/' /etc/cobbler/settings

问题2:

#修改next_erver为本机的IP

sed -i 's/^next_server: 127.0.0.1/next_server: 10.0.0.101/' /etc/cobbler/settings

问题3:

SELinux处于开启状态,前面已经临时关闭selinux并修改了selinux配置文件,只是没有重启,要消除这个提示重启下服务器即可,也可以直接忽略。

问题4:

#修改/etc/xinetd.d/tftp,把disable修改为no

sed -i 's#yes#no#g' /etc/xinetd.d/tftp

问题5:

cobbler get-loaders

#如果网太差导致下载失败,第二次下载会报python的错误。使用如下方法:
[root@cobbler ~]# yum -y install syslinux
[root@cobbler ~]# cp -r /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
[root@cobbler ~]# cp -r /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
[root@cobbler ~]# systemctl restart cobblerd

再次执行cobbler get-loaders,如果出现下图情况,原因是安装的cobbler版本中,压根就不支持使用该命令下载引导启动文件,只要保证安装了最新的syslinux软件包,然后忽略本条内容即可。

 问题6:

#添加rsync到自启动并启动rsync

systemctl enable rsyncd
systemctl start rsyncd

问题7:

#与debain相关,如果不使用cobbler推送debain系统可以忽略不记
[root@cobbler ~]# yum -y install debmirror
[root@cobbler ~]# sed -i  's|@dists=.*|#@dists=|'  /etc/debmirror.conf
[root@cobbler ~]# sed -i  's|@arches=.*|#@arches=|'  /etc/debmirror.conf


问题8 :

#ksvalidator未找到,安装pykickstart软件包。

yum install pykickstart -y

问题9:

# 设置默认root密码(客户端安装之后,系统的root密码)。
首先,,生成你想要的密码的加密字符串,然后复制运行命令之后的加密代码:
#执行
openssl passwd -1 -salt 'abc' '123456'
#得到新密码
$1$abc$mJPQCTATLDV5aNzcHMYLr/            
#再执行
vim /etc/cobbler/settings
#修改settings配置文件中下面位置,将双引号中的旧密码替换成新密码
default_password_crypted: "$1$123456$wOSEtcyiP2N/IfIl15W6Z0"

问题10:

#未找到防护工具,并且必须使用防护工具才能使用(可选)电源管理功能。 安装cman或fence-agents以使用它们。

yum -y install fence-agents

 接着重启Cobbler服务

service cobblerd restart

最后再次执行cobbler check

#忽略这两条即可,第一条是修改了selinux配置文件后未重启服务器的原因,第二条与debian相关。

4.7 配置Cobbler-DHCP 

(1)修改cobbler配置

vim /etc/cobbler/settings
#修改settings中参数,由cobbler控制dhcp
manage_dhcp: 1

 (2)修改dhcp.templates配置文件

[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.139.0 netmask 255.255.255.0 {
     option routers             192.168.139.2;                        #修改成本机网关
     option domain-name-servers 114.114.114.114;                      #修改成本机DNS
     option subnet-mask         255.255.255.0;                        #修改成本机子网掩码
     range dynamic-bootp        192.168.139.100 192.168.139.254;      #可分配的IP范围

 (3)重新启动Cobbler服务

systemctl restart cobblerd.service

(4)运行Cobbler sync命令使配置生效,让DHCP、HTTP被Cobbler接管

cobbler sync

效果图如下:

 4.8 导入CentOs-7的镜像

(1)创建目录存放镜像

mkdir /mnt/CentOS7.1

(2)挂载光盘镜像

mount /dev/cdrom /mnt/CentOS7.1

如果报错mount: 在 /dev/sr0 上找不到媒体

 解决办法:打开虚拟机设置,在镜像选项中将设备状态的已连接勾选上,然后点击确定即可。

 再次执行 mount /dev/cdrom /mnt/CentOS7.1 成功

 (3)使用cobbler import命令导入镜像

cobbler import --path=/mnt/CentOS7.1 --name=Centos-7.1 --arch=x86_64

#命令格式说明:
--path:镜像路径;
--name:安装引导名;
--arch:32位或64位。


#参数说明:
--name为安装源定义一个名字;
--arch指定安装源是32位还是64位、ia6,目前支持的选项有:x86| x86_64|ia64


#两点注意事项如下。
a.该安装源的唯一标示就是这两个参数。
本例导人成功后,安装源的唯一标示就是:CentOS-7.1-x86_64,如果重复,系统会提示导人
失败,其他命令可通过cobbler --help来进行查看。如果需要更多的参数定制,也可以查看官
方文档:man cobbler,然后查找import的配置,可以使用另外一个命令:cobbler distro。

导入时间需要那么两三分钟,静静等待即可,正常导完之后会给出如下提示:

(4)查看镜像列表

cobbler list

 4.9 Ks文件配置

默认的kickstarts文件放在/var/lib/cobbler/kickstarts/目录下

(1)进入目录

cd /var/lib/cobbler/kickstarts

(2)自定义ks文件

执行vim CentOS-7.1-x86_64.ks进行编辑,将下方Ks文件粘贴进去

# kickstart template for Fedora 8 and later.
# (includes %end blocks)
# do not use with earlier distros
 
#platform=x86, AMD64, or Intel EM64T
# System authorization information
#auth  --useshadow  --enablemd5
authconfig --enableshadow --passalgo=sha512
# System bootloader configuration
bootloader --location=mbr --driveorder=sda --append="nomodeset crashkernel=auto rhgb quiet"
# 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=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot
logging --level=info
 
#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone  Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
#autopart
part /boot --fstype=ext4 --asprimary --size=200
part swap --asprimary --size=1024
part / --fstype=ext4 --grow --asprimary --size=200
 
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
 
%packages
@base
@compat-libraries
@core
@debugging
@development
@dial-up
@hardware-monitoring
@performance
@server-policy
sgpio
device-mapper-persistent-data
systemtap-client
tree
lrzsz
telnet
nmap
dos2unix
%end
 
%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end
 
%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
%end
 
%post
systemctl disable postfix.service
 
$yum_config_stanza
%end

(3)查看Kickstart配置

cobbler profile report --name=Centos-7.1-x86_64

(4)修改指定的Kickstart文件

[root@localhost kickstarts]# cobbler profile list
   Centos-7.1-x86_64
[root@localhost kickstarts]# cobbler profile getks --name "Centos-7.1-x86_64"
[root@localhost kickstarts]# cobbler profile edit --name=Centos-7.1-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.1-x86_64.ks
[root@localhost kickstarts]# cobbler profile edit --name Centos-7.1-x86_64 --kopts='net.ifnames=0 biosdevname=0'

(5)同步Cobbler

cobbler sync

5.验证

5.1 将服务端所有服务重启

systemctl restart xinetd.service
systemctl restart cobblerd.service
systemctl restart httpd.service

5.2 新建一台虚拟机

至此cobbler算是配置完成了,现在可以愉快的安装操作系统了,新建一台虚拟机,虚拟机指定用PXE网络启动,然后选择我们挂载的镜像安装即可。


评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

翊科技

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值