zabbix基礎之環境搭建

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 1820php

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=mysqlmysql

#獲取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對應的參數便可web

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-serversql

2:進程佔用問題
修改zabbix_server.conf中discovery進程數量
StartDiscoverers=5
重啓zabbix-servershell

count(): Parameter must be an array or an object that implements Countable [ in latest.php:103]

PHP7.x以上版本的報錯,還沒有解決數據庫

相關文章
相關標籤/搜索