[CentOS] Zabbix + Grafana 安裝

Zabbix 安裝步驟

安裝環境:CentOS 7

1. 關閉 SELINUX

1
2
3
4
5
6
vim /etc/selinux/config

## 將 SELINUX 修改為 disabled ##
config>SELINUX=disabled

reboot

2. 安裝 Zabbix 4.0 LTS

1
2
3
rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum clean all
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent

3. 若沒有安裝 MySQL 或 Maria DB,請按照以下步驟安裝 Maria DB

1
vim /etc/yum.repos.d/MariaDB.repo

貼上以下內容(根據需求參考以下網址調整 http://downloads.mariadb.org/mariadb/repositories/

1
2
3
4
5
6
7
# MariaDB 10.3 CentOS repository list - created 2019-05-28 01:56 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
1
yum install MariaDB-server MariaDB-client

4. 啟動 MariaDB 並設定開機啟動

1
2
systemctl start mariadb
systemctl enable mariadb

5. 設定 MariaDB root 密碼

1
/usr/bin/mysqladmin -u root password 'new-password'

6. MariaDB 安全性設定

1
/usr/bin/mysql_secure_installation

7. 建立 Zabbix 用帳號 & Database

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mysql -u root -p
Enter password:

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

## 建立 zabbix 帳號,記得修改 <password> 並拿掉 <> ##
MariaDB [(none)]> CREATE USER 'zabbix'@'localhost' IDENTIFIED BY '<password>';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye

8. 將 Zabbix 初始 SQL 架構和數據導入 MariaDB

1
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

9. 編輯 zabbix_server.conf

1
2
3
4
vim /etc/zabbix/zabbix_server.conf

## 將 DB 密碼設成剛剛 zabbix@localhost 所設定的 ##
DBPassword=<password>

10. 編輯 zabbix.conf

1
2
3
4
vim /etc/httpd/conf.d/zabbix.conf

## 將 timezone 修改為 Asia/Taipei ##
php_value date.timezone Asia/Taipei

11. 重開服務並設定開機啟動

1
2
systemctl restart zabbix-server zabbix-agent httpd
systemctl enable zabbix-server zabbix-agent httpd

12. 打開防火牆

1
2
3
4
5
firewall-cmd --permanent --add-port=10050/tcp
firewall-cmd --permanent --add-port=10051/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
systemctl restart firewalld

13. 打開 http://server_ip_or_name/zabbix 測試

1
2
Default Username: Admin
Default Password: zabbix

Grafana 安裝步驟

1. 安裝 Grafana(https://grafana.com/grafana/download

1
2
wget https://dl.grafana.com/oss/release/grafana-6.2.1-1.x86_64.rpm 
yum localinstall grafana-6.2.1-1.x86_64.rpm

2. 設定開機自動啟動 & 啟動 Grafana

1
2
systemctl enable grafana-server
systemctl start grafana-server

3. 打開防火牆

1
2
3
firewall-cmd --permanent --add-port=3000/tcp
firewall-cmd --reload
systemctl restart firewalld

4. 打開 http://server_ip_or_name:3000 測試

1
2
Default Username: admin
Default Password: admin

5. 安裝 Zabbix Plugin

1
2
grafana-cli plugins install alexanderzobnin-zabbix-app
systemctl restart grafana-server

6. 增加 Data source

1
2
3
URL: http://localhost/zabbix/api_jsonrpc.php
Username: Admin
Password: zabbix

7. 新增 Dashboard 監控設備
可以到這邊找模板 https://grafana.com/dashboards?category=zabbix

參考資料