zoukankan      html  css  js  c++  java
  • centos7+cobbler+kickstart

    一、cobbler简介

      cobbler 是一个系统启动服务boot server,可以通过pxe得方式用来快速安装,重装系统,支持安装不同linux发行版和windows。这个工具是用python开发,方便小巧,15k行代码,使用简单得命令完成pxe网络安装环境配置,还可以管理dhcp,dns,yum包镜像。

      cobbler可以命令行,也可以web(cobbler-web),还提供api接口,可以方便二次开发使用

      其实就是多安装树得pxe环境,是pxe得高级应用

    二、cobbler可以提供得功能

      1、pxe支持

      2、dhcp管理

      3、dns服务管理(bind,dnsmasq)

      4、电源管理

      5、kickstart支持

      6、yum仓库管理

      7、tftp(pxe启动时需要)

      8、apache,提供ks得安装源,并提供定制化得ks配置,同时,它和apache做了深度整合,通过cobbler,可以师兄redhat/centos/fedora系统得快速部署,同时也支持suse、debian(ubuntu)系统,通过配置开可以支持windows

    三、cobbler架构及工作原理、核心框架(自己画了一张,又找了几张图,可以很清晰架构了)

      介绍一下profile,核心,由三个组件组成

        repositories (安装树或安装源)

          mirror 镜像,光盘或者网络中得安装源

          import 导入

        distribution(vmlinuz-内核,initrd.img-引导映像文件)

          cobbler 自动从reporitories抽取出来生成

        kickstart file 组成得完完整整得系统发行版

      

      cobbler就是较早pxe得升级版,优点容易配置,还自带web界面比较易于管理,但是中文资料少,(有人测试:cobbler不会应为在局域网中启动了dhcp而导致有些机器因为默认从pxe启动在重启服务器后加载tftp内容导致启动终止,这部分没有验证)

      可以通过cobbler自动部署dhcp,tftp,http,在安装过程中加载ks无人值守安装应答文件实现无人值守,从客户端使用pxe引导启动安装

     

    四、开始安装

    1、安装cobbler依赖的服务及相关目录

      cobbler的运行依赖于dhcp、tftp、rsync、dns、http、xinetd服务

      yum -y install cobbler cobbler cobbler-web pykickstart debmirror httpd dhcp xinetd

     
        cobbler        #cobbler程序包
        cobbler-web     #cobbler的web服务包
        pykickstart    #cobbler检查kickstart语法错误
        httpd      #Apache web服务
        dhcp       #Dhcp服务
        tftp      #tftp服务

        xinetd  #诸多服务的超级守护进程,

        ###扩展部分可以忽略:很多人不知道这是干啥的,xinetd,可以把一些小服务放在xinetd里进行托管,托管后的好处就是可以使用xinetd强大的参数来控制这些服务,并增强安全性,但也又一些缺点,它最大的缺点就是RPC支持的不够稳定,但也可以启动protmap,使它与xinetd共存来解决。###

        ###系统默认支持xinetd服务可以分为

          1)标准internet服务:telnet,ftp

          2)信息服务:finger、netstat、systat

          3)邮件服务:imap、imaps、pop2、pop3、pops

          4)RPC服务:rquotad、rstatd、rusersd、sprayd、walld

          5)BSD服务:comsta、exec、login、ntalk、shell、talk

          6)内部服务:chargen、daytime、echo、servers、services、time

          7)安全服务:irc

          8)其他服务:name,tftp,uucp

        ###

        

        配置文件目录:/etc/cobbler


        /etc/cobbler       #配置文件目录
        /etc/cobbler/settings       #cobbler主配置文件
        /etc/cobbler/dhcp.template       #DHCP服务的配置模板
        /etc/cobbler/tftpd.template     #tftp服务的配置模板
        /etc/cobbler/rsync.template     #rsync服务的配置模板
        /etc/cobbler/iso      #iso模板配置文件目录
        /etc/cobbler/pxe      #pxe模板文件目录
        /etc/cobbler/power     #电源的配置文件目录
        /etc/cobbler/users.conf     #web服务授权配置文件
        /etc/cobbler/users.digest     #web访问的用户名密码配置文件
        /etc/cobbler/dnsmasq.template     #DNS服务的配置模板
        /etc/cobbler/modules.conf     #Cobbler模块配置文件
        

        Cobbler数据目录

        /var/lib/cobbler     
        /var/lib/cobbler/config       #配置文件
        /var/lib/cobbler/kickstarts       #默认存放kickstart文件
        /var/lib/cobbler/loaders      #存放的各种引导程序
        /var/www/cobbler        #系统安装镜像目录
        /var/www/cobbler/ks_mirror       #导入的系统镜像列表,cobbler distro文件目录
        /var/www/cobbler/images       #导入的系统镜像启动文件
        /var/www/cobbler/repo_mirror      #yum源存储目录
        

        日志目录

        /var/log/cobbler         
        /var/log/cobbler/install.log       #客户端系统安装日志
        /var/log/cobbler/cobbler.log       #cobbler日志

    2、安装使用cobbler

      1)先添加epel源

        wget https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

        rpm -ivh epel-release-latest-7.noarch.rpm

        yum clean all

        yum makecache all

      2)开启http,cobbler

        先启动httpd,在启动cobblerd

         systemctl start httpd.service

         systemctl start cobblerd.service

         systemctl enable httpd

         systemctl enabled cobblerd

        netstart -tnlp

        14091端口

        先看一下面两条命令

          cobbler help

          cobbler check

          

          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 : 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 : since iptables may be running, ensure 69, 80/443, and 25151 are unblocked                                                                                                                                                                                                                                                                                                                                                                                                                                                               
      			7 : comment out 'dists' on /etc/debmirror.conf for proper debian support                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
      			8 : comment out 'arches' on /etc/debmirror.conf for proper debian support                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
      			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                                                                                                                                                                                                                                                        
      			                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
      			Restart cobblerd and then run 'cobbler sync' to apply changes.  
    

      

    3、配置cobbler主配置文件及处理check问题

      1)server和next_server

      vim /etc/cobbler/setting

        server 192.168.216.149      #server用于cobbler服务器指定ip地址

        next-server 192.168.216.149  #next-server DHCP/PXE网络引导文件被下载的tftp服务器ip,可以和server是同一台也可以是其他主机

        用sed免去vim编辑

        sed -i 's/server:127.0.0.1/server: 192.168.216.149/g' /etc/cobbler/settings

        sed -i 's/next-server:127.0.0.1/next-server: 192.168.216.149/g' /etc/cobbler/settings

      2)生成cobbler安装系统root初始密码(上面出现第9项)

      

      	[root@node3 ~]# openssl passwd -1 -salt $(openssl rand -hex 4)                                                                                                                                                                                                                        
            Password:                                                     
            $1$5b5e6a7a$ZdD7Yn4i5ExKKcqxtFZth1   
            
            vim /etc/cobbler/setting
            default_password_crypted: "$1$5b5e6a7a$ZdD7Yn4i5ExKKcqxtFZth1" 
    

      3)cobbler管理rsync

        默认时0,不对rsync进行管理,可以修改为1进行管理

        ###cobbler 支持/etc/cobbler/rsync.template   #rsync服务的配置模板###

        用sed解决

        sed -i  's/manage_dhcp:0/manage_dhcp: 1/g' /etc/cobbler/settings

        grep '^manage_dhcp' /etc/cobbler/settings

      4)cobbler管理dhcp

        pxe启动需要dhcp服务器地址,并直接引导系统,它就可以从网络中下载引导文件到tftp的服务器,cobbler可以通manage_dhcp的设置来进行管理

        配置dhcp服务

        修改cobbler配置让cobbler来管理dhcp服务,在做自定义配置时,需要修改dhcp相关配置,以配合pxe

          同上也是改为1

          manage_dhcp: 1

          sed -i 's/manage_dhcp:0/manage_dhcp: 1/g' /etc/cobbler/settings

          grep '^manage_dhcp' /etc/cobbler/settings

        注意还需要修改cobbler管理dhcp的模板

          ###/etc/cobbler/dhcp.template,此文件是cobbler管理dhcp的模板,确保dhcp分配的地址和cobbler在一个网段###

          vim /etc/cobbler/dhcp.template

          subnet 192.168.216.0 netmask 255.255.255.0{
          option routers 192.168.216.2;
          #option domain-name-servers x.x.x.x;
          #option subnet-mask x.x.x.x;
          range dynamic-bootp 192.168.216.200 192.168.216.210;
          default-lease-time 21600;
          max-lease-time 43200;
          next-server $next_server;

          }

        #

      5)配置debmirror

        注释掉@dists和@arches的行

        sed -i -e 's|@dists=.*|#@dists=|' /etc/debmirror.conf

        sed -i -e 's|@arches=.*|#@arches=|' /etc/debmirror.conf

       6)配置tftp

        ###cobbler也可以管理tftpd     /etc/cobbler/tftpd.tmplate   #tftp服务的配置模板###

        我这里没有用cobbler管理

        vim /etc/xinetd.d/tftp

        disabled    =no

        chkconfig tftp on 开机自启

        systemctl enable tftp.service

        systemctl restart tftp.servcie

        systemctl enabled xinetd.service

        systemctl start xinetd.servcie

        检查xinetd进行

        ps  -ef |grep xinetd

        检查tftp监听端口69

          ss -untlp

       7)配置启动rsync

         vim /etc/xinetd.d/rysnc

         disabled  =no

         systemctl start ryncd

          rsync和tftpd都起来后启动xinetd

         service xinetd restart

       8)关闭selinux

          setenforce 0

          getenforce

            permissive

          

       9)可以下载或复制本机的bootload

          ls /var/lib/cobbler/loaders

          cobbler get-loaders

          复制本机的

            cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders

            cp /usr/share/syslinux/pexlinux.o /var/lib/cobbler/loaders

       10)如果不用cobbler管理dhcp,则配置dhcp配置文件

          cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /dhcpd.conf

          vim /etc/dhcp/dhcpd.conf

              option domain-name "zhangxingeng.com";

              option domain-name-servers 192.168.216.149;

               subnet 192.168.216.0 netmask 255.255.255.0 {

                range 192.168.216.200 192.168.216.220

               option routers 192.168.216.149;

               }

    4、启动各项服务

            systemctl start dhcpd

            systemctl start ryncd

            systemctl start tftpd

            systemctl start httpd

            systemctl start xinted

       cobbler sync 同步

       cobbler sync 命令用于将tftpboot目录和/var/www/cobbler(系统江西目录)保持最新,当/var/lib/cobbler或者ks发生变化,应该执行一次cobbler sync或重启cobbler服务

    五、cobbler 子命令介绍及启动cobbler

      1、cobbler 子命令

        cobbler [command] --help

        cobbler report  #查看cobbler报告

        cobbler list    #查看操作

        cobbler profile  #查看配置文件信息

        cobbler distro  #查看cobbler导入系统发行版系统信息

        cobbler system  #查看system信息

        cobbler repo  #查看repo信息

        cobbler sync  #同步cobbler配置,更改配置最好都要执行下

        cobbler reposync  #同步yum仓库

    注:profile与distro是多对一的关系,profile 是对distro进行定制后的描述

    1 [root@node3 ~]# cobbler --help
    2 usage
    3 =====
    4 cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... 
    5         [add|edit|copy|getks*|list|remove|rename|report] [options|--help]
    6 cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help]
    7 [root@node3 ~]# 
     1 [root@node3 ~]# cobbler distro list
     2    centos7-x86_64
     3 [root@node3 ~]# cobbler profile list
     4    centos7-x86_64
     5 [root@node3 ~]# cobbler distro --help
     6 usage
     7 =====
     8 cobbler distro add
     9 cobbler distro copy
    10 cobbler distro edit
    11 cobbler distro find
    12 cobbler distro list
    13 cobbler distro remove
    14 cobbler distro rename
    15 cobbler distro report

     六、开始生成distro,ks,及profile文件

      1、挂载光盘并生成distro

    1 [root@node3 kickstarts]# mount /dev/cdrom /media/cdrom/
    2 mount: /dev/sr0 is write-protected, mounting read-only
    3 [root@node3 kickstarts]# cobbler import --name=centos7-x86_64 --path=/media/cdrom
    4 task started: 2018-06-30_174436_import
    5 task started (id=Media import, time=Sat Jun 30 17:44:36 2018)

    等待导入完成,distro就生成完成了,从本地导入默认就是把镜像中的文件复制到/var/www/cobbler/

    1 [root@node3 kickstarts]# ll /var/www/cobbler/images/centos7-
    2 centos7-Everything-x86_64/ centos7-x86_64/            
    3 [root@node3 kickstarts]# ll /var/www/cobbler/images/centos7-x86_64/
    4 total 47628
    5 -rw-r--r--. 3 root root 43372552 Dec  5  2016 initrd.img
    6 -rwxr-xr-x. 3 root root  5392080 Nov 23  2016 vmlinuz
    7 [root@node3 kickstarts]# 
     1 [root@node3 kickstarts]# ll /var/www/cobbler/ks_mirror/centos7
     2 total 312
     3 -rw-r--r--. 1 root root     14 Dec  5  2016 CentOS_BuildTag
     4 drwxr-xr-x. 3 root root     35 Dec  5  2016 EFI
     5 -rw-r--r--. 1 root root    215 Dec 10  2015 EULA
     6 -rw-r--r--. 1 root root  18009 Dec 10  2015 GPL
     7 drwxr-xr-x. 3 root root     57 Dec  5  2016 images
     8 drwxr-xr-x. 2 root root    198 Dec  5  2016 isolinux
     9 drwxr-xr-x. 2 root root     43 Dec  5  2016 LiveOS
    10 drwxrwxr-x. 2 root root 217088 Dec  5  2016 Packages
    11 drwxrwxr-x. 2 root root   4096 Dec  5  2016 repodata
    12 -rw-r--r--. 1 root root   1690 Dec 10  2015 RPM-GPG-KEY-CentOS-7
    13 -rw-r--r--. 1 root root   1690 Dec 10  2015 RPM-GPG-KEY-CentOS-Testing-7
    14 -r--r--r--. 1 root root   2883 Dec  5  2016 TRANS.TBL

      2、提供ks文件  

        centos6的话只需要修改keyboard改为keyboard us,及%post脚本内容即可。

        centos7修改如下:

     1 [root@node3 kickstarts]# pwd
     2 /var/lib/cobbler/kickstarts
     3 [root@node3 kickstarts]# vim centos7.ks 
     4 
     5 #version=DEVEL
     6 # System authorization information
     7 auth --enableshadow --passalgo=sha512
     8 # Install OS instead of upgrade
     9 install
    10 # Use network installation
    11 url --url=$tree
    12 #也可以写成 url="http://192.168.216.149/cobbler/ks_mirror/centos7/"
    13 # Use text mode install
    14 text
    15 # Firewall configuration
    16 firewall --disabled
    17 firstboot --disable
    18 # ignoredisk --only-use=sda   #centos7默认的项,但是cobbler便宜ks文件不支持此语法,所以将此项注释
    19 #Keyboard layouts
    20 # old format: keyboard us
    21 # new format:
    22 keyboard --vckeymap=us --xlayouts='us'
    23 # System language
    24 lang en_US.UTF-8
    25 
    26 # Network information
    27 network  --onboot=yes --bootproto=dhcp --device=eth0 --noipv6
    28 network  --hostname=node4.zhangxingeng.com
    29 # Reboot after installation
    30 reboot
    31 # Root password
    32 rootpw --iscrypted $1$5b5e6a7a$ZdD7Yn4i5ExKKcqxtFZth1
    33 # SELinux configuration
    34 selinux --disabled
    35 # Do not configure the X Window System
    36 skipx
    37 # System timezone
    38 timezone Asia/Shanghai
    39 # System bootloader configuration
    40 bootloader --append="quiet crashkernel=auto" --location=mbr --boot-drive=sda
    41 # Clear the Master Boot Record
    42 zerombr
    43 # Partition clearing information
    44 clearpart --all --initlabel
    45 # Disk partitioning information
    46 part /boot --asprimary --fstype="xfs" --size=250
    47 part swap --fstype="swap" --size=2000
    48 part / --asprimary --fstype="xfs" --grow --size=5000
    49 
    50 #LVM分区才亏考虑一下的分区
    51 # part /boot --fstype ext4 --size=100
    52 # part swap --fstype=swap --size=2048
    53 # part pv26 --size=100 --grow
    54 # volgroup VG00 --pesize=32768 pv26
    55 # logvol / --fstype ext4 --name=LVroot --vgname=VG00 --size=29984
    56 # logvol /data --fstype ext4 --name=LVdata --vgname=VG00 --size=100 --grow
    57 
    58 %post
    59 rm -f /etc/yum.repos.d/*
    60 cat >>/etc/yum.repos.d/my.repo<<eof
    61 [base]
    62 name=sohu
    63 baseurl=http://mirrors.sohu.com/centos/7/os/x86_64/
    64 gpgcheck=0
    65 enable=1
    66 [epel]
    67 name=epel
    68 baseurl=http://mirrors.aliyun.com/epel/7Server/x86_64/
    69 enable=1
    70 gpgcheck=0
    71 eof
    72 sed -i "s/rhgb //" /boot/grub2/grub.cfg
    73 sed -i "/UUID/d" /etc/sysconfig/network-scripts/ifcfg-eth0
    74 echo "DNS1=114.114.114.114" >> /etc/sysconfig/network-scripts/ifcfg-eth0
    75 echo "UseDNS no" >> /etc/ssh/sshd_config
    76 sed -i "s/GSSAPIAuthentication yes/GSSAPIAuthentication no/" /etc/ssh/ssh_config
    77 sed -i "s/^SELINUX=.*$/SELINUX=disabled/" /etc/sysconfig/selinux
    78 systemctl disable firewalld
    79 %end
    80 
    81 %packages
    82 @base
    83 @core
    84 @development
    85 @platform-devel
    86 kexec-tools
    87 lftp
    88 tree
    89 lrzsz
    90 
    91 %end
    92 
    93 %addon com_redhat_kdump --enable --reserve-mb='auto'
    94 
    95 %end
    96                                             

      3、提供profile

        导入镜像生成的distro过程会自动生成一个profile

    1 [root@node3 kickstarts]# cobbler profile list
    2    centos7-Everything-x86_64
    3    centos7-x86_64

        profile默认使用的ks是/var/lib/cobbler/kickstarts/sample_end.ks,所以需要修改此项

     1 [root@node3 kickstarts]# cobbler profile list
     2    centos7-Everything-x86_64
     3    centos7-x86_64
     4 [root@node3 kickstarts]# cobbler profile report --name=centos7-x86_64
     5 Name                           : centos7-x86_64
     6 TFTP Boot Files                : {}
     7 Comment                        : 
     8 DHCP Tag                       : default
     9 Distribution                   : centos7-x86_64
    10 Enable gPXE?                   : 0
    11 Enable PXE Menu?               : 1
    12 Fetchable Files                : {}
    13 Kernel Options                 : {}
    14 Kernel Options (Post Install)  : {}
    15 Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks
    16 Kickstart Metadata             : {}
    17 Management Classes             : []
    18 Management Parameters          : <<inherit>>
    19 Name Servers                   : []
    20 Name Servers Search Path       : []
    21 Owners                         : ['admin']
    22 Parent Profile                 : 
    23 Internal proxy                 : 
    24 Red Hat Management Key         : <<inherit>>
    25 Red Hat Management Server      : <<inherit>>
    26 Repos                          : []
    27 Server Override                : <<inherit>>
    28 Template Files                 : {}
    29 Virt Auto Boot                 : 1
    30 Virt Bridge                    : xenbr0
    31 Virt CPUs                      : 1
    32 Virt Disk Driver Type          : raw
    33 Virt File Size(GB)             : 5
    34 Virt Path                      : 
    35 Virt RAM (MB)                  : 512
    36 Virt Type                      : kvm
    [root@node3 kickstarts]# cobbler profile edit --name=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.ks
    1 [root@node3 kickstarts]# cobbler profile report --name=centos7-x86_64 |grep -i kickstart
    2 Kickstart                      : /var/lib/cobbler/kickstarts/centos7.ks
    3 Kickstart Metadata             : {}

        centos7应该加上内核启动参数netifnames和biosdevname使得网卡名使用ethN而不使用enoXXX这样的随机名称

    1 [root@node3 kickstarts]# cobbler profile report --name=centos7-x86_64 |grep -Ei 'kernel|kickstart'
    2 Kernel Options                 : {'biosdevname': '0', 'net.ifnames': '0'}
    3 Kernel Options (Post Install)  : {}
    4 Kickstart                      : /var/lib/cobbler/kickstarts/centos7.ks
    5 Kickstart Metadata             : {}
    6 [root@node3 kickstarts]# 

        如果不是生成profile也可以添加一个,比如cobbler profile add --name=centos7-x86_64 --distro=centos7-x86_64 --      kickstart=/var/lib/cobbler/kicstarts/centos7.ks

        每添加一个profile都是在项/var/lib/tftpboot/pxelinux.cfg/default中添加一个label

     1 [root@node3 kickstarts]# cat /var/lib/tftpboot/pxelinux.cfg/default 
     2 DEFAULT menu
     3 PROMPT 0
     4 MENU TITLE Cobbler | http://cobbler.github.io/
     5 TIMEOUT 200
     6 TOTALTIMEOUT 6000
     7 ONTIMEOUT local
     8 
     9 LABEL local
    10         MENU LABEL (local)
    11         MENU DEFAULT
    12         LOCALBOOT -1
    13 
    14 LABEL centos7-Everything-x86_64
    15         kernel /images/centos7-Everything-x86_64/vmlinuz
    16         MENU LABEL centos7-Everything-x86_64
    17         append initrd=/images/centos7-Everything-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.216.149/cblr/svc/op/ks/profile/centos7-Everything-x86_64
    18         ipappend 2
    19 
    20 LABEL centos7-x86_64
    21         kernel /images/centos7-x86_64/vmlinuz
    22         MENU LABEL centos7-x86_64
    23         append initrd=/images/centos7-x86_64/initrd.img ksdevice=bootif lang=  text net.ifnames=0 biosdevname=0 kssendmac  ks=http://192.168.216.149/cblr/svc/op/ks/profile/centos7-x86_64
    24         ipappend 2
    25 
    26 
    27 
    28 MENU end
    29 [root@node3 kickstarts]# 

        其实也可以自己修改编辑,我们把默认的menu.c32改为vesamenu.c32更喜欢这个界面,把默认菜单等待时间改为2s,也可以设置成更短,并进入菜单默认停留在local(从本地启动系统)

     1 [root@node3 kickstarts]# cat /var/lib/tftpboot/pxelinux.cfg/default 
     2 DEFAULT vesamenu.c32
     3 PROMPT 0
     4 MENU TITLE Cobbler | http://cobbler.github.io/
     5 TIMEOUT 20
     6 TOTALTIMEOUT 6000
     7 ONTIMEOUT centos7-x86_64
     8 
     9 LABEL local
    10         MENU LABEL (local)
    11         MENU DEFAULT
    12         LOCALBOOT -1
    13 
    14 LABEL centos7-Everything-x86_64
    15         kernel /images/centos7-Everything-x86_64/vmlinuz
    16         MENU LABEL centos7-Everything-x86_64
    17         append initrd=/images/centos7-Everything-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.216.149/cblr/svc/op/ks/profile/centos7-Everything-x86_64
    18         ipappend 2
    19 
    20 LABEL centos7-x86_64
    21         kernel /images/centos7-x86_64/vmlinuz
    22         MENU LABEL centos7-x86_64
    23         append initrd=/images/centos7-x86_64/initrd.img ksdevice=bootif lang=  text net.ifnames=0 biosdevname=0 kssendmac  ks=http://192.168.216.149/cblr/svc/op/ks/profile/centos7-x86_64
    24         ipappend 2
    25 
    26 
    27 
    28 MENU end
    29 [root@node3 kickstarts]# 

        注意,需要确保ks路径是有效并正确,我们可以在浏览器访问

        http://192.168.216.149/cblr/svc/op/ks/profile/centos7-x86_64

        如出现下面情况就是出错了

    # This kickstart had errors that prevented it from being rendered correctly.
    # The cobbler.log should have information relating to this failure.

        如果排错完成需要重新编辑profile加载新的kickstart文件

        cobbler profile edit --name=xxxxx --kickstart=xxxxx重新编译xxxxx的profile文件或者支持cobbler sync命令,知道浏览器能获取到kickstart的内容时才算成功或者使用cobbler profile getks --name=xxxxx命令获取名为xxxxx的profile的ks内容

      4、定制化的安装

        kickstart 实现某台服务器使用给指定ks文件可能有些复杂,但是cobbler就很简单,物理mac地址的唯一性,来进行ks文件的选择定制

        在做个镜像,我们指定这个节点使用centos7-Everything.ks

     1 [root@node3 xinetd.d]# cobbler import --name=centos7-Everything --path=/media/cdrom
     2 task started: 2018-06-30_220847_import
     3 task started (id=Media import, time=Sat Jun 30 22:08:47 2018)
     4 Found a candidate signature: breed=redhat, version=rhel6
     5 Found a candidate signature: breed=redhat, version=rhel7
     6 Found a matching signature: breed=redhat, version=rhel7
     7 Adding distros from path /var/www/cobbler/ks_mirror/centos7-Everything:
     8 creating new distro: centos7-Everything-x86_64
     9 creating new profile: centos7-Everything-x86_64
    10 associating repos
    11 checking for rsync repo(s)
    12 checking for rhn repo(s)
    13 checking for yum repo(s)
    14 starting descent into /var/www/cobbler/ks_mirror/centos7-Everything for centos7-Everything-x86_64
    15 processing repo at : /var/www/cobbler/ks_mirror/centos7-Everything
    16 need to process repo/comps: /var/www/cobbler/ks_mirror/centos7-Everything
    17 looking for /var/www/cobbler/ks_mirror/centos7-Everything/repodata/*comps*.xml
    18 Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7-Everything/repodata
    19 *** TASK COMPLETE ***
     1 [root@node3 kickstarts]# cobbler profile report --name=centos7-Everything-x86_64
     2 Name                           : centos7-Everything-x86_64
     3 TFTP Boot Files                : {}
     4 Comment                        : 
     5 DHCP Tag                       : default
     6 Distribution                   : centos7-Everything-x86_64
     7 Enable gPXE?                   : 0
     8 Enable PXE Menu?               : 1
     9 Fetchable Files                : {}
    10 Kernel Options                 : {}
    11 Kernel Options (Post Install)  : {}
    12 Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks
    13 Kickstart Metadata             : {}
    14 Management Classes             : []
    15 Management Parameters          : <<inherit>>
    16 Name Servers                   : []
    17 Name Servers Search Path       : []
    18 Owners                         : ['admin']
    19 Parent Profile                 : 
    20 Internal proxy                 : 
    21 Red Hat Management Key         : <<inherit>>
    22 Red Hat Management Server      : <<inherit>>
    23 Repos                          : []
    24 Server Override                : <<inherit>>
    25 Template Files                 : {}
    26 Virt Auto Boot                 : 1
    27 Virt Bridge                    : xenbr0
    28 Virt CPUs                      : 1
    29 Virt Disk Driver Type          : raw
    30 Virt File Size(GB)             : 5
    31 Virt Path                      : 
    32 Virt RAM (MB)                  : 512
    33 Virt Type                      : kvm
    34 
    35 [root@node3 kickstarts]# cobbler profile edit --name=centos7-Everything-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7-Everything.ks
     1 [root@node3 kickstarts]# cobbler system add --name=test --mac=00:50:56:29:32:09 --profile=centos7-Everything-x86_64 --ip-address=192.168.216.222 subnet=255.255.255.0 --gateway=192.168.216.2 --interface=eth0 --static=1 --hostname=node5 
     2 [root@node3 kickstarts]# cobbler system list
     3    test
     4 [root@node3 kickstarts]# cobbler sync
     5 task started: 2018-06-30_224520_sync
     6 task started (id=Sync, time=Sat Jun 30 22:45:20 2018)
     7 running pre-sync triggers
     8 cleaning trees
     9 removing: /var/www/cobbler/images/centos7-x86_64
    10 removing: /var/www/cobbler/images/centos7-Everything-x86_64
    11 removing: /var/lib/tftpboot/pxelinux.cfg/default
    12 removing: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-29-32-09
    13 removing: /var/lib/tftpboot/grub/images
    14 removing: /var/lib/tftpboot/grub/grub-x86.efi
    15 removing: /var/lib/tftpboot/grub/grub-x86_64.efi
    16 removing: /var/lib/tftpboot/grub/efidefault
    17 removing: /var/lib/tftpboot/grub/01-00-50-56-29-32-09
    18 removing: /var/lib/tftpboot/images/centos7-x86_64
    19 removing: /var/lib/tftpboot/images/centos7-Everything-x86_64
    20 removing: /var/lib/tftpboot/s390x/profile_list
    21 copying bootloaders
    22 trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
    23 copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
    24 trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
    25 copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
    26 trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
    27 copying: /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
    28 trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
    29 copying: /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
    30 trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
    31 trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
    32 copying distros to tftpboot
    33 copying files for distro: centos7-x86_64
    34 trying hardlink /var/www/cobbler/ks_mirror/centos7/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos7-x86_64/vmlinuz
    35 trying hardlink /var/www/cobbler/ks_mirror/centos7/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos7-x86_64/initrd.img
    36 copying files for distro: centos7-Everything-x86_64
    37 trying hardlink /var/www/cobbler/ks_mirror/centos7-Everything/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos7-Everything-x86_64/vmlinuz
    38 trying hardlink /var/www/cobbler/ks_mirror/centos7-Everything/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos7-Everything-x86_64/initrd.img
    39 copying images
    40 generating PXE configuration files
    41 generating: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-29-32-09
    42 generating: /var/lib/tftpboot/grub/01-00-50-56-29-32-09
    43 generating PXE menu structure
    44 copying files for distro: centos7-x86_64
    45 trying hardlink /var/www/cobbler/ks_mirror/centos7/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos7-x86_64/vmlinuz
    46 trying hardlink /var/www/cobbler/ks_mirror/centos7/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos7-x86_64/initrd.img
    47 Writing template files for centos7-x86_64
    48 copying files for distro: centos7-Everything-x86_64
    49 trying hardlink /var/www/cobbler/ks_mirror/centos7-Everything/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos7-Everything-x86_64/vmlinuz
    50 trying hardlink /var/www/cobbler/ks_mirror/centos7-Everything/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos7-Everything-x86_64/initrd.img
    51 Writing template files for centos7-Everything-x86_64
    52 rendering TFTPD files
    53 generating /etc/xinetd.d/tftp
    54 processing boot_files for distro: centos7-x86_64
    55 processing boot_files for distro: centos7-Everything-x86_64
    56 cleaning link caches
    57 running: find /var/lib/tftpboot/images/.link_cache -maxdepth 1 -type f -links 1 -exec rm -f '{}' ';'
    58 received on stdout: 
    59 received on stderr: 
    60 running post-sync triggers
    61 running python triggers from /var/lib/cobbler/triggers/sync/post/*
    62 running python trigger cobbler.modules.sync_post_restart_services
    63 running shell triggers from /var/lib/cobbler/triggers/sync/post/*
    64 running python triggers from /var/lib/cobbler/triggers/change/*
    65 running python trigger cobbler.modules.scm_track
    66 running shell triggers from /var/lib/cobbler/triggers/change/*
    67 *** TASK COMPLETE ***

        看一下自动生成了一个以mac地址的文件,里面的label的ks地址指向刚刚创建的test,http://192.168.216.149/cblr/svc/op/ks/system/test

     1 [root@node3 pxelinux.cfg]# cat 01-00-50-56-29-32-09 
     2 default linux
     3 prompt 0
     4 timeout 1
     5 label linux
     6         kernel /images/centos7-Everything-x86_64/vmlinuz
     7         ipappend 2
     8         append initrd=/images/centos7-Everything-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.216.149/cblr/svc/op/ks/system/test
     9 
    10 [root@node3 pxelinux.cfg]# 

    附录扩展

      1、搭建yum源

      添加repos源

      cobbler repo add --name=centos7-x86_64-epel --mirror=http://mirrors.aliyun.com/epel/7/x86_64 --arch=x86_64 --breed=yum

      cobbler reposync

      添加repo到对应的profile

      cobbler profile edit --name=centos7-x86_64 --repos="centos7-x86_64-epel "

      修改ks文件添加%post %end中间

      systemctl disable postfix.service

      %yum_config_stanza

      2、koan (kickstart-over-a-network)实现客户机自动重新安装

        1)客户端安装koan

        yum install -y koan

        2)执行安装命令

        koan --server=192.168.216.149 --list=profiles 

         - looking for cobbler at http://192.168.216.149:80/cobbler_api

        centos7-x86_64

        3)在指定要重装的系统上执行要重装的哪个系统

        koan --replace-self --server=192.168.216.149 --profile=centos7-x86_64

        4)重启就会自动安装新系统了

     

    转载请注明出处:https://www.cnblogs.com/zhangxingeng/p/9702625.html 

     

  • 相关阅读:
    flash 3d基础学习
    3d中的镜头
    [转]Android Canvas 切割 clipRect
    绘制球形
    绘制圆筒
    stage3d学习笔记1
    (转)Region.Op效果解析
    游戏中的镜头
    无向网的最小生成树——Prim算法(转)
    最短路径之——Dijkstra算法(转)
  • 原文地址:https://www.cnblogs.com/zhangxingeng/p/9702625.html
Copyright © 2011-2022 走看看