cobbler自动安装

cobbler是PXE的二次封装,可以将多个安装参数封装到一个菜单中。和PXE一样,也是通过网络安装的。

百度百科的一句话足以说明:网络安装服务器套件 Cobbler(补鞋匠)从前,我们一直在做
装机民工这份很有前途的职业。自打若干年前 Red Hat 推出了 Kickstart,此后我们顿觉身价倍增。不再需要刻了光盘一台一台地安装 Linux,只要搞定 PXE、DHCP、TFTP,还有那满屏眼花缭乱不知所云的 Kickstart 脚本,我们就可以像哈里波特一样,轻点魔棒,瞬间安装上百台服务器。这一堆花里胡哨的东西可不是一般人都能整明白的,没有大专以上学历,通不过英语四级, 根本别想玩转。总而言之,这是一份多么有前途,多么有技术含量的工作啊。很不幸,Red Hat 最新(Cobbler项目最初在2008年左右发布)发布了网络安装服务器套件 Cobbler(补鞋匠),它已将 Linux 网络安装的技术门槛,从大专以上文化水平,成功降低到初中以下,连补鞋匠都能学会。对于我们这些在装机领域经营多年,经验丰富,老骥伏枥,志在千里的民工兄弟们来说,不啻为一个晴天霹雳。

工作流程

转载至百度的图片

  • client裸机配置了从网络启动后,开机后会广播请求DHCP服务器(cobbler server管控),得到其分配好的一个ip地址
  • DHCP服务器收到请求后,发送reponese,包括其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 image
  • client加载kickstart
  • client接收os image,安装os image

cobbler工作组件

  • distor:发行版,可以理解为一个操作系统,它内部含有vmlinuz和initrd的信息,以及内核其它的数据
  • repository:保存了一个yum以及一个rsync仓库的镜像信息。
  • profile:由发行版和一个kickstart一起生成的,还有repo仓库
  • system:表示定制的客户端机器,它包含了一个配置文件或一个镜像,还包含了ip和mac地址,电源管理(地址,凭据,类型)以及更为专业的数据信息。
  • 镜像(image):可替换一个包含不属于此类别的文件的发行版对象(eg: 无法作为内核和initrd的对象)。

配置文件

1)安装cobbler 安装cobbler时,会自动生成httpd和tftp-server。 它属于epel源。
[root@localhost ~]# yum install cobbler
配置文件目录解释
/etc/cobbler/settingscobbler主配置文件
/etc/cobbler/isoiso模板配置文件
/etc/cobbler/pxepxe模板文件
/etc/cobbler/power电源配置文件
/etc/cobbler/user.confweb服务授权配置文件
/etc/cobbler/users.digstweb访问的用户密码配置文件
/etc/cobbler/dhcp.templatedhcp服务器的配置模板
/etc/cobbler/dnsmasq.templateDHS配置模板
/etc/cobbler/tftp.templatetftp配置模板
/etc/cobbler/modules.conf模块配置文件
数据目录解释
/var/lib/cobbler/config/用于存放distors,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_mirroryum仓库存储目录
日志目录解释
/var/www/cobbler/installing客户端安装日志
/var/www/cobbler /cobbler.cfgcobbler安装日志

cobbler几个重要的参数

  • default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac.":新安装机器的默认root密码
  • manage_dhcp: 0:是否有cobbler来控制dhcp服务器,0表示不是
  • manage_tftpd: 1 :是否由cobbler控制tftp服务器,1表示是
  • pxe_just_once: 0:防止始终从网络引导,机器会告诉cobbler安装已完成,cobbler会将netboot标志更改为false 强制机器从本地磁盘引导。如果你的第一个选项是pxe安装,则启动此项,否则禁用此项。
  • next_server: 127.0.0.1:tftp服务器地址
  • server:cobbler服务器地址

使用cobbler

第一次使用cobbler之前,我们需要对cobbler进行一次check。使用命令cobbler check即可

[root@localhost ~]# systemctl start cobblerd  # 首先启动cobbler
[root@localhost ~]# systemctl start httpd #cobbler启动需要htppd的支持

