zabbix监控服务部署脚本

搭建平台脚本:

 1 #!/bin/bash
 2 #zabbix监控服务部署
 3 #脚本使用前提:yum搭建,nginx-1.12.2源码包,zabbix-3.4.4源码包,要求源码包尽量在单一目录下,最好在默认管理员家目录下
 4 #数据库主机,名称,账户,密码,日志为默认,不可修改
 5 #选择部署和一键部署的选择需要注释脚本操作,默认为选择部署;一键部署将选择部署的1和2合并
 6 source /root/moudle.sh
 7 while :
 8 do
 9 echo "############################__menu__################################"
10 echo "1.环境部署"
11 echo "2.安装监控平台"
12 echo "3.启动监控服务"
13 echo "4.部署被监控主机(在被监控主机上)"
14 echo "5.exit"
15 echo "####################################################################"
16 read -p "请输入您要部署的服务:选择部署(1|2|3|4|5);一键部署(1|2|3|4):" select
17 
18 #选择部署
19 if [ "$select" == "1" ];then
20     install_nginx
21 elif [ "$select" == "2" ];then
22     install_zabbix
23 elif [ "$select" == "3" ];then
24     start_zabbix
25 elif [ "$select" == "4" ];then
26     install_zabbix_webx
27 elif [ "$select" == "5" ];then
28     exit
29 else
30     echo "I AM SORRY"
31 fi
32 
33 #一键部署
34 #if [ $select == "1" ];then
35 #        install_nginx;install_zabbix
36 #elif [ $select == "2" ];then
37 #        start_zabbix
38 #elif [ $select == "3" ];then
39 #        install_zabbix_webx
40 #elif [ "$select" == "4" ];then
41 #        exit
42 #else
43 #        echo "I AM SORRY"
44 #fi
45 done

