zoukankan      html  css  js  c++  java
  • CentOS 7 Cobbler 自动化安装系统

    上一篇Cobbler 安装中,配置好了Cobbler,下面来配置自动化安装

    配置cobbler-DHCP

    # 修改settings中参数,由cobbler控制dhcp
    [root@cobbler ~]# egrep '^manage_dhcp' /etc/cobbler/settings
    manage_dhcp: 1
    

    修改dhcp.templates配置文件(仅列出修改部分)

    [root@cobbler ~]# vim /etc/cobbler/dhcp.template
    subnet 10.0.0.0 netmask 255.255.255.0 {
         option routers             10.0.0.2;
         option domain-name-servers 114.114.114.114;
         option subnet-mask         255.255.255.0;
         range dynamic-bootp        10.0.0.100 10.0.0.254;
    

    重启服务并同步配置

    改完dhcp必须要sync同步配置

    [root@cobbler ~]# systemctl restart cobblerd
    [root@cobbler ~]# cobbler sync
    task started: 2018-09-27_161333_sync
    task started (id=Sync, time=Thu Sep 27 16:13:33 2018)
    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.efi -> /var/lib/tftpboot/grub/grub-x86.efi
    trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
    copying distros to tftpboot
    copying images
    generating PXE configuration files
    generating PXE menu structure
    rendering DHCP files
    generating /etc/dhcp/dhcpd.conf
    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: dhcpd -t -q
    received on stdout: 
    received on stderr: 
    running: service dhcpd restart
    received on stdout: 
    received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
    
    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 ***
    
    

    检查dhcp

    [root@cobbler ~]# netstat -lntup | grep dhcp
    udp        0      0 0.0.0.0:67              0.0.0.0:*                           1733/dhcpd
    

    导入CentOs-7的镜像

    # 挂载光盘镜像
    [root@cobbler ~]# mount /dev/cdrom  /mnt
    mount: /dev/sr0 is write-protected, mounting read-only
    [root@cobbler ~]# cobbler import --path=/mnt --name=Centos-7.5 --arch=x86_64
    task started: 2018-09-27_161633_import
    task started (id=Media import, time=Thu Sep 27 16:16:33 2018)
    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/Centos-7.5-x86_64:
    creating new distro: Centos-7.5-x86_64
    trying symlink: /var/www/cobbler/ks_mirror/Centos-7.5-x86_64 -> /var/www/cobbler/links/Centos-7.5-x86_64
    creating new profile: Centos-7.5-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/Centos-7.5-x86_64 for Centos-7.5-x86_64
    processing repo at : /var/www/cobbler/ks_mirror/Centos-7.5-x86_64
    need to process repo/comps: /var/www/cobbler/ks_mirror/Centos-7.5-x86_64
    looking for /var/www/cobbler/ks_mirror/Centos-7.5-x86_64/repodata/*comps*.xml
    Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos-7.5-x86_64/repodata
    *** TASK COMPLETE ***
    
    # --path 镜像路径
    # --name 为安装源定义一个名字
    # --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
    # 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7.1-x86_64,如果重复,系统会提示导入失败
    
    

    查看

    [root@cobbler ~]# cobbler list
    distros:
       Centos-7.5-x86_64
    
    profiles:
       Centos-7.5-x86_64
    
    systems:
    
    repos:
    
    images:
    
    mgmtclasses:
    
    packages:
    
    files:
    
    

    导入kickstarts配置文件

    [root@cobbler ~]# cd /var/lib/cobbler/kickstarts
    [root@cobbler kickstarts]# ls
    default.ks    esxi5-ks.cfg      legacy.ks     sample_autoyast.xml  sample_esx4.ks   sample_esxi5.ks  sample.ks        sample.seed
    esxi4-ks.cfg  install_profiles  pxerescue.ks  sample_end.ks        sample_esxi4.ks  sample_esxi6.ks  sample_old.seed
    

    查看导入信息及默认ks文件

    [root@cobbler kickstarts]# cobbler report
    distros:
    ==========
    Name                           : Centos-7.5-x86_64
    Architecture                   : x86_64
    TFTP Boot Files                : {}
    Breed                          : redhat
    Comment                        : 
    Fetchable Files                : {}
    Initrd                         : /var/www/cobbler/ks_mirror/Centos-7.5-x86_64/images/pxeboot/initrd.img
    Kernel                         : /var/www/cobbler/ks_mirror/Centos-7.5-x86_64/images/pxeboot/vmlinuz
    Kernel Options                 : {}
    Kernel Options (Post Install)  : {}
    Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/Centos-7.5-x86_64'}
    Management Classes             : []
    OS Version                     : rhel7
    Owners                         : ['admin']
    Red Hat Management Key         : <<inherit>>
    Red Hat Management Server      : <<inherit>>
    Template Files                 : {}
    
    
    profiles:
    ==========
    Name                           : Centos-7.5-x86_64
    TFTP Boot Files                : {}
    Comment                        : 
    DHCP Tag                       : default
    Distribution                   : Centos-7.5-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
    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
    
    
    systems:
    ==========
    
    repos:
    ==========
    
    images:
    ==========
    
    mgmtclasses:
    ==========
    
    packages:
    ==========
    
    files:
    ==========
    

    我ks文件(只是简单配置的,具体可以按自己业务来)

    [root@cobbler kickstarts]# cat Centos7.5-x86_64.cfg
    #platform=x86, AMD64, or Intel EM64T
    #version=DEVEL
    # Install OS instead of upgrade
    install
    # Keyboard layouts
    keyboard 'us'
    # Root password
    rootpw --iscrypted $1$m1pE0DG6$vALBphGGynqvUzfJaWZ6U1
    # Use network installation
    url --url="$tree"
    # System language
    lang en_US
    # Firewall configuration
    firewall --disabled
    # System authorization information
    auth  --useshadow  --passalgo=sha512
    # Use graphical install
    graphical
    firstboot --disable
    # SELinux configuration
    selinux --disabled
    # Network information
    network  --bootproto=dhcp --device=eth0
    network  --bootproto=dhcp --device=eth1
    # Reboot after installation
    reboot
    # System timezone
    timezone Asia/Shanghai
    # 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="ext4" --size=200
    part swap --fstype="swap" --size=1024
    part / --fstype="ext4" --grow --size=1
    %packages
    @base
    @core
    @compat-libraries
    @debugging
    @development
    @gnome-desktop
    @X Window System
    %end
    

    检查ks命令

    # 写完 ks 文件之后,先通过 validateks 测试一下有没有语法错误
    # cobbler validateks
    # 通过下面这个命令查看 ks 文件,发现一些逻辑上的问题
    # cobbler system getks --name=test
    

    编辑修改指定ks文件为我们刚刚上传的ks

    [root@cobbler kickstarts]# cobbler profile edit --name Centos-7.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/Centos7.5-x86_64.cfg
    # 编辑profile,修改ks文件为我们刚刚上传的Centos7.2-x86_64.cfg
    [root@cobbler kickstarts]# cobbler profile edit --name Centos-7.5-x86_64 --kopts='net.ifnames=0 biosdevname=0'
    # 修改安装系统的内核参数,在CentOS7系统有一个地方变了,就是网卡名变成eno16777736这种形式,但是为了运维标准化,我们需要将它变成我们常用的eth0,因此使用上面的参数。但要注意是CentOS7才需要上面的步骤,CentOS6不需要。
    [root@cobbler kickstarts]# cobbler profile report
    Name                           : Centos-7.5-x86_64
    TFTP Boot Files                : {}
    Comment                        : 
    DHCP Tag                       : default
    Distribution                   : Centos-7.5-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/Centos7.5-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
    
    

    同步cobbler

    [root@cobbler kickstarts]# cobbler sync
    task started: 2018-09-27_162820_sync
    task started (id=Sync, time=Thu Sep 27 16:28:20 2018)
    running pre-sync triggers
    cleaning trees
    removing: /var/www/cobbler/images/Centos-7.5-x86_64
    removing: /var/lib/tftpboot/pxelinux.cfg/default
    removing: /var/lib/tftpboot/grub/images
    removing: /var/lib/tftpboot/grub/grub-x86.efi
    removing: /var/lib/tftpboot/grub/grub-x86_64.efi
    removing: /var/lib/tftpboot/grub/efidefault
    removing: /var/lib/tftpboot/images/Centos-7.5-x86_64
    removing: /var/lib/tftpboot/s390x/profile_list
    copying bootloaders
    trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
    trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
    copying distros to tftpboot
    copying files for distro: Centos-7.5-x86_64
    trying hardlink /var/www/cobbler/ks_mirror/Centos-7.5-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/Centos-7.5-x86_64/vmlinuz
    trying hardlink /var/www/cobbler/ks_mirror/Centos-7.5-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/Centos-7.5-x86_64/initrd.img
    copying images
    generating PXE configuration files
    generating PXE menu structure
    copying files for distro: Centos-7.5-x86_64
    trying hardlink /var/www/cobbler/ks_mirror/Centos-7.5-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/Centos-7.5-x86_64/vmlinuz
    trying hardlink /var/www/cobbler/ks_mirror/Centos-7.5-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/Centos-7.5-x86_64/initrd.img
    Writing template files for Centos-7.5-x86_64
    rendering DHCP files
    generating /etc/dhcp/dhcpd.conf
    rendering TFTPD files
    generating /etc/xinetd.d/tftp
    processing boot_files for distro: Centos-7.5-x86_64
    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: dhcpd -t -q
    received on stdout: 
    received on stderr: 
    running: service dhcpd restart
    received on stdout: 
    received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
    
    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 ***
    

    新建一个虚拟机测试

    为避免发生未知问题,先把服务端所有服务重启

    [root@cobbler ~]# systemctl restart xinetd.service
    [root@cobbler ~]# systemctl restart cobblerd.service
    [root@cobbler ~]# systemctl restart httpd.service
    
    [root@cobbler cobbler]# vim /etc/cobbler/pxe/pxedefault.template
    MENU TITLE Cobbler | I'm here # 修改这里为你想修改的内容
    [root@cobbler cobbler]# cobbler sync # 同步之后就可以看到效果了
    

    通过MAC地址定制化安装

    我们可以根据不同的MAC地址来给安装不同的操作系统,配置不同的静态iP,设置不同的主机名等等,虚拟机查看MAC地址步骤

    配置定制化安装(需要验证,后续验证后添加验证结果)

    [root@cobbler ~]# cobbler system add    
    --name=linux-web01 
    --mac=00:0C:29:3B:03:9B 
    --profile=Centos-7.2-x86_64 
    --ip-address=10.0.0.200 
    --subnet=255.255.255.0 
    --gateway=10.0.0.2 
    --interface=eth0 
    --static=1 
    --hostname=linux-web01 
    --name-servers="10.0.0.2" 
    --kickstart=/var/lib/cobbler/kickstarts/Centos7.2-x86_64.cfg
    
    参数 解释
    system add 添加定制系统
    name 定制系统名称
    mac mac地址
    profile 指定profile
    ip-address 指定IP地址
    subnet 指定子网掩码
    gateway 指定网关
    interface 指定网卡,eth0上面配置已经修改,centos7默认网卡名称不是eth0
    static 1表示启用静态IP
    hostname 定义hostname
    name-server dns服务器
    kickstart 指定ks文件

    配置成功后我们可以查看到刚才定制的系统

    [root@cobbler ~]# cobbler system list
    linux-web01
    

    接下来我们创建一个虚拟机,mac地址为00:0C:29:3B:03:9B,启动后你就会发现自动进入安装系统了,等安装完以后,所有的配置都和我们当初设置的一样。

    使用koan实现重新安装系统

    在客户端安装koan(要配置好源)

    [root@cobbler ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm
    [root@cobbler ~]# yum install koan
    

    查看cobbler上的配置文件

    [root@cobbler ~]# koan --server=10.0.0.101 --list=profiles   
    -looking for Cobbler at http://10.0.0.101:80/cobbler_api Centos-7.2-x86_64
    

    重新安装客户端系统

    [root@cobbler ~]# koan --replace-self --server=10.0.0.101 --profile=webserver1
    

    重启系统后会自动重装系统

  • 相关阅读:
    SNOI2017炸弹
    tarjan进阶
    BZOJ3331压力
    将多个对象合并为一个对象
    原型模式详解
    HTML5
    isAnimated函数
    让函数执行的各种方式
    zepto源码注解
    mobileTech
  • 原文地址:https://www.cnblogs.com/winstom/p/9716946.html
Copyright © 2011-2022 走看看