码迷,mamicode.com
首页 > 其他好文 > 详细

init_install_v3.sh

时间:2019-07-17 00:10:17      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:bio   ice   span   interface   gre   idc   repo   数字   usr   

  1 #!/usr/bin/env bash
  2 set -o errexit
  3 
  4 #注意事项:
  5 #   1、需要先保证能联网,使用curl
  6 #   2、添加了一块sdb磁盘,并全部给一个分区
  7 #   3、hostname的规格是:kaiqi-server-10078
  8 #   4、运行脚本时,加上$1,$2
  9 
 10 servername="$1"
 11 ipaddr="$2"
 12 netmask="255.255.248.0"
 13 interface_old_name=`ip addr|grep BROADCAST|grep MULTICAST|awk {print $2}|sed s/://g`
 14 interface_new_name="eth0"
 15 #ipaddr=`ip addr|grep "${interface_old_name}"|grep inet|grep brd|grep global|awk {print $2}|grep -Eo ([0-9]{1,3}\.){3}[0-9]{1,3}`
 16 gateway="`echo $2|grep -Eo ‘([0-9]{1,3}\.){3}‘`1"
 17 
 18 # 服务器编号
 19 #read  -p "请输入服务器编号 ->" servername
 20 #servername="$1"
 21 if [[ ${servername} =~ ^[a-z]+-[a-z]+-[0-9]+$ ]];then
 22     echo "服务器编号:${servername}"
 23     echo ${servername} > /etc/hostname
 24 else
 25     echo "服务器编号错误,正确格式:kaiqi-server-数字编号"
 26     exit 4
 27 fi
 28 
 29 # grub
 30 set flag=0
 31 grep -e "net.ifnames=0" /etc/default/grub  > /dev/null 2>&1 || flag=1
 32 if [ ${flag}  -ne 0 ];then
 33     s=`grep GRUB_CMDLINE_LINUX /etc/default/grub`
 34     s2="${s%\"*} net.ifnames=0 biosdevname=0\""
 35     sed -i "s#GRUB_CMDLINE_LINUX=.*#${s2}#g" /etc/default/grub
 36     grub2-mkconfig -o /boot/grub2/grub.cfg
 37     unset s
 38     unset s2
 39     flag=0
 40 fi
 41 
 42 #disable networkmanager
 43 systemctl stop NetworkManager || true
 44 systemctl disable NetworkManager || true
 45 
 46 # dns,通过编号前2位判断是否为IDC,判断比较肤浅
 47 hostname_num=`echo ${servername} | awk -F "-" {print $NF}`
 48 echo ${hostname_num}
 49 if [[ ${hostname_num:0:2} == "10" ]];then
 50     cat > /etc/resolv.conf << EOF
 51 nameserver 10.1.8.27
 52 nameserver 119.29.29.29
 53 nameserver 223.5.5.5
 54 EOF
 55 fi
 56 
 57 # saltstack
 58 sudo rpm --import https://repo.saltstack.com/yum/redhat/7/x86_64/archive/2018.3.4/SALTSTACK-GPG-KEY.pub
 59 cat > /etc/yum.repos.d/saltstack.repo << EOF
 60 [saltstack-repo]
 61 name=SaltStack repo for RHEL/CentOS \$releasever
 62 baseurl=https://repo.saltstack.com/yum/redhat/\$releasever/\$basearch/archive/2018.3.4
 63 enabled=1
 64 gpgcheck=1
 65 gpgkey=https://repo.saltstack.com/yum/redhat/\$releasever/\$basearch/archive/2018.3.4/SALTSTACK-GPG-KEY.pub
 66 EOF
 67 sudo yum clean expire-cache
 68 sudo yum update << EOF
 69 y
 70 EOF
 71 sudo yum -y install salt-minion
 72 sudo systemctl enable salt-minion
 73 sed -i "s/^#id:/id: ${servername}/g" /etc/salt/minion
 74 sed -i "s/^#master:.*/master: syndic-10001.salt.qipai007cs.com/g" /etc/salt/minion
 75 sudo systemctl start salt-minion
 76 
 77 
 78 #添加eth0网卡,并配置内容
 79 mv /etc/sysconfig/network-scripts/ifcfg-${interface_old_name} /etc/sysconfig/network-scripts/ifcfg-${interface_old_name}.bak || true
 80 cat > /etc/sysconfig/network-scripts/ifcfg-${interface_new_name} << EOF
 81 TYPE="Ethernet"
 82 PROXY_METHOD="none"
 83 BOOTPROTO="static"
 84 NAME="${interface_new_name}"
 85 DEVICE="${interface_new_name}"
 86 ONBOOT="yes"
 87 IPADDR="${ipaddr}"
 88 GATEWAY="${gateway}"
 89 NETMASK="${netmask}"
 90 EOF
 91 if fdisk -l|grep /dev/sdb > /dev/null 2>&1 ;then
 92 fdisk /dev/sdb  << EOF
 93 n
 94 p
 95 
 96 
 97 
 98 EOF
 99 if [[ $? -eq 0 ]];then
100     mkfs.xfs  /dev/sdb1 && echo "/dev/sdb1 /data                       xfs    defaults        0 0" >> /etc/fstab  && mkdir /data && mount -a
101 else
102     echo "mount fail"
103 
104 fi
105 # end
106 echo "初始化安装完成,请重启系统."

 

init_install_v3.sh

标签:bio   ice   span   interface   gre   idc   repo   数字   usr   

原文地址:https://www.cnblogs.com/zhj5551/p/11198335.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!