測試環境為 CentOS 8 x86_64 虛擬機.
- Zabbix Server (需 Database 與 Front-end) – https://benjr.tw/103709
- Zabbix Proxy (Database)
Agent 無法直接連到 Server 時可以架設 Proxy,下面介紹. - Zabbix Agent – https://benjr.tw/103741
要監控的裝置只需安裝 Agent , Agent 有支援的作業系統如 Windows , Linux , macOS , AIX , FreeBSD , OpenBSD , Solaris .
安裝 Zabbix Proxy 前需要先安裝好 Zabbix server, front-end 請參考 – https://benjr.tw/103709
Zabbix Proxy
我選擇的是 Zabbix Proxy version : 5.0 , Database : mysql (MariaDB)
Zabbix 沒有在預設的 Repository ,需手動增加 zabbix Repository .
[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/8/x86_64/zabbix-release-5.0-1.el8.noarch.rpm [root@localhost ~]# ll /etc/yum.repos.d/zabbix.repo -rw-r--r-- 1 root root 409 5月 11 2020 /etc/yum.repos.d/zabbix.repo
使用 dnf 安裝 Zabbix Proxy 所需套件.
[root@localhost ~]# dnf -y install zabbix-proxy-mysql
資料庫 MaraiDB
安裝 MariaDB (與 MySQL 資料庫相容)
[root@localhost ~]# dnf install -y mariadb mariadb-server mariadb-devel
啟動 MariaDB 服務.
[root@localhost ~]# systemctl enable mariadb [root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl status mariadb ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2017-07-21 11:30:32 CST; 2s ago Process: 5733 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS) Process: 5705 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS) Main PID: 5732 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─5732 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─5890 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql -...
設定 MariaDB ,主要是設定 MariaDB root (非系統 root ) 的帳號與密碼,其餘設定皆可使用預設值.
[root@localhost ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] n ... skipping. By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
建立 Zabbix server 所需資料庫.
[root@localhost ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 9 Server version: 10.3.28-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
新增 zabbix_proxy 資料庫(名稱可自訂,不能與 Zabbix Server 的資料庫名稱一樣).
MariaDB [(none)]> create database zabbix_proxy character set utf8 collate utf8_bin; Query OK, 1 row affected (0.001 sec)
新增使用者 zabbix@localhost 與其密碼 ‘password’ (請自行修改).
MariaDB [(none)]> create user zabbix@localhost identified by 'password'; Query OK, 0 rows affected (0.002 sec)
給予使用者 zabbix@localhost 存取 zabbix_proxy 資料庫權限(ALL).
MariaDB [(none)]> grant all privileges on zabbix_proxy.* to zabbix@localhost; Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> quit; Bye
使用資料庫使用者 zabbix (密碼剛剛設定為 password) 並匯入 Zabbix server 所需 架構(schema) 與 資料(data) 到資料庫.
[root@localhost ~]# zcat /usr/share/doc/zabbix-proxy-mysql*/schema.sql.gz | mysql -uzabbix -ppassword zabbix_proxy
設定 Zabbix Proxy
指定 Zabbix Proxy 所使用的資料庫(DBName) , 使用者(DBUser) 與 密碼(DBPassword).
目前我的 Zabbix server 與 Proxy IP.
- Zabbix server – 192.168.111.32
- Zabbix Proxy – 192.168.111.37
[root@localhost ~]# vi /etc/zabbix/zabbix_proxy.conf DBName=zabbix_proxy DBUser=zabbix DBPassword=password Server=192.168.111.32 Hostname=Proxy1 ConfigFrequency=60
其中 ConfigFrequency 是 Proxy 在指定時間( 預設為 3600 秒)去 Server 端同步監控配置檔的頻率,也就是預設要 1 小時(3600 秒) Proxy 才會知道在 Server 端網頁設定好哪些 Proxy 下的 Agent .
並啟動 zabbix-proxy 服務.
[root@localhost ~]# systemctl enable zabbix-proxy.service [root@localhost ~]# systemctl start zabbix-proxy.service [root@localhost ~]# systemctl status zabbix-proxy.service
Zabbix Server Frontend
透過 網頁來設定 Zabbix Proxy
在 Administrator / Proxies / Create Proxy
- 這邊的 proxy name 需與前面 Proxy 設定檔 /etc/zabbix/zabbix_proxy.conf 裡的 Hostname=Proxy1 一致.
- Proxy mode 可以選擇 Active / Passive ,我們安裝好的 Proxy 預設為 Active – the proxy will connect to the Zabbix server and request configuration data 或是選擇 Passive – Zabbix server connects to the proxy (需變更 ProxyMode=1 , 1 – proxy in the passive mode ).
- Zabbix Proxy Address 為 192.168.111.37
回到 Administrator / Proxies 就可以看到剛剛新增好的 Proxy , 注意 last seen (age)狀態不能為 Never (可以檢視 log 檔 – /var/log/zabbix/zabbix_proxy.log )
但目前尚未有 Zabbix Agent 是透過這一台 Proxy ,關於 Agent 請參考 – https://benjr.tw/103741
新增 Agent 時在 Configuration / Hosts / Create Host 設定 Monitored by proxy 需選擇剛剛設定好的 Proxy1.