1.架构
zabbix-server
zabbix5.0LTS-centos7-mysql5.7-nginx1.16

2.数据库端口
数据库:mysql5.7
端口:3306
密码:root Admin@1234
密码:zabbix Admin@1234

3.相关服务
systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm

4.各种客户端的安装
centos7客户端
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-agent-5.0.0-1.el7.x86_64.rpm
yum install zabbix-agent -y
sed -i ‘s/Server=127.0.0.1/Server=192.168.1.179/g’ /etc/zabbix/zabbix_agentd.conf
systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service

ubuntu16客户端:
wget https://mirrors.aliyun.com/zabbix/zabbix/5.0/ubuntu/pool/main/z/zabbix/zabbix-agent_5.0.6-2+xenial_amd64.deb
dpkg -i zabbix-agent_5.0.6-2+xenial_amd64.deb
sed -i ‘s/Server=127.0.0.1/Server=192.168.1.179/g’ /etc/zabbix/zabbix_agentd.conf
systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service

ubuntu14客户端:
wget https://mirrors.aliyun.com/zabbix/zabbix/5.0/ubuntu/pool/main/z/zabbix/zabbix-agent_5.0.9-1+trusty_amd64.deb
dpkg -i zabbix-agent_5.0.9-1+trusty_amd64.deb
sed -i ‘s/Server=127.0.0.1/Server=192.168.1.179/g’ /etc/zabbix/zabbix_agentd.conf
sed -i ‘s/ServerActive=127.0.0.1/ServerActive=192.168.1.179/g’ /etc/zabbix/zabbix_agentd.conf
vim /etc/rc.local
/etc/init.d/zabbix-agent start
service zabbix-agent start

卸载:
apt-get —purge remove zabbix-agent

红帽6客户端:
wget https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/6/x86_64/zabbix-agent2-5.0.9-1.el6.x86_64.rpm —no-check-certificate
yum install zabbix-agent -y
sed -i ‘s/Server=127.0.0.1/Server=192.168.1.179/g’ /etc/zabbix/zabbix_agentd2.conf
vim /etc/rc.local
/etc/init.d/zabbix-agent2 start
service zabbix-agent2 start

5.企业微信告警脚本

!/usr/bin/python
#coding:utf-8

import urllib,urllib2
import json
import sys
import simplejson

reload(sys)
sys.setdefaultencoding(‘utf-8’)

def gettoken(corpid,corpsecret):
gettoken_url = ‘https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=‘ + corpid + ‘&corpsecret=’ + corpsecret
print gettoken_url
try:
token_file = urllib2.urlopen(gettoken_url)
except urllib2.HTTPError as e:
print e.code
print e.read().decode(“utf8”)
sys.exit()
token_data = token_file.read().decode(‘utf-8’)
token_json = json.loads(token_data)
token_json.keys()
token = token_json[‘access_token’]
return token

def senddata(access_token,user,subject,content):

  1. send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + access_token
  2. send_values = {
  3. "touser":"AiSmart Zabbix Alert", #企业号中的用户帐号,在zabbix用户Media中配置,如果配置不正常,将按部门发送。此处可以写部门名字。
  4. "toparty":"2", #企业号中的部门id。其实此处就是写第几个部门号,默认第一个是大部门 第二个就是刚创建的子部门。
  5. "msgtype":"text", #消息类型。
  6. "agentid":"1000002", #企业号中的应用id。
  7. "text":{
  8. "content":subject + '\n' + content
  9. },
  10. "safe":"0"
  11. }

send_data = json.dumps(send_values, ensure_ascii=False)

  1. send_data = simplejson.dumps(send_values, ensure_ascii=False).encode('utf-8')
  2. send_request = urllib2.Request(send_url, send_data)
  3. response = json.loads(urllib2.urlopen(send_request).read())
  4. print str(response)

if name == ‘main‘:
user = str(sys.argv[1]) #zabbix传过来的第一个参数
subject = str(sys.argv[2]) #zabbix传过来的第二个参数
content = str(sys.argv[3]) #zabbix传过来的第三个参数

  1. corpid = 'ww741933187b64ab74' #CorpID是企业号的标识,此处在微信企业号内我的企业中企业信息最下面查看
  2. corpsecret = '-mJdLp-r3pXD9w4ZXctdClJ60afaPkNZZtBT-VrGhlc' #corpsecretSecret是管理组凭证密钥,此处写的是子部门的secret。
  3. accesstoken = gettoken(corpid,corpsecret)
  4. senddata(accesstoken,user,subject,content)