前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >shell-read交互配置hostname、bond、salt、ip

shell-read交互配置hostname、bond、salt、ip

作者头像
用户9949933
发布2023-02-24 17:13:31
4830
发布2023-02-24 17:13:31
举报

​ 公司生产环境每次安装新服务器之后都会安装salt,配置hostname、bond等。刚好自己最近在学习shell。然后就有了下面的脚本。(如果有需要还可以扩展安装zabbix-agent、Megacli等。)

代码语言:javascript
复制
#!/bin/bash
#=========set hostname====================
stty erase ^H		#避免read交互是按退格键出现 ^H
read -p "Please enter hostname:" hostname
hostnamectl set-hostname $hostname

#=========config bond=====================
stty erase ^H
read -p "Please enter your IP:" ip
GW=`echo $ip |awk -F "." '{print $1"."$2"."$3"."1}'`

/usr/bin/ping -c 3 $ip > /dev/null 2>&1
if [ $? -eq 0 ];then
        echo "$ip existing"
        exit 1
else
        echo "ip ok!"
fi

cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
MASTER=bond0
SLAVE=yes
EOF

cat > /etc/sysconfig/network-scripts/ifcfg-bond0 << EOF
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=static
IPADDR=$ip
NETMASK=255.255.255.0
GATEWAY=$GW
DNS1=114.114.114.114
EOF

cat > /etc/sysconfig/network-scripts/ifcfg-eth1 << EOF
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=static
MASTER=bond1
SLAVE=yes
EOF

cat > /etc/sysconfig/network-scripts/ifcfg-bond1 << EOF
DEVICE=bond1
ONBOOT=yes
BOOTPROTO=static
EOF

cat > /etc/modprobe.d/bonding.conf << EOF
alias bond0 bonding
options bond0 miimon=100 mode=0
alias bond1 bonding
options bond1 miimon=100 mode=0
EOF

systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl restart network
sleep 3

#===================install salt=====================
yum install -y salt-minion
sleep 1
sed -i 's/#master: salt/master: ip/g' /etc/salt/minion	#这里的ip替换成你的masterip地址
sed -i "s/#id:/id: $hostname/g" /etc/salt/minion
sleep 1

systemctl enable salt-minion
systemctl start salt-minion
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-12-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档