init_install_v4.sh
1 #!/usr/bin/env bash 2 3 set -o errexit 4 ipaddr="10.1.8.42" 5 gateway="10.1.8.1" 6 netmask="255.255.248.0" 7 interface_name="eth0" 8 servername="$1" 9 #servername="$1" 10 11 #配置eth0 12 mv /etc/sysconfig/network-scripts/ifcfg-ens32 /etc/sysconfig/network-scripts/ifcfg-ens32.bak || true 13 cat > /etc/sysconfig/network-scripts/ifcfg-${interface_name} << EOF 14 TYPE="Ethernet" 15 PROXY_METHOD="none" 16 BOOTPROTO="static" 17 NAME="${interface_name}" 18 DEVICE="${interface_name}" 19 ONBOOT="yes" 20 IPADDR="${ipaddr}" 21 GATEWAY="${gateway}" 22 NETMASK="${netmask}" 23 EOF 24 25 26 27 28 # 服务器编号 29 #read -p "请输入服务器编号 ->" servername 30 if [[ ${servername} =~ ^[a-z]+-[a-z]+-[0-9]+$ ]];then 31 echo "服务器编号:${servername}" 32 echo ${servername} > /etc/hostname 33 else 34 echo "服务器编号错误,正确格式:kaiqi-server-数字编号" 35 exit 4 36 fi 37 38 # grub 39 set flag=0 40 grep -e "net.ifnames=0" /etc/default/grub > /dev/null 2>&1 || flag=1 41 if [ ${flag} -ne 0 ];then 42 s=`grep GRUB_CMDLINE_LINUX /etc/default/grub` 43 s2="${s%\"*} net.ifnames=0 biosdevname=0\"" 44 sed -i "s#GRUB_CMDLINE_LINUX=.*#${s2}#g" /etc/default/grub 45 grub2-mkconfig -o /boot/grub2/grub.cfg 46 unset s 47 unset s2 48 flag=0 49 fi 50 51 #disable networkmanager 52 systemctl stop NetworkManager || true 53 systemctl disable NetworkManager || true 54 55 # dns,通过编号前2位判断是否为IDC,判断比较肤浅 56 hostname_num=`echo ${servername} | awk -F "-" '{print $NF}'` 57 echo ${hostname_num} 58 if [[ ${hostname_num:0:2} == "10" ]];then 59 cat > /etc/resolv.conf << EOF 60 nameserver 10.1.8.27 61 nameserver 119.29.29.29 62 nameserver 223.5.5.5 63 EOF 64 fi 65 66 # saltstack 67 sudo rpm --import https://repo.saltstack.com/yum/redhat/7/x86_64/archive/2018.3.4/SALTSTACK-GPG-KEY.pub 68 cat > /etc/yum.repos.d/saltstack.repo << EOF 69 [saltstack-repo] 70 name=SaltStack repo for RHEL/CentOS \$releasever 71 baseurl=https://repo.saltstack.com/yum/redhat/\$releasever/\$basearch/archive/2018.3.4 72 enabled=1 73 gpgcheck=1 74 gpgkey=https://repo.saltstack.com/yum/redhat/\$releasever/\$basearch/archive/2018.3.4/SALTSTACK-GPG-KEY.pub 75 EOF 76 sudo yum clean expire-cache 77 sudo yum -y install salt-minion 78 sudo systemctl enable salt-minion 79 sed -i "s/^#id:/id: ${servername}/g" /etc/salt/minion 80 sed -i "s/^#master:.*/master: syndic-10001.salt.qipai007cs.com/g" /etc/salt/minion 81 sudo systemctl start salt-minion 82 83 84 # end 85 echo "初始化安装完成,请重启系统." 86 echo -e "10s after reboot..." 87 sleep 10 88 reboot
狂暴小子