cobbler自动化部署

cobblerlinux



目录web

  前言vim

   1、简介centos

   2、工做原理浏览器

   3、cobbler安装配置bash

    一、启动cobbler配置并检查配置服务器

    二、执行Cobbler check报错解决方式网络

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

    一、dhcp服务koa

    二、TFTP服务

   4、配置Cobbler

    一、管理profile

   5、配置cobble_web

    一、配置cobbler_web的认证功能

    二、使用authn_pam模块认证cobbler_web用户

    三、使用authn_configfile模块认证cobbler_web用户

    四、centos7配置cobbler-web时问题

 

 前言

        cobbler是一个免费开源系统安装部署软件,用户自动化网络安装操做系统。cobbler集成了DNS,DHCP,等方便操做系统安装自动化。cobbler能够支持pxe启动,操做系统从新安装,以及虚拟化客户机建立,包括xen,KVM or Vmware。 cobbler透过koan程序以支持虚拟化客户机安装。cobbler能够支持管理负责网络环境,如建立在链路聚合以太网的桥接环境等。『维基百科』

 1、简介

    关于操做系统安装方面的自动化,早前咱们使用 RedHat 推出的 Kickstart来批量安装操做系统,近年来 RedHat 又推出一个 Cobbler 。Cobbler 使用 Python 开发,小巧轻便,可以完成系统安装、甚至一些服务的管理。( 号称是补鞋匠都能学会的工具)Cobbler 支持命令行管理、web 界面管理、还提供了 API 接口,以便二次开法。

2、工做原理

 

wKiom1iNWRLAPyWwAABdD7fI-qY436.jpg

 

工做流:

    一、  client裸机配置了从网络启动后,开机后会发送广播包请求dhcp服务器(cobbler server) 发送其分配好的ip一个ip

    二、  dhcp服务器(cobbler server)收到请求后发送responese,包括其ip地址

    三、  client裸机拿到ip后在向cobbler server 发送请求os引导文件的请求

    四、  cobbler server 告诉裸机os引导文件的名字和TFTP server的i和port

    五、  client 裸机经过上面告知的TFTP server 地址和port通讯,下载引导文件

    六、  client裸机执行该引导文件,肯定加载细腻,选择要安装的os,期间会在向cobbler server请求kickstart文件和os p_w_picpath

    七、  cobbler server 发送请求的kickstart和os iamges

    八、  client 裸机加载kickstart文件

    九、  client 裸机osp_w_picpath ,安装该os p_w_picpath

 

 3、cobbler安装配置

         yuminstall cobbler –y

一、启动cobbler配置并检查配置

        

 [root@centos7_1 ~]#systemctlcobblerd restart
 [root@centos7_1 ~]#cobbler check
  1 : The ‘server’ field in/etc/cobbler/settings must be set to something
   other than localhost, orkickstarting features will not work. This should
    be a resolvable hostname or IPfor 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
  mustbe set to something other than 127.0.0.1, and should match the IP of the 
  bootserver on the PXE network.
 3 :some network boot-loaders are missing from /var/lib/cobbler/loaders, you
  mayrun‘cobbler get-loaders’to download them, or, if you only want to handle
   x86/x86_64 netbooting, you mayensure that you have installed a recent version
    of the syslinux packageinstalled and can ignore this message entirely. 
    Files in this directory, shouldyou want to support all architectures, 
    should include pxelinux.0, menu.c32,elilo.efi, and yaboot. 
    The ‘cobbler get-loaders’ command is the easiest way toresolve 
    these requirements.
  4 : change ‘disable’ to ‘no’ in/etc/xinetd.d/rsync
  5 : comment ‘dists’ on /etc/debmirror.conffor proper debian support
  6 : comment ‘arches’ on /etc/debmirror.conffor proper debian support
  7 : The default password used by the sampletemplates 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 generatenew one
  8 : fencing tools were not found, and arerequired to use the (optional) power 
  management features. install cman orfence-agents to use them.
 
二、执行Cobblercheck报错解决方式
一、 修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机相应的IP地址或主机名,如172.16.100.15;
二、 修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址,如172.16.100.16;
三、 若是当前节点能够访问互联网,执行“ cobbler get-loaders”命令便可;不然, 须要安装syslinux程序包,然后复制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目录中;
四、执行“ chkconfig rsync on”命令便可;
五、 注释/etc/debmirror.conf文件中的“ @dists=”sid”;”一行;
六、 注释/etc/debmirror.conf文件中的“@arches=”i386”;”一行;
七、 执行“ openssl passwd -1 -salt $(openssl rand -hex 4)”生成密码,并用其替换/etc/cobbler/settings文件中default_password_crypted参数的值;
八、 执行“ yum install cman fence-agents”命令安装相应的程序包便可.


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

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

        cobbler可自行管理这些服务中的部分甚至是所有,但须要配置/etc/cobbler/settings文件中的“manage_dhcp”、“manage_tftpd”、“manage_rsync”和“manage_dns”分别进行定义。另外,因为

每种服务都有着不一样的实现方式,如若须要进行自定义,须要经过修改/etc/cobbler/modules.conf配置文件中各服

务的模块参数的值来实现。

       本文采用了独立管理的方式,即不经过cobbler来管理这些服务。

 一、dhcp服务

# yum install -y dhcp
 定义好所需的“subnet”及其它参数或选项,然后启动dhcpd守护进程便可。本示例中所用的dhcpd
 的配置以下所示:
