自动化运维平台之系统自动化安装Cobbler系统使用详解

本文涉及的产品
运维安全中心(堡垒机),企业双擎版 50资产 7天
全局流量管理 GTM,标准版 1个月
云解析 DNS,旗舰版 1个月
简介:

一、简介

   Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。该工具使用python开发,小巧轻便(才15k行python代码),使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP、DNS、以及yum仓库、构造系统ISO镜像。

   Cobbler支持命令行管理,web界面管理,还提供了API接口,可以方便二次开发使用。

   Cobbler客户端Koan支持虚拟机安装和操作系统重新安装,使重装系统更便捷。

二、cobbler提供的功能

   使用 Cobbler,您无需进行人工干预即可安装机器。Cobbler 设置一个 PXE 引导环境(它还可使用 yaboot 支持 PowerPC),并控制与安装相关的所有方面,比如网络引导服务(DHCP 和 TFTP)与存储库镜像。当希望安装一台新机器时,Cobbler 可以:

  • 使用一个以前定义的模板来配置 DHCP 服务(如果启用了管理 DHCP)

  • 将一个存储库(yum 或 rsync)建立镜像或解压缩一个媒介,以注册一个新操作系统

  • 在 DHCP 配置文件中为需要安装的机器创建一个条目,并使用您指定的参数(IP 和 MAC 地址)

  • 在 TFTFP 服务目录下创建适当的 PXE 文件

  • 重新启动 DHCP 服务以反映更改

  • 重新启动机器以开始安装(如果电源管理已启用)

   Cobbler 支持众多的发行版:Red Hat、Fedora、CentOS、Debian、Ubuntu 和 SuSE。当添加一个操作系统(通常通过使用 ISO 文件)时,Cobbler 知道如何解压缩合适的文件并调整网络服务,以正确引导机器。

   Cobbler 可使用 kickstart 模板。基于 Red Hat 或 Fedora 的系统使用 kickstart 文件来自动化安装流程。通过使用模板,您就会拥有基本的 kickstart 模板,然后定义如何针对一种配置文件或机器配置而替换其中的变量。例如,一个模板可能包含两个变量 domainmachine_name。在 Cobbler 配置中,一个配置文件指定 domain=mydomain.com,并且每台使用该配置文件的机器在machine_name 变量中指定其名称。该配置文件中的所有机器都使用相同的 kickstart 安装且针对 domain=mydomain.com 进行配置,但每台机器拥有其自己的机器名称。您仍然可以使用 kickstart 模板在不同的域中安装其他机器并使用不同的机器名称。

   为了协助管理系统,Cobbler 可通过 fence scripts 连接到各种电源管理环境。Cobbler 支持 apc_snmp、bladecenter、bullpap、drac、ether_wake、ilo、integrity、ipmilan、ipmitool、lpar、rsa、virsh 和 wti。要重新安装一台机器,可运行 reboot system foo命令,而且 Cobbler 会使用必要的凭据和信息来为您运行恰当的 fence scripts(比如机器插槽数)。

   除了这些特性,还可使用一个配置管理系统 (CMS)。您有两种选择:该工具内的一个内部系统,或者集成一个现有的外部 CMS,比如 Chef 或 Puppet。借助内部系统,您可以指定文件模板,这些模板会依据配置参数进行处理(与 kickstart 模板的处理方式一样),然后复制到您指定的位置。如果必须自动将配置文件部署到特定机器,那么此功能很有用。

   使用 koan 客户端,Cobbler 可从客户端配置虚拟机并重新安装系统。我不会讨论配置管理和koan 特性,因为它们不属于本文的介绍范畴。但是,它们是值得研究的有用特性

三、安装配置

   1.安装方式

   cobbler可以手动编译安装,也可以基于yum源的安装, 如果需要通过yum源安装,则需要配置epel源,epel源可以通过下载官方给的epel源的目录来实现安装https://fedoraproject.org/wiki/EPEL

1
[root@node1 ~]# yum install cobbler cobbler-web pykickstart debmirror -y

   2.检查配置文件,需要在cobblerd和httpd启动的情况下检查

