Zabbix-部署

  • 2020 年 5 月 19 日
  • 筆記
目錄

一. apt安裝 Zabbix

部署結構圖和主機環境

在這裡插入圖片描述

1.1 Zabbix-server 安裝配置

1.1.1 安裝zabbix倉庫

# 下載二進位包
[root@Zabbix_server ~]#wget //repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-3+bionic_all.deb
[root@Zabbix_server ~]#dpkg -c zabbix-release_4.0-3+bionic_all.deb
drwxr-xr-x root/root         0 2019-07-31 00:34 ./
drwxr-xr-x root/root         0 2019-07-31 00:34 ./etc/
drwxr-xr-x root/root         0 2019-07-31 00:34 ./etc/apt/
drwxr-xr-x root/root         0 2019-07-31 00:34 ./etc/apt/sources.list.d/
-rw-r--r-- root/root       118 2019-07-31 00:34 ./etc/apt/sources.list.d/zabbix.list # 會生成一個.list結尾的文件
drwxr-xr-x root/root         0 2019-07-31 00:34 ./etc/apt/trusted.gpg.d/
-rwxr-xr-x root/root      2083 2019-07-31 00:34 ./etc/apt/trusted.gpg.d/zabbix-official-repo.gpg
drwxr-xr-x root/root         0 2019-07-31 00:34 ./usr/
drwxr-xr-x root/root         0 2019-07-31 00:34 ./usr/share/
drwxr-xr-x root/root         0 2019-07-31 00:34 ./usr/share/doc/
drwxr-xr-x root/root         0 2019-07-31 00:34 ./usr/share/doc/zabbix-release/
-rw-r--r-- root/root       267 2019-07-31 00:17 ./usr/share/doc/zabbix-release/README.Debian
-rw-r--r-- root/root      1665 2019-07-31 00:34 ./usr/share/doc/zabbix-release/changelog.Debian
-rw-r--r-- root/root       561 2019-07-31 00:17 ./usr/share/doc/zabbix-release/copyright
# 安裝源文件
[root@Zabbix_server ~]#dpkg -i zabbix-release_4.0-3+bionic_all.deb
# 更新apt源
[root@Zabbix_server ~]#apt update
Hit:1 //cn.archive.ubuntu.com/ubuntu bionic InRelease                                               
Hit:2 //security.ubuntu.com/ubuntu bionic-security InRelease                                                                  
Hit:3 //cn.archive.ubuntu.com/ubuntu bionic-updates InRelease                                            
Hit:4 //cn.archive.ubuntu.com/ubuntu bionic-backports InRelease                                          
Hit:5 //repo.zabbix.com/zabbix/4.0/ubuntu bionic InRelease                         
Reading package lists... Done                                
Building dependency tree       
Reading state information... Done
159 packages can be upgraded. Run 'apt list --upgradable' to see them.

1.1.2 安裝Zabbix server、web前端、agent

[root@Zabbix_server ~]#apt install zabbix-server-mysql zabbix-frontend-php zabbix-agent

1.2 zabbix_mysql配置

1.2.1 zabbix_mysql伺服器安裝資料庫服務

[root@Zabbix_mysql_master ~]#apt update
Hit:1 //security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 //cn.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 //cn.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:4 //cn.archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
159 packages can be upgraded. Run 'apt list --upgradable' to see them.
[root@Zabbix_mysql_master ~]#apt install mysql-server mysql-client

1.2.2 修改mysql配置文件配置監聽地址(用以外部的主機可以訪問mysql)

[root@Zabbix_mysql_master ~]#vim /etc/mysql/mysql.conf.d/mysqld.cnf 
# localhost which is more compatible and is not less secure.
bind-address            = 0.0.0.0      # 最好寫指定網段
# 重啟mysql
[root@Zabbix_mysql_master ~]#systemctl restart mysql

1.2.3 創建資料庫並授權用戶

[root@Zabbix_mysql_master ~]#mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database zabbix_server2 character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)

mysql> grant all privileges on zabbix_server2.* to zabbix@"172.20.8.%" identified by 'linux39';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 

1.2.4 在zabbix_server主機驗證資料庫和創建用戶是否可用(這一步一定要測試)

[root@Zabbix_server ~]#mysql -uzabbix -plinux39 -h172.20.8.104
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| zabbix_server2     |
+--------------------+
2 rows in set (0.00 sec)

MySQL [(none)]> 

1.2.5 導入初始結構和數據

# 以下是遠端導入
[root@Zabbix_server ~]#zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -plinux39 -h172.20.8.104 zabbix_server2

# 驗證初始結構和數據是否導入
[root@Zabbix_server ~]#mysql -uzabbix -plinux39 -h172.20.8.104
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| zabbix_server2     |
+--------------------+
2 rows in set (0.00 sec)

