实现cobbler+pxe自动化装机

1、简介

Cobbler是一个自动化和简化系统安装的工具,通过使用网络引导来实现系统自动化安装。Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler构成组件包括:

Distros(发行版):表示一个操作系统,它承载了内核和initrd的信息,以及内核参数等其他数据
Profile(配置文件):包含一个发行版、一个kickstart文件以及可能的存储库,还包含更多特定的内核参数等其他数据
Systems(系统):表示要配给的额机器。它包含一个配置文件或一个景象,还包含IP和MAC地址、电源管理(地址、凭据、类型)、(网卡绑定、设置valn等)
Repository(镜像):保存一个yum或rsync存储库的镜像信息
Image(存储库):可替换一个包含不属于此类比的额文件的发行版对象(例如,无法分为内核和initrd的对象)。

本次实例我使用一台虚拟机来模拟pxe+cobbler,相关服务都安装在此服务器上,系统为centos 7

 

2、配置pxe支持服务

首先需要安装pxe支持所需要的相关服务:

[root@cobbler ~]# yum install -y tftp tftp-server dhcp httpd    #pxe可通过http或ftp等方式提供yum repository,本次我使用http提供仓库
[root@cobbler ~]# yum install -y syslinux  #提供pxe安装所需要的pxelinux.0等文件

接着配置dhcp服务,编辑创建dhcp配置文件:

[root@cobbler ~]# vim /etc/dhcp/dhcpd.conf
option domain-name "magedu.com";
option domain-name-servers 114.114.114.114,8.8.8.8;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 10.10.10.0 netmask 255.255.255.0 {
        range 10.10.10.100 10.10.10.200;
        option routers 10.10.10.254;
        filename "pxelinux.0";
        next-server 10.10.10.254;
}

配置完成后启动dhcp服务:

[root@cobbler ~]# systemctl start dhcpd
[root@cobbler ~]# cat /var/lib/dhcpd/dhcpd.leases
[root@cobbler ~]# systemctl start httpd
[root@cobbler ~]# systemctl start tftp.socket

3、配置cobbler

[root@cobbler ~]# yum install -y epel-release
[root@cobbler ~]# yum install -y cobbler
[root@cobbler ~]# systemctl start cobblerd
[root@cobbler ~]# 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 : SELinux is enabled. Please review the following wiki page for details on ensuring 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, 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.  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.
6 : enable and start rsyncd.service with systemctl
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
8 : ksvalidator was not found, install pykickstart
9 : 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
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.

通常来说cobbler服务在初次检查时总会有各种各样的报错,我们只需要按照对应的报错寻找解决办法即可。

首先第1,2、9点都是cobbler 的配置文件,编辑修改cobbler 的配置文件即可:

[root@cobbler ~]# openssl passwd -1 -salt '123456' 'magedu'    #创建新建系统默认登录密码的密钥串
$1$123456$QMBx42LRqK1ZWPfItmpYG0
[root@cobbler ~]# vim /etc/cobbler/settings    #在cobbler配置文件中修改以下配置
server: 10.10.10.254
next_server: 10.10.10.254
default_password_crypted: "$1$123456$QMBx42LRqK1ZWPfItmpYG0"    #此处是指定自动安装的系统的登录密钥
[root@cobbler ~]# systemctl stop firewalld
[root@cobbler ~]# systemctl disable firewalld
[root@cobbler ~]# setenforce 0
[root@cobbler ~]# vim /etc/xinetd.d/tftp
        disable                 = no

第五点,如果当前节点可以访问互联网,执行“cobblerget-loader”命令下载pxelinux.0,menu.c32,elilo.efi, 或yaboot文件,否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/中的pxelinux.0,menu.c32等文件至/var/lib/cobbler/loaders目录中,此处我们先直接复制/usr/share/syslinux目录中的文件到指定目录,看看是否能解决:

