shellscript linux系统初始化
来源:互联网 发布:网络红歌2016流行歌曲 编辑:程序博客网 时间:2024/05/18 00:31
系统初始化脚本 shell 基本的变量截取 主机名 salt配置 网卡配置等 部分信息已隐藏去
#!/bin/bash# ===============================# Desc: System init Script# Author: Wuxp,Bailm# Version: 2017.07.26# ===============================HW=`ip a | grep ether | head -n1 | awk '{print $2}'` &>/dev/nullIP=`ip a | grep 'brd' | grep -v : | egrep -o "([0-9]{1,3}\.){3}[0-9]{1,3}/" | egrep -E "^(192\.168|10\.|172\.1[6789]\.|172\.2[0-9]\.|172.3[01]\.)" | sed "s~/~~"`PIP=`ip a | grep 'brd' | grep -v : | egrep -o "([0-9]{1,3}\.){3}[0-9]{1,3}/" | egrep -v "^0|^10|^172\.1[6789]\.|^172\.2[0-9]\.|^172.3[01]\.|^192\.168|^127|^169\.254|^255|255$" | sed "s~/~~"` &>/dev/nullGATEW=`ip route show | grep $IP | awk -F' ' '{print $NF}' | awk -F'.' '{print $1"."$2"."$3".250"}'` &>/dev/nullGATEW_ZQ=`ip route show | grep $IP | awk -F' ' '{print $NF}' | awk -F'.' '{print $1"."$2"."$3".1"}'` &>/dev/nullOSV=`cat /etc/redhat-release | egrep -o [0-9] | head -n 1` &>/dev/nullNET_segment=`echo $IP | awk -F'.' '{print $1}'`#################### selinux and iptables ###################sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux#################### eth0 ####################mod_eth0 (){if [ ${NET_segment} == 10 ]thencat << EOF1 > /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0ONBOOT=yesBOOTPROTO=staticTYPE=Ethernet#HWADDR=$HWIPADDR=$IPNETMASK=255.255.255.0GATEWAY=$GATEWEOF1echo '---eth0 OK---'elsecat << EOF1 > /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0ONBOOT=yesBOOTPROTO=staticTYPE=Ethernet#HWADDR=$HWIPADDR=$IPNETMASK=255.255.255.0GATEWAY=$GATEW_ZQEOF1echo '---eth0 OK---'fi}##################### Hostname ###################mod_hostname (){echo -ne "======================================================== ZW: ZxxxxxxxxxxxxxxxxxxxxxxxxxIPIP DXT: DxxxxxxxxxxxxxxxxxxxxxxxxxxxxP {0xxxxxxxxxxxxx} SandBox: ZxxxxxxxxxxxxxxxxxxxIP QY: ZxxxxxxxxxxxxxxxxxxxxP {Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}========================================================"read -p 'please input hostname: ' namesed -e '/^HOSTNAME/c HOSTNAME='$name'' -e '/^$/d' -i /etc/sysconfig/networkhostname $nameecho "127.0.0.1 $name " >>/etc/hostsecho "---hostname OK---"}############################## intranet #############################intranet (){mod_eth0mod_hostname#################### ROUTE ################cat << EOF > /sbin/ifup-local#!/bin/bashif [ "\$1" = "eth0" ];thenip route add 172.16.0.0/12 via $GATEip route add 192.168.0.0/16 via $GATEip route add 10.0.0.0/8 via $GATEfiEOFchmod 755 /sbin/ifup-localecho "---route OK---"}########################### internet ###########################internet (){mod_eth0mod_hostnamestart_udev &>/dev/nullipmac=`ifconfig eth0 | grep H | awk '{print toupper($5)}'`udevmac=`cat /etc/udev/rules.d/70-persistent-net.rules | grep eth0 | awk -F\" '{print toupper($8)}'`if [ "$ipmac" = "$udevmac" ];then################## eth1 ##################IP1=`ifconfig eth1 | grep inet | awk '{print $2}' | cut -d: -f2`cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth1DEVICE=eth1ONBOOT=yesBOOTPROTO=staticTYPE=EthernetIPADDR=${IP1}NETMASK=255.255.255.0EOFecho "---eth1 OK---"#################### ROUTE ################GATE1=`ifconfig eth1 | grep inet | awk '{print $2}' | cut -d: -f2 | awk -F. '{print $1"."$2"."$3".1"}'`cat << EOF > /sbin/ifup-local#!/bin/bashif [ "\$1" = "eth1" ];thenip route add 172.16.0.0/12 via $GATE1ip route add 192.168.0.0/16 via $GATE1ip route add 10.0.0.0/8 via $GATE1fiEOFchmod 755 /sbin/ifup-localecho "---route OK---"fi}################### System Release #########################system_release () {for i in `seq 4 7`docat /etc/redhat-release | egrep -w "$i\..+" 1>/dev/null if [ $? == 0 ];then return $i fidone}###################### Yum Install Salt-Minion ##############################salt_install () {system_releasecase $? in6) #6.X cd /etc/yum.repos.d/; #rm -fr *; # # yum install salt-minion zeromq -y chkconfig salt-minion on ;;7) #7.X yum install wget -y cd /etc/yum.repos.d/; # rm -fr *; # # yum install salt-minion zeromq -y chkconfig salt-minion on ;;esac}salt_config () {rm -fr /etc/salt/pki/minion/minion_master.pubNet12=$(echo $IP | awk -F. '{print $1$2}')if [ ${Net12} -eq 10100 ] then# # sed -e '/^master/d' -e '/^id:/d' -e '/^#id:/a id: '$IP'' -i /etc/salt/minion;service salt-minion restart;chkconfig salt-minion on sed -e '/^master/d' -e '/^#master:/a master: 192.168.30.56' -e '/^id:/d' -e '/^#id:/a id: '$IP'' -i /etc/salt/minion systemctl restart salt-minion 2>/dev/null || service salt-minion restart systemctl enable salt-minion 2>/dev/null || chkconfig salt-minion onelif [ ${Net12} -eq 1xxxxxxxxxxxxx ] then sed -e '/^master/d' -e '/^#master:/a master:2.168.30.56' -e '/^id:/d' -e '/^#id:/a id: '$IP'' -i /etc/salt/minion
systemctl restart salt-minion 2>/dev/null || service salt-minion restart systemctl enable salt-minion 2>/dev/null || chkconfig salt-minion onelse sed -e '/^master/d' -e '/^#master:/a master: 1xxxxxxxxxxx47' -e '/^id:/d' -e '/^#id:/a id: '$IP'' -i /etc/salt/minion systemctl restart salt-minion 2>/dev/null || service salt-minion restart systemctl enable salt-minion 2>/dev/null || chkconfig salt-minion onfi}###########################################################################################################################################echo -ne "======================================================== Input: 1:Local | 2:Public | 3:Salt | 4:Hostname======================================================== Please: " read modecase $mode in1) intranet /etc/init.d/network restart ;;2) internet /etc/init.d/network restart ;;3) salt_install salt_config ;;4) mod_hostname ;;*) echo "please input 1 | 2 | 3:Salt | 4:Hostname" ;;esac
阅读全文
0 0
- shellscript linux系统初始化
- Linux ShellScript 执行 Sybase SQL
- Linux系统安装初始化
- 认识linux 系统初始化
- 理解linux系统初始化
- linux 系统初始化工作
- linux系统初始化脚本
- LINUX 系统初始化脚本
- linux系统时间初始化
- Linux初始化init系统
- Linux 初始化 init 系统
- Linux系统初始化流程
- 利用Linux Shellscript 安装网卡驱动
- linux下shellscript实现二分查找
- Linux学习第二十六篇--ShellScript基础
- Linux 内存管理系统:初始化
- Linux 内存管理系统:初始化
- linux 系统初始化过程详解
- redis持久化
- javascript数组排序Sort()
- 邮箱-验证码-手机号码输入框测试用例参考
- P1031 均分纸牌
- ***********快排改进
- shellscript linux系统初始化
- 八皇后问题(一)
- python 简单的数据库操作之转账
- 广搜模板
- 127. Word Ladder
- JAVA基本数据类型学习总结
- 2017 Multi-University Training Contest
- 使用DevC++编程时出现无法读取自定文件的错误
- OSG 学习第三天:渲染状态