自动化运维之cobbler安装实战。

7年前 (2017-09-16) gtj cobbler, WEB应用, 自动化 0评论 已收录 1893℃

一.简介

1.PXE

PXE(preboot execute environment,预启动执行环境)是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行,由这个启动软件包完成终端(客户端)基本软件设置,从而引导预先安装在服务器中的终端操作系统。PXE可以引导多种操作系统,如:Windows95/98/2000/windows2003/windows2008/winXP/win7/win8,linux系列系统等。

2.KickStart

KickStart是一种无人职守安装方式。KickStart的工作原理是通过记录典型的安装过程中所需人工干预填写的各种参数,并生成一个名为ks.cfg的文件;在其后的安装过程中(不只局限于生成KickStart安装文件的机器)当出现要求填写参数的情况时,安装程序会首先去查找KickStart生成的文件,当找到合适的参数时,就采用找到的参数,当没有找到合适的参数时,才需要安装者手工干预。这样,如果KickStart文件涵盖了安装过程中出现的所有需要填写的参数时,安装者完全可以只告诉安装程序从何处取ks.cfg文件,然后去忙自己的事情。等安装完毕,安装程序会根据ks.cfg中设置的重启选项来重启系统,并结束安装。

3.Cobbler介绍

Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
总结:Cobbler是对kickstart的封装,简化安装步骤、使用流程,降低使用者的门槛。官网:http://cobbler.github.io/

4.Cobbler集成的服务

PXE服务支持
DHCP服务管理
DNS服务管理(可选bind,dnsmasq)
电源管理
Kickstart服务支持
YUM仓库管理
TFTP(PXE启动时需要)
Apache(提供kickstart的安装源,并提供定制化的kickstart配置)

5.cobbler各主要组件关系图


二.cobbler环境准备

[root@client openvpn]# cat /etc/redhat-release 
CentOS Linux release 7.1.1503 (Core)
[root@client openvpn]# uname -r
3.10.0-229.el7.x86_64
[root@client kickstarts]# ifconfig eth0|awk -F "[ :]+" 'NR==2 {print $3}'
10.0.0.9
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config && grep 'SELINUX=disabled' /etc/selinux/config
[root@client kickstarts]#  getenforce
Disabled
[root@client ~]# iptables -F

三.安装cobbler

1. 安装EPEL源

rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

2.安装cobbler

 yum install  dhcp tftp-server pykickstart httpd  xinetd cobbler cobbler-web rsync  cman -y

3.启动服务

systemctl start  httpd.service
systemctl start  cobblerd

四.配置cobbler

1.Cobbler的检测

[root@client ~]# 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.Filesin 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.

2.cobbler配置setting

对于上述问题,一个个的解决,其实每个问题的后面都给出了解决方法。

a.sed -i 's/server: 127.0.0.1/server:10.20.23.245 /' /etc/cobbler/settings
b.sed -i 's/next_server: 127.0.0.1/next_server:10.20.23.245/' /etc/cobbler/settings
c.修改/etc/xinetd.d/tftp文件中的disable参数修改为 disable = no
d.用 Cobbler 管理 DHCP
sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings && grep
'manage_dhcp: 1' /etc/cobbler/settings
e.执行 systemctl enable rsyncd命令即可;
f.[root@client ~]# openssl passwd -1 -salt 'gtj' 'gtj'
$1$gtj$RGFlrTiwWUbU54xBN4C/L0
 /etc/cobbler/settings
default_password_crypted: "$1$gtj$RGFlrTiwWUbU54xBN4C/L0"
g.yum -y install  fence-agents  debmirror
sed -i  's/@arches="i386";/#@arches="i386";/'  /etc/debmirror.conf 
sed -i 's/@dists="sid";/#@dists="sid";/'  /etc/debmirror.conf
systemctl restart cobblerd
h.[root@client ~]# cobbler get-loaders

3.再次检查环境:

[root@client conf.d]# cobbler check
No configuration problems found.  All systems go.

4.配置DHCP

 sed -i 's#manage_dhcp: 0#manage_dhcp: 1#g' /etc/cobbler/settings #使用cobbler管理dhcp
 cat  /etc/cobbler/dhcp.template