[root@cobbler ~]# cp -ar /usr/share/syslinux/* /var/lib/cobbler/loaders/
[root@cobbler ~]# systemctl start rsyncd
[root@cobbler ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd
[root@cobbler ~]# yum install -y debmirror pykickstart fence-agents
[root@cobbler ~]# systemctl restart cobblerd
[root@cobbler ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
    https://github.com/cobbler/cobbler/wiki/Selinux
2 : 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.  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.
3 : comment out 'dists' on /etc/debmirror.conf for proper debian support
4 : comment out 'arches' on /etc/debmirror.conf for proper debian support

第一点报错已经停用了,所以无关要紧;第二点依旧有报错,可根据提示执行cobbler get-loaders即可解决,但是前提是服务器能上网。
最后两点在的指定的文件中注释掉相应的配置段即可:

[root@cobbler ~]# vim /etc/debmirror.conf
#@arches="i386";
#@dists="sid";
[root@cobbler ~]# systemctl restart cobblerd
[root@cobbler ~]# cobbler sync
[root@cobbler ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@cobbler ~]# cobbler import --name=centos-7.2-x86_64 --path=/mnt     #此过程耗时较长,需耐心等待
[root@cobbler ~]# cobbler distro list    #导入完成后,即可查看到相应的distro名字
   centos-7.2-x86_64

镜像会被自动导入到此路径下/var/www/cobbler/ks_mirror,方便后续通过http的方式获取安装源。
另外默认情况下,cobbler会生成一个最小化安装的kickstart文件,如果想要自定义其对应的kickstart profile,可通过下面操作进行:

[root@cobbler ~]# cp centos7.cfg /var/lib/cobbler/kickstarts/    #复制自定义的kickstart文件到指定的目录下
[root@cobbler ~]# cobbler profile add --name=centos-7.2-x86_64-custom --distro=centos-7.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg    #创建自定义的kickstart profile
[root@cobbler ~]# cobbler profile list
   centos-7.2-x86_64
   centos-7.2-x86_64-custom
[root@cobbler ~]# ll /var/www/cobbler/
总用量 0
drwxr-xr-x. 4 root root 54 1月   5 01:56 images
drwxr-xr-x. 5 root root 67 1月   5 01:54 ks_mirror
drwxr-xr-x. 2 root root 54 1月   5 01:56 links
drwxr-xr-x. 2 root root  6 9月  18 23:16 localmirror
drwxr-xr-x. 2 root root 37 1月   5 00:28 misc
drwxr-xr-x. 2 root root  6 9月  18 23:16 pub
drwxr-xr-x. 2 root root  6 9月  18 23:16 rendered
drwxr-xr-x. 2 root root  6 9月  18 23:16 repo_mirror
drwxr-xr-x. 2 root root 62 1月   5 00:28 svc
[root@cobbler ~]# ll /var/lib/tftpboot/
总用量 308
drwxr-xr-x. 3 root root     17 1月   5 01:00 boot
drwxr-xr-x. 2 root root      6 9月  18 23:16 etc
drwxr-xr-x. 2 root root     77 1月   5 01:00 grub
drwxr-xr-x. 4 root root     54 1月   5 01:56 images
drwxr-xr-x. 2 root root      6 9月  18 23:16 images2
-rw-r--r--. 1 root root  26140 1月   5 01:00 memdisk
-rw-r--r--. 1 root root  55012 1月   5 01:00 menu.c32
drwxr-xr-x. 2 root root      6 9月  18 23:16 ppc
-rw-r--r--. 1 root root  26764 1月   5 01:00 pxelinux.0
drwxr-xr-x. 2 root root     20 1月   5 02:18 pxelinux.cfg
drwxr-xr-x. 2 root root     25 1月   5 01:00 s390x
-rw-r--r--. 1 root root 198236 1月   5 01:00 yaboot

如果确认文件都创建无误,即可进行cobbler的自动化安装测试。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值