搭建平臺腳本:php
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.shhtml
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 }