1
2
3
4
5
6
7
8
9
10
[root@node1 ~]# 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  : 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.
4  : change  'disable'  to  'no'  in  /etc/xinetd.d/rsync
5  : comment out  'dists'  on /etc/debmirror.conf  for  proper debian support
6  : comment out  'arches'  on /etc/debmirror.conf  for  proper debian support
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

   如上个问题的解决办法为

   1.修改/etc/cobbler/settings文件的server参数的值为提供cobbler服务的主机对应的ip地址

   2.修改/etc/cobbler/settings文件的next_server参数的值为提供PXE服务的主机的对应IP地址  

   3.如果当前节点可以访问互联网,执行“cobbler get-loader”命令下载pxelinux.0,menu.c32,elilo.efi, 或yaboot文件,否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/中的pxelinux.0,menu.c32等文件至/var/lib/cobbler/loaders目录中        4.将/etc/xinetd.d/rsync中的disable改为no,或者执行“chkconfig rsync on”

   5.注释/etc/dedmirror.conf文件中的“@dists="sid";”一行

   6.注释/etc/dedmirror.conf文件中的“@arches="i386";”一行

   7.执行“openssl passwd -1 -salt $(openssl rand -hex 4)”生成密码,并用其替换/etc/cobbler/settings文件中default_password_crypted参数

   8.安装cam和fance-agents来实现电源管理

   通过cobbler get-loaders同步文件

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@node1 ~]# cobbler  get -loaders
task started:  2014 - 04 -23_212251_get_loaders
task started (id=Download Bootloader Content, time=Wed Apr  23  21 : 22 : 51  2014 )
downloading http: //www.cobblerd.org/loaders/README to /var/lib/cobbler/loaders/README
downloading http: //www.cobblerd.org/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading http: //www.cobblerd.org/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading http: //www.cobblerd.org/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading http: //www.cobblerd.org/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading http: //www.cobblerd.org/loaders/yaboot-1.3.14-12 to /var/lib/cobbler/loaders/yaboot
downloading http: //www.cobblerd.org/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading http: //www.cobblerd.org/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading http: //www.cobblerd.org/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading http: //www.cobblerd.org/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi

四、配置及启动cobbler所依赖的各服务

   cobbler的运行依赖于dhcp、tftp、rsync及dns服务,其中dhcp可由dhcpd(isc)提供,也可由dnsmasq提供;tftp可由tftp-server程序包提供,也可由cobbler功能提供,rsync有rsync程序包提供,dns可由bind提供,也可由dnsmasq提供

   cobbler可自行管理这些服务中的部分甚至是全部,但需要配置/etc/cobbler/settings文件中的“manange_dhcp”、“manager_tftpd”、“manager_rsync”、“manager_dns”分别来进行定义,另外,由于各种服务都有着不同的实现方式,如若需要进行自定义,需要通过修改/etc/cobbler/modules.conf配置文件中各服务的模块参数的值来实现

   本处通过独立管理。即不通过cobbler来管理这些服务

   1.配置dhcp服务

     定义好所需的“subnet”及其他参数,本处的配置如下    

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@node1 ~]# cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
编辑配置文件
option domain-name  "wangfeng7399" ;
option domain-name-servers  192.168 . 1.201 ;
default -lease-time  43200 ;
max-lease-time  86400 ;
log-facility local7;
subnet  192.168 . 1.0  netmask  255.255 . 255.0  {
         range  192.168 . 1.210  192.168 . 1.230
         option routers  192.168 . 1.253
}
next-server  192.168 . 1.210 ;
filename= "pxelinux.0" ;

   2.配置tftpd服务

1
[root@node1 ~]# chkconfig tftp on

五、配置cobbler

   cobbler的各主要组件间的关系如下图所示

