cobbler实现批量系统安装

一、Cobbler介绍:

Cobbler(补鞋匠)是一个快速网络安装Linux操作系统服务,并支持众多的Linux发行版:Red Hat、Fedora、CentOS、Debian、Ubuntu和SuSE,同样也支持网络安装windows系统。使用Cobbler,无需进行人工操作即可安装系统。
Cobbler为Python编写,具有小巧轻便的特点,提供了CLI和Web的管理形式,作为PXE的二次开发,将多种安装参数都集合封装到一个菜单里,实现了更便捷的系统无人批量安装。
以下为Cobbler组成结构:

安装包:

Cobbler

Cobbler服务集成:

PXE
??DHCP
??rsync
??HTTP
??DNS
??Kickstart
??IPMI电源管理

检查Cobbler环境:

Cobbler check

二、Cobbler工作流程

  • Client裸机配置从网络启动后,开机会广播包请求DHCP服务器(Cobbler Server)发送其分配好的一个IP地址
  • DHCP服务器(Cobbler Server)收到请求后发送responese,包括其IP地址
  • Client裸机获取到IP地址后再向Cobbler Server发送请求OS引导文件的请求
  • Client裸机通过上面告知的TFTP Server地址通信,下载引导文件
  • Client裸机执行该引导文件,确定加载信息,选择要安装的OS,期间会再向Cobbler Server请求kickstart文件和OS image
  • Client裸机加载kickstart文件
  • Client裸机接收到OS image,安装该os image

三、Cobbler目录介绍

数据目录:
  • /var/lib/cobbler/config/:用于存放distros,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_mirror/:yum仓库存储目录
日志目录:
  • /var/log/cobbler/installing:客户端安装日志
  • /var/log/cobbler/cobbler.log:cobbler日志

四、命令介绍

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

五、安装配置(以下安装配置均在Centos7.3下进行)

1.确保实验进行顺利,建议关闭SElinux、iptables
[root@CentOS7 ~]#setenforce 0 #临时关闭
[root@CentOS7 ~]#vim /etc/selinux/config  
SELINUX=disabled #设置为disabled,永久生效
[root@CentOS7 ~]#systemctl disable firewalld.service #禁止Firewall开机启动
[root@CentOS7 ~]#systemctl stop firewalld.service #停止Firewall
[root@CentOS7 ~]#iptables -F #清空防火墙策略
2.通过yum安装相关程序包,并开启服务
[root@CentOS7 ~]#yum install cobbler dhcp
[root@CentOS7 ~]#systemctl enable cobblerd #设置服务开机启动
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
[root@CentOS7 ~]#systemctl start cobblerd  #启动服务
[root@CentOS7 ~]#systemctl enable tftp  #设置服务开机启动
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
[root@CentOS7 ~]#systemctl start tftp  #启动服务
[root@CentOS7 ~]#systemctl enable httpd  #设置服务开机启动
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@CentOS7 ~]#systemctl start httpd  #启动服务

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

3.cobbler check检查配置文件,并根据提示进行修改
[root@CentOS7 ~]#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.

上述部分配置报错可以置之不理

根据提示修改/etc/cobbler/settings配置文件

default_password_crypted: "$1$8ckh4FrM$ayLsgQi85bi8Nt5Gj4Drj/"    #openssl passwd -1 生成口令
next_server: 192.168.25.107
manage_dhcp: 1  
server: 192.168.25.107

重新启动cobbler并同步数据响应的目录

