安装
zabbix服务器上
服务器上安装步骤
1、下载
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum clean all
yum install zabbix-server-mysql zabbix-agent
2、更换SCL源
yum install centos-release-scl
cd /etc/yum.repos.d/
mv CentOS-SCLo-scl.repo CentOS-SCLo-scl.repo.bak
mv CentOS-SCLo-scl-rh.repo CentOS-SCLo-scl-rh.repo.bak
3、编辑SCL
vim CentOS-SCLo-scl-rh.repo
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
4、安装前台页面
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl
yum -y install mariadb mariadb-server
5、启动数据库
systemctl enable mariadb
systemctl start mariadb
6、授权数据库
mysql
create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified by 'AGLAREvv.1';
grant all privileges on zabbix.* to zabbix@localhost;
flush privileges;
exit
7、初始化zabbix
zcat /usr/share/doc/zabbix-server-mysql-5.0.43/create.sql.gz | mysql -u zabbix -p zabbix
8、配置账号密码
vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=AGLAREvv.1
9、启动zabbix
systemctl enable zabbix-server.service
systemctl start zabbix-server.service
10、配置zabbix前端php
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
只需更改时区为 Asia/Shanghai
11、启动服务
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
12、进入前台页面(本机ip:80/zabbix)按照指示操作
被监控主机上
被监控主机上安装步骤
1、设置主机名
hostname web1
2、关闭防火墙,selinux
3、准备镜像源
vim /etc/yum.repos.d/zabbix.repo
[zabbix]
name=alibaba zabbix
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/
gpgcheck=0
enabled=1
[zabbix2]
name=alibaba zabbix frontend
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/frontend/
gpgcheck=0
enabled=1
4、安装
yum -y install zabbix-agent
5、修改服务器地址
vim /etc/zabbix/zabbix_agentd.conf
修改Server、ServerActive、Hostname值
Server=192.168.209.143,192.168.100.11 被动模式 zabbix-server-ip
ServerActive=192.168.209.143,192.168.100.11 主动模式 zabbix-server-ip
Hostname=web1
6、启动zabbix-agent
systemctl start zabbix-agent
systemctl enable zabbix-agent
至此结束
中文乱码解决
中文乱码解决
1、复制字体文件
- win+r 输入fonts,复制 微软雅黑 字体文件并重命名为msyh.ttf
2、上传到服务器字体目录下
- /usr/share/zabbix/fonts/
3、修改文件权限
chmod 777 /usr/share/zabbix/assets/fonts/msyh.ttf
4、替换
sed -i "s/graphfont/msyh/g" /usr/share/zabbix/include/defines.inc.php
5、确认替换结果
grep FONT_NAME /usr/share/zabbix/include/defines.inc.php -n
至此结束
告警模式
微信告警
微信告警
1、注册企业微信
2、创建自己的应用。例:
3、记住 AgentId 和 Secret 。例:
4、记住企业id。例:
5、记住部门id。例:
6、在zabbix-server服务器上创建脚本。
vim /usr/lib/zabbix/alertscripts/wechat.py
修改如下内容:
- self.__corpid = '公司的corpid'
- self.__secret = '应用的secret'
- 'toparty':部门id,
- 'agentid':"应用id",
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib,urllib2,json
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
class WeChat(object):
__token_id = ''
# init attribute
def __init__(self,url):
self.__url = url.rstrip('/')
self.__corpid = '公司的corpid'
self.__secret = '应用的secret'
# Get TokenID
def authID(self):
params = {'corpid':self.__corpid, 'corpsecret':self.__secret}
data = urllib.urlencode(params)
content = self.getToken(data)
try:
self.__token_id = content['access_token']
# print content['access_token']
except KeyError:
raise KeyError
# Establish a connection
def getToken(self,data,url_prefix='/'):
url = self.__url + url_prefix + 'gettoken?'
try:
response = urllib2.Request(url + data)
except KeyError:
raise KeyError
result = urllib2.urlopen(response)
content = json.loads(result.read())
return content
# Get sendmessage url
def postData(self,data,url_prefix='/'):
url = self.__url + url_prefix + 'message/send?access_token=%s' % self.__token_id
request = urllib2.Request(url,data)
try:
result = urllib2.urlopen(request)
except urllib2.HTTPError as e:
if hasattr(e,'reason'):
print 'reason',e.reason
elif hasattr(e,'code'):
print 'code',e.code
return 0
else:
content = json.loads(result.read())
result.close()
return content
# send message
def sendMessage(self,touser,message):
self.authID()
data = json.dumps({
'touser':touser,
'toparty':部门id,
'msgtype':"text",
'agentid':"应用id",
'text':{
'content':message
},
'safe':"0"
},ensure_ascii=False)
response = self.postData(data)
print response
if __name__ == '__main__':
a = WeChat('https://qyapi.weixin.qq.com/cgi-bin')
a.sendMessage(sys.argv[1],sys.argv[3])
7、修改权限
chown zabbix.zabbix /usr/lib/zabbix/alertscripts/wechat.py
chmod 777 /usr/lib/zabbix/alertscripts/wechat.py
8、添加可信域名。例:
9、下载文件,上传到域名对应的服务器上。例:
10、添加可信ip。例:
11、测试脚本
cd /usr/lib/zabbix/alertscripts
./wechat.py jack test test {u'invalidparty': u'2', u'invaliduser': u'wusong', u'errcode': 0, u'errmsg': u'ok'}
至此结束
邮件告警
邮件告警
1、邮箱开启SMTP服务
2、zabbix设置邮箱
3、用户添加报警媒介
4、设置触发器产生的动作
Trigger: {TRIGGER.NAME}
Trigger status {TRIGGER.STATUS}
1. {ITEM.NAME1}({HOST.NAME1}:{ITEM.KEY1}):{ITEM.VALUE1}
至此结束
自动发现
自动注册
1、客户端配置
vim /etc/zabbix/zabbix_agentd.conf
ServerActive=192.168.209.143
主动模式 改成 zabbix-server-ip
systemctl restart zabbix-agent
至此完成