Linux高级篇--企业级运维自动化工具Cobbler

Linux高级篇–企业级运维自动化工具Cobbler

一、 cobbler企业级应用

cobbler介绍

  • Cobbler:
      快速网络安装linux操作系统的服务,支持众多的Linux发行版:Red Hat、Fedora、CentOS、Debian、Ubuntu和SuSE,也可以支持网络安装windows
      PXE的二次封装,将多种安装参数封装到一个菜单
      Python编写
      提供了CLI和Web的管理形式

cobbler工作流程

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

cobbler相关介绍

  • 安装包
      cobbler 基于EPEL源
  • cobbler 服务集成
      PXE
      DHCP
      rsync
      Http
      DNS
      Kickstart
      IPMI 电源管理
  • 检查cobbler环境
      cobbler check

cobbler相关术语

  • 发行版:
      表示一个操作系统版本,它承载了内核和 initrd 的信息,以及内核参数等其他数据
  • 配置文件:
      包含一个发行版、一个 kickstart 文件以及可能的存储库,还包含更多特定的内核参数等其他数据
  • 系统:
      表示要配置的主机,它包含一个配置文件或一个镜像,还包含 IP 和 MAC 地址、电源管理(地址、凭据、类型)以及更为专业的数据等信息
  • 存储库:
      保存一个 yum 或 rsync 存储库的镜像信息
  • 镜像:
      可替换一个包含不属于此类别的文件的发行版对象(例如,无法分为内核和 initrd 的对象)

cobbler各种配置目录说明

  • 安装:yum install cobbler dhcp
  • 配置文件目录 /etc/cobbler
    /etc/cobbler/settings : cobbler 主配置文件
    /etc/cobbler/iso/: iso模板配置文件
    /etc/cobbler/pxe: pxe模板文件
    /etc/cobbler/power: 电源配置文件
    /etc/cobbler/user.conf: web服务授权配置文件
    /etc/cobbler/users.digest: web访问的用户名密码配置文件
    /etc/cobbler/dhcp.template : dhcp服务器的的配置末班
    /etc/cobbler/dnsmasq.template : dns服务器的配置模板
    /etc/cobbler/tftpd.template : tftp服务的配置模板
    /etc/cobbler/modules.conf : 模块的配置文件

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命令介绍

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

cobbler配置中的重要参数

  • /etc/cobbler/settings中重要的参数设置
default_password_crypted: "$1$gEc7ilpP$pg5iSOj/mlxTxEslhRvyp/"
manage_dhcp:1
manage_tftpd:1
pxe_just_once:1
next_server:< tftp服务器的 IP 地址>
server:<cobbler服务器的 IP 地址>

cobbler环境检查

  • 执行Cobbler check命令会报如下异常
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 ‘dists’ on /etc/debmirror.conf for proper debian support
6 : comment ‘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
  • 执行Cobbler check报错解决方式
      修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机相应的IP地址或主机名
      修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址
      如果当前节点可以访问互联网,执行“cobbler get-loaders”命令即可;否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目录中
      执行“chkconfig rsync on”命令即可
      执行"openssl passwd -1"生成密码,并用其替换/etc/cobbler/settings文件中default_password_crypted参数的值
    另外:建议修改的配置:
    vim /etc/cobbler/setting
    242 manage_dhcp: 1
    dhcp配置文件默认为空,把该项0改为1,由cobbler管理dhcp自动生成dhcp配置文件,无需手动创建
    更改后,重启cobbler服务
    此时还需更改由cobbler自动生成的dhcp配置文件
    vim /etc/cobbler/dhcp.template
    21 subnet 192.168.32.0 netmask 255.255.255.0 {
    22 option routers 192.168.32.5;
    23 option domain-name-servers 192.168.1.1;
    24 option subnet-mask 255.255.255.0;
    25 range dynamic-bootp 192.168.32.100 192.168.32.254;
    把默认网段,更改为dhcp分配的地址网段即可,如:地址池范围,网关等,其他项无需更改
    更改后进行同步:cobbler sync

cobbler相关管理

  • 下载启动菜单:
    联网:cobbler get-loaders
    不联网:cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot
  • 管理distro
    cobbler import --name=centos-6.9-x86_64 --path=/media/cdrom --arch=x86_64
  • 管理profile
    cobbler profile add --name=centos-6.9-x86_64-basic
    –distro=centos-6.9-x86_64 --kickstart= /var/lib/cobbler/kickstarts/centos-6.9-x86_64.cfg

cobbler命令

扫描二维码关注公众号,回复: 3303989 查看本文章
  • 查看profiles
      cobbler profile list
  • 查看引导文件
      cat /var/lib/tftpboot/pxelinux.cfg/default
  • 同步cobbler配置
      cobbler sync
  • 多系统引导方案
      cobbler import --name=CentOS-7-x86_64 --path=/media/cdrom   cobbler distro list
      cobbler profile list
      cobbler sync

知识扩展:

以上实现的是系统自动生成的应答文件引导,是最小化安装系统,如果要自定义系统,需要自定义制作应答文件,制作完成以后,需要对该文件进行更改:
vim ks_centos7.cfg
 14 url --url=$tree
此时不知道yum仓库路径,把url路径指定为$tree变量,该变量为cobbler变量,它能够自动添加cobbler自己生成的仓库路径
把应答文件与发行版本centos7.5-x8_64进行关联,需要把应答文件复制到cobbler准们存放应答文件的目录下
/var/lib/cobbler/kickstarts/是cobbler专门用于存放应答文件的目录
cp ks_centos7.cfg /var/lib/cobbler/kickstarts/ks7.cfg
把应答文件复制到对应目录下并改名为ks7.cfg
手动关联应答文件与发行版本
cobbler profile add --name=centos7.5-x8_64-x86_64_desktop --distro=centos7.5-x8_64-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7.cfg
add   新增应答文件
可以把原来系统默认生成的应答文件删除
cobbler profile remove --name=centos7.5-x86_64
--name  指定系统启动菜单项的名称
--distro   指定系统发行版本
--kickstart  指定应答文件名,该文件路径必须为绝对路径
查看生成的菜单项:
cat /var/lib/tftpboot/pxelinux.cfg/default

cobbler实现步骤
1、安装包,并设置服务
2、检查配置
3、根据上面提示修改配置
4、下载启动相关文件菜单
5、配置DHCP服务
6、分别导入centos的安装源,并查看
7、准备kickstart文件并导入cobbler
8、测试

cobbler的web管理实现

  • cobbler-web
      提供cobbler的基于web管理界面,epel源
      yum install cobbler-web
  • 认证方式
      认证方法配置文件:/etc/cobbler/modules.conf
      支持多种认证方法:
        authn_configfile
        authn_pam
  • 使用authn_configfile模块认证cobbler_web用户
vim /etc/cobbler/modules.conf
[authentication]
module=authn_configfile
创建其认证文件/etc/cobbler/users.digest,并添加所需的用户  
htdigest -c /etc/cobbler/users.digest Cobbler admin  

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

  • 使用authn_pam模块认证cobbler_web用户
vim /etc/cobbler/modules.conf
[authentication]
module = authn_pam
创建cobbler用户
useradd cobbler
vim /etc/cobbler/users.conf
[admins]
admin = "cobbler“
  • Web访问cobbler
      重启cobblerd服务
      通过https://cobblerserver/cobbler_web访问

猜你喜欢

转载自blog.csdn.net/u013168176/article/details/82817163
今日推荐