本文环境基于Ubuntu1604
Contents
-
Server
Installation
Database
Service
Configure
-
Agent
Installation
Service
Add Agent To Server
Send SMS Notification
Set Profile Language
Server
Installation
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
# sudo mysql_secure_installation
# sudo mysql -uroot -p
# GRANT ALL PRIVILEGES on *.* to 'root'@'localhost' IDENTIFIED BY '123456';
# FLUSH PRIVILEGES;
sudo apt install -y zabbix-agent
Database
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
Service
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
# 保证80和443端口未被占用
sudo service apache2 restart
sudo service zabbix-server restart
sudo service zabbix-server status # active (running)
Configure
Chrome Open http://192.168.56.222/zabbix
Check of pre-requisites => Configure DB connection => Zabbix Server Details
Congratulations! You have successfully installed Zabbix frontend
账号: Admin
密码: zabbix
Agent
Installation
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
Service
sudo vim /etc/zabbix/zabbix_agentd.conf
# Server=127.0.0.1
# Hostname=Test1
sudo service zabbix-agent restart
sudo service zabbix-agent status # active (running)
Add Agent To Server
Chrome Open http://192.168.56.222/zabbix
Configuration => Hosts => Create host
Host
Host name: Test1
Visible name: Test1
Groups: Linux servers
Agent interfaces: 127.0.0.1
Templates
Linked templates: Template OS Linux
- Monitoring => Graphs => Group (Linux servers) => Host (Test1) => Graph (CPU load)
Send SMS Notification
sudo apt install -y python-pip
sudo pip install aliyun-python-sdk-core
cat /etc/zabbix/zabbix_server.conf| grep AlertScriptsPath
# AlertScriptsPath=/usr/lib/zabbix/alertscripts
sudo vim /usr/lib/zabbix/alertscripts/sendsms.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
client = AcsClient('', '', 'cn-hangzhou')
request = CommonRequest()
request.set_accept_format('json')
request.set_domain('dysmsapi.aliyuncs.com')
request.set_method('POST')
request.set_protocol_type('https')
request.set_version('2017-05-25')
request.set_action_name('SendSms')
request.add_query_param('RegionId', "cn-hangzhou")
request.add_query_param('PhoneNumbers', "PhoneNumbers")
request.add_query_param('SignName', "SignName")
request.add_query_param('TemplateCode', "TemplateCode")
request.add_query_param('TemplateParam', "{\"code\": \"1234\"}")
response = client.do_action(request)
print(response)
sudo vim /usr/lib/zabbix/alertscripts/sendsms.sh
#!/bin/sh
python /usr/lib/zabbix/alertscripts/sendsms.py
sudo chown -R zabbix:zabbix /usr/lib/zabbix
sudo chmod +x /usr/lib/zabbix/alertscripts/sendsms.*
- Administration => Media types => Create media type
Name: AliyunSMS
Type: Script
Script name: sendsms.sh
- Administration => Users => Media
Type: AliyunSMS
- Configuration => Actions => CREATRE ACTION
Action
Name: SMS Alert
New condition: Host = Test1
Operations
Send to Users: Admin
Send only to: AliyunSMS
Conditions: New Default
- Generating a Test Alert (Agent)
df -h
# Filesystem Size Used Avail Use% Mounted on
# /dev/mapper/ubuntu--vg-root 18G 2.2G 15G 13% /
fallocate -l 14G /tmp/temp.img
rm /tmp/temp.img
Set Profile Language
sudo locale-gen zh_CN.UTF-8
cd /usr/share/zabbix/locale/zh_CN/LC_MESSAGES
sudo cp frontend.mo frontendbk.mo
sudo wget https://github.com/echohn/zabbix-zh_CN/archive/master.zip
# sudo apt install -y zip
sudo unzip master.zip
sudo cp zabbix-zh_CN-master/frontend.mo frontend.mo
# sudo rm -rf master.zip zabbix-zh_CN-master
wget https://raw.githubusercontent.com/hs-web/hsweb-printer/master/config/font/simkai.ttf
sudo mv simkai.ttf /usr/share/zabbix/fonts/
sudo sed -i 's/graphfont/simkai/g' /usr/share/zabbix/include/defines.inc.php
sudo service apache2 restart
sudo service zabbix-server restart
- Chrome Open http://192.168.56.222/zabbix/profile.php => Language (Chinese (ch_ZN))
参考
How To Install and Configure Zabbix to Securely Monitor Remote Servers on Ubuntu 18.04
How to Install Zabbix Server 4.0 on Ubuntu 18.04 & 16.04 LTS
How To Install Zabbix Agent on Ubuntu 18.04 & 16.04 LTS
How to Add Host in Zabbix Server to Monitor
What is the difference between pip install and sudo pip install?