[root@CentOS7 ~]#systemctl restart cobblerd
[root@CentOS7 ~]#cobbler sync
4.生成dhcp模板文件
[root@CentOS7 ~]#vim /etc/cobbler/dhcp.template
 subnet 192.168.7.0 netmask 255.255.255.0 {
option subnet-mask         255.255.255.0;
range dynamic-bootp        192.168.7.100 192.168.7.200;
5.准备启动文件和菜单风格文件

以下有两种方式:
??连接internet:
[root@CentOS7 /var/lib/cobbler/loaders]#cobbler get-loaders
??拷贝文件:
cp /var/lib/tftpboot/{menu.c32,pxelinux.0} /var/lib/cobbler/loaders

6.import导入yum

import将挂载的光盘镜像文件导入

[root@CentOS7 /var/lib/cobbler/loaders]#cobbler import --path=/mnt/cdrom --name=centos7.3 --arch=x86_64
[root@CentOS7 /var/lib/cobbler/loaders]#cobbler distro list  #查看导入的发行版系统信息
   centos7.3-x86_64
7.准备kickstart 文件并导入cobbler

如果有kickstart文件,可以使用--kickstart=/path/to/kickstart_file进行导入,因此import会自动为导入的distro生成一个profile
[root@CentOS7 /var/lib/cobbler/kickstarts]#cp /app/anaconda-ks.cfg centos7.cfg
将修改好的应答文件cp至当前目录

将应答文件与配置文件做关联

[root@CentOS7 /var/lib/cobbler/kickstarts]#cobbler profile remove --name=centos7.3-x86_64 #删除profile
[root@CentOS7 /var/lib/cobbler/kickstarts]#cobbler profile add --name=centos7.3_mini --distro=centos7.3-x86_64  --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg #与配置文件关联
[root@CentOS7 /var/lib/cobbler/kickstarts]#cobbler sync
[root@CentOS7 /var/lib/cobbler/kickstarts]#cobbler profile list
   centos7.3_mini
8.测试:
image.png
9.使用cobbler_web

cobbler_web支持多种认证方式,如authn_configfil、authn_ldap或authn_pam等,默认为authn_denyall,既拒绝所有用户登陆。下面使用两种认证方式登陆cobbler_web方式。
? 首先安装cobbler-web
[root@CentOS7 ~]#yum install cobbler-web
? 安装完成后需重启httpd服务,不然无法显示cobbler界面
[root@CentOS7 ~]#systemctl restart httpd

? 打开/etc/cobbler/modules.conf查看默认认证方式

# cobbler module configuration file
# =================================

# authentication: 
# what users can log into the WebUI and Read-Write XMLRPC?
# choices:
#    authn_denyall    -- no one (default)
#    authn_configfile -- use /etc/cobbler/users.digest (for basic setups)
#    authn_passthru   -- ask Apache to handle it (used for kerberos)
#    authn_ldap       -- authenticate against LDAP
#    authn_spacewalk  -- ask Spacewalk/Satellite (experimental)
#    authn_pam        -- use PAM facilities
#    authn_testing    -- username/password is always testing/testing (debug)
#    (user supplied)  -- you may write your own module
# WARNING: this is a security setting, do not choose an option blindly.
# for more information:
# https://github.com/cobbler/cobbler/wiki/Cobbler-web-interface
# https://github.com/cobbler/cobbler/wiki/Security-overview
# https://github.com/cobbler/cobbler/wiki/Kerberos
# https://github.com/cobbler/cobbler/wiki/Ldap

[authentication]
module = authn_configfile  #默认的认证方式

9.1使用authn_configfile ??槿现obbler_web用户,创建其认证文件/etc/cobbler/users.digest ,并添加所需的用户

[root@CentOS7 ~]#htdigest -c /etc/cobbler/users.digest Cobbler lai
Adding password for lai in realm Cobbler.
New password: 
Re-type new password: 

[root@CentOS7 ~]#cat /etc/cobbler/users.digest 
lai:Cobbler:7d2dd34ccc1e2dfce76d8f0de1d74487
1f3  #创建的用户内容

[root@CentOS7 ~]#systemctl restart cobblerd #重启cobblerd服务

(注意:添加第一个用户时,使用“-c”选项,后续添加其他用户时不要再使用,cobbler_web的realm只能为cobber)

通过https://192.168.7.63/cobbler_web访问

image.png

9.2使用authn_pam模块认证cobbler_web用户

[root@CentOS7 ~]#vim /etc/cobbler/modules.conf    
 1 # cobbler module configuration file
 2 # =================================
 3 
 4 # authentication: 
 5 # what users can log into the WebUI and Read-Write XMLRPC?
 6 # choices:
 7 #    authn_denyall    -- no one (default)
 8 #    authn_configfile -- use /etc/cobbler/users.digest (for basic setups)
 9 #    authn_passthru   -- ask Apache to handle it (used for kerbe ros)
10 #    authn_ldap       -- authenticate against LDAP
11 #    authn_spacewalk  -- ask Spacewalk/Satellite (experimental)
12 #    authn_pam        -- use PAM facilities
13 #    authn_testing    -- username/password is always testing/testing (debug)
14 #    (user supplied)  -- you may write your own module
15 # WARNING: this is a security setting, do not choose an option blindly.
16 # for more information:
17 # https://github.com/cobbler/cobbler/wiki/Cobbler-web-interface
18 # https://github.com/cobbler/cobbler/wiki/Security-overview
19 # https://github.com/cobbler/cobbler/wiki/Kerberos
20 # https://github.com/cobbler/cobbler/wiki/Ldap
21 
22 [authentication]
23 module = authn_pam  #修改为基于authn_pam???

创建针对authn_pam??槿现さ恼撕?/em>

[root@CentOS7 ~]#useradd cobbleruser
[root@CentOS7 ~]#echo centos | passwd --stdin cobbleruser
Changing password for user cobbleruser.
passwd: all authentication tokens updated successfully.

修改/etc/cobbler/users.conf文件,将设定的用户添加为admin参数的值即可。

[root@CentOS7 ~]#vim /etc/cobbler/users.conf 
  1 # Cobbler WebUI / Web Services authorization config file
  2 #
  3 # NOTICE:
  4 # this file is only used when /etc/cobbler/modules.conf
  5 # specifies an authorization mode of either:
  6 #
  7 #   (A) authz_configfile
  8 #   (B) authz_ownership
  9 #
 10 # For (A), any user in this file, in any group, are allowed
 11 # full access to any object in cobbler configuration.
 12 #
 13 # For (B), users in the "admins" group are allowed full access
 14 # to any object, otherwise users can only edit an object if
 15 # their username/group is listed as an owner of that object. If 
    a
 16 # user is not listed in this file they will have no access.
 17 #
 18 #     cobbler command line example:
 19 #
 20 #     cobbler system edit --name=server1 --owner=dbas,mac,pete,j
    ack
 21 #
 22 # NOTE:  yes, you do need the equal sign after the names.
 23 # don't remove that part.  It's reserved for future use.
 24 
 25 [admins]
 26 admin = "cobbleruser"  #添加用户
 27 cobbler = ""
[root@CentOS7 ~]#systemctl restart cobblerd #重启cobblerd服务

cobbleruser登陆

1.png

总结:

Cobbler作为一款快速网络安装linux服务,实现了批量系统安装,无需进行人工干预即可安装,达到了基本的自动化运维需求

最后编辑于
?著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,992评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,212评论 3 388
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事?!?“怎么了?”我有些...
    开封第一讲书人阅读 159,535评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,197评论 1 287
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,310评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,383评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,409评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,191评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,621评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,910评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,084评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,763评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,403评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,083评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,318评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,946评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,967评论 2 351

推荐阅读更多精彩内容