Zabbix安装

本文环境基于Ubuntu1604

Contents

Server

Installation

1
2
3
4
5
6
7
8
9
10
11
12
13
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

1
2
3
4
5
6
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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

1
2
3
账号: Admin

密码: zabbix

Agent

Installation

1
2
3
4
5
6
7
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

1
2
3
4
5
6
7
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

1
2
3
4
5
6
7
8
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

1
2
3
sudo apt install -y python-pip

sudo pip install aliyun-python-sdk-core
1
2
3
4
cat /etc/zabbix/zabbix_server.conf| grep AlertScriptsPath
# AlertScriptsPath=/usr/lib/zabbix/alertscripts

sudo vim /usr/lib/zabbix/alertscripts/sendsms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
client = AcsClient('<accessKeyId>', '<accessSecret>', '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)
1
sudo vim /usr/lib/zabbix/alertscripts/sendsms.sh
1
2
3
#!/bin/sh

python /usr/lib/zabbix/alertscripts/sendsms.py
1
2
3
sudo chown -R zabbix:zabbix /usr/lib/zabbix

sudo chmod +x /usr/lib/zabbix/alertscripts/sendsms.*
  • Administration => Media types => Create media type
1
2
3
Name: AliyunSMS
Type: Script
Script name: sendsms.sh
  • Administration => Users => Media
1
Type: AliyunSMS
  • Configuration => Actions => CREATRE ACTION
1
2
3
4
5
6
7
8
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)
1
2
3
4
5
6
7
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

1
2
3
4
5
6
7
8
9
10
11
12
13
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
1
2
3
4
5
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
1
2
3
sudo service apache2 restart

sudo service zabbix-server restart

参考