• PXE与cobbler实现系统自动安装


     1.安装yum 源

    [root@n1 ~]#rpm -vih https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

    2.安装服务程序

    [root@n1 ~]# yum install -y httpd dhcp tftp  xinetd cobbler cobbler-web pykickstart 

    cobbler                      #cobbler程序包

    cobbler-web             #cobbler的web服务包

    pykickstart               #cobbler检查kickstart语法错误

    [root@n1 ~]# rpm -ql cobbler  # 查看安装的文件,下面列出部分。
    /etc/cobbler                  # 配置文件目录
    /etc/cobbler/settings         # cobbler主配置文件,这个文件是yaml格式,cobbler是python写的程序。
    /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模块配置文件
    
    数据目录:
    /var/lib/cobbler              # cobbler数据目录
    /var/lib/cobbler/config       # 配置文件
    /var/lib/cobbler/kickstarts   # 默认存放kickstart文件
    /var/lib/cobbler/loaders      # 存放的各种引导程序
    /var/www/cobbler              # 系统安装镜像目录
    /var/www/cobbler/ks_mirror    # 导入的系统镜像列表
    /var/www/cobbler/p_w_picpaths # 导入的系统镜像启动文件
    /var/www/cobbler/repo_mirror  # yum源存储目录
    
    日志目录:
    /var/log/cobbler              # 日志目录
    /var/log/cobbler/install.log  # 客户端系统安装日志
    /var/log/cobbler/cobbler.log  # cobbler日志
    
    命令介绍
    cobbler commands介绍
    cobbler check 核对当前设置是否有问题
    cobbler list 列出所有的cobbler元素
    cobbler report 列出元素的详细信息
    cobbler sync 同步配置到数据目录,更改配置最好都要执行下
    cobbler reposync 同步yum仓库
    cobbler distro 查看导入的发行版系统信息
    cobbler system 查看添加的系统信息
    cobbler profile 查看配置信息

    检测cobbler
    [root@n1 ~]# cobbler check

    Traceback (most recent call last):
      File "/usr/bin/cobbler", line 36, in <module>
        sys.exit(app.main())
      File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 662, in main
        rc = cli.run(sys.argv)
      File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 269, in run
        self.token         = self.remote.login("", self.shared_secret)
      File "/usr/lib64/python2.7/xmlrpclib.py", line 1233, in __call__
        return self.__send(self.__name, args)
      File "/usr/lib64/python2.7/xmlrpclib.py", line 1587, in __request
        verbose=self.__verbose
      File "/usr/lib64/python2.7/xmlrpclib.py", line 1273, in request
        return self.single_request(host, handler, request_body, verbose)
      File "/usr/lib64/python2.7/xmlrpclib.py", line 1306, in single_request
        return self.parse_response(response)
      File "/usr/lib64/python2.7/xmlrpclib.py", line 1482, in parse_response
        return u.close()
      File "/usr/lib64/python2.7/xmlrpclib.py", line 794, in close
        raise Fault(**self._stack[0])
    xmlrpclib.Fault: <Fault 1: "<class 'cobbler.cexceptions.CX'>:'login failed'">
    解决办法
    
    [root@cobbler ~]#systemctl restart httpd.service
    [root@cobbler ~]#systemctl restart cobblerd.service
    
    # 关闭防火墙、selinux等
    [root@cobbler ~]# systemctl stop firewalld
    [root@cobbler ~]# systemctl disable firewalld
    [root@cobbler ~]# setenforce 0
    [root@cobbler ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux
    检测cobbler
    [root@n1 ~]# 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 : enable and start rsyncd.service with systemctl
     
    6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
     
    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
     
    Restart cobblerd and then run 'cobbler sync' to apply changes.
    
    
    按照指示修改
    
    1.修改/etc/cobbler/settings中的"server"字段为提供cobbler服务的主机的IP或主机名
    [root@n1 ~]# sed -i 's/server: 127.0.0.1/server: 32.153.3.166/' /etc/cobbler/settings
    [root@n1 ~]# grep "server" /etc/cobbler/settings
    server: 192.168.231.60
     
    2.修改/etc/cobbler/settings中"next_server"为PXE网络上启动服务器的IP(这里PXE服务器和cobbler在同一主机)
    [root@n1 ~]# sed -i 's/next_server: 127.0.0.1/next_server: 32.153.3.166/' /etc/cobbler/settings
    [root@n1 ~]# grep "next_server" /etc/cobbler/settings
    next_server: 192.168.231.60
     
    3.修改/etc/xinet.d/tftp文件中的disable的参数为no
    [root@n1 ~]# cp /etc/xinetd.d/tftp{,.bak}  #备份
    [root@n1 ~]# vi /etc/xinetd.d/tftp
            disable                 = no
            
    [root@liu ~]# systemctl restart cobbler   重启一下cobbler
    
    [root@liu ~]# vi /etc/cobbler/dhcp.template    修改DHCP 配置文件
    
    
    subnet 32.153.3.0 netmask 255.255.255.0 {
         option routers             32.153.3.2;
         option domain-name-servers 32.153.3.2;
         option subnet-mask         255.255.255.0;
         range dynamic-bootp        32.153.3.100 32.153.3.120;
         default-lease-time         21600;
         max-lease-time             43200;
         next-server                $next_server;
         class "pxeclients" {
    
            
     
    4.执行cobbler get-loaders命令
    
    [root@liu ~]# systemctl restart cobbler   重启一下cobbler
    [root@liu ~]# cobbler  sync 
     
    5.启动rsync服务
    [root@n1 ~]# systemctl start rsyncd.service
    [root@n1 ~]# systemctl enable rsyncd.service
     
    6.安装包用来管理debian部署和存储库,这里不需要,就不安装了
     
    7.修改cobbler中的加密密码(即为自动安装系统后的root登录密码)
    #生成加密密码openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'
    [root@n1 ~]# openssl passwd -1 
    $1$123456$jMyuS0sKNP4A/OOlui3lR/
    [root@n1 ~]# vim /etc/cobbler/settings
    default_password_crypted: "$1$123456$jMyuS0sKNP4A/OOlui3lR/"
     
    8.安装cman fence-agents(可选),电源管理功能
    [root@n1 ~]# yum install cman fence-agents -y
    
    
    修改一些其他配置
    [root@n1 ~]# vim /etc/cobbler/settings
    manage_dhcp: 1  #用cobbler管理dhcp
    pxe_just_once: 1   #防止循环安装系统,适用于服务器第一启动选项是pxe启动
    同步cobbler配置
    
    [root@n1 ~]# cobbler sync
    [root@n1 ~]# systemctl restart cobblerd.service
    
    重新检测cobbler
    [root@n1 ~]# cobbler check
    The following are potential configuration items that you may want to fix:
    1 : 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.
    #管理deban,这里不需要安装
    
        同步cobbler配置
    
    [root@n1 ~]# cobbler sync
    
    重新检测cobbler
    [root@n1 ~]# cobbler check
    The following are potential configuration items that you may want to fix:
    1 : 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@liu ~]# mount /dev/cdrom /mnt
    mount: /dev/loop0 is write-protected, mounting read-only
    
    导入镜像
    [root@n1 ~]# cobbler import --path=/mnt/ --name=Centos-6.9 --arch=x86_64
    
    [root@n1 ~]# cobbler import --path=/mnt/ --name=Centos-7.2 --arch=x86_64
    
    [root@n1 ~]# cobbler import --path=/mnt/ --name=Centos-7.4 --arch=x86_64
    
    [root@n1 ~]# cobbler import --path=/mnt/ --name=Centos-7.6 --arch=x86_64
    
    [root@n1 ~]# cobbler import --path=/mnt/ --name=Centos-7.7 --arch=x86_64
    
    [root@n1 ~]# cobbler import --path=/mnt/ --name=Centos-7.8 --arch=x86_64
    --path:镜像路径
    --name:为安装源定义一个名字
    --arch :指定安装源是64位或32位
    
    
    [root@liu kickstarts]# cobbler profile list
       Centos-6.9-x86_64
       Centos-7.2-x86_64
       Centos-7.4-x86_64
       Centos-7.6-x86_64
       Centos-7.7-x86_64
       Centos-7.8-x86_64
    
    
    [root@liu kickstarts]#vi /var/lib/cobbler/kickstarts/      分别新建KS配置文件到目录下
       Centos-6.9.cfg
       Centos-7.2.cfg
       Centos-7.4.cfg
       Centos-7.6.cfg
       Centos-7.7.cfg
       Centos-7.8.cfg
       
       
    编辑  替换  /var/lib/cobbler/kickstarts/sample_end.ks默认的配置文件为自己的KS文件
    [root@liu ~]#cobbler profile edit --name=Centos-6.9-x86_64 --kickstar=/var/lib/cobbler/kickstarts/Centos-6.9-x86_64.cfg
    
    [root@liu ~]#cobbler profile edit --name=Centos-7.2-x86_64 --kickstar=/var/lib/cobbler/kickstarts/Centos-7.2-x86_64.cfg
    
    [root@liu ~]#cobbler profile edit --name=Centos-7.4-x86_64 --kickstar=/var/lib/cobbler/kickstarts/Centos-7.4-x86_64.cfg
    
    [root@liu ~]#cobbler profile edit --name=Centos-7.6-x86_64 --kickstar=/var/lib/cobbler/kickstarts/Centos-7.6-x86_64.cfg
    
    [root@liu ~]#cobbler profile edit --name=Centos-7.7-x86_64 --kickstar=/var/lib/cobbler/kickstarts/Centos-7.7-x86_64.cfg
    
    [root@liu ~]#cobbler profile edit --name=Centos-7.8-x86_64 --kickstar=/var/lib/cobbler/kickstarts/Centos-7.8-x86_64.cfg
    
    
    [root@liu kickstarts]# cobbler profile report
    Name                           : Centos-7.2-x86_64
    TFTP Boot Files                : {}
    Comment                        : 
    DHCP Tag                       : default
    Distribution                   : Centos-7.2-x86_64
    Enable gPXE?                   : 0
    Enable PXE Menu?               : 1
    Fetchable Files                : {}
    Kernel Options                 : {}
    Kernel Options (Post Install)  : {}
    Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks-------Centos-7.2-x86_64.cfg
    Kickstart Metadata             : {}
    Management Classes             : []
    Management Parameters          : <<inherit>>
    Name Servers                   : []
    Name Servers Search Path       : []
    Owners                         : ['admin']
    Parent Profile                 : 
    Internal proxy                 : 
    Red Hat Management Key         : <<inherit>>
    Red Hat Management Server      : <<inherit>>
    Repos                          : []
    Server Override                : <<inherit>>
    Template Files                 : {}
    Virt Auto Boot                 : 1
    Virt Bridge                    : xenbr0
    Virt CPUs                      : 1
    Virt Disk Driver Type          : raw
    Virt File Size(GB)             : 5
    Virt Path                      : 
    Virt RAM (MB)                  : 512
    Virt Type                      : kvm
    
    Name                           : Centos-6.9-x86_64
    TFTP Boot Files                : {}
    Comment                        : 
    DHCP Tag                       : default
    Distribution                   : Centos-6.9-x86_64
    Enable gPXE?                   : 0
    Enable PXE Menu?               : 1
    Fetchable Files                : {}
    Kernel Options                 : {}
    Kernel Options (Post Install)  : {}
    Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks--------Centos-6.9-x86_64.cfg
    Kickstart Metadata             : {}
    Management Classes             : []
    Management Parameters          : <<inherit>>
    Name Servers                   : []
    Name Servers Search Path       : []
    Owners                         : ['admin']
    Parent Profile                 : 
    Internal proxy                 : 
    Red Hat Management Key         : <<inherit>>
    Red Hat Management Server      : <<inherit>>
    Repos                          : []
    Server Override                : <<inherit>>
    Template Files                 : {}
    Virt Auto Boot                 : 1
    Virt Bridge                    : xenbr0
    Virt CPUs                      : 1
    Virt Disk Driver Type          : raw
    Virt File Size(GB)             : 5
    Virt Path                      : 
    Virt RAM (MB)                  : 512
    Virt Type                      : kvm
    
    
    第二个方案:上面不能改的化,选择这个方案。
    
    
    配置ks文件
    查看ks文件位置
    [root@n1 ~]# cd /var/lib/cobbler/kickstarts/
    [root@n1 kickstarts]# ls
    default.ks        legacy.ks            sample_esx4.ks   sample.ks
    esxi4-ks.cfg      pxerescue.ks         sample_esxi4.ks  sample_old.seed
    esxi5-ks.cfg      sample_autoyast.xml  sample_esxi5.ks  sample.seed
    install_profiles  sample_end.ks (默认使用的ks文件)       sample_esxi6.ks
    
    配置自定义ks文件,以sample_end.ks为模板
    [root@n1 kickstarts]# cp sample_end.ks Centos-7-x86_64.ks
    [root@n1 kickstarts]# vim Centos-7-x86_64.ks    #只修改如下内容
    firewall --disable     #关闭防火墙
    timezone  Asia/Shanghai  #设置时区
    # autopart    #把自动分区注释,手动如下设置
    part /boot --fstype=ext4 --asprimary --size=200
    part swap --asprimary --size=1024
    part / --fstype=ext4 --grow --asprimary --size=10240
    %packages   #安装需要安装的软件包
    $SNIPPET('func_install_if_enabled')  #这里默认
    %end
     
    解释
    --asprimary,强迫把分区分配为主分区,否则提示分区失败.
     
    --fstype=,为分区设置文件系统类型.有效的类型为ext2,ext3,swap和vfat
     
    --grow  让分区自动增长利用可用的磁盘空间,或是增长到设置的maxsize值;
     
    --size=  设置分区的最小值,默认单位为M,但是不能写单位;
     
     %packages部分,这部分选择需要安装的软件包.
    
    #第一次导入系统镜像后,cobbler会给镜像指定一个默认的kickstart自动安装文件(/var/lib/cobbler/kickstarts/sample_end.ks)
    
    [root@liu kickstarts]# cp sample_end.ks sample_end-bak.ks   备份原先的配置文件
    [root@liu kickstarts]# rm -rf sample_end.ks 
    
    [root@liu kickstarts]# vi sample_end.ks                   重新建立一个
    
    
    ---内核参数Kernel Options   网卡名称 eth0   eth1  [只改变7的网卡名称就行]
    [root@liu kickstarts]# cobbler profile edit --name=Centos-7.2-x86_64  --kopts='net.ifnames=0  biosdevname=0'
    [root@liu kickstarts]# cobbler profile edit --name=Centos-7.4-x86_64  --kopts='net.ifnames=0  biosdevname=0'
    [root@liu kickstarts]# cobbler profile edit --name=Centos-7.6-x86_64  --kopts='net.ifnames=0  biosdevname=0'
    [root@liu kickstarts]# cobbler profile edit --name=Centos-7.7-x86_64  --kopts='net.ifnames=0  biosdevname=0'
    [root@liu kickstarts]# cobbler profile edit --name=Centos-7.8-x86_64  --kopts='net.ifnames=0  biosdevname=0'
    
    
    [root@liu kickstarts]# cobbler profile report
    Name                           : Centos-7.2-x86_64
    TFTP Boot Files                : {}
    Comment                        : 
    DHCP Tag                       : default
    Distribution                   : Centos-7.2-x86_64
    Enable gPXE?                   : 0
    Enable PXE Menu?               : 1
    Fetchable Files                : {}
    Kernel Options                 : {'biosdevname': '0', 'net.ifnames': '0'}
    Kernel Options (Post Install)  : {}
    Kickstart                      : /var/lib/cobbler/kickstarts/Centos-7.2-x86_64.cfg
    Kickstart Metadata             : {}
    Management Classes             : []
    Management Parameters          : <<inherit>>
    Name Servers                   : []
    Name Servers Search Path       : []
    Owners                         : ['admin']
    Parent Profile                 : 
    Internal proxy                 : 
    Red Hat Management Key         : <<inherit>>
    Red Hat Management Server      : <<inherit>>
    Repos                          : []
    Server Override                : <<inherit>>
    Template Files                 : {}
    Virt Auto Boot                 : 1
    Virt Bridge                    : xenbr0
    Virt CPUs                      : 1
    Virt Disk Driver Type          : raw
    Virt File Size(GB)             : 5
    Virt Path                      : 
    Virt RAM (MB)                  : 512
    Virt Type                      : kvm
    
    
    [root@n1 ~]# cobbler sync
    
    
    修改PXE默认启动选项
    
    默认情况下PXE启动的是Local(启动后会出现local和自定义Centos-7-x86_64两个选项,需手动,要无人工干涉,就需要修改)
    
    修改前
    [root@n1 ~]# cd /var/lib/tftpboot/pxelinux.cfg/
    [root@n1 pxelinux.cfg]# vi default
    DEFAULT menu
    PROMPT 0
    MENU TITLE Cobbler | http://cobbler.github.io/
    TIMEOUT 200                        #菜单停留超时时间
    TOTALTIMEOUT 6000
    ONTIMEOUT (local)-----------------将括号里面的内容改为Centos-7-x86_64
    LABEL local    -------------------删除
           MENU LABEL (local)---------删除
           MENU DEFAULT---------------删除
           LOCALBOOT -1---------------删除
           
    LABEL Centos-7-x86_64                            #选项栏
           kernel /images/Centos-7-x86_64/vmlinuz   #选项标题自动安装7系统
           MENU LABEL Centos-7-x86_64               #指定内核镜像文件位置,参考TFTP的根目录/var/lib/tftpboot的相对路径
           append initrd=/images/Centos-7-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  
           ks=http://192.168.231.60/cblr/svc/op/ks/profile/Centos-7-x86_64
           #指定为根系统所在位置同样参考TFTP服务器的根目录的相对路径,指定ks文件的位置。
           ipappend 2
    MENU end
    
    
    不用cobbler sync,否则会恢复原来的配置
    
    [root@n1 ~]#tail -f /var/log/messages   查看日志
    说明:在client端系统安装时,可以在cobbler服务端上查看日志/var/log/messages,观察安装的每一个流程
  • 相关阅读:
    深入理解计算机系统(第三版)作业题答案(第三章)
    深入理解计算机系统(第三版)作业题答案(第二章)
    greedy算法(python版)
    Dijkstra算法(Swift版)
    Breadth-first search 算法(Swift版)
    递归演示程序(swift)
    Node.js之异步流控制
    Node.js之单利模式
    Node.js之循环依赖
    一个完整的Node.js RESTful API
  • 原文地址:https://www.cnblogs.com/wjlovezzd/p/13178561.html
Copyright © 2020-2023  润新知