Zabbix系列教程0:安装与配置

刚开机时,资源占用为:

default

服务器上还运行着另一个网站,可能会有误差。

CentOS

先到官网下载相应平台的软件包,我的平台是CentOS8+MySQL+Apache。

安装软件包仓库

1
2
rpm -Uvh https://repo.zabbix.com/zabbix/5.4/rhel/8/x86_64/zabbix-release-5.4-1.el8.noarch.rpm
dnf clean all

对应输出为:

1
2
3
4
5
6
7
8
Retrieving https://repo.zabbix.com/zabbix/5.4/rhel/8/x86_64/zabbix-release-5.4-1.el8.noarch.rpm
warning: /var/tmp/rpm-tmp.KXPgnl: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-5.4-1.el8 ################################# [100%]

48 files removed

安装Zabbix server,Web前端,agent

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
dnf install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-sql-scripts zabbix-agent

#输出为
CentOS Linux 8 - AppStream 13 MB/s | 8.9 MB 00:00
CentOS Linux 8 - BaseOS 6.9 MB/s | 6.5 MB 00:00
CentOS Linux 8 - Extras 14 kB/s | 10 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 58 MB/s | 10 MB 00:00
Zabbix Official Repository - x86_64 25 kB/s | 65 kB 00:02
Zabbix Official Repository non-supported - x86_64 854 B/s | 1.2 kB 00:01
Dependencies resolved.
=========================================================================================================================================================================================
Package Architecture Version Repository Size
=========================================================================================================================================================================================
Installing:
zabbix-agent x86_64 5.4.4-1.el8 zabbix 497 k
zabbix-apache-conf noarch 5.4.4-1.el8 zabbix 20 k
zabbix-server-mysql x86_64 5.4.4-1.el8 zabbix 1.4 M
zabbix-sql-scripts noarch 5.4.4-1.el8 zabbix 4.9 M
zabbix-web-mysql noarch 5.4.4-1.el8 zabbix 19 k
Installing dependencies:
OpenIPMI-libs x86_64 2.0.29-1.el8 baseos 508 k
dejavu-sans-fonts noarch 2.35-7.el8 baseos 1.6 M
fping x86_64 4.2-2.el8 epel 43 k
net-snmp-libs x86_64 1:5.8-20.el8 baseos 824 k
php-bcmath x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 appstream 79 k
php-ldap x86_64 7.2.24-1.module_el8.2.0+313+b04d0a66 appstream 79 k
unixODBC x86_64 2.3.7-1.el8 appstream 458 k
zabbix-web noarch 5.4.4-1.el8 zabbix 3.3 M
zabbix-web-deps noarch 5.4.4-1.el8 zabbix 20 k

Transaction Summary
=========================================================================================================================================================================================
Install 14 Packages

Total download size: 14 M
Installed size: 47 M
Is this ok [y/N]: y
Downloading Packages:
(1/14): php-ldap-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64.rpm 1.9 MB/s | 79 kB 00:00
(2/14): php-bcmath-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64.rpm 1.8 MB/s | 79 kB 00:00
(3/14): unixODBC-2.3.7-1.el8.x86_64.rpm 4.7 MB/s | 458 kB 00:00
(4/14): dejavu-sans-fonts-2.35-7.el8.noarch.rpm 19 MB/s | 1.6 MB 00:00
(5/14): fping-4.2-2.el8.x86_64.rpm 4.5 MB/s | 43 kB 00:00
(6/14): net-snmp-libs-5.8-20.el8.x86_64.rpm 9.7 MB/s | 824 kB 00:00
(7/14): OpenIPMI-libs-2.0.29-1.el8.x86_64.rpm 2.6 MB/s | 508 kB 00:00
(8/14): zabbix-apache-conf-5.4.4-1.el8.noarch.rpm 23 kB/s | 20 kB 00:00
(9/14): zabbix-agent-5.4.4-1.el8.x86_64.rpm 189 kB/s | 497 kB 00:02
(10/14): zabbix-server-mysql-5.4.4-1.el8.x86_64.rpm 295 kB/s | 1.4 MB 00:04
(11/14): zabbix-web-deps-5.4.4-1.el8.noarch.rpm 103 kB/s | 20 kB 00:00
(12/14): zabbix-web-mysql-5.4.4-1.el8.noarch.rpm 98 kB/s | 19 kB 00:00
(13/14): zabbix-web-5.4.4-1.el8.noarch.rpm 694 kB/s | 3.3 MB 00:04
(14/14): zabbix-sql-scripts-5.4.4-1.el8.noarch.rpm 675 kB/s | 4.9 MB 00:07
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.4 MB/s | 14 MB 00:09
warning: /var/cache/dnf/zabbix-d3df1b2842222a01/packages/zabbix-agent-5.4.4-1.el8.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Zabbix Official Repository - x86_64 1.6 MB/s | 1.7 kB 00:00
Importing GPG key 0xA14FE591:
Userid : "Zabbix LLC <packager@zabbix.com>"
Fingerprint: A184 8F53 52D0 22B9 471D 83D0 082A B56B A14F E591
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : fping-4.2-2.el8.x86_64 1/14
Installing : net-snmp-libs-1:5.8-20.el8.x86_64 2/14
Installing : dejavu-sans-fonts-2.35-7.el8.noarch 3/14
Installing : zabbix-web-5.4.4-1.el8.noarch 4/14
Running scriptlet: zabbix-web-5.4.4-1.el8.noarch 4/14
Installing : OpenIPMI-libs-2.0.29-1.el8.x86_64 5/14
Installing : unixODBC-2.3.7-1.el8.x86_64 6/14
Running scriptlet: unixODBC-2.3.7-1.el8.x86_64 6/14
Installing : php-ldap-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 7/14
Installing : php-bcmath-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 8/14
Installing : zabbix-web-mysql-5.4.4-1.el8.noarch 9/14
Installing : zabbix-web-deps-5.4.4-1.el8.noarch 10/14
Installing : zabbix-apache-conf-5.4.4-1.el8.noarch 11/14
Running scriptlet: zabbix-apache-conf-5.4.4-1.el8.noarch 11/14
Running scriptlet: zabbix-server-mysql-5.4.4-1.el8.x86_64 12/14
Installing : zabbix-server-mysql-5.4.4-1.el8.x86_64 12/14
Running scriptlet: zabbix-server-mysql-5.4.4-1.el8.x86_64 12/14
Installing : zabbix-sql-scripts-5.4.4-1.el8.noarch 13/14
Running scriptlet: zabbix-agent-5.4.4-1.el8.x86_64 14/14
Installing : zabbix-agent-5.4.4-1.el8.x86_64 14/14
Running scriptlet: zabbix-agent-5.4.4-1.el8.x86_64 14/14
Verifying : php-bcmath-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 1/14
Verifying : php-ldap-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 2/14
Verifying : unixODBC-2.3.7-1.el8.x86_64 3/14
Verifying : OpenIPMI-libs-2.0.29-1.el8.x86_64 4/14
Verifying : dejavu-sans-fonts-2.35-7.el8.noarch 5/14
Verifying : net-snmp-libs-1:5.8-20.el8.x86_64 6/14
Verifying : fping-4.2-2.el8.x86_64 7/14
Verifying : zabbix-agent-5.4.4-1.el8.x86_64 8/14
Verifying : zabbix-apache-conf-5.4.4-1.el8.noarch 9/14
Verifying : zabbix-server-mysql-5.4.4-1.el8.x86_64 10/14
Verifying : zabbix-sql-scripts-5.4.4-1.el8.noarch 11/14
Verifying : zabbix-web-5.4.4-1.el8.noarch 12/14
Verifying : zabbix-web-deps-5.4.4-1.el8.noarch 13/14
Verifying : zabbix-web-mysql-5.4.4-1.el8.noarch 14/14