执行脚本:/root/moudle.sh

  1 #!/bin/bash
  2 #函数定义
  3 install_nginx()
  4 {
  5      yum -y install gcc pcre-devel zlib-devel openssl-devel
  6     
  7     if [ -f */nginx-1.12.2.tar.gz ];then
  8         find / -name "nginx-1.12.2.tar.gz" > /1.txt && sed -i 's/\/nginx-1.12.2.tar.gz//' /1.txt
  9         cd `cat /1.txt`
 10         tar -xf nginx-1.12.2.tar.gz
 11         cd nginx-1.12.2
 12         ./configure --with-http_ssl_module
 13         make && make install
 14     else
 15         echo "没有nginx源码包"
 16         exit 1
 17     fi
 18     
 19     yum -y install php php-mysql mariadb mariadb-server mariadb-devel php-fpm
 20 
 21     sed -i '65,68s/#//' /usr/local/nginx/conf/nginx.conf
 22     sed -i '70,71s/#//' /usr/local/nginx/conf/nginx.conf
 23     sed -i '/fastcgi/,70s/_params/.conf/' /usr/local/nginx/conf/nginx.conf
 24     
 25     systemctl start mariadb
 26     systemctl start php-fpm
 27     /usr/local/nginx/sbin/nginx
 28     ss -untlp | grep :80 >/dev/null
 29     if [ $? -eq 0 ];then
 30         echo "环境部署完毕,请进行监控平台安装"
 31     else
 32         echo "部署失败,请检查!"
 33     fi
 34 }
 35 
 36 install_zabbix()
 37 {
 38     yum -y install net-snmp-devel curl-devel libevent-devel
 39     
 40     if [ -f */zabbix-3.4.4.tar.gz ];then
 41                 find / -name "zabbix-3.4.4.tar.gz" > /1.txt ; sed -i '2,100d' /1.txt ; sed -i '1s/\/zabbix-3.4.4.tar.gz//' /1.txt 
 42         cd `cat /1.txt`
 43                 tar -xf zabbix-3.4.4.tar.gz
 44                 cd zabbix-3.4.4
 45         ./configure \
 46         --enable-server --enable-proxy --enable-agent \
 47         --with-mysql=/usr/bin/mysql_config \
 48         --with-net-snmp --with-libcurl
 49         make install
 50     else
 51         echo "没有zabbix源码包"
 52         exit 2
 53     fi
 54 
 55     cd frontends/php/
 56     cp -a * /usr/local/nginx/html/
 57     chmod -R 777 /usr/local/nginx/html/*
 58 
 59     sed -i "/keepalive_timeout  65;/a fastcgi_buffers 8 16k;\nfastcgi_buffer_size 32k;\nfastcgi_connect_timeout 300;\nfastcgi_send_timeout 300;\nfastcgi_read_timeout 300;" /usr/local/nginx/conf/nginx.conf        
 60     /usr/local/nginx/sbin/nginx -s stop
 61     /usr/local/nginx/sbin/nginx
 62 
 63     echo "开始数据库配置,请耐心等待......"
 64     mysql -e "create database zabbix character set utf8"
 65     mysql -e "grant all on zabbix.* to zabbix@'localhost' identified by 'zabbix'"
 66     cd `cat /1.txt`
 67     cd zabbix-3.4.4/database/mysql/
 68     mysql -uzabbix -pzabbix zabbix < schema.sql
 69     mysql -uzabbix -pzabbix zabbix < images.sql
 70     mysql -uzabbix -pzabbix zabbix < data.sql    
 71     
 72     cd /root/
 73     yum -y install php-gd php-xml php-ldap php-bcmath php-mbstring
 74 
 75     sed -i '/;date.timezone/s/;date.timezone =/date.timezone = Asia\/Shanghai/' /etc/php.ini
 76     sed -i '/max_exe/s/30/300/' /etc/php.ini
 77     sed -i '/post_max/s/8/32/' /etc/php.ini
 78     sed -i '/^max_input/s/60/300/' /etc/php.ini
 79     
 80     systemctl restart php-fpm
 81     ip=`ifconfig eth1 | awk  '/inet/ {print $2}'`
 82     echo "请访问http://$ip/index.php进行监控平台配置"
 83 }
 84 
 85 start_zabbix()
 86 {
 87     sed -i '/^# DBHost/s/#//' /usr/local/etc/zabbix_server.conf
 88     sed -i '/^# DBPassword/s/# DBPassword=/DBPassword=zabbix/' /usr/local/etc/zabbix_server.conf
 89     useradd zabbix
 90     zabbix_server
 91     netstat -utnlp | grep :10051 &>/dev/null
 92     if [ $? -eq 0 ];then
 93                 echo "监控启动成功"
 94         else
 95                 echo "失败,请检查"
 96         fi
 97 }
 98 
 99 install_zabbix_webx()
100 {
101     yum -y install gcc pcre-devel
102     
103     if [ -f */zabbix-3.4.4.tar.gz ];then
104                 find / -name "zabbix-3.4.4.tar.gz" > /1.txt ; sed -i '2,100d' /1.txt ; sed -i '1s/\/zabbix-3.4.4.tar.gz//' /1.txt
105                 cd `cat /1.txt`
106                 tar -xf zabbix-3.4.4.tar.gz
107                 cd zabbix-3.4.4
108                 ./configure --enable-agent 
109          make install
110     else
111                 echo "没有zabbix源码包"
112                 exit 3
113         fi
114 
115     read -p "请输入监控平台主机IP:" ip
116     sed -i "/^server=/s/127.0.0.1/127.0.0.1,$ip/" /usr/local/etc/zabbix_agentd.conf
117     sed -i "/^serveractive/s/127.0.0.1/$ip:10051/" /usr/local/etc/zabbix_agentd.conf
118     echo "正在开启,请耐心等待......"
119     useradd zabbix
120     zabbix_agentd
121     ss -untlp | grep :10050 &>/dev/null
122     if [ $? -eq 0 ];then
123                 echo "监控启动成功"
124         else
125                 echo "失败,请检查"
126         fi
127 }

你可能感兴趣的:(zabbix监控服务部署脚本)