1.安裝zabbix服務端
3.4的源
rpm -ivh https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
b. 安裝Zabbix server,Web前端,agent
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
c.安裝mariadb資料庫(設定開機啟動)
yum install -y mariadb-server #更新MARIABD資料庫
systemctl start mariadb.service #啟動
systemctl enable mariadb.service #設定開機啟動
d. 建立初始資料庫
mysql -uroot -p
password 回車
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to [email protected] identified by 'password';
mysql> quit;
e.入初始架構和資料,系統将提示您輸入新建立的密碼
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
或者導入自建的資料庫
gunzip create.sql.gz
MariaDB [(none)]> use zabbix;
source /data/zabbix.sql
f.為Zabbix server配置資料庫 編輯配置檔案 /etc/zabbix/zabbix_server.conf
DBPassword=password
g.為Zabbix前端配置PHP 編輯配置檔案 /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai
httpd端口改成8001
vim /etc/httpd/conf/httpd.conf
Listen 8001
h.啟動Zabbix server和agent程序 啟動Zabbix server和agent程序,并為它們設定開機自啟:
systemctl restart zabbix-server zabbix-agent httpd
systemctl enable zabbix-server zabbix-agent httpd
i.配置Zabbix前端
連接配接到新安裝的Zabbix前端: http://server_ip_or_name/zabbix
2、用戶端安裝:
rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
yum clean all
a.安裝agent
yum install -y zabbix-agent
#更改zabbix-agent配置檔案
host_ip=$(ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:")
sed -i "s/Server=127.0.0.1/Server=x.x.x.x/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/ServerActive=127.0.0.1/ServerActive=x.x.x.x/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/Hostname=Zabbix server/Hostname=$host_ip/g" /etc/zabbix/zabbix_agentd.conf
systemctl start zabbix-agent
systemctl enable zabbix-agent
3.微信報警
安裝郵件傳送代理MTA自帶的postfix
yum -y install postfix
systemctl start postfix
systemctl enable postfix
拷貝weixin.py到alertscripts下授權
chmod 777 /usr/lib/zabbix/alertscripts/weixin.py
注意:格式和PIP版本
yum install dos2unix -y
dos2unix weixin.py
#安裝pip 微信python依賴 需要更新到20.X.X
yum -y install epel-release
yum -y install python-pip
pip --version
pip install --upgrade pip
pip install requests
微信企業号申請(不會的百度)
位址: http://work.weixin.qq.com/
corpid='xxxxxxxxxxxxxx'
appsecret='xxxxxxxxxxxxxxxxxxxxxxxx'
agentid=1xxxxxxxxx
#微信腳本
cat weixin.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import requests
import sys
import os
import json
import logging
logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s, %(filename)s, %(levelname)s, %(message)s',
datefmt = '%a, %d %b %Y %H:%M:%S',
filename = os.path.join('/tmp','weixin.log'),
filemode = 'a')
corpid='xxxxxxxxxxxxxx'
appsecret='xxxxxxxxxxxxxxxxxxxxxxxx'
agentid=1xxxxxxxxx
#擷取accesstoken
token_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret
req=requests.get(token_url)
accesstoken=req.json()['access_token']
#發送消息
msgsend_url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + accesstoken
touser=sys.argv[1]
subject=sys.argv[2]
#toparty='3|4|5|6'
message=sys.argv[2] + "\n\n" +sys.argv[3]
params={
"touser": touser,
# "toparty": toparty,
"msgtype": "text",
"agentid": agentid,
"text": {
"content": message
},
"safe":0
}
req=requests.post(msgsend_url, data=json.dumps(params))
logging.info('sendto:' + touser + ';;subject:' + subject + ';;message:' + message)[roo
報警WEB配置微信報警(郵件報警同理)
配置媒介報警:

參數:
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
#配置動作
故障:
故障{TRIGGER.STATUS},伺服器名:{HOSTNAME1}發生: {TRIGGER.NAME}故障!
項目名稱:xxxxxx
告警主機:{HOSTNAME}
告警主機IP位址:{HOST.IP}
告警時間:{EVENT.DATE} {EVENT.TIME}
告警等級:{TRIGGER.SEVERITY}
告警資訊: {TRIGGER.NAME}
告警項目:{TRIGGER.KEY1}
問題詳情:{ITEM.NAME}:{ITEM.VALUE}
目前狀态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
恢複:
恢複{TRIGGER.STATUS}, 伺服器名:{HOSTNAME1}: {TRIGGER.NAME}已恢複!
項目名稱:xxxxxx
告警主機:{HOSTNAME}
告警主機IP位址:{HOST.IP}
告警時間:{EVENT.DATE} {EVENT.TIME}
告警等級:{TRIGGER.SEVERITY}
告警資訊: {TRIGGER.NAME}
告警項目:{TRIGGER.KEY1}
問題詳情:{ITEM.NAME}:{ITEM.VALUE}
目前狀态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
報警結果:
#安裝grafana
yum install https://dl.grafana.com/oss/release/grafana-6.3.6-1.x86_64.rpm
systemctl start grafana-server
systemctl enable grafana-server
#zabbix插件
grafana-cli工具從指令行安裝Zabbix :
grafana-cli plugins install alexanderzobnin-zabbix-app
#nginx反向代理grafana
add_header X-Frame-Options ALLOWALL;
location /grafana {
root html;
index index.html index.htm;
add_header 'Access-Control-Allow-Origin' '*';
add_header Access-Control-Allow-Methods GET,POST,OPTIONS,DELETE;
add_header 'Access-Control-Allow-Headers' 'userId,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
proxy_pass http://x.x.x.x:3000;
rewrite ^/grafana/(.*) /$1 break;
proxy_set_header Host $host;
}
vi /usr/share/grafana/conf/default.ini
root_url=%(protocol)s://%(domain)s:%(http_port)s/grafana
#展示