Installed:
OpenIPMI-libs-2.0.29-1.el8.x86_64 dejavu-sans-fonts-2.35-7.el8.noarch fping-4.2-2.el8.x86_64 net-snmp-libs-1:5.8-20.el8.x86_64
php-bcmath-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 php-ldap-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 unixODBC-2.3.7-1.el8.x86_64 zabbix-agent-5.4.4-1.el8.x86_64
zabbix-apache-conf-5.4.4-1.el8.noarch zabbix-server-mysql-5.4.4-1.el8.x86_64 zabbix-sql-scripts-5.4.4-1.el8.noarch zabbix-web-5.4.4-1.el8.noarch
zabbix-web-deps-5.4.4-1.el8.noarch zabbix-web-mysql-5.4.4-1.el8.noarch

Complete!

MySQL数据库

安装配置不在本文范围内容,可以在本站找到安装配置教程。

1
2
sudo systemctl enable mariadb
sudo systemctl start mariadb

启动MySQL服务器之后,资源占用为:

mariadb

数据库相关,先登录数据库,然后执行

1
2
3
4
5
6
7
8
9
10
mysql -uroot -p
input-your-password
mysql> create database zabbix character set utf8 collate utf8_bin;
# Query OK, 1 row affected (0.000 sec)
mysql> create user zabbix@localhost identified by 'your-password';
# Query OK, 0 row affected (0.000 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost;
# Query OK, 0 row affected (0.000 sec)
mysql> quit;
# Bye

导入初始架构和数据,系统将提示您输入新创建的密码。

1
zcat /usr/share/doc/zabbix-sql-scripts/mysql/create.sql.gz | mysql -uzabbix -p zabbix 

密码就是上面的your-password

没有任何输出,过程会持续十几秒。

为了确定成功,我们登录数据库查看一下。

db

刚刚我们只创建了数据库zabbix,并没有添加数据表,现在有了166个数据表。

为Zabbix server配置数据库

编辑配置文件/etc/zabbix/zabbix_server.conf第129行

1
DBPassword=your-password 

启动Zabbix server和agent进程

单独启动php的话,资源占用为:

php

启动Zabbix server和agent进程,并为它们设置开机自启:

1
2
systemctl restart zabbix-server zabbix-agent httpd php-fpm
systemctl enable zabbix-server zabbix-agent httpd php-fpm

全部启动完之后,资源占用为:

server

/usr/share/zabbix文件夹中的PHP网站复制到Apache网站根目录下。

具体安装过程见安装Zabbix前端

Ubuntu

安装Zabbix前端

根据安装教程安装。

打开主页,会自动显示安装向导页面

setup

我选择了中文,然后点击下一步。

会出现检测页面,有几个错误

check

为了避免以后的麻烦,在此将所有错误修复。

noerror

继续点击下一步,出现数据库配置页面

database

将之前配置的信息填入,点击下一步,会出现信息设置界面

info

随便填。点击下一步,会出现设置界面,主要是设置时区和主题

settings

我设置的是东八区UTC+8亚洲上海。点击下一步继续。

出现安装汇总

sum

点击下一步

完成

点击完成之后会自动跳转到登录界面

login

默认登录用户为Admin,密码为zabbix

登录之后会显示默认的界面

控制台

接下来就是各种操作了。

总结

  • 部署的服务器至少需要1核1G内存
  • 至少要学会一种Linux发行版的软件包安装与服务配置
  • 如果熟悉shell脚本的话,可以把一些配置过程简化为脚本