美文网首页
cobbler自动化部署

cobbler自动化部署

作者: 素白流殇 | 来源:发表于2017-06-07 12:27 被阅读77次

    PXE+Kickstart 工作概述

    1. 网卡上的pxe芯片有521字节,存放了dhcp和tftp的客户端
    2. 以网卡方式启动计算机
    3. pxe上的dhcp客户端回向dhcp服务器,申请IP地址
    4. DHCP服务器分配给它IP地址的同时通过以下字段,告诉pxe,TFTP的地址和它需要下载的文件(next-sterver filename “pxslinux.0”)
    5. pxelinux.0告诉pxe要下载的配置文件pxelinux.cfg目录下面的default
    6. pxe下载并根据配置文件的内容下载启动必须的文件,并通过ks.cfg开始安装系统

    Cobbler 功能

    1. 使用一个以前定义的模板来配置DHCP服务(如果弃用了管理DHCP)
    2. 将一个存储库(yum或rsync)建立镜像或解压缩一个媒介,以注册一个新的操作系统
    3. 在DHCP配置文件中为需要安装的机器创建一个条目,并使用您指定的参数(IP和MAC地址)
    4. 在TFTP服务目录下创建适当的PXE文件
    5. 重新启动DHCP服务以反映更改
    6. 重新启动机器以开始安装

    安装Cobbler

    [root@localhost ~]# yum install epel-release -y
    [root@localhost ~]# yum install cobbler cobbler-web tftp httpd xinetd -y
    

    安装完成执行 cobbler check

    [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 : change 'disable' to 'no' in /etc/xinetd.d/rsync
    6 : file /etc/xinetd.d/rsync does not exist
    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.
    

    按照提示解决错误

    • 1和2按照提示修改/etc/cobbler/settings 中 server 和 next_server 为指定的kickstar服务器(一般为本机的IP地址)
    server: 9.110.187.140
    next_server: 9.110.187.140
    
    • 3和5开启守护进程控制rsync和tftp
    service tftp
    {
            socket_type             = dgram
            protocol                = udp
            wait                    = yes
            user                    = root
            server                  = /usr/sbin/in.tftpd
            server_args             = -s /var/lib/tftpboot
            disable                 = no
            per_source              = 11
            cps                     = 100 2
            flags                   = IPv4
    }
    
    service rsync
    {
            disable = no
            flags           = IPv6
            socket_type     = stream
            wait            = no
            user            = root
            server          = /usr/bin/rsync
            server_args     = --daemon
            log_on_failure  += USERID
    }
    
    • 4 直接执行 cobbler get-loaders
    [root@localhost ~]# cobbler get-loaders
    task started: 2017-06-07_113154_get_loaders
    task started (id=Download Bootloader Content, time=Wed Jun  7 11:31:54 2017)
    downloading http://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
    downloading http://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
    downloading http://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
    downloading http://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
    downloading http://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
    downloading http://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
    downloading http://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
    downloading http://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
    downloading http://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
    downloading http://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
    *** TASK COMPLETE ***
    
    • 8和10直接进行yum安装
    [root@localhost ~]# yum install pykickstart cman fence-agents -y
    
    • 9 修改配置文件中的默认密码
    [root@localhost ~]# openssl passwd -1 -salt 'cobbler' 'cobbler'
    $1$cobbler$M6SE55xZodWc9.vAKLJs6.
    

    重启cobbler,检查,同步

    [root@localhost ~]# /etc/init.d/cobblerd restart
    Stopping cobbler daemon:                                   [  OK  ]
    Starting cobbler daemon:                                   [  OK  ]
    [root@localhost ~]# cobbler check
    The following are potential configuration items that you may want to fix:
    
    1 : file /etc/xinetd.d/rsync does not exist
    2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
    
    Restart cobblerd and then run 'cobbler sync' to apply changes.
    
    [root@localhost ~]# cobbler sync
    task started: 2017-06-07_120058_sync
    task started (id=Sync, time=Wed Jun  7 12:00:58 2017)
    running pre-sync triggers
    cleaning trees
    removing: /var/lib/tftpboot/grub/images
    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
    trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
    trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
    trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
    copying distros to tftpboot
    copying images
    generating PXE configuration files
    generating PXE menu structure
    rendering TFTPD files
    generating /etc/xinetd.d/tftp
    cleaning link caches
    running post-sync triggers
    running python triggers from /var/lib/cobbler/triggers/sync/post/*
    running python trigger cobbler.modules.sync_post_restart_services
    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 ***
    

    利用 kickstart 图形界面生成需要的 cfg 文件

    具体如何使用请参考上篇文章:
    http://www.jianshu.com/p/1d1d46069a44
    本文主要利用 HTTP 的方式进行系统安装

    挂载镜像文件到 /var/www/html/CentOS-6.9-x86_64目录下

    [root@localhost ~]# mkdir /var/www/html/CentOS-6.9-x86_64
    [root@localhost ~]# mount /dev/cdrom /var/www/html/CentOS-6.9-x86_64
    mount: block device /dev/sr0 is write-protected, mounting read-only
    

    修改 /etc/cobbler/settings 利用cobbler管理DHCP服务

    # set to 1 to enable Cobbler's DHCP management features.
    # the choice of DHCP management engine is in /etc/cobbler/modules.conf
    manage_dhcp: 1
    

    修改 /etc/cobbler/dhcp.template 配置文件

    subnet 9.110.187.0 netmask 255.255.255.0 {
         option routers             9.110.187.2;
         option domain-name-servers 9.110.187.2;
         option subnet-mask         255.255.255.0;
         range dynamic-bootp        9.110.187.100 9.110.187.254;
         default-lease-time         21600;
         max-lease-time             43200;
         next-server                $next_server;
         class "pxeclients" {
              match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
              if option pxe-system-type = 00:02 {
                      filename "ia64/elilo.efi";
              } else if option pxe-system-type = 00:06 {
                      filename "grub/grub-x86.efi";
              } else if option pxe-system-type = 00:07 {
                      filename "grub/grub-x86_64.efi";
              } else {
                      filename "pxelinux.0";
              }
         }
    

    重启 cobbler 服务,同步 cobbler 配置

    [root@localhost ~]# /etc/init.d/cobblerd restart
    [root@localhost ~]# cobbler sync
    

    导入相关的系统镜像文件

    [root@localhost ~]# cobbler import --path=/var/www/html/CentOS-6.9-x86_64/ --name=CentOS-6.9-x86_64 --arch=x86_64
    

    查看镜像时候导入成功
    `

    [root@localhost ~]# cobbler profile list
       CentOS-6.9-x86_64
    

    导入编辑的 cfg文件

    [root@localhost ~]# cd /var/lib/cobbler/kickstarts/
    
    #platform=x86, AMD64, 或 Intel EM64T
    #version=DEVEL
    # Install OS instead of upgrade
    install
    # Keyboard layouts
    keyboard 'us'
    # Root password
    rootpw --iscrypted $1$TjakpGzz$Kfx8GocFqs9sQgfrnBjxu1
    # System timezone
    timezone Asia/Shanghai
    # Use network installation
    url --url="http://9.110.187.140/CentOS-6.9-x86_64"
    # System language
    lang en_US
    # Firewall configuration
    firewall --disabled
    # System authorization information
    auth  --useshadow  --passalgo=sha512
    # Use graphical install
    graphical
    # SELinux configuration
    selinux --disabled
    # Do not configure the X Window System
    skipx
    
    # Network information
    network  --bootproto=dhcp --device=eth0
    # Reboot after installation
    reboot
    # System bootloader configuration
    bootloader --location=mbr
    # Clear the Master Boot Record
    zerombr
    # Partition clearing information
    clearpart --all --initlabel
    # Disk partitioning information
    part /boot --asprimary --fstype="xfs" --size=500
    part / --asprimary --fstype="xfs" --grow --size=1
    
    [root@localhost ~]# cobbler profile edit --name=CentOS-6.9-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.9-x86_64.cfg
    [root@localhost ~]# cobbler sync
    

    用网卡方式启动一台新的服务器

    image.png

    相关文章

      网友评论

          本文标题:cobbler自动化部署

          本文链接:https://www.haomeiwen.com/subject/qnlofxtx.html