1 #!/bin/bash 2 #by zhangjia 3 #2019.5.9 4 #########################333 5 set -e 6 7 zabbix_server_install() { 8 zabbix_version="zabbix-4.2.1" 9 zabbix_server_ip="10.1.0.95" 10 dbuser="zabbix" 11 user="zabbix" 12 dbname="zabbix" 13 conf_file="/usr/local/zabbix/etc/zabbix_server.conf" 14 yum install net-snmp-devel curl-devel iksemel-devel libxml2-devel unixODBC-devel OpenIPMI-devel libssh2-devel java-1.8.0-openjdk* 15 mv ${zabbix_version}.tar.gz /usr/local/src 16 cd /usr/local/src 17 tar -xzvf ${zabbix_version}.tar.gz && cd ${zabbix_version} 18 ./configure --prefix=/usr/local/zabbix/ 19 --enable-agent 20 --with-mysql 21 --enable-ipv6 22 --with-net-snmp 23 --with-libcurl 24 --enable-server 25 --enable-java 26 --with-net-snmp 27 --with-libcurl 28 make && make install 29 } 30 31 zabbix_proxy_install() { 32 #zabbix_proxy与mysql在同一台机器上 33 zabbix_version="zabbix-4.2.1" 34 zabbix_server_ip="10.1.0.95" 35 dbuser="zabbix_proxy" 36 user="zabbix" 37 dbname="zabbix_proxy" 38 conf_file="/usr/local/zabbix/etc/zabbix_proxy.conf" 39 mysql -uroot -pZHj1203110904! -e "create database ${dbname} charset=utf8;" 40 mysql -uroot -pZHj1203110904! -e "grant all on *.* to ${dbuser}@‘%‘ identified by ‘ZHj1203110904\!‘; flush privileges;" 41 id ${dbuser} &>/dev/null 42 if [ $? -ne 0 ];then 43 useradd ${dbuser} -s /sbin/nologin -M 44 fi 45 id ${user} &>/dev/null 46 if [ $? -ne 0 ];then 47 useradd ${user} -s /sbin/nologin -M 48 fi 49 yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI mysql-devel libevent-devel 50 cd /usr/local/src 51 mv ${zabbix_version}.tar.gz . && tar -xzvf ${zabbix_version}.tar.gz 52 cd ${zabbix_version} 53 mysql -u${dbuser} -pZHj1203110904! zabbix_proxy <database/mysql/schema.sql 54 mysql -u${dbuser} -pZHj1203110904! zabbix_proxy <database/mysql/images.sql 55 ./configure --prefix=/usr/local/zabbix/ 56 --enable-proxy 57 --enable-agent 58 --with-mysql 59 --enable-ipv6 60 --with-net-snmp 61 --with-libcurl 62 63 make && make install 64 ln -s /usr/local/zabbix/sbin/zabbix_* /usr/local/sbin/ 65 cd /usr/local/zabbix/etc/ 66 cp zabbix_proxy.conf zabbix_proxy.conf.bak 67 68 sed -i ‘s/^Server=.*/Server=10.1.0.95/g‘ ${conf_file} 69 sed -i "s/^DBName=.*/DBName=${dbname}/g" ${conf_file} 70 sed -i "s/^DBUser=.*/DBUser=${dbuser}/g" ${conf_file} 71 72 grep ‘^DBPassword=‘ ${conf_file} || sed -i ‘s/# DBPassword=.*/DBPassword=ZHj1203110904\!/g‘ ${conf_file} 73 grep ‘^DataSenderFrequency=‘ ${conf_file} || sed -i ‘s/# DataSenderFrequency=.*/DataSenderFrequenc=30/g‘ ${conf_file} 74 grep ‘^CacheSize=‘ ${conf_file} || sed -i ‘s/# CacheSize=.*/CacheSize=128M/g‘ ${conf_file} 75 grep ‘^HistoryCacheSize=‘ ${conf_file} || sed -i ‘s/# HistoryCacheSize=.*/HistoryCacheSize=128M/g‘ ${conf_file} 76 77 /usr/local/zabbix/sbin/zabbix_proxy 78 } 79 80 zabbix_agent_install() { 81 zabbix_version="zabbix-4.2.1" 82 zabbix_server="10.1.0.95" 83 zabbix_proxy="10.1.0.74" 84 ip="`ifconfig eth0|grep inet|grep netmask|grep broadcast|awk ‘{print $2}‘`" 85 user="zabbix" 86 config_file="/usr/local/zabbix/etc/zabbix_agentd.conf" 87 yum -y install pcre* libevent-devel curl curl-devel net-snmp net-snmp-devel perl-DBI mysql-devel make 88 id ${user} &>/dev/null 89 if [ $? -ne 0 ];then 90 useradd ${user} -s /sbin/nologin -M 91 fi 92 mv ${zabbix_version}.tar.gz /usr/local/src 93 cd /usr/local/src 94 tar -xzvf ${zabbix_version}.tar.gz && cd ${zabbix_version} 95 ./configure --prefix=/usr/local/zabbix --enable-agent 96 make && make install 97 cd /etc/init.d/ 98 ln -s /usr/local/zabbix/sbin/zabbix_* /usr/local/sbin/ 99 cp /usr/local/src/${zabbix_version}/misc/init.d/tru64/zabbix_agentd /etc/init.d/zabbix_agentd 100 chmod o+x /etc/init.d/zabbix_agentd 101 chkconfig --add /etc/init.d/zabbix_agentd && chkconfig zabbix_agentd on 102 grep "^Server=${zabbix_proxy}" ${config_file} || sed -i "/^Server=/ s/Server=.*/Server=${zabbix_proxy}/g" ${config_file} 103 grep "^ServerActive=${zabbix_proxy}" ${config_file} || sed -i "/^ServerActive=/ s/ServerActive=.*/ServerActive=${zabbix_proxy}/g" ${config_file} 104 grep "^Hostname=${ip}" ${config_file} || sed -i "/^Hostname=/ s/Hostname=.*/Hostname=${ip}/g" ${config_file} 105 /etc/init.d/zabbix_agentd start 106 }
原文地址:https://www.cnblogs.com/zhj5551/p/11198252.html
时间: 2024-10-14 22:26:27