Cobbler无人值守安装centos6.8系统

Cobbler简介

Cobbler是通过将DHCP、TFTP、DNS、HTTP等服务进行集成,创建一个中央管理节点,其可以实现的功能有配置服务,创建存储库,解压缩操作系统媒介,代理或集成一个配置管理系统,控制电源管理等。 Cobbler的最终目的是实现无需进行人工干预即可安装机器。在进行进一步的操作之前,我们有必要先了解下pxe和kickstart 。

Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。该工具使用python开发,小巧轻便(才15k行python代码),使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP、DNS、TFTP、RSYNC以及yum仓库、构造系统ISO镜像。 Cobbler支持命令行管理,web界面管理,还提供了API接口,可以方便二次开发使用。 Cobbler客户端Koan支持虚拟机安装和操作系统重新安装,同时支持服务器的电源管理,使重装系统更便捷。更多内容可以查看cobbler官方网站!

cobbler官方网站

Cobbler功能:

pxe支持
dhcp管理
dns服务管理(bind,dnsmasq)
电源管理
kickstart支持
yum仓库管理
tftp(pxe启动时需要)
apache,提供ks得安装源,并提供定制化得ks配置,同时,它和apache做了深度整合,通过cobbler,可以使redhat/centos/fedora系统得快速部署,同时也支持suse、debian(ubuntu)系统,通过配置开可以支持windows

Server端

启动Cobbler服务
进行Cobbler错误检查,执行cobbler check命令
进行配置同步,执行cobbler sync命令
复制相关启动文件到TFTP目录中
启动DHCP服务,提供地址分配
DHCP服务分配IP地址
TFTP传输启动文件
Server端接收安装信息
Server端发送ISO镜像与Kickstart文件

Client端

客户端以PXE模式启动
客户端获取IP地址
通过TFTP服务器获取启动文件
进入Cobbler安装选择界面
根据配置信息准备安装系统
加载Kickstart文件
传输系统安装的其它文件
进行安装系统

环境部署

centos 7.7-1908 外网10.0.0.44 内网176.16.1.44
说明:虚拟机网卡采用NAT模式或者仅主机模式,不要使用桥接模式,因为后面会搭建DHCP服务器,在同一个局域网多个DHCP服务会有冲突。VMware的NAT模式的dhcp服务也关闭,避免干扰。

安装

[root@c7-44 ~]# yum -y install cobbler cobbler-web tftp-server pykickstart httpd dhcp xinetd debmirror
cobbler        #cobbler程序包
cobbler-web     #cobbler的web服务包
pykickstart    #cobbler检查kickstart语法错误
httpd      	#Apache web服务
dhcp       #Dhcp服务
tftp      #tftp服务
xinetd  #诸多服务的超级守护进程

[root@c7-44 ~]# systemctl start httpd cobblerd            #启动cobbler及httpd并加入开机启动
[root@c7-44 ~]# systemctl enable httpd cobblerd

配置cobbler

检查Cobbler的配置,如果看不到下面的结果,再次重启cobbler。

