生产环境虚拟机克隆后的统一部署脚本

简单说明:

生产环境依据《CentOS6实验机模板搭建部署》部署模板机,
模板机主机名:temp_web_3
模板机IP和网关:10.85.13.200/10.85.13.254
依据《CentOS6u9 Zabbix2.2安装配置监控告警(三)Zabbix Agent安装配置》部署agent
关闭zabbix agent 自动启动

统一部署脚本为:

cat >/tmp/change.sh<<EOFALL
#!/bin/bash
#main
if [ "\$#" -ne 6 ]
then
    echo \$"Usage: bash \$(basename \$0) -h hostname -n ipaddr -g gateway_ipaddr"
    echo \$"Example: bash \$(basename \$0) -h temp_web_3 -n 10.85.13.200 -g 10.85.13.254"
    echo \$"Example: bash \$(basename \$0) -h 主机名 -n IP地址 -g 网关地址"
    exit 1
fi
while [ "\$#" -gt 0 ]
do
    case "\$1" in
            -h)
                shift
                Hostname="\$1"
                shift
                ;;
            -n)
                shift
                Ipaddr="\$1"
                shift
                ;;
            -g)
                shift
                Gateway_ipaddr="\$1"
                shift
                ;;
    esac
done
##########
cat>/etc/hosts<<EOF
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.65.13.201 salt_master salt
\$Ipaddr \$Hostname
EOF
##########
sed -i "s/temp_web_3/\$Hostname/g" /etc/sysconfig/network
sed -i "s/10.85.13.254/\$Gateway_ipaddr/g" /etc/sysconfig/network
##########
echo 'nameserver 223.5.5.5'>/etc/resolv.conf
echo 'nameserver 114.114.114.114'>>/etc/resolv.conf
##########
sed -i '/DNS1/d' /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i '/DNS2/d' /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'DNS1=223.5.5.5'>>/etc/sysconfig/network-scripts/ifcfg-eth0
echo 'DNS2=114.114.114.114'>>/etc/sysconfig/network-scripts/ifcfg-eth0
sed -i "s/10.85.13.200/\$Ipaddr/g" /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i "s/10.85.13.254/\$Gateway_ipaddr/g" /etc/sysconfig/network-scripts/ifcfg-eth0
##########
M=\$(grep eth1 /etc/udev/rules.d/70-persistent-net.rules)
if [ -n "\$M" ]
then
     sed -i '/eth0"\$/d' /etc/udev/rules.d/70-persistent-net.rules
     sed -i 's/eth1/eth0/g' /etc/udev/rules.d/70-persistent-net.rules
fi
##########
echo -e "\n\n/etc/hosts:\n"
cat /etc/hosts
echo -e "\n\n/etc/sysconfig/network:\n"
cat /etc/sysconfig/network
echo -e "\n\n/etc/resolv.conf:\n"
cat /etc/resolv.conf
echo -e "\n\n/etc/sysconfig/network-scripts/ifcfg-eth0:\n"
cat /etc/sysconfig/network-scripts/ifcfg-eth0
echo -e "\n\n/etc/udev/rules.d/70-persistent-net.rules:\n"
cat /etc/udev/rules.d/70-persistent-net.rules|grep -Ev '^\$|^#'
EOFALL

chmod 700 /tmp/change.sh
chattr +i /tmp/change.sh
cat >/tmp/zabbix_agent.sh<<EOF
sed -i "s/temp_web_3/\$(HOSTNAME)/g" /etc/zabbix/zabbix_agentd.conf
chkconfig zabbix-agent on
/etc/init.d/zabbix-agent start
EOF

sed -i 's/HOSTNAME/hostname/g' zabbix_agent.sh
chmod 700 /tmp/zabbix_agent.sh
chattr +i /tmp/zabbix_agent.sh
cat >/tmp/salt.sh<<EOF
sed -i "s/temp_web_3/\$(HOSTNAME)/g" /etc/salt/minion
/etc/init.d/salt-minion start
chkconfig salt-minion on
EOF

sed -i 's/HOSTNAME/hostname/g' salt.sh
chmod 700 /tmp/salt.sh
chattr +i /tmp/salt.sh

[TOC]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值