本文vagrantfile配置详细参考vagrant-zabbix
目录
安装
vagrant ssh zabbix
wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.4-1%2Bxenial_all.deb
sudo dpkg -i zabbix-release_3.4-1+xenial_all.deb
sudo apt update
sudo apt install -y zabbix-server-mysql zabbix-frontend-php zabbix-agent
# sudo mysql_secure_installation
# sudo mysql -uroot -p
# CREATE DATABASE zabbix character set utf8 collate utf8_bin;
# GRANT ALL PRIVILEGES on zabbix.* to zabbix@localhost IDENTIFIED BY '123456';
# FLUSH PRIVILEGES;
zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix
sudo vim /etc/zabbix/apache.conf
# php_value date.timezone Asia/Shanghai
sudo vim /etc/zabbix/zabbix_server.conf
# DBHost=localhost
# DBName=zabbix
# DBUser=zabbix
# DBPassword=123456
sudo service apache2 restart
sudo service apache2 status # active (running)
sudo service zabbix-server restart
sudo service zabbix-server status # active (running)
账号: Admin
密码: zabbix
报警
- 企业微信 => 创建应用 => 保存参数
agentid 1000002
secret xxxx
corpid ww14ea6cc9f25696d5
sudo vim /usr/lib/zabbix/alertscripts/wechat.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import json
import requests
import sys
sendto = str(sys.argv[1])
subject = str(sys.argv[2])
content = str(sys.argv[3])
# 获取access_token
# https://work.weixin.qq.com/api/doc/90000/90135/91039
corpid = 'ww14ea6cc9f25696d5'
corpsecret = 'xxxx'
res = requests.get(
"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={}&corpsecret={}".format(corpid, corpsecret))
token = res.json()['access_token']
print(token)
# 发送应用消息
# https://work.weixin.qq.com/api/doc/90000/90135/90236
data = json.dumps({'agentid': 1000002,
'toparty': sendto,
'msgtype': 'text',
"text": {
"content": subject + '\n' + content
}})
res = requests.post(
"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}".format(token), data=data)
print(res.json())
sudo chmod 777 /usr/lib/zabbix/alertscripts/wechat.py
/usr/lib/zabbix/alertscripts/wechat.py 1 hello world
- Administration => Media types => Create media type
Name: 企业微信通知
Type: Script
Script name: wechat.py
Script parameters: {ALERT.SENDTO} {ALERT.SUBJECT} {ALERT.MESSAGE}
- Administration => Users => admin => Media
Type: 企业微信通知
Send to: 1
- Configuration => Actions => Create action
Name: 企业微信报警
Conditions: Maintenance status not in maintenance
Default operation step duration: 60
Operations:
Send to User Groups: Zabbix administrators
Send only to: 企业微信通知
Recovery operations:
Send to User Groups: Zabbix administrators
Send only to: 企业微信通知
- Configuration => Hosts => Zabbix server => Enabled
sudo service zabbix-agent start
sudo service zabbix-agent status # active (running)
sudo dd if=/dev/zero of=/swapfile bs=1G count=2
sudo mkswap /swapfile
sudo swapon /swapfile
sudo vim /etc/fstab
# /swapfile none swap sw 0 0
网页
- Configuration => Hosts => Zabbix server => Web => Create web scenario
Name: 网站监测
Agent: Chrome 38.0 (Mac)
Steps:
URL: http://file.nuozhilin.site
Required status codes: 200
- Configuration => Templates => Template App HTTP Service => Triggers => Create trigger
Name: HTTP response is not 200 on {HOST.NAME}
Severity: High
Expression:
Item: Zabbix server: Zabbix server: Response code for step "http://file.nuozhilin.site" of scenario "网站监测".
Function: last()
Last Of (T): 2
Time Shift: 5m
Result: <> 200
{Zabbix server:web.test.rspcode[网站监测,http://file.nuozhilin.site].last(#2,5m)}<>200
监控
vagrant ssh web
wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.4-1%2Bxenial_all.deb
sudo dpkg -i zabbix-release_3.4-1+xenial_all.deb
sudo apt update
sudo apt install -y zabbix-agent
sudo vim /etc/zabbix/zabbix_agentd.conf
# Server=192.168.56.101
sudo service zabbix-agent restart
sudo service zabbix-agent status # active (running)
-
Configuration => Hosts => Create host
Host
Host name: web
Visible name: web
Groups: Linux servers
New group: Web
Agent interfaces: 192.168.56.102 10050
Templates
Linked templates: Template OS Linux
- Monitoring => Graphs => Group (Web) => Host (web1) => Graph (CPU utilization)
模式
-
主动模式(Push) 客户端向服务端主动发动数据
-
被动模式(Pull) 客户端等待服务端来获取数据 <= Zabbix默认模式
sudo dd if=/dev/zero of=/swapfile bs=1G count=2
sudo mkswap /swapfile
sudo swapon /swapfile
sudo vim /etc/fstab
# /swapfile none swap sw 0 0
网友评论