[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 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.  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 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
# check之后会有一大推问题,每个解决之后,就能正常使用。



1、在setting配置文件中的server字段应该是local_host之外的地址,否则kickstart文件将无法使用,它的地址或主机名称是所有计算机可以访问的。需要将其设置成dhcp同网段的地址
server:192.168.30.2


2、next-server为tftp的服务器地址,需要将它设置127.0.0.1以外的地址
 next_server: 192.168.30.2

3、将tftp设置开机启动。  因为是centos7系统,所以不用xinetd。
[root@localhost ~]# systemctl is-enabled tftp.socket
enabled

4、缺少一些网络加载程序,如pxelinux.0,menu.c32等等。如果你有网络的话可以使用“cobbler get-loaders”下载它们。  如果你已经安装syslinux的包,则可以忽略此消息。
[root@localhost ~]# cobbler get-loaders
[root@localhost ~]# ls /var/lib/cobbler/loaders
COPYING.elilo     COPYING.yaboot  grub-x86_64.efi  menu.c32    README
COPYING.syslinux  elilo-ia64.efi  grub-x86.efi     pxelinux.0  yaboot


5、启动rsyncd.service(增量文件传输服务)并设置成开机启动
[root@localhost ~]# systemctl start rsyncd.service 
[root@localhost ~]# systemctl enable rsyncd.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

6、缺少debian的安装包,用来debian的部署。咱用的是centos,所以可以忽略此消息

7、新安装的计算机的密码是cobbler,不安全,需要使用"openssl passwd -1 -salt"命令来重新生成。并`修改default_password_crypted`此项
[root@localhost ~]# openssl passwd -1 -salt 1234
Password: 
$1$1234$8anOOnKezp8tgVOI5G0gb/

8、电源管理功能,可以忽略


全部修改完之后。重新check一下
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
2 : 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.

配置dhcp服务器

直接由cobbler管理dhcp服务器,需要将manage dhcp:0 改为1

manage_dhcp: 1

cobbler控制dhcp服务器,是通过/etc/cobbler/dhcp.template来对/etc/dhcp/dhcpd.confg文件直接进行修改
在这里插入图片描述

在这里插入图片描述

修改完之后重启服务 ,查看/etc/dhcp/dhcpd.conf

[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler sync  # 每次重启之后,sync一下

[root@localhost ~]# cat /etc/dhcp/dhcpd.conf   #自动生成模板 
# ******************************************************************
# Cobbler managed dhcpd.conf file
# generated from cobbler dhcp.conf template (Tue Jan 14 20:24:22 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.
...

创建distro

使cobbler变得可用的第一步为定义distro,其可以通过为其指定外部的安装引导内核及ramdisk文件的方式实现。而如果已经有完整的系统安装树(如CentOS6的安装镜像)则推荐使用import直接导入的方式进行。

[root@localhost ~]# cobbler import --name=centos-7.7-x86_64 --path=/mnt/cdrom --arch=x86_64
#这个操作会将cdrom里的文件全部复制到/var/www/cobbler目录下。

[root@localhost ~]# cobbler distro list
   centos-7.7-x86_64

定义了distro之后,就可以进行安装了。不过是最小化得安装,如果想按照你的ks文件进行安装的话,需要定义个profile。

创建profile

profile文件就是distro加上一个kickstart文件来提供系统的安装配置。如果已经定义好distro,那么我们就可以创建出distro的引导安装条目

[root@localhost tftpboot]# cobbler profile add --name=x86_64-centos7-desktop --distro=centos-7.7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7.cfg
[root@localhost tftpboot]# cobbler profile list
   centos-7.7-x86_64
   x86_64-centos7-desktop
[root@localhost ~]# cobbler sync


查看一下profile 详情
[root@localhost tftpboot]# cobbler profile report --name=x86_64-centos7-desktop
Kickstart                      : /var/lib/cobbler/kickstarts/ks7.cfg #这行表示这个profile已经使用了ks7.cfg文件

PS:ks文件中指定的url,也可以写成$tree,cobbler看到这个变量之后,会自动的去寻找网址。默认的小化安装的ks文件就是使用这个变量

[root@localhost ~]# cat /var/lib/cobbler/kickstarts/sample_end.ks 
url --url=$tree

[root@localhost ~]# cat /var/lib/cobbler/kickstarts/ks7.cfg 
url --url="http://192.168.30.2/cblr/ks_mirror/centos-7.7-x86_64/"

#此处的cblr目录是cobbler的别名。它在/etc/httpd/conf.d/cobbler.confg有定义

测试,使用自己的kickstart安装。

在这里插入图片描述

安装gnome图形包。成功安装。

在这里插入图片描述

补充:
kickstart文件不要出现中文,如果出现了中文,可能会报以下的错误。

Sun May 24 13:06:22 2020 - INFO | REMOTE generate_kickstart; user(?)
Sun May 24 13:06:22 2020 - INFO | generate_kickstart
Sun May 24 13:06:22 2020 - INFO | Exception occured: <class 'cobbler.cexceptions.CX'>
Sun May 24 13:06:22 2020 - INFO | Exception value: 'calling find with no arguments'
Sun May 24 13:06:22 2020 - INFO | Exception Info:
  File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 1052, in generate_kickstart
    return self.api.generate_kickstart(profile,system)
   File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 680, in generate_kickstart
    return self.kickgen.generate_kickstart_for_profile(profile)
   File "/usr/lib/python2.7/site-packages/cobbler/kickgen.py", line 286, in generate_kickstart_for_profile
    g = self.api.find_profile(name=g)
   File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 511, in find_profile
    return self._config.profiles().find(name=name, return_list=return_list, no_errors=no_errors, **kargs)
   File "/usr/lib/python2.7/site-packages/cobbler/collection.py", line 90, in find
    raise CX(_("calling find with no arguments"))

只要利用网页的方式可以打开ks文件,那就没问题。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值