MySQL [(none)]> use zabbix_server2;
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 [zabbix_server2]> show tables;
+----------------------------+
| Tables_in_zabbix_server2   |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |
| conditions                 |
| config                     |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dashboard                  |
| dashboard_user             |
| dashboard_usrgrp           |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_suppress             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| hstgrp                     |
| httpstep                   |
| httpstep_field             |
| httpstepitem               |
| httptest                   |
| httptest_field             |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| item_preproc               |
| items                      |
| items_applications         |
| maintenance_tag            |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |
| media                      |
| media_type                 |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| rights                     |
| screen_user                |
| screen_usrgrp              |
| screens                    |
| screens_items              |
| scripts                    |
| service_alarms             |
| services                   |
| services_links             |
| services_times             |
| sessions                   |
| slides                     |
| slideshow_user             |
| slideshow_usrgrp           |
| slideshows                 |
| sysmap_element_trigger     |
| sysmap_element_url         |
| sysmap_shape               |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| tag_filter                 |
| task                       |
| task_acknowledge           |
| task_check_now             |
| task_close_problem         |
| task_remote_command        |
| task_remote_command_result |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
| widget                     |
| widget_field               |
+----------------------------+
144 rows in set (0.00 sec)

1.3 在配置zabbix_server用以連接資料庫

1.3.1 配置Zabbix server配置文件,添加連接資料庫的配置。

[root@Zabbix_server ~]#vim /etc/zabbix/zabbix_server.conf 
### Option: DBHost
#       Database host name.
#       If set to localhost, socket is used for MySQL.
#       If set to empty string, socket is used for PostgreSQL.
#
# Mandatory: no
# Default:
DBHost=172.20.8.104

### Option: DBName
#       Database name.
#
# Mandatory: yes
# Default:
# DBName=

DBName=zabbix_server2

### Option: DBPassword
#       Database password.
#       Comment this line if no password is used.
#
# Mandatory: no
# Default:
DBPassword=linux39

1.3.2 啟動zabbix服務並設為開機自啟動

[root@Zabbix_server ~]#systemctl restart zabbix-server.service zabbix-agent.service apache2
[root@Zabbix_server ~]#systemctl enable zabbix-server.service zabbix-agent.service apache2
Synchronizing state of zabbix-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable zabbix-server
Synchronizing state of zabbix-agent.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable zabbix-agent
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable apache2

1.4 web介面訪問及配置

1.4.1 web頁面測試訪問(需要在IP後面指定/zabbix目錄訪問)

在這裡插入圖片描述

  • zabbix web訪問路徑定義文件
