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

2019-04-14 20:19发布

class="markdown_views prism-dracula">

简单说明:

生产环境依据《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<#!/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<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 " /etc/hosts: " cat /etc/hosts echo -e " /etc/sysconfig/network: " cat /etc/sysconfig/network echo -e " /etc/resolv.conf: " cat /etc/resolv.conf echo -e " /etc/sysconfig/network-scripts/ifcfg-eth0: " cat /etc/sysconfig/network-scripts/ifcfg-eth0 echo -e " /etc/udev/rules.d/70-persistent-net.rules: " 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]