[root@centos7_1 ~]# cp/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
[root@centos7_1 ~]# vim/etc/dhcp/dhcpd.conf
subnet 192.168.10.0 netmask 255.255.255.0 {
 range 192.168.10.100 192.168.10.110;
 option domain-name-servers 172.16.0.1;
 option routers 192.168.10.1;
 default-lease-time 600;
 max-lease-time 7200;
  filename"pxelinux.0";
 next-server 192.168.10.10;
}
接着使用从新启动服务便可
# systemctl restart dchpd


二、TFTP服务

  [root@centos7_1~]# vim /etc/xinetd.d/tftp
    service tftp
    {
        disable                 = no
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -B 1380 -v -s /var/lib/tftpboot
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
    }
  [root@centos7_1~]# systemctl restart tftp.socket


5、配置Cobbler

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

    例如,对于已经挂载至/mnt/dvd/目录的centos7的安装镜像,则能够了使用相似以下命令进行导入。

[root@centos7_1 ~]# mount /dev/sr0  /mnt/dvd/
[root@centos7_1 ~]# cobbler import--name="Centos7-x86_64" --path=/mnt/dvd 
task started: 2017-01-01_213654_import
task started (id=Media import, time=SunJan  1 21:36:54 2017)
Found a candidate signature: breed=redhat,version=rhel6
Found a candidate signature: breed=redhat,version=rhel7
Found a matching signature: breed=redhat,version=rhel7
Adding distros from path/var/www/cobbler/ks_mirror/Centos7-x86_64:
creating new distro: Centos7-x86_64
trying symlink:/var/www/cobbler/ks_mirror/Centos7-x86_64 ->/var/www/cobbler/links/
Centos7-x86_64
creating new profile: Centos7-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/Centos7-x86_64 for Centos7-x86_64
processing repo at :/var/www/cobbler/ks_mirror/Centos7-x86_64
need to process repo/comps:/var/www/cobbler/ks_mirror/Centos7-x86_64
looking for/var/www/cobbler/ks_mirror/Centos7-x86_64/repodata/*comps*.xml
Keeping repodata as-is:/var/www/cobbler/ks_mirror/Centos7-x86_64/repodata
*** TASK COMPLETE ***
#可以使用“cobbler distrolist” 列出全部的distro
[root@centos7_1 ~]# cobbler distro list 
  Centos7-x86_64
[root@centos7_1 ~]#

    若是有kickstart文件,也可使用“—kickstart=/path/to/kickstart_file”进行导入,所以import会自动为导入的distro生成一个profile。但因生成的kickstart适用咱们的实际生产要求因此kickstart因此咱们要作出必定的修改才能够。

 

 

一、管理profile

cobble使用profile来为特定的需求类别提供所须要安装配置,即在distro的基础之上经过提供kickstart文件来生成一个特定的系统安装配置。distro的profile能够出如今pxe的引导菜单中做为安装的选择之一。

所以,若是须要为前面建立的centos7-x86_64这个distro提供一个可引导安装条目,其用到的kickstart文件为/var/lib/cobbler/kickstarts/ks.cfg ,则可经过以下命令实现。

[root@centos7_1 ~]# cp ks.cfg  /var/lib/cobbler/kickstarts/
[root@centos7_1 ~]# cobbler profile add--name= Centos7-mini-x86_64 \
      --distro=Centos7-x86_64\ --kickstart=/var/lib/cobbler/kickstarts/ks.cfg
#可以使用“cobbler profilelist”查看已经建立的profile。
[root@centos7_1 ~]# cobbler profile  list
  Centos7-mini-x86_64
  Centos7-x86_64
[root@centos7_1 ~]#


至此即可实现自动化安装操做系统。


 wKioL1iNWs6RQOydAAA-epq-IUo414.jpg

6、配置cobble_web

一、配置cobbler_web的认证功能

cobbler_web支持多种认证方式,如authn_configfile 、authn_ldap或authn_pam等,默认authn_denyall,即拒绝全部用户登陆,下面说两种认证用户登陆cobbler_web的方式。

 二、使用authn_pam模块认证cobbler_web用户

         使用authn_pam模块认证cobbler_web用户

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

     接着添加系统用户,用户名和密码按需设定便可, 例以下面的命令所示

     #useradd cblradmin

    # echo 'cblrpass' | passwd --stdincblradmin

三、使用authn_configfile模块认证cobbler_web用户

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

     接着建立其认证文件/etc/cobbler/users.digest, 并添加所需的用户便可,须要注意的是,添加第一个用户时, 须要为htdigest命令使用“ -c”选项, 后续添加其余用户时不能再使用; 另外, cobbler_web的realm只能为Cobbler。 以下所示。

     #htdigest -c /etc/cobbler/users.digest Cobbler cblradmin

访问http://ip/cobbler_web便可实现web方式配置cobbler

wKiom1iNW2nh-4e7AAAsNq3qRYM252.jpg

 

四、centos7配置cobbler-web时问题

    在访问http://192.168.10.10/cobbler_web时。浏览器报错、

wKioL1iNW5Hxa-BgAAAbVML68BQ073.jpg

    解决方法1:

         使用https访问即 https://192.168.10.10/cobbler_web

    解决方法2:

  [root@centos7_1~]# vim /etc/httpd/conf.d/cobbler_web.conf
   将如下配置在配置文件内的注释掉:(全部)
   #  <IfModule mod_ssl.c>
   #    SSLRequireSSL
   # </IfModule>