subnet 10.0.0.0 netmask 255.255.255.128 {
     option routers             10.0.0.2;
     option domain-name-servers 10.0.0.2;
     option subnet-mask         255.255.255.128;
     range dynamic-bootp        10.0.0.10 10.0.0.120;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
................

5.同步cobbler

systemctl restart xinetd 
systemctl restart cobblerd
# 同步最新 cobbler 配置,它会根据配置自动修改 dhcp 等服务。
cobbler sync 
# 再看一下 dhcp 的配置文件。
 less /etc/dhcp/dhcpd.conf
  设置开机启动
chkconfig httpd on
chkconfig xinetd on
chkconfig cobblerd on
chkconfig dhcpd on

五.Cobbler管理

1.导入镜像

mount /dev/cdrom /mnt/
[root@client network-scripts]# cobbler import --path=/mnt/ --name=CentOS-7.2-x86_64   --arch=x86_64
参数说明:
# --path 镜像路径
# --name 为安装源定义一个名字
# --arch 指定安装源是 32 位、64 位、ia64, 目前支持的选项有: x86│x86_64│ia64
# 安装源的唯一标示就是根据 name 参数来定义,本例导入成功后,安装源的唯一标示就是:
CentOS-7.1-x86_64,如果重复,系统会提示导入失败。
 cobbler distro list #列出所有的distro
cobbler profile list #导入distro会自动生成profile
删除一个镜像:
 cobbler profile remove --name=centos6.5-64-x86_64 
cobbler distro remove --name=CentOS-7.1-x86_64
rm /var/www/cobbler/ks_mirror/CentOS-7.* -rf
[root@client config]#  cobbler profile list
   CentOS-7.1-x86_64
[root@client config]#  cobbler distro list
   CentOS-7.1-x86_64

# 镜像存放目录,cobbler 会将镜像中的所有安装文件拷贝到本地一份,放在
/var/www/cobbler/ks_mirror 下的 CentOS-7.1-x86_64 目录下。因此/var/www/cobbler
目录必须具有足够容纳安装文件的空间。
通过浏览器查看镜像:

2.查看安装镜像文件信息

[root@client kickstarts]#  cobbler distro report --name=CentOS-7.1-x86_64 
Name                           : CentOS-7.1-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/CentOS-7.1-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/CentOS-7.1-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7.1-x86_64'}
Management Classes             : []
OS Version                     : rhel7
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

3.指定 ks.cfg文件及调整内核参数

cd /var/lib/cobbler/kickstarts/
cat  CentOS-7-x86_64.cfg
[root@client kickstarts]# cat  CentOS-7-x86_64.cfg 
#Kickstart Configurator for cobbler by Jason Zhao
#platform=x86, AMD64, or Intel EM64T
#System  language
lang en_US
#System keyboard
keyboard us
#Sytem timezone
timezone Asia/Shanghai
#Root password
rootpw --iscrypted $default_password_crypted
#Use text mode install
text
#Install OS instead of upgrade
install
#Use NFS installation Media
url --url=$tree
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr
#Partition clearing information
clearpart --all --initlabel 
#Disk partitioning information
part /boot --fstype xfs --size 1024 --ondisk sda
part swap --size 4096 --ondisk sda    
part / --fstype xfs --size 1 --grow --ondisk sda
#System authorization infomation
auth  --useshadow  --enablemd5 
#Network information
$SNIPPET('network_config')
#network --bootproto=dhcp --device=em1 --onboot=on
# Reboot after installation
reboot
#Firewall configuration
firewall --disabled 
#SELinux configuration
selinux --disabled
#Do not configure XWindows
skipx
#Package install information
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end

%packages
@ base
@ core
sysstat
iptraf
ntp
lrzsz
ncurses-devel
openssl-devel
zlib-devel
OpenIPMI-tools
mysql
nmap
screen
%end

%post
systemctl disable postfix.service
%end

备注:实验的时候part swap --size参数设置大了,不能自动安装了

4.编辑profile,修改关联的ks文件

[root@client kickstarts]# cobbler profile list
   CentOS-7.1-x86_64
[root@client kickstarts]# cobbler profile edit --name=CentOS-7.1-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
CentOS7系统网卡名变成eno...这种,为了运维标准化,我们需要修改为我们常用的eth0,使用下面的参数。但要注意是CentOS7才需要下面的步骤,CentOS6不需要。
[root@client kickstarts]#  cobbler profile edit --name=CentOS-7.1-x86_64  --kopts='net.ifnames=0 biosdevname=0'
新部署机器安装yum源,并同步。建议使用内网yum源,在这里使用阿里云yum源
 yum install -y wget
[root@client kickstarts]#  cobbler reposync #同步yum源
cobbler repo add --name=base --mirror=http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/  --arch=x86_64 --breed=wget  ##wget方式添加yum源
cobbler reposync ##同步yum源
# 每次修改完都要同步一次
cobbler sync  #每次修改profile都需要同步
[root@client kickstarts]# cobbler sync
task started: 2017-09-14_235427_sync
task started (id=Sync, time=Thu Sep 14 23:54:27 2017)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/CentOS-7.1-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/CentOS-7.1-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
copying: /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
copying: /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
...............................

六.客户端通过cobbler安装系统

1.创建一台虚拟机,并开机。


2.可以自定义上面的网址等信息

#修改 Cobbler 提示

[root@client kickstarts]#  vim /etc/cobbler/pxe/pxedefault.template
cobbler sync # 修改配置都要同步


3.然后就开启了自动化安装。


七.定制化安装系统

由于kickstart指定某台服务器使用某个ks文件比较复杂,所以引用Cobbler就很简单。通过物理MAC地址来区分。

1.查看mac地址


2.根据机器的MAC地址,自动绑定IP,网关,dns等。

00:50:56:34:C1:7B
[root@client kickstarts]#  cobbler system add --name=blogcool1 --mac=00:50:56:34:C1:7B  --profile=CentOS-7.1-x86_64  --ip-address=10.0.0.42 --subnet=255.255.255.0 --gateway=10.0.0.2 --interface=eth0 --static=1  --hostname=blogcool1.example.com --name-servers="114.114.114.114 8.8.8.8"
[root@client kickstarts]#  cobbler sync
[root@client kickstarts]# cobbler system list
   blogcool

再次开机安装就不再询问选择了,直接安装。

3.安装完成


八.cobbler的web界面

已经安装 cobbler-web 软件。
访问网址: http://10.0.0.9/cobbler_web 和 https://10.0.0.9/cobbler_web
默认用户名:cobbler
默认密码 :cobbler


web界面也就是命令的图形化,操作很方便.


这里不做演示了,搭建完成。

博主

这货来去如风,什么鬼都没留下!!!

相关推荐

嗨、骚年、快来消灭0回复。

×
订阅图标按钮
Less is more!!!