wKiom1Nw3UnBVNxHAAJgNktBY9o030.jpg

  1.管理distro

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@node1 ~]# mount /dev/cdrom /media
mount: block device /dev/sr0  is  write- protected , mounting read-only
[root@node1 ~]# cobbler  import  --name=centos6. 5 -x86- 64  --path=/media/
task started:  2014 - 04 -23_214916_import
task started (id=Media  import , time=Wed Apr  23  21 : 49 : 16  2014 )
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path / var /www/cobbler/ks_mirror/centos6. 5 -x86- 64 :
creating  new  distro: centos6. 5 - 64 -x86_64
trying symlink: / var /www/cobbler/ks_mirror/centos6. 5 -x86- 64  -> / var /www/cobbler/links/centos6. 5 - 64 -x86_64
creating  new  profile: centos6. 5 - 64 -x86_64
associating repos
checking  for  rsync repo(s)
checking  for  rhn repo(s)
checking  for  yum repo(s)
starting descent into / var /www/cobbler/ks_mirror/centos6. 5 -x86- 64  for  centos6. 5 - 64 -x86_64
processing repo at : / var /www/cobbler/ks_mirror/centos6. 5 -x86- 64
need to process repo/comps: / var /www/cobbler/ks_mirror/centos6. 5 -x86- 64
looking  for  / var /www/cobbler/ks_mirror/centos6. 5 -x86- 64 /repodata/*comps*.xml
Keeping repodata  as - is  :/ var /www/cobbler/ks_mirror/centos6. 5 -x86- 64 /repodata
*** TASK COMPLETE ***

     列出所有的distro

1
2
[root@node1 ~]# cobbler distro list
    centos6. 5 - 64 -x86_64

     如果有kickstart文件,也可以使用--kickstart=/path/to/kickstart_file进行导入,因此import会自动为导入的distro生成一个profile

   2.管理profile

     cobbler使用profile来为特定的需求类别提供锁需要安装的配置,即在distro的基础上通过提供kiskstart文件来生成一个特定的系统安装配置。distro的profile可以出现在pxe的引导菜单中作为安装的选择之一,关于kickstark文件的讲解可以移步本人的相关博客http://wangfeng7399.blog.51cto.com/3518031/1369553,不出就不再做详细说明

1
[root@node1 ~]# cobbler profile add --name=centos6. 5 -x86_64 --distro=centos6. 5 - 64 -x86_64 kickstart=/root/anaconda-ks.cfg

   列出当前系统上的profile

1
2
3
[root@node1 ~]# cobbler profile list
    centos6. 5 - 64 -x86_64
    centos6. 5 -x86_64

   删除一个profile

1
[root@node1 ~]# cobbler profile remove --name=centos6. 5 - 64 -x86_64

   3.重启服务及同步数据到响应的目录    

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@node1 ~]# service cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]
[root@node1 ~]# cobbler sync
task started:  2014 - 04 -23_220652_sync
task started (id=Sync, time=Wed Apr  23  22 : 06 : 52  2014 )
running pre-sync triggers
cleaning trees
removing: / var /www/cobbler/images/centos6. 5 - 64 -x86_64
removing: / var /lib/tftpboot/pxelinux.cfg/ default
removing: / var /lib/tftpboot/grub/images
removing: / var /lib/tftpboot/grub/efidefault
removing: / var /lib/tftpboot/images/centos6. 5 - 64 -x86_64
removing: / var /lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink / var /lib/cobbler/loaders/pxelinux. 0  -> / var /lib/tftpboot/pxelinux. 0
trying hardlink / var /lib/cobbler/loaders/menu.c32 -> / var /lib/tftpboot/menu.c32
trying hardlink / var /lib/cobbler/loaders/yaboot -> / var /lib/tftpboot/yaboot
中间省去N行
received on stderr:
running shell triggers from / var /lib/cobbler/triggers/sync/post/*
running python triggers from / var /lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running shell triggers from / var /lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

  4.测试  


wKioL1Nw_OLB236xAACzwYdDGI8873.jpg

可以看到我们定制的系统启动页面,开始安装系统

wKiom1Nw_Q2zpiUNAAEV8Xm_Jps672.jpg

系统安装成功,登陆系统

wKiom1Nw_92gOcwhAAEITWN87Q4866.jpg

六、使用cobbler_web

   cobbler_web支持多种认证方式,如authn_configfil、authn_ldap或authn_pam等,默认为authn_denyall,即拒绝所有用户登陆。下面说明两种能认证用户登录cobbler_web的方式

   1.使用authn_pam模块认证cobbler_web用户

   首先修改modules中的[authentication]段中的module参数的值为authn_pam

   接着设定系统用户,并为用户设定密码

   而后将设定的系统用户添加至cobbler_web的admin组中,修改/etc/cobbler/users.conf文件,将设定的用户添加为admin参数的值即可    

  2.使用authn_configfile模块认证cobbler_web用户

   首先修改modules中的[authentication]段中的module参数的值为authn_configfile

   接着创建其认证文件/etc/cobbler/users.digest,并添加所需要的用户即可。需要注意的是,添加第一用户时,需要为htdigest命令使用“-c”选项,后续添加其他用户则不能再使用

   本处使用的为authn_pam

1
2
3
4
5
6
7
8
9
10
11
12
[root@node1 ~]# vi /etc/cobbler/modules.conf
[authentication]
module = authn_pam
[root@node1 ~]# useradd wangfeng7399
[root@node1 ~]# passwd wangfeng7399
Changing password  for  user wangfeng7399.
New password:
Retype  new  password:
passwd: all authentication tokens updated successfully.
[root@node1 ~]# vi /etc/cobbler/users.conf
[admins]
admin =  "wangfeng7399"

wKioL1NxAGDh2J3xAAJOswKBn8c655.jpg

wKiom1NxAIyQhR8MAAGb1odXoqw457.jpg

wKioL1NxAGGzzHAfAAHX4uWbjiE851.jpg

wKiom1NxAIzzqVTaAAJoJMvRY5w390.jpg

   完全可以手动添加,这也不为记不住命令而发愁了!!!哈哈!!

   大功告成,后续将推出自动化运维的相关内容,敬请期待!!欢迎各位大神拍砖



本文转自wangfeng7399 51CTO博客,原文链接:http://blog.51cto.com/wangfeng7399/1410169,如需转载请自行联系原作者


目录
打赏
0
0
0
0
69
分享
相关文章
阿里云服务器一键安装Docker社区版教程,基于系统运维管理OOS
阿里云服务器一键安装Docker社区版教程,基于系统运维管理OOS自动化部署。支持Ubuntu 22.04/20.04、CentOS 7.7-7.9及Alibaba Cloud Linux 3.2104 LTS。前提条件:ECS实例需运行中且有公网。步骤:选择Docker扩展并安装,验证成功通过命令`docker -v`查看版本号。
240 79
HTTPS 证书自动化运维:https证书管理系统- 自动化监控
本文介绍如何设置和查看域名或证书监控。步骤1:根据证书状态选择新增域名或证书监控,线上部署推荐域名监控,未部署选择证书监控。步骤2:查询监控记录详情。步骤3:在详情页查看每日定时检测结果或手动测试。
HTTPS 证书自动化运维:https证书管理系统- 自动化监控
HTTPS 证书自动化运维:https证书管理系统-自动化部署
本指南介绍如何部署Linux服务器节点。首先复制生成的Linux脚本命令,然后将其粘贴到目标服务器上运行。接着刷新页面查看节点记录,并点击“配置证书”选择证书以自动部署。最后,节点部署完成,后续将自动调度,无需人工干预。
HTTPS 证书自动化运维:https证书管理系统-自动化部署
HTTPS 证书自动化运维:https证书管理系统之自动化签发
通过访问【https://www.lingyanspace.com】注册账户,进入证书服务菜单并新增证书。填写域名(单域名、多域名或泛域名),创建订单后添加云解析DNS记录进行质检。确认完成后可下载证书,并支持后续查看、更新和定时更新功能。证书过期前15天自动更新,需配置邮箱接收通知。
HTTPS 证书自动化运维:https证书管理系统之自动化签发
基于AI的自动化事件响应:智慧运维新时代
基于AI的自动化事件响应:智慧运维新时代
74 11
AI辅助的运维流程自动化:实现智能化管理的新篇章
AI辅助的运维流程自动化:实现智能化管理的新篇章
406 22
小团队 CI/CD 实践:无需运维,Java Web应用的自动化部署
本文介绍如何使用GitHub Actions和阿里云Kubernetes(ACK)实现Java Web应用的自动化部署。通过CI/CD流程,开发人员无需手动处理复杂的运维任务,从而提高效率并减少错误。文中详细讲解了Docker与Kubernetes的概念,并演示了从创建Kubernetes集群、配置容器镜像服务到设置GitHub仓库Secrets及编写GitHub Actions工作流的具体步骤。最终实现了代码提交后自动构建、推送镜像并部署到Kubernetes集群的功能。整个过程不仅简化了部署流程,还确保了应用在不同环境中的稳定运行。
52 9
构建深度可观测、可集成的网络智能运维平台
本文介绍了构建深度可观测、可集成的网络智能运维平台(简称NIS),旨在解决云上网络运维面临的复杂挑战。内容涵盖云网络运维的三大难题、打造云原生AIOps工具集的解决思路、可观测性对业务稳定的重要性,以及产品发布的亮点,包括流量分析NPM、网络架构巡检和自动化运维OpenAPI,助力客户实现自助运维与优化。
构建高效运维体系:从自动化到智能化的演进
本文探讨了如何通过自动化和智能化手段,提升IT运维效率与质量。首先介绍了自动化在简化操作、减少错误中的作用;然后阐述了智能化技术如AI在预测故障、优化资源中的应用;最后讨论了如何构建一个既自动化又智能的运维体系,以实现高效、稳定和安全的IT环境。
104 4
,自动化运维成为现代IT基础设施的关键部分。Puppet是一款强大的自动化运维工具
【10月更文挑战第7天】随着云计算和容器化技术的发展,自动化运维成为现代IT基础设施的关键部分。Puppet是一款强大的自动化运维工具,通过定义资源状态和关系,确保系统始终处于期望配置状态。本文介绍Puppet的基本概念、安装配置及使用示例,帮助读者快速掌握Puppet,实现高效自动化运维。
88 4