zoukankan      html  css  js  c++  java
  • 2.Cobbler自动化安装Centos7

    <!doctype html>

    一、CentOS配置过程

    1.1 挂载镜像

     
     
     
     
     
     
     
     
    # 上传CentOS的镜像到Cobbler server端
    $ mkdir /mnt/centos7
    $ mount CentOS-7-x86_64-DVD-1804.iso /mnt/centos7/
     

    1.2 导入镜像

     
     
     
     
     
     
     
     
    $ cobbler import --path=/mnt/centos7 --arch=x86_64 --name=centos7
     

    21

    导入完镜像之后会生成一个distros默认的profile(将distros和ks绑定在一起就相当于是一个profiles),profiles展示在安装选择栏

    可以通过cobbler profile report查看当前profile的信息。

    profile report

    在上述中我们可以看到与之绑定的ks文件,我们可以去修改这个ks文件的内容,也可以自己编辑一个新的ks文件,通过去

     
     
     
     
     
     
     
     
    $ cobbler profile edit --name="centos7-x86_64" 
        --kickstart="/var/lib/cobbler/kickstarts/centos7.ks"
     

    修改绑定的ks文件

    也可以创建一个新的profile绑定一个新的ks文件,通过定制不同的ks文件,从而实现不同的profile定制不同的机器。

     
     
     
     
     
     
     
     
    $ cobbler profile add --name="centos7-web" 
        --kickstart="/var/lib/cobbler/kickstarts/centos7-web.ks" 
         --kopts="net.ifnames=0 biosdevname=0" 
        --distro="centos7-x86_64"
     

    两个不同的profile显示在装机界面效果如下:

    jiemian

    至此就可以根据自定义的选择栏去选择,但是要实现完全的自动化,应该也不需要我们手动选择。我们可以根据MAC地址去实现。

    1.3 完全自动化

    1.3.1 单台
     
     
     
     
     
     
     
     
    # 前面DHCP获取了动态IP,但是我们想要设置他固定IP,并且是在固定的其他网段,则可以在system加上ip-address之后的一些列参数
    $ cobbler system add 
     --name="web" 
     --profile="centos7-web" 
     --interface="eth0" 
     --mac="00:0C:29:C7:96:77" 
     --hostname="web" 
     --ip-address="10.0.0.10" 
     --subnet="255.0.0.0" 
     --gateway="10.0.0.1" 
     --name-servers="114.114.114.114 8.8.8.8" 
     --static="1" 
     --netboot-enabled="Y"
    # 查看system是否生成
    $ cobbler system list
     

    至此,我们打开机器,识别到mac地址,则会完全自动的安装机器。

    特别说明:指定固定IP时,必须指定的IP要可以访问到cobber的IP ,否则获取不到安装源,就会报错

    1.3.2 多台

    如果有多台机器则先获取他们的mac地址就可以实现机器的安装,脚本化实现

    配置文件:

     
     
     
     
     
     
     
     
    00:50:56:24:C8:14  centos7  eth0  web-1  web-1  192.168.0.111  255.255.255.0  192.168.0.1  114.114.114.114 1 Y
    00:50:56:2F:FC:9B  centos7  eth0  web-2  web-2  192.168.0.112  255.255.255.0  192.168.0.1  8.8.8.8 1 Y
     

    脚本

     
     
     
     
     
     
     
     
    #!/bin/bash
    while read line
    do
        # 获取变量值
        mac=`echo $line | awk '{print $1}'`
        profile=`echo $line | awk '{print $2}'`
        interface=`echo $line | awk '{print $3}'`
        name=`echo $line | awk '{print $4}'`
        hostname=`echo $line | awk '{print $5}'`
        ip=`echo $line | awk '{print $6}'`
        subnet=`echo $line | awk '{print $7}'`
        gateway=`echo $line | awk '{print $8}'`
        dns=`echo $line | awk '{print $9}'`
        static=`echo $line | awk '{print $10}'`
        onboot=`echo $line | awk '{print $11}'`
        # 赋值执行
        cobbler system add 
        --name="${name}" 
        --profile="${profile}" 
        --interface="${interface}" 
        --mac="${mac}" 
        --hostname="${hostname}" 
        --ip-address="${ip}" 
        --subnet="${subnet}" 
        --name-servers="${dns}" 
        --static="${static}" 
        --netboot-enabled="${onboot}"
    done < ./menu_host.txt 
     

    1.4 配置ISO镜像自动值守安装文件

    从上述report中可以看到,导入系统相关配置文件路径为/var/lib/cobbler/kickstarts/sample_end.ks,可以指定其他文件,也可以直接修改该文件

    参考实例 ks 文件

     
     
     
     
     
     
     
     
    # This kickstart file should only be used with EL > 5 and/or Fedora > 7.
    # For older versions please use the sample.ks kickstart file.
    #platform=x86, AMD64, or Intel EM64T
    # System authorization information
    auth  --useshadow  --enablemd5
    # System bootloader configuration
    bootloader --location=mbr
    # Partition clearing information
    clearpart --all --initlabel
    # Use text mode install
    text
    # Firewall configuration
    firewall --disabled
    # Run the Setup Agent on first boot
    firstboot --disable
    # System keyboard
    keyboard us
    # System language
    lang en_US
    # Use network installation
    url --url=$tree
    # If any cobbler repo definitions were referenced in the kickstart profile, include them here.
    $yum_repo_stanza
    # Network information
    $SNIPPET('network_config')
    # Reboot after installation
    reboot
    #Root password
    # perl -e 'print crypt("redhat",q($1$password)),"
    "' 设置加密的密码,也可以直接使用明文
    rootpw --iscrypted $default_password_crypted
    # SELinux configuration
    selinux --disabled
    # Do not configure the X Window System
    skipx
    # System timezone
    timezone  Asia/Shanghai
    # Install OS instead of upgrade
    install
    # Clear the Master Boot Record
    zerombr
    # Allow anaconda to partition the system as needed
    autopart
    %pre
    $SNIPPET('log_ks_pre')
    $SNIPPET('kickstart_start')
    $SNIPPET('pre_install_network_config')
    # Enable installation monitoring
    $SNIPPET('pre_anamon')
    %end
    %packages
    $SNIPPET('func_install_if_enabled')
    %end
    %post --nochroot
    $SNIPPET('log_ks_post_nochroot')
    %end
    %post
    $SNIPPET('log_ks_post')
    # Start yum configuration
    $yum_config_stanza
    # End yum configuration
    $SNIPPET('post_install_kernel_options')
    $SNIPPET('post_install_network_config')
    $SNIPPET('func_register_if_enabled')
    $SNIPPET('download_config_files')
    $SNIPPET('koan_environment')
    $SNIPPET('redhat_register')
    $SNIPPET('cobbler_register')
    # Enable post-install boot notification
    $SNIPPET('post_anamon')
    # Start final steps
    $SNIPPET('kickstart_done')
    # End final steps
    %end
     

    配置文件中使用$tree是在导入镜像时会自动生成,我们可以通过cobbler distro report看到tree的值

    Kickstart语法
    auth 或者 authconfig(自选)
    • --enablenis - 打开NIS支持,默认情况下--enablenis使用它在网络中找到的任意域。必须手动使用--nisdomain= 选项设置域
    • --nisdmain= -NIS服务使用的NIS域名
    • --nisserver= -NIS服务使用的服务器(默认报文)
    • --useshadow 或者 --enableshadow -使用影子密码
    • --enableldap - 打开 /etc/nsswitch.conf中的LDAP支持,允许系统在LDAP目录中检索用户信息(如UID、主目录和shell)。要使用此选项就必须安装nss-pam-ldapd软件包。还必须使用--ldapserver= 和 --ldapbasedn= 指定服务器和基础DN。
    • --ldapserver= - 如果指定 --enableldap 或者 --enableldapauth,则可以使用这个选项来指定所使用的LDAP服务器名称,在/etc/ldap.conf文件中设置这个选项
    • --ldapbasedn= - 如果指定--enableldap 或者 --enableldapauth,则可以使用这个选项指定存放用户信息的LDAP目录树中的DN。在/etc/ldap.conf文件中设置这个选项
    • --enableldaptls - 使用TLS(传输加密)查寻。该选项允许LDAP在验证前向LDAP服务器传送加密的用户名和密码
    • --disableldaptls - 不使用TLS(传输加密)在使用LDAP验证的环境中查找。
    autopart(自选)

    自动生成分区: root(/)分区(1GB或者更大),该架构的swap分区和正确的/boot 分区。在有足够空间的驱动器(50GB和更大的驱动器)中还会生成/home分区

    autopart 选项不能与 part /partitionraidlogvol 或者volgroup在同样的Kickstart文件中一同使用。

    • --type= - 选择您要使用的预定义的自动分区方案之一。

      • lvm: LVM分区方案
      • btrfs:Btrfs分区方案
      • plain:不附带 LVM 或者 Btrfs的常规分区
      • thinp:LVM精简分区方案
    • --fstype= - 选择可用文件系统类型之一。可用值为ext2ext3ext4xfs,默认是xfs。

    • --nolvm - 不使用LVM或者Btrfs进行自动分区。

    • --encrypted - 加密所有分区。等同于在手动图形安装过程中的起始分区页面选中加密分区复选框

    • --passphrase= - 为所有加密设备提供默认的系统范围内的密码短语

    • --escrowcert= URL_of_X.509_certificate - 将所有加密卷数据加密密码保存在/root中,使用来自 URL_of_X.509_certificate 指定的URL的X.509证书加密。每个加密卷的密码作为单独的文件保存。只有指定--encrypted时这个选项才有意义。

    • --backuppassphrase - 为每个加密卷添加随机生成的密码短语。将这些密码保存在/root 目录下的独立文件,使用 --escrowcert指定的X.509证书加密。只有指定 --escrowcert 时,这个选项才有意义。

    • --cipher= - 如果指定Anaconda 默认 aes-xts-plain64 无法满足需求,则可以指定要使用的加密类型。这个选项必须与 --encrypted 选项一同使用,单独使用无效

    autostep(自选)

    Kickstart安装会跳过不必要的页面。这个选项可让安装程序浏览所有页面,并摘要显示每个页面。部署系统时不应使用这个选项,因为它会干扰软件包安装。

    • --autoscreenshot - 在安装的每一步均截屏。这些截屏将在安装过程中保存在 /tmp/anaconda-screenshots 中,并在安装完成后保存在 /root/anaconda-screenshots 中。
  • 相关阅读:
    使用mail架包发送邮件javax.mail.AuthenticationFailedException: failed to connect at javax.mail.Service.connec
    java容器 Map Set List
    COJ 1686:记忆化搜索
    POJ 3694:桥
    COJ 1685:贪心+set
    COJ 1687:Set
    COJ 1684:线段树
    POJ 3693:RMQ+后缀数组
    URAL 1297:后缀数组求最长回文串
    POJ 1743:后缀数组
  • 原文地址:https://www.cnblogs.com/xll970105/p/12409167.html
Copyright © 2011-2022 走看看