• Cobbler自动化装机脚本


    #!/bin/bash
    ens33_ip=192.168.1.3
    ens33_gateway=192.168.1.1
    ens37_ip=192.168.207.2
    dhcp_wd=192.168.207.0
    dhcp_range1=192.168.207.10
    dhcp_range2=192.168.207.15
    GZLJ=/root/ni
    /usr/bin/echo -e "TYPE=Ethernet
    BOOTPROTO=static
    DEVICE=ens33
    ONBOOT=yes
    IPADDR="$ens33_ip"
    GATEWAY="$ens33_gateway"
    NETMASK=255.255.255.0
    DNS2=8.8.8.8
    DNS2=114.114.114.114" > /etc/sysconfig/network-scripts/ifcfg-ens33
    /usr/bin/cp -a /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens37
    /usr/bin/echo -e "TYPE=Ethernet
    BOOTPROTO=static
    DEVICE=ens37
    ONBOOT=yes
    IPADDR="$ens37_ip"
    NETMASK=255.255.255.0" > /etc/sysconfig/network-scripts/ifcfg-ens37
    /usr/bin/systemctl restart network
    if [ $? -eq 0 ] ;then
        echo "重启网络成功"
    else
        echo "重启失败"
    fi
    #/usr/bin/sed -i '3a nameserver 114.114.114.114' /etc/resolv.conf && /usr/bin/ping -c 1 -w 1 baidu.com &> /dev/null
    if [ $? -eq 0 ];then
        echo "可以使用网络了"
    else
        echo "网络还不能使用"
    fi
    /usr/bin/echo -e "[epel]
    name=epel
    enable=1
    gpgcheck=0
    baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
    [centos]
    name=centos base
    enabled=1
    gpgcheck=0
    baseurl=http://mirrors.163.com/centos/7/os/x86_64/" >> /etc/yum.repos.d/nmb.repo 
    /usr/bin/yum clean all &> /dev/null 
    /usr/bin/yum makecache &> /dev/null 
    /usr/bin/yum install cobbler dhcp tftp-server xinetd syslinux httpd pykickstart -y &> /dev/null
    installed1=`yum list installed | grep "httpd" | awk -F " +" 'NR==1 {print $1}'`
    installed2=`yum list installed | grep "dhcp" | awk -F " +" 'NR==1 {print $1}'`
    installed3=`yum list installed | grep "cobbler" | awk -F " +" 'NR==1 {print $1}'`
    installed4=`yum list installed | grep "xinetd" | awk -F " +" 'NR==1 {print $1}'`
    installed5=`yum list installed | grep "syslinux" | awk -F " +" 'NR==1 {print $1}'`
    installed6=`yum list installed | grep "tftp-server" | awk -F " +" 'NR==1 {print $1}'`
    installed7=`yum list installed | grep "pykickstart" | awk -F " +" 'NR==1 {print $1}'`
    if [ "$installed3" == "cobbler.x86_64" ];then
        echo "cobbler is ok"
    else
        echo "cobbler is lose"
    fi 
    if [ "$installed2" == "dhcp.x86_64"  ];then
        echo "dhcp is ok"
    else
        echo "dhcp is lose"
    fi
    if [ "$installed1" == "httpd.x86_64" ];then
        echo "httpd is ok"
    else
        echo "httpd is lose"
    fi
    if [  "$installed7" == "pykickstart.noarch" ];then
        echo "pykickstart is ok"
    else
        echo "pykickstart is lose"
    fi
    if [  "$installed5" == "syslinux.x86_64" ];then
        echo "syslinux is ok"
    else 
        echo "syslinux is lose"
    fi 
    if [  "$installed6" == "tftp-server.x86_64" ];then
        echo "tftp is ok"
    else 
        echo "tftp is lose"
    fi
    if [  "$installed4" == "xinetd.x86_64" ];then
        echo "xinetd is ok"
    else
        echo "xinetd is lose"
    fi 
    /usr/bin/echo -e "subnet  $dhcp_wd  netmask 255.255.255.0 {
    range $dhcp_range1 $dhcp_range2;
    default-lease-time 600;
    max-lease-time 7200;
    }" > /etc/dhcp/dhcpd.conf
    /usr/bin/systemctl restart dhcpd
    if [ $? -eq 0 ];then
        echo "dhcpd重启成功"
    else 
        echo "dhcpd重启失败"
    fi
    /usr/bin/sed -i '14c            disable                 = no' /etc/xinetd.d/tftp
    /usr/bin/systemctl restart xinetd && /usr/bin/systemctl enable xinetd
    if [ $? -eq 0 ];then
        echo "xinetd重启成功并设置开机自启ok"
    else
        echo "xinetd重启失败设置开机自启失败"
    fi 
    /usr/bin/sed -i "272c next_server: $ens37_ip" /etc/cobbler/settings
    /usr/bin/sed -i "384c server: $ens37_ip" /etc/cobbler/settings
    /usr/bin/systemctl restart rsyncd && /usr/bin/systemctl restart rsyncd.service
    if [ $? -eq 0 ];then
        echo "rsyncdc重启成功"
    else
        echo "rsyncd重启失败"
    fi
    /usr/bin/systemctl enable rsyncd
    if [ $? -eq 0 ];then
        echo "rsyncd已成功设置开机自启"
    else
        echo "rsyncd设置开机自启失败"
    fi
    /usr/bin/sed -i '101c default_password_crypted: "$1$123$7mft0jKnzzvAdU4t0unTG1"' /etc/cobbler/settings
    /usr/bin/systemctl restart cobblerd
    if [ $? -eq 0 ];then
        echo "cobbler重启成功"
    else
        echo "cobbler重启失败"
    fi
    /usr/bin/systemctl restart httpd.service &> /dev/null
    /usr/bin/cobbler sync &> /dev/null
    check=`cobbler check | wc -l`
    if [ $check -eq  7  ];then
        echo "检查没有问题"
    else
        echo "警报!请检查settings文本"
    fi
    /usr/bin/cobbler import --path=$GZLJ --name="centos7.5" &> /dev/null
    jiance1=`cobbler distro list | awk 'NR==1{print $1}'`
    jiance2=`cobbler profile list | awk 'NR==1{print $1}'`
    if [ "$jiance1" == "centos7.5-x86_64" ];then
        echo "创建centos7.5发行版本成功"
    else
        echo "创建centos7.5发行版本失败"
    fi
    if [ "$jiance2" == "centos7.5-x86_64" ];then
        echo "创建centos7.5ok"
    else
        echo "创建centos7.5lose"
    fi
    /usr/bin/cp -a /root/anaconda-ks.cfg /var/lib/cobbler/kickstarts/ks.cfg
    /usr/bin/sed -i '4a filename "pxelinux.0";' /etc/dhcp/dhcpd.conf
    /usr/bin/sed -i "5c url --url=http://$ens37_ip/cobbler/ks_mirror/centos7.5/" /var/lib/cobbler/kickstarts/ks.cfg 
    /usr/bin/cobbler profile add  --distro=centos7.5-x86_64 --name=centos7.5_ken --kickstart=/var/lib/cobbler/kickstarts/ks.cfg    
    fengzhuang=`cobbler profile list | wc -l`
    if [ "$fengzhuang" -eq 2 ];then
        echo "封装成功"
    else
        echo "封装失败"
    fi
    /usr/bin/cobbler profile remove --name=centos7.5-x86_64 &> /dev/null
    /usr/bin/cobbler sync &> /dev/null
    /usr/bin/systemctl restart dhcpd
    /usr/sbin/service httpd restart &> /dev/null 
    /usr/sbin/service cobblerd restart &> /dev/null
    /usr/sbin/service dhcpd restart &> /dev/null
    /usr/sbin/service xinetd restart &> /dev/null
  • 相关阅读:
    C++---使用类
    C++---函数
    C++---指针和引用
    C++---面向对象
    C++---数组
    C++---条件结构和循环结构
    C++---变量、数据类型和运算符
    C++---初识C++
    MySQL---什么是事务
    MySQL---char和varchar的区别
  • 原文地址:https://www.cnblogs.com/shuaiyin/p/11120236.html
Copyright © 2020-2023  润新知