# 可以在apache2的配置文件定位查找這幾行來確定訪問路徑。
[root@Zabbix_server apache2]#vim /etc/apache2/apache2.conf 
221 # Include generic snippets of statements
222 IncludeOptional conf-enabled/*.conf
223 
224 # Include the virtual host configurations:
225 IncludeOptional sites-enabled/*.conf

# zabbix訪問路徑定義文件。
[root@Zabbix_server apache2]#vim /etc/apache2/conf-enabled/zabbix.conf
# Define /zabbix alias, this is the default
<IfModule mod_alias.c>
    Alias /zabbix /usr/share/zabbix
</IfModule>

1.4.2 web介面配置時區這一項會報錯

在這裡插入圖片描述

  • 編輯PHP配置文件修改時區
# PHP是幾版本就寫在幾版本下面如果加錯了可能會不生效,主要添加32這一行改為中國時區。
[root@Zabbix_server apache2]#vim /etc/zabbix/apache.conf 
 23     <IfModule mod_php7.c>
 24         php_value max_execution_time 300
 25         php_value memory_limit 128M
 26         php_value post_max_size 16M
 27         php_value upload_max_filesize 2M
 28         php_value max_input_time 300
 29         php_value max_input_vars 10000
 30         php_value always_populate_raw_post_data -1
 31         # php_value date.timezone Europe/Riga
 32         php_value date.timezone Asia/Shanghai
# 重啟zabbix服務
[root@Zabbix_server apache2]#systemctl restart zabbix-server.service zabbix-agent.service apache2
  • 修改完後的時區
    在這裡插入圖片描述

1.4.3 資料庫配置

在這裡插入圖片描述

1.4.4 Zabbix_server配置

在這裡插入圖片描述

1.4.5 資訊確認

在這裡插入圖片描述

1.4.6 配置完成

在這裡插入圖片描述

  • 最後生成的文件是記錄你的配置。
[root@Zabbix_server apache2]#cat /usr/share/zabbix/conf/zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB;

$DB['TYPE']     = 'MYSQL';
$DB['SERVER']   = '172.20.8.104';
$DB['PORT']     = '3306';
$DB['DATABASE'] = 'zabbix_server2';
$DB['USER']     = 'zabbix';
$DB['PASSWORD'] = 'linux39';

// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';

$ZBX_SERVER      = '172.20.8.101';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'test-Zabbix-server';

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

1.4.7 登錄zabbix(默認賬戶密碼下圖)

在這裡插入圖片描述

1.4.8 zabbix登陸後的圖形介面

在這裡插入圖片描述

二. Ubuntu 1804/Centos 7 編譯安裝 Zabbix

編譯安裝zabbix_server與agent

zabbix源碼包下載地址

部署環境

  • 主機環境
# 實驗環境需要2台虛擬機
Zabbix-server         IP:172.20.8.101
Zabbix_mysql_master   IP:172.20.8.104
  • 最好把apt源都換為中國apt源
# ubuntu更換apt源為中國源
[root@Zabbix_server ~]#cd /etc/apt
# 備份一份
[root@Zabbix_server apt]#cp sources.list sources.list.backup
# 修改apt的包管理器的源的列表文件
[root@Zabbix_server apt]#vim sources.list
deb //mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src //mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb //mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src //mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb //mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src //mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb //mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src //mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

# 更新apt源
[root@Zabbix_server apt]#apt update 

2.1 解決依賴環境

2.1.1 Centos 7

yum install gcc  libxml2-devel   net-snmp net-snmp-devel   curl  curl-devel
php  php-bcmath  php-mbstring mariadb mariadb-devel

2.1.2 Ubuntu 1804

[root@Zabbix_server ~]#apt update 
Hit:1 //repo.zabbix.com/zabbix/4.0/ubuntu bionic InRelease
Hit:2 //security.ubuntu.com/ubuntu bionic-security InRelease        
Hit:3 //cn.archive.ubuntu.com/ubuntu bionic InRelease
Hit:4 //cn.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:5 //cn.archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
160 packages can be upgraded. Run 'apt list --upgradable' to see them.
[root@Zabbix_server ~]#apt-get  install   apache2 apache2-bin apache2-data apache2-utils fontconfig-config fonts-dejavu-core fping libapache2-mod-php   libapache2-mod-php7.2 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libfontconfig1 libgd3 libiksemel3   libjbig0 libjpeg-turbo8 libjpeg8 liblua5.2-0 libodbc1 libopenipmi0 libsensors4 libsnmp-base libsnmp30 libsodium23 libssh2-1  libtiff5 libwebp6 libxpm4 php-bcmath php-common php-gd php-ldap php-mbstring php-mysql php-xml php7.2-bcmath php7.2-cli  php7.2-common php7.2-gd php7.2-json php7.2-ldap php7.2-mbstring php7.2-mysql php7.2-opcache php7.2-readline   php7.2-xml snmpd  ssl-cert ttf-dejavu-core      libmysqlclient-dev  libxml2-dev  libxml2 snmp  libsnmp-dev   libevent-dev  openjdk-8-jdk curl libcurl4-openssl-dev -y

2.2 下載源碼包

[root@Zabbix_server src]#wget //cdn.zabbix.com/zabbix/sources/stable/4.0/zabbix-4.0.20.tar.gz
# 解壓源碼包
[root@Zabbix_server src]#tar xvf zabbix-4.0.20.tar.gz

2.3 創建用戶和組

[root@Zabbix_server src]#groupadd -g 1001 zabbix          # 創建zabbix用戶和組
[root@Zabbix_server src]#useradd -u 1001 -g 1001 zabbix   
[root@Zabbix_server src]#id zabbix                        # 驗證用戶id
uid=1001(zabbix) gid=1001(zabbix) groups=1001(zabbix)

2.4 開始編譯

[root@Zabbix_server zabbix-4.0.20]#pwd
/usr/local/src/zabbix-4.0.20
# 如果編譯有以下報錯安裝對應的包就可以
[root@Zabbix_server zabbix-4.0.20]#./configure --prefix=/apps/zabbix_server  --enable-server --enable-agent --with-mysql  --with-net-snmp --with-libcurl --with-libxml2 --enable-java
configure: error: MySQL library not found  ## 這個報錯安裝mysql-devel包(Ubuntu 安裝libmysql-dev)
configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config ## 安裝net-snmp-devel包
configure: error: Unable to find "javac" executable in path
# 安裝java-1.8.0-openjdk-devel
[root@zabbix-server1 zabbix-4.0.15]# yum install java-1.8.0-openjdk-devel

# 安裝完成後在進行編譯如果不在報錯就可以了
[root@zabbix-server1 zabbix-4.0.15]# ./configure --prefix=/apps/zabbix_server  --enable-server --enable-agent --with-mysql  --with-net-snmp --with-libcurl --with-libxml2  --enable-java

[root@Zabbix_server zabbix-4.0.20]#make install

# 生成這些目錄就代表編譯成功了
[root@Zabbix_server zabbix-4.0.20]#ll /apps/zabbix_server/
total 28
drwxr-xr-x 7 root root 4096 May 13 16:31 ./
drwxr-xr-x 3 root root 4096 May 13 16:31 ../
drwxr-xr-x 2 root root 4096 May 13 16:31 bin/
drwxr-xr-x 4 root root 4096 May 13 16:31 etc/
drwxr-xr-x 3 root root 4096 May 13 16:31 lib/
drwxr-xr-x 3 root root 4096 May 13 16:32 sbin/
drwxr-xr-x 4 root root 4096 May 13 16:32 share/

2.5 準備資料庫

[root@Zabbix_mysql_master ~]#apt update
[root@Zabbix_mysql_master ~]#apt install mysql-server mysql-client -y
# 修改mysql配置文件配置監聽地址(用以外部的主機可以訪問mysql)
[root@Zabbix_mysql_master ~]#vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address            = 0.0.0.0
# 重啟資料庫並設為開機自啟動
[root@Zabbix_mysql_master ~]#systemctl restart mysql.service 
[root@Zabbix_mysql_master ~]#systemctl enable mysql.service 
Synchronizing state of mysql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mysql

[root@Zabbix_mysql_master ~]#mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database zabbix_server character set utf8 collate utf8_bin;  # 創建資料庫
Query OK, 1 row affected (0.00 sec)

mysql> grant all privileges on zabbix_server.* to zabbix@"172.20.8.%" identified by '123456';   
# 授權zabbix用戶zabbix_server庫的許可權

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;  # 刷新許可權
Query OK, 0 rows affected (0.00 sec)

2.6 導入基礎數據到資料庫

2.6.1 在 zabbix-server 上使用 zabbix 賬戶測試資料庫的連通性

# 安裝mysql客戶端命令,用於測試zabbix 資料庫帳號許可權
[root@Zabbix_server zabbix-4.0.20]#apt  install mysql-client -y
[root@Zabbix_server zabbix-4.0.20]#mysql -uzabbix -p123456 -h172.20.8.104
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

2.6.2 導入資料庫

[root@Zabbix_server zabbix-4.0.20]#cd /usr/local/src/zabbix-4.0.20/database/mysql/
[root@Zabbix_server mysql]#ll
total 6104
drwxr-xr-x 2 zabbix zabbix    4096 May 13 16:26 ./
drwxr-xr-x 8 zabbix zabbix    4096 May 13 16:26 ../
-rw-r--r-- 1 zabbix zabbix 4079668 Apr 27 20:59 data.sql
-rw-r--r-- 1 zabbix zabbix 1978341 Apr 27 20:59 images.sql
-rw-r--r-- 1 root   root     15625 May 13 16:26 Makefile
-rw-r--r-- 1 zabbix zabbix     392 Apr 27 20:59 Makefile.am
-rw-r--r-- 1 zabbix zabbix   15806 Apr 27 20:59 Makefile.in
-rw-r--r-- 1 zabbix zabbix  140265 Apr 27 20:59 schema.sql

可以看到,zabbix 源碼文件夾下提供了schema.sqlimages.sqldata.sql三個 sql 文件,使用這三個文件將 zabbix server 所需的數據導入到資料庫。

# 第一種導入方法(使用sql語句導入)
[root@Zabbix_server mysql]#pwd
/usr/local/src/zabbix-4.0.20/database/mysql
[root@Zabbix_server mysql]#mysql -uzabbix -p123456 -h172.20.8.104
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use zabbix_server;
Database changed
mysql> source schema.sql
......(省略顯示過程)
mysql> source images.sql
......(省略顯示過程)
mysql> source data.sql
......(省略顯示過程)


# 第二種導入方法(重定嚮導入)
[root@Zabbix_server mysql]#mysql -uzabbix -p123456 -h172.20.8.104 zabbix_server < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@Zabbix_server mysql]#mysql -uzabbix -p123456 -h172.20.8.104 zabbix_server < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@Zabbix_server mysql]#mysql -uzabbix -p123456 -h172.20.8.104 zabbix_server < data.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.


# 驗證是否導入
[root@Zabbix_server mysql]#mysql -uzabbix -p123456 -h172.20.8.104
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use zabbix_server;
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_server    |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
......省略。
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
| widget                     |
| widget_field               |
+----------------------------+
144 rows in set (0.00 sec)

2.7 編輯zabbix_server配置文件

[root@Zabbix_server mysql]#vim /apps/zabbix_server/etc/zabbix_server.conf
........
[root@Zabbix_server mysql]#grep "^[a-Z]" /apps/zabbix_server/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBHost=172.20.8.104           # 資料庫地址
DBName=zabbix_server          # 資料庫名
DBUser=zabbix                 # 資料庫用戶名
DBPassword=123456             # 用戶密碼
DBPort=3306
Timeout=4
LogSlowQueries=3000

2.8 啟動zabbix_server

[root@Zabbix_server ~]#/apps/zabbix_server/sbin/zabbix_server  -c /apps/zabbix_server/etc/zabbix_server.conf
[root@Zabbix_server ~]#tail /tmp/zabbix_server.log
  1185:20200513:174050.566 server #24 started [trapper #5]
  1186:20200513:174050.568 server #25 started [icmp pinger #1]
  1187:20200513:174050.569 server #26 started [alert manager #1]
  1188:20200513:174050.570 server #27 started [alerter #1]
  1189:20200513:174050.570 server #28 started [alerter #2]
  1190:20200513:174050.572 server #29 started [alerter #3]
  1191:20200513:174050.573 server #30 started [preprocessing manager #1]
  1194:20200513:174050.574 server #33 started [preprocessing worker #3]
  1192:20200513:174050.674 server #31 started [preprocessing worker #1]
  1193:20200513:174050.674 server #32 started [preprocessing worker #2]
# 驗證是否啟動zabbix
[root@Zabbix_server ~]#ps -ef | grep zabbix
zabbix     1161      1  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server -c /apps/zabbix_server/etc/zabbix_server.conf
zabbix     1162   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: configuration syncer [synced configuration in 0.023613 sec, idle 60 sec]
zabbix     1163   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
zabbix     1164   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: timer #1 [updated 0 hosts, suppressed 0 events in 0.000702 sec, idle 59 sec]
zabbix     1165   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: http poller #1 [got 0 values in 0.000612 sec, idle 5 sec]
zabbix     1166   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.000758 sec, idle 60 sec]
zabbix     1167   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: history syncer #1 [processed 0 values, 0 triggers in 0.000072 sec, idle 1 sec]
zabbix     1168   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: history syncer #2 [processed 0 values, 0 triggers in 0.000032 sec, idle 1 sec]
zabbix     1169   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: history syncer #3 [processed 0 values, 0 triggers in 0.000087 sec, idle 1 sec]
zabbix     1170   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: history syncer #4 [processed 0 values, 0 triggers in 0.000038 sec, idle 1 sec]
zabbix     1171   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.002316 sec, idle 3 sec]
zabbix     1172   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000067 sec, idle 5 sec]
zabbix     1173   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: self-monitoring [processed data in 0.000057 sec, idle 1 sec]
zabbix     1174   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: task manager [processed 0 task(s) in 0.001836 sec, idle 5 sec]
zabbix     1175   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: poller #1 [got 0 values in 0.000037 sec, idle 2 sec]
zabbix     1176   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: poller #2 [got 0 values in 0.000006 sec, idle 2 sec]
zabbix     1177   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: poller #3 [got 0 values in 0.000007 sec, idle 2 sec]
zabbix     1178   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: poller #4 [got 0 values in 0.000006 sec, idle 2 sec]
zabbix     1179   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: poller #5 [got 0 values in 0.000007 sec, idle 2 sec]
zabbix     1180   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000012 sec, idle 5 sec]
zabbix     1181   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection]
zabbix     1182   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting for connection]
zabbix     1183   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection]
zabbix     1184   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection]
zabbix     1185   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection]
zabbix     1186   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000058 sec, idle 5 sec]
zabbix     1187   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: alert manager #1 [sent 0, failed 0 alerts, idle 5.014519 sec during 5.014609 sec]
zabbix     1188   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: alerter #1 started
zabbix     1189   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: alerter #2 started
zabbix     1190   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: alerter #3 started
zabbix     1191   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: preprocessing manager #1 [queued 0, processed 2 values, idle 5.990199 sec during 5.990282 sec]
zabbix     1192   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: preprocessing worker #1 started
zabbix     1193   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: preprocessing worker #2 started
zabbix     1194   1161  0 17:40 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: preprocessing worker #3 started
root       1299   1120  0 17:41 pts/0    00:00:00 grep --color=auto zabbix

2.9 配置web介面

2.9.1 拷貝 PHP WEB 前端程式碼拷貝到 apache 服務目錄

[root@Zabbix_server ~]#mkdir /var/www/html/zabbix
[root@Zabbix_server zabbix-4.0.20]#pwd
/usr/local/src/zabbix-4.0.20
[root@Zabbix_server zabbix-4.0.20]#cd frontends/php/
[root@Zabbix_server php]#cp -a . /var/www/html/zabbix/

2.9.2 訪問web介面

在這裡插入圖片描述

2.9.3 當前報錯頁面

在這裡插入圖片描述

2.9.4 解決報錯

# 安裝php服務
[root@Zabbix_server php]#apt-get install php-gettext   php-xml php-net-socket php-gd php-mysql
# 修改php的配置配置時區和記憶體大小、連接數等。
[root@Zabbix_server php]#vim /etc/php/7.2/apache2/php.ini
date.timezone = Asia/Shanghai
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
# 重啟apache2服務
[root@Zabbix_server php]#systemctl restart apache2.service 

2.9.5 解決報錯後頁面

在這裡插入圖片描述

2.9.6 配置資料庫

在這裡插入圖片描述

2.9.7 zabbix_server配置

在這裡插入圖片描述

2.9.8 資訊確認

在這裡插入圖片描述

2.9.10 創建配置文件

需要手動下載配置文件並上傳至zabbix server的/var/www/html/zabbix/conf/zabbix.conf.php路徑
在這裡插入圖片描述
點擊上面的紅框,下載後放在下面的紅框指定的位置
/var/www/html/zabbix/conf/zabbix.conf.php

[root@Zabbix_server php]#cd /var/www/html/zabbix/conf/
[root@Zabbix_server conf]#pwd
/var/www/html/zabbix/conf
[root@Zabbix_server conf]#rz -E
rz waiting to receive.
[root@Zabbix_server conf]#ll
total 24
drwxr-xr-x  2 zabbix zabbix 4096 May 16 10:55 ./
drwxr-xr-x 10 zabbix zabbix 4096 Apr 27 20:59 ../
-rw-r--r--  1 zabbix zabbix  163 Apr 27 20:59 .htaccess
-rw-r--r--  1 zabbix zabbix 1036 Apr 27 20:59 maintenance.inc.php
-rw-r--r--  1 root   root    449 May 16 10:53 zabbix.conf.php
-rw-r--r--  1 zabbix zabbix  741 Apr 27 20:59 zabbix.conf.php.example
[root@Zabbix_server conf]#cat zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB;

$DB['TYPE']     = 'MYSQL';
$DB['SERVER']   = '172.20.8.104';
$DB['PORT']     = '3306';
$DB['DATABASE'] = 'zabbix_server';
$DB['USER']     = 'zabbix';
$DB['PASSWORD'] = '123456';

// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';

$ZBX_SERVER      = '172.20.8.101';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'Zabbix-server-test';

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

2.9.11 刷新web介面

在這裡插入圖片描述

2.9.12 登錄

在這裡插入圖片描述

2.9.13 zabbix web主介面

在這裡插入圖片描述

2.10 啟動 agent 查看監控數據

2.10.1 在 zabbix server 主機啟動 zabbix agent

[root@Zabbix_server conf]#/apps/zabbix_server/sbin/zabbix_agentd
[root@Zabbix_server conf]# ps -ef | grep zabbix_agentd
zabbix     2405      1  0 11:04 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_agentd
zabbix     2406   2405  0 11:04 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix     2407   2405  0 11:04 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix     2408   2405  0 11:04 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix     2409   2405  0 11:04 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix     2410   2405  0 11:04 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root       2415   1855  0 11:04 pts/0    00:00:00 grep --color=auto zabbix_agentd

2.10.2 查看是否有數據

這個看的是zabbix_server的記憶體,分的記憶體小網站響應速度特別慢,server的配置不能太低。
在這裡插入圖片描述

三. 編寫 zabbix server 與 agent 的啟動文件

編譯安裝的 zabbix 服務端和 agent 端的啟動文件可以從 yum 或 apt 安裝的 zabbix 啟動文件中更改參數得來。

# 在apt安裝的zabbix主機拷貝啟動腳本到編譯安裝的主機
[root@Zabbix_node2 ~]#ip addr show eth0 | grep inet
    inet 172.20.8.107/24 brd 172.20.8.255 scope global eth0
    inet6 fe80::20c:29ff:fe3c:4063/64 scope link
[root@Zabbix_node2 ~]#scp /lib/systemd/system/zabbix-server.service 172.20.8.101:/etc/systemd/system/zabbix-server.service
The authenticity of host '172.20.8.101 (172.20.8.101)' can't be established.
ECDSA key fingerprint is SHA256:4F3nJjf/rDz1yY/ZfUm7+O+oyZFKluMMDLD60Mqq3vU.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.20.8.101' (ECDSA) to the list of known hosts.
[email protected]'s password: 
zabbix-server.service                                                                                                                     100%  327   699.2KB/s   00:00    
[root@Zabbix_node2 ~]#scp /lib/systemd/system/zabbix-agent.service 172.20.8.101:/etc/systemd/system/zabbix-agent.service
[email protected]'s password: 
zabbix-agent.service                                                                                                                      100%  238   134.1KB/s   00:00    

3.1 zabbix_server啟動腳本

# 先停止zabbix_server進程
[root@Zabbix_server conf]#pkill zabbix_server

[root@Zabbix_server conf]#vim /etc/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/apps/zabbix_server/etc/zabbix_server.conf"
EnvironmentFile=-/etc/default/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/apps/zabbix_server/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=infinity
[Install]
WantedBy=multi-user.target

3.2 zabbix_agent啟動腳本

# 先停止zabbix_agent進程
[root@Zabbix_server conf]#pkill zabbix_agentd 

[root@Zabbix_server conf]#vim /etc/systemd/system/zabbix-agent.service
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=apps/zabbix_server/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/default/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/apps/zabbix_server/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix

[Install]
WantedBy=multi-user.target

3.3 使用啟動腳本重啟服務並設置開機自啟動

# 啟動server
[root@Zabbix_server conf]#systemctl  restart zabbix-server && systemctl  enable zabbix-server
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /etc/systemd/system/zabbix-server.service.
# 驗證是否啟動
[root@Zabbix_server conf]#ps -ef | grep zabbix_server
zabbix     3031      1  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server -c /apps/zabbix_server/etc/zabbix_server.conf
zabbix     3036   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: configuration syncer [synced configuration in 0.010873 sec, idle 60 sec]
zabbix     3055   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
zabbix     3056   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: timer #1 [updated 0 hosts, suppressed 0 events in 0.001219 sec, idle 59 sec]
zabbix     3057   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: http poller #1 [got 0 values in 0.000839 sec, idle 5 sec]
zabbix     3058   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.000632 sec, idle 60 sec]
zabbix     3059   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: history syncer #1 [processed 0 values, 0 triggers in 0.000010 sec, idle 1 sec]
zabbix     3060   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: history syncer #2 [processed 0 values, 0 triggers in 0.000028 sec, idle 1 sec]
zabbix     3061   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: history syncer #3 [processed 0 values, 0 triggers in 0.000009 sec, idle 1 sec]
zabbix     3062   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: history syncer #4 [processed 0 values, 0 triggers in 0.000029 sec, idle 1 sec]
zabbix     3063   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.001102 sec, idle 3 sec]
zabbix     3064   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000010 sec, idle 5 sec]
zabbix     3065   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: self-monitoring [processed data in 0.000028 sec, idle 1 sec]
zabbix     3066   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: task manager [processed 0 task(s) in 0.000451 sec, idle 5 sec]
zabbix     3067   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: poller #1 [got 0 values in 0.000028 sec, idle 5 sec]
zabbix     3068   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: poller #2 [got 0 values in 0.000006 sec, idle 5 sec]
zabbix     3069   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: poller #3 [got 0 values in 0.000007 sec, idle 5 sec]
zabbix     3070   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: poller #4 [got 0 values in 0.000008 sec, idle 5 sec]
zabbix     3071   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: poller #5 [got 0 values in 0.000007 sec, idle 5 sec]
zabbix     3072   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000027 sec, idle 5 sec]
zabbix     3073   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection]
zabbix     3074   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: trapper #2 [processed data in 0.000635 sec, waiting for connection]
zabbix     3075   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection]
zabbix     3076   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection]
zabbix     3077   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection]
zabbix     3078   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000025 sec, idle 5 sec]
zabbix     3079   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: alert manager #1 [sent 0, failed 0 alerts, idle 5.023119 sec during 5.023249 sec]
zabbix     3080   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: alerter #1 started
zabbix     3081   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: alerter #2 started
zabbix     3084   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: alerter #3 started
zabbix     3085   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: preprocessing manager #1 [queued 0, processed 0 values, idle 5.019437 sec during 5.019574 sec]
zabbix     3086   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: preprocessing worker #1 started
zabbix     3087   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: preprocessing worker #2 started
zabbix     3088   3031  0 11:54 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_server: preprocessing worker #3 started
root       3101   1855  0 11:56 pts/0    00:00:00 grep --color=auto zabbix_server

# 啟動agent
[root@Zabbix_server conf]#systemctl  restart zabbix-agent && systemctl  enable zabbix-agent
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-agent.service → /etc/systemd/system/zabbix-agent.service.
# 驗證是否啟動
[root@Zabbix_server conf]#ps -ef | grep zabbix_agent
zabbix     3132      1  0 11:58 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_agentd -c apps/zabbix_server/etc/zabbix_agentd.conf
zabbix     3133   3132  0 11:58 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix     3134   3132  0 11:58 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix     3135   3132  0 11:58 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix     3136   3132  0 11:58 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix     3137   3132  0 11:58 ?        00:00:00 /apps/zabbix_server/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root       3161   1855  0 11:59 pts/0    00:00:00 grep --color=auto zabbix_agent

四. Ubuntu 下使用 zabbix web時漢化方法

4.1 在 Ubuntu 安裝中文簡體語言環境

[root@Zabbix_server conf]#apt install language-pack-zh*
[root@Zabbix_server conf]#vim /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
LANG="zh_CN.UTF-8"
[root@Zabbix_server conf]#dpkg-reconfigure locales

在這裡插入圖片描述
在這裡插入圖片描述

[root@Zabbix_server conf]#dpkg-reconfigure locales
Generating locales (this might take a while)...
  en_AG.UTF-8... done
  en_AU.UTF-8... done
  en_BW.UTF-8... done
  en_CA.UTF-8... done
  en_DK.UTF-8... done
  en_GB.UTF-8... done
  en_HK.UTF-8... done
  en_IE.UTF-8... done
  en_IL.UTF-8... done
  en_IN.UTF-8... done
  en_NG.UTF-8... done
  en_NZ.UTF-8... done
  en_PH.UTF-8... done
  en_SG.UTF-8... done
  en_US.UTF-8... done
  en_ZA.UTF-8... done
  en_ZM.UTF-8... done
  en_ZW.UTF-8... done
  zh_CN.UTF-8... done
  zh_HK.UTF-8... done
  zh_SG.UTF-8... done
  zh_TW.UTF-8... done
Generation complete.
# 需要重啟apache2服務才可以在web介面配置
[root@Zabbix_server conf]#systemctl restart apache2.service

4.2 在web介面選擇語言

在這裡插入圖片描述
在這裡插入圖片描述

在這裡插入圖片描述
在這裡插入圖片描述

4.3 解決部分介面亂碼問題

當前系統有些監控項部分顯示有亂碼,是由於 web 介面顯示為中文但是系統沒有相關字體支援導致,因此需要相關字體的支援才能正常顯示,如下:
在這裡插入圖片描述

4.3.1 上傳字體文件

4.3.1.1 在 windows 拷貝字體

在 Windows 上找到控制面板,然後將字體拷貝到 windows 系統其他目錄,等待上傳到 zabbix 前端目錄。
在這裡插入圖片描述
在這裡插入圖片描述
直接拖到另一個文件夾即可(注意最好使用楷體字體)
在這裡插入圖片描述

4.3.1.2 上傳字體到 apache 服務的 zabbix 目錄
[root@Zabbix_server conf]#cd /var/www/html/zabbix/assets/fonts/
[root@Zabbix_server fonts]#pwd
/var/www/html/zabbix/assets/fonts
[root@Zabbix_server fonts]#rz -E
rz waiting to receive.
[root@Zabbix_server fonts]#ll
total 12172
drwxr-xr-x 2 zabbix zabbix     4096 May 16 14:14 ./
drwxr-xr-x 5 zabbix zabbix     4096 Apr 27 20:59 ../
-rw-r--r-- 1 zabbix zabbix   756072 Apr 27 20:59 DejaVuSans.ttf
-rw-r--r-- 1 root   root   11697600 Dec  2 20:44 simkai.ttf
# 修改許可權
[root@Zabbix_server fonts]#chown zabbix.zabbix ./*
[root@Zabbix_server fonts]#ll
total 12172
drwxr-xr-x 2 zabbix zabbix     4096 May 16 14:14 ./
drwxr-xr-x 5 zabbix zabbix     4096 Apr 27 20:59 ../
-rw-r--r-- 1 zabbix zabbix   756072 Apr 27 20:59 DejaVuSans.ttf
-rw-r--r-- 1 zabbix zabbix 11697600 Dec  2 20:44 simkai.ttf
4.3.1.3 修改調用字體的文件
[root@Zabbix_server fonts]#vim /var/www/html/zabbix/include/defines.inc.php 
 72 # define('ZBX_GRAPH_FONT_NAME',         'DejaVuSans'); // font file name   # 注釋這行
 73 define('ZBX_GRAPH_FONT_NAME',           'simkai'); // font file name       
 114 # define('ZBX_FONT_NAME', 'DejaVuSans');                                  # 注釋這行
 115 define('ZBX_FONT_NAME', 'simkai');
4.3.1.4 修改調用字體的文件
[root@Zabbix_server fonts]#vim /var/www/html/zabbix/include/defines.inc.php 
 72 # define('ZBX_GRAPH_FONT_NAME',         'DejaVuSans'); // font file name   # 注釋這行
 73 define('ZBX_GRAPH_FONT_NAME',           'simkai'); // font file name       
 114 # define('ZBX_FONT_NAME', 'DejaVuSans');                                  # 注釋這行
 115 define('ZBX_FONT_NAME', 'simkai');
4.3.1.5 驗證字體是否生效

通常不需要重啟zabbix及apache,修改後的字體文件即可直接生效。
在這裡插入圖片描述