Zabbix-部署

目录

一. apt安装 Zabbix

部署结构图和主机环境

在这里插入图片描述

1.1 Zabbix-server 安装配置

1.1.1 安装zabbix仓库

# 下载二进制包
[root@Zabbix_server ~]#wget https://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 http://cn.archive.ubuntu.com/ubuntu bionic InRelease                                               
Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease                                                                  
Hit:3 http://cn.archive.ubuntu.com/ubuntu bionic-updates InRelease                                            
Hit:4 http://cn.archive.ubuntu.com/ubuntu bionic-backports InRelease                                          
Hit:5 http://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 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 http://cn.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://cn.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:4 http://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 https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://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 http://repo.zabbix.com/zabbix/4.0/ubuntu bionic InRelease
Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease        
Hit:3 http://cn.archive.ubuntu.com/ubuntu bionic InRelease
Hit:4 http://cn.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:5 http://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 https://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.
root@172.20.8.101'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
root@172.20.8.101'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,修改后的字体文件即可直接生效。
在这里插入图片描述

posted @ 2020-05-19 11:55  鱼与于玉  阅读(333)  评论(0编辑  收藏  举报