zabbix入門
環境部署
安裝mysql
#安裝MySQL,官方的MySQL的repo源地址:http://repo.mysql.com/
#選擇指定的MySQL版本,我這里選mysql5.7的版本,復制對應版本的鏈接地址。
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
rpm -ivh mysql57-community-release-el7-10.noarch.rpm
yum repolist all |grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 118
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 95
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 364
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server - disabled
#最后面的enabled代表已開啟版本的MySQL源
yum-config-manager --enable mysql57-community #開啟mysql57-community的源
yum-config-manager --disable mysql57-community #關閉mysql57-community的源
#無論哪個版本,必須有mysqlxx-community、mysql-connectors-community、mysql-tools-community這三個源是開啟的,開啟的是哪個版本的源,安裝的就是哪個的版本。
#安裝mysql
yum -y install mysql-community-server
#啟動/關閉/重啟:systemctl start/stop/restart mysqld
#開機自啟:systemctl enable mysqld
安裝php&httpd
#php7.x版本的,web UI安裝后在最新數據的底部會有報錯:count(): Parameter must be an array or an object that implements Countable [ in latest.php:103]。介意的話用5.4版本的沒有報錯。
#安裝php7.2,php的repo源地址:https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install epel-release
rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php72w httpd php72w-mysql php72w-mbstring php72w-gd php72w-bcmath php72w-ldap php72w-xml
初始化MySQL(修改MySQL初始密碼)
必須初始化修改密碼,否則大部分操作會報錯,如:
mysql> show databases;
ERROR 1820 (HY000): Unknown error 1820
mysql> use mysql;
ERROR 1820 (HY000): Unknown error 1820
systemctl start mysqld #先啟動mysql
sudo grep 'temporary password' /var/log/mysqld.log #獲取初始密碼
2019-09-17T10:32:39.902324Z 1 [Note] A temporary password is generated for root@localhost: eQj:=VuCw43h # “eQj:=VuCw43h” 即為初始密碼
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; #修改登錄密碼
flush privileges;
#修改密碼的復雜性規則:
set global validate_password_policy=0;
#上面這個參數用於控制validate_password的驗證策略 0-->low 1-->MEDIUM 2-->strong。
set global validate_password_mixed_case_count=0; #大小寫的最小個數。
set global validate_password_number_count=3; #密碼中數字的最小個數。
set global validate_password_special_char_count=0;#特殊字符的最小個數。
set global validate_password_length=3; #密碼長度的最小值。
#查看密碼策略設置
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 3 |
| validate_password_mixed_case_count | 0 |
| validate_password_number_count | 3 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 0 |
+--------------------------------------+-------+
創建zabbix數據庫
mysql -uroot -p
password:
create database zabbix charset 'utf8';
Query OK, 1 row affected (0.00 sec)
#將zabbix用戶授予所有對zabbix數據庫的權限(授權時自動創建zabbix用戶)
grant all privileges on zabbix.* to zabbix@localhost identified by '123123';
Query OK, 1 row affected (0.00 sec)
flush privileges;
Query OK, 1 row affected (0.00 sec)
安裝配置zabbix 3.0
官方安裝文檔:https://www.zabbix.com/cn/download?zabbix=3.0&os_distribution=centos&os_version=7&db=mysql
#獲取zabbix3.0的repo源,
rpm -Uvh https://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
#安裝zabbix服務端和agent和web組件
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-web zabbix-agent zabbix-get
#解壓zabbix自帶的數據庫表
cd /usr/share/doc/zabbix-server-mysql-3.0.28/
gunzip create.sql.gz
#導入到MySQL
mysql -uroot -p -Dzabbix <create.sql
password: #輸入密碼可以看到zabbix數據庫中的表
mysql -uzabbix -p
password:
use zabbix
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
...
#修改zabbix-server配置文件
vim /etc/zabbix/zabbix_server.conf
#取消下面參數的備注並修改為數據庫中設置的參數
DBName=zabbix
...
DBUser=zabbix
...
DBPassword=123123
...
DBPort=3306
...
#保存退出
#修改zabbix-web配置文件
vim /etc/httpd/conf.d/zabbix.conf
#將如下這行取消注釋,並修改時區為亞洲上海
php_value date.timezone Asia/Shanghai
#修改zabbix-agent配置文件
vim /etc/zabbix/zabbix_agentd.conf
#agent的被動模式,允許哪台服務器拉取當前服務器的數據。server端的agent最好寫本地lo+網卡IP,被監控端只寫監控端的IP,這個IP只能寫本端到目標主機的最后一跳IP。多個IP用逗號隔開。
Server=127.0.0.1
#agent的主動模式,將本端服務器的數據主動推送給哪個主機。server端的agent寫本地回環,被監控端寫監控端的IP
ServerActive=127.0.0.1
#主機名稱,使用hosts文件中對應顯示的名稱
Hostname=zabbix-server
#注:主動模式和被動模式可以同時存在,但是server端的agent會報錯,但是不影響使用。
啟動服務
systemctl start mysqld
systemctl enable mysqld
systemctl start zabbix-server
systemctl enable zabbix-server
systemctl start zabbix-agent
systemctl enable zabbix-agent
systemctl start httpd
systemctl enable httpd
查看監聽端口
ss tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:*
LISTEN 0 128 *:10050 #agent監聽端口 *:*
LISTEN 0 128 *:10051 #server端監聽端口 *:*
LISTEN 0 128 127.0.0.1:9000 #PHP監聽端口 *:*
LISTEN 0 128 :::80 #httpd監聽端口 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 :::10050 :::*
LISTEN 0 128 :::10051 :::*
LISTEN 0 80 :::3306 #MySQL監聽端口 :::*
使用瀏覽器訪問:hostIP/zabbix
一般報錯的項是php的參數不符合要求,在/etc/php.ini中找到報錯的項,將參數改為圖中Required對應的參數即可
vim /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone =Asia/Shanghai
#保存退出,重啟httpd和zabbix-server,刷新瀏覽器網頁
修改語言
修改管理員登陸密碼
圖表字體亂碼,更換字體
#在控制面版中,查看方式設置為大圖標,然后找到“字體”,選擇字體文件。
#將windows中的字體文件放在如下目錄,一般文件后綴為TTF,將大寫的后綴改為小寫的ttf。
cd /usr/share/zabbix/fonts
#編輯配置文件
vim /usr/share/zabbix/include/defines.inc.php
#找到如下兩項,將引號中的graphfont改為目標字體名稱,不用帶后綴
define('ZBX_GRAPH_FONT_NAME', 'STFANGSO');
define('ZBX_FONT_NAME', 'STFANGSO');
#改完保存退出即可,刷新網頁,即可看到圖表中的亂碼已為中文。
可能遇到的問題
Zabbix discoverer processes more than 75% busy
嚴重性:Average
建議:
1:內存調度問題
在zabbix_server.conf配置文件中
增加初始化進程 StartPollers=12
重啟zabbix-server
2:進程占用問題
修改zabbix_server.conf中discovery進程數量
StartDiscoverers=5
重啟zabbix-server
count(): Parameter must be an array or an object that implements Countable [ in latest.php:103]
PHP7.x以上版本的報錯,尚未解決