[root@c7-44 ~]# 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 fe will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines thatuse it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other tha0.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 dowthem, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* verf the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want port all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' coms the easiest way to resolve these requirements.
5 : enable and start rsyncd.service with systemctl
6 : comment out 'dists' on /etc/debmirror.conf for proper debian support
7 : comment out 'arches' on /etc/debmirror.conf for proper debian support
8 : The default password used by the sample templates for newly installed machines (default_password_crypted in /bbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-herur-password-here'" to generate new one
9 : fencing tools were not found, and are required to use the (optional) power management features. install cman ce-agents to use them

Restart cobblerd and then run 'cobbler sync' to apply changes.

看到上面出现的问题,然后一个一个的进行解决,先进行设置为可以动态配置,也可以直接更改配置文件

[root@c7-44 ~]# sed -ri '/allow_dynamic_settings:/c\allow_dynamic_settings: 1' /etc/cobbler/settings
[root@c7-44 ~]# grep allow_dynamic_settings /etc/cobbler/settings
allow_dynamic_settings: 1
[root@c7-44 ~]# systemctl restart cobblerd

逐个解决上面的问题

[root@c7-44 ~]# cobbler setting edit --name=server --value=10.0.0.44      #1.配置server地址
[root@c7-44 ~]# cobbler setting edit --name=next_server --value=10.0.0.44    #2,配置next_server地址
[root@c7-44 ~]# sed -ri '/disable/c\disable = no' /etc/xinetd.d/tftp           #3.配置xinetd管理tftp
[root@c7-44 ~]# systemctl enable xinetd    
[root@c7-44 ~]# systemctl restart xinetd
[root@c7-44 ~]# cobbler get-loaders                # 4.boot-loaders 
[root@c7-44 ~]# systemctl start rsyncd           #5.启动sync
[root@c7-44 ~]# systemctl enable rsyncd
[root@c7-44 ~]# sed -i 's#@dists="sid";#\#@dists="sid";#gp' /etc/debmirror.conf        #6和7.debian support
[root@c7-44 ~]# sed -i 's#@arches="i386";#\#@arches="i386";#g' /etc/debmirror.conf   
   #8.default_password_crypted
# 注意:这里设置的密码是clbbler安装完系统后,默认root用户初始化登录密码,用 openssl 生成一串密码后加入到 cobbler 的配置文件(/etc/cobbler/settings)里,替换 default_password_crypted 字段 
[root@c7-44 ~]# openssl passwd -1 -salt `openssl rand -hex 4` '123456'
$1$2a939c66$8/OJHSFoQfA86pRhHpt2j1
[root@c7-44 ~]# cobbler setting edit --name=default_password_crypted --value='$1$2a939c66$8/OJHSFoQfA86pRhHpt2j1'
[root@c7-44 ~]# yum -y install fence-agents           #9.安装fencing tools
[root@c7-44 ~]# systemctl restart cobblerd
[root@c7-44 ~]# cobbler sync
[root@c7-44 ~]# cobbler check
No configuration problems found.  All systems go.

配置DHCP

[root@c7-44 ~]# cobbler setting edit --name=manage_dhcp --value=1
[root@c7-44 ~]# vim /etc/cobbler/dhcp.template
#修改一下几处
subnet 10.0.0.0 netmask 255.255.255.0 {   #这里改为分配的网段和掩码
     option routers             10.0.0.254;  #如果有网关,这里改为网关地址
     option domain-name-servers 223.5.5.5;   #如果有DNS,这里改为DNS地址
     option subnet-mask         255.255.255.0;  #改为分配的IP的掩码
     range dynamic-bootp        10.0.0.100 10.0.0.200;  #改为分配的IP的范围

同步cobbler配置

[root@c7-44 ~]# cobbler sync

查看一下dhcp,查看cobbler是否可以管理dhcp

[root@c7-44 ~]# cat /etc/dhcp/dhcpd.conf
# ******************************************************************
# Cobbler managed dhcpd.conf file
# generated from cobbler dhcp.conf template (Fri Apr 24 08:34:20 2020)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
# ******************************************************************

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

option pxe-system-type code 93 = unsigned integer 16;

subnet 10.0.0.0 netmask 255.255.255.0 {
     option routers             10.0.0.254;
     option domain-name-servers 223.5.5.5;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        10.0.0.100 10.0.0.200;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                10.0.0.44;
     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 {
                  filename "ia64/elilo.efi";
          } else if option pxe-system-type = 00:06 {
                  filename "grub/grub-x86.efi";
          } else if option pxe-system-type = 00:07 {
                  filename "grub/grub-x86_64.efi";
          } else if option pxe-system-type = 00:09 {
                  filename "grub/grub-x86_64.efi";
          } else {
                  filename "pxelinux.0";
          }
     }

}

# group for Cobbler DHCP tag: default
group {
}

cobbler命令帮助

命令 说明
cobbler check 核对当前设置是否有问题
cobbler list 列出所有的cobbler元素
cobbler report 列出元素的详细信息
cobbler sync 同步配置到数据目录,更改配置最好都执行一下
cobbler reposync 同步yum仓库
cobbler distro 查看导入的发行版系统信息
cobbler system 查看添加的系统信息
cobbler profile 查看配置信息

这时候创建一个新虚拟机可以获取到如下信息,没有镜像选择,只能从本地启动。
在这里插入图片描述

Cobbler安装centos6.8

注意:由于我这台是在centos7系统上面配置的cobbler,并没有centos6.8镜像,所以需要上传了一个centos6.8的镜像并进行挂载。

创建挂载点并挂载

[root@cobbler ~]# ll
total 3824644
-rw-------. 1 root root       1273 Apr 17 14:41 anaconda-ks.cfg
-rw-r--r--  1 root root 3916431360 Apr 24 16:44 CentOS-6.8-x86_64-bin-DVD1.iso
[root@cobbler ~]# mkdir /centos6.8/
[root@cobbler ~]# mount -o loop CentOS-6.8-x86_64-bin-DVD1.iso /centos6.8

查看挂载后的目录

[root@cobbler ~]# ls /centos6.8/
CentOS_BuildTag  isolinux                  RPM-GPG-KEY-CentOS-Debug-6
EFI              Packages                  RPM-GPG-KEY-CentOS-Security-6
EULA             RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Testing-6
GPL              repodata                  TRANS.TBL
images           RPM-GPG-KEY-CentOS-6

导入镜像

[root@cobbler ~]# cobbler import --path=/centos6.8 --name=centos6.8 --arch=x86_64
# --path 镜像路径
# --name 为安装源定义一个名字
# --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
# 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:centos6.8,如果重复,系统会提示导入失败。

查看导入后镜像信息

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

查看profile信息

[root@cobbler ~]# cobbler profile report --name=centos6.8-x86_64
Name                           : centos6.8-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : centos6.8-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
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
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

编辑centos6.8镜像的kickstart文件

[root@cobbler ~]# cd /var/lib/cobbler/kickstarts/
[root@cobbler kickstarts]# cp sample_end.ks centos6.8.ks
[root@cobbler kickstarts]# vim centos6.8.ks
# This kickstart file should only be used with EL > 5 and/or Fedora > 7.
# For older versions please use the sample.ks kickstart file.
# Install OS instead of upgrade
install
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# System timezone
timezone  Asia/ShangHai
#Root password
rootpw --iscrypted $default_password_crypted
# System authorization information
auth  --useshadow  --enablemd5
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Use network installation
url --url=$tree

# Clear the Master Boot Record
zerombr
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
part /boot --fstype=ext4 --size=200
part swap --fstype=swap --size=2048
part / --fstype=ext4 --grow --size=200 --asprimary

# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Do not configure the X Window System
skipx
# Run the Setup Agent on first boot
firstboot --disable
# Reboot after installation
reboot


%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end

%packages
$SNIPPET('func_install_if_enabled')
@core
@base
tree
nmap
wget
lftp
lrzsz
telnet
%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

sed -ri "/^#UseDNS/c\UseDNS no" /etc/ssh/sshd_config
sed -ri "/^GSSAPIAuthentication/c\GSSAPIAuthentication no" /etc/ssh/sshd_config
%end

# 动态编辑指定使用新的kickstart文件
[root@cobbler kickstarts]# cobbler profile edit --name=centos6.8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.8.ks
[root@cobbler kickstarts]# cobbler profile report --name=centos6.8-x86_64 |grep Kickstart   # 验证是否更改成功
Kickstart                      : /var/lib/cobbler/kickstarts/centos6.8.ks
Kickstart Metadata             : {}

同步cobbler配置

[root@cobbler kickstarts]# cobbler sync

新建虚拟机进行测试

在这里插入图片描述
用键盘方向键选择安装的系统,如果超时未选择,默认不安装,安装完后即可登录系统。

原创文章 96 获赞 4 访问量 2169

猜你喜欢

转载自blog.csdn.net/weixin_46380571/article/details/105740180