3.2安装zabbix server及agent
2.安装zabbix server
在安装zabbix server 之前,需要满足一定的环境要求。例如,需要安装数据库,为了方便,这里直接安装Mariadb(也可以安装MySQL数据库),zabbix也支持其他数据库,像Oracle,pgsql等。Mariadb是MySQL数据库的一个分支数据库,与MySQL数据库的使用方法相同。
2.1准备
需要准备一台Linux主机。在这台主机上安装数据库(存储数据)、zabbix server(采集数据、检测问题、管理事件、发送通知)、zabbix前端(展示数据、配置管理)、zabbix agent(收集主机信息)。
提示
这里需要遵循Zabbix官方建议。
为了方便,主机提前做好以下配置:
- 配置ip
- 配置主机名
- 关闭防火墙
#关闭防火墙
systemctl stop firewalld
#取消开机自启动
systemctl disable firewalld
#查看防火墙状态
systemctl status firewalld
- 关闭Selinux
将SELINUX=enforcing
改成SELINUX=disabled
- 配置yum源
[server1]
name=8.10
baseurl=http://192.168.3.8/redhat/AppStream
gpgcheck=0
[server2]
name=8.10
baseurl=http://192.168.3.8/redhat/BaseOS
gpgcheck=0
检查yum源配置
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server.
You can use subscription-manager to register.
repo id repo name status
server1 8.10 enabled
server2 8.10 enabled
2.2操作步骤
2.2.1 添加zabbix6.0的安装源
在centos Linux或者redhat Linux主机中执行以下安装命令。
dnf install -y https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-latest.el8.noarch.rpm
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Last metadata expiration check: 0:10:43 ago on Sat 22 Jun 2024 06:37:57 PM CST.
zabbix-release-latest.el8.noarch.rpm 22 kB/s | 19 kB 00:00
Dependencies resolved.
============================================================================================================================================================================================================
Package Architecture Version Repository Size
============================================================================================================================================================================================================
Installing:
zabbix-release noarch 6.0-5.el8 @commandline 19 k
Transaction Summary
============================================================================================================================================================================================================
Install 1 Package
Total size: 19 k
Installed size: 22 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : zabbix-release-6.0-5.el8.noarch 1/1
Verifying : zabbix-release-6.0-5.el8.noarch 1/1
Installed products updated.
Installed:
zabbix-release-6.0-5.el8.noarch
Complete!
2.2.2 配置mariadb安装源
在Linux主机上添加mariadb数据库的安装源,安装命令如下:
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod u+x mariadb_repo_setup
./mariadb_repo_setup
[root@zabbix ~]# wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
--2024-11-06 11:22:46-- https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
Resolving downloads.mariadb.com (downloads.mariadb.com)... 104.18.135.24, 104.17.191.14, 2606:4700::6812:8718, ...
Connecting to downloads.mariadb.com (downloads.mariadb.com)|104.18.135.24|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 36734 (36K) [application/octet-stream]
Saving to: ‘mariadb_repo_setup’
mariadb_repo_setup 100%[================================================================================================================>] 35.87K 72.3KB/s in 0.5s
2024-11-06 11:22:51 (72.3 KB/s) - ‘mariadb_repo_setup’ saved [36734/36734]
[root@zabbix ~]# chmod u+x mariadb_repo_setup
[root@zabbix ~]# ./mariadb_repo_setup
# [info] Checking for script prerequisites.
# [info] MariaDB Server version 11.rolling is valid
# [info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo
# [info] Adding trusted package signing keys...
/etc/pki/rpm-gpg ~
~
# [info] Successfully added trusted package signing keys
# [info] Cleaning package cache...
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
28 files removed
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# cd /etc/yum.repos.d/
[root@zabbix yum.repos.d]# ll
total 20
-rw-r--r-- 1 root root 786 Nov 6 11:23 mariadb.repo
-rw-r--r-- 1 root root 358 Jun 22 18:36 redhat.repo
-rw-r--r-- 1 root root 149 Jun 22 18:35 server.repo
-rw-r--r-- 1 root root 230 Jul 3 02:28 zabbix-agent2-plugins.repo
-rw-r--r-- 1 root root 628 Jul 3 02:28 zabbix.repo
2.2.3 安装和启动mariadb
在Linux主机上安装mariadb数据库,安装和启动命令如下:
[root@zabbix yum.repos.d]# dnf install mariadb-server
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
MariaDB Server 94 kB/s | 739 kB 00:07
MariaDB MaxScale 574 B/s | 7.0 kB 00:12
MariaDB Tools 512 B/s | 4.3 kB 00:08
8.10 76 MB/s | 8.7 MB 00:00
8.10 63 MB/s | 2.4 MB 00:00
Zabbix Official Repository - x86_64 86 kB/s | 493 kB 00:05
Zabbix Official Repository (non-supported) - x86_64 985 B/s | 1.4 kB 00:01
Zabbix Official Repository (Agent2 Plugins) - x86_64 754 B/s | 1.7 kB 00:02
Dependencies resolved.
============================================================================================================================================================================================================
Package Architecture Version Repository Size
============================================================================================================================================================================================================
Installing:
MariaDB-server x86_64 11.5.2-1.el8 mariadb-main 27 M
Installing dependencies:
MariaDB-client x86_64 11.5.2-1.el8 mariadb-main 17 M
MariaDB-common x86_64 11.5.2-1.el8 mariadb-main 88 k
MariaDB-shared x86_64 11.5.2-1.el8 mariadb-main 131 k
galera-4 x86_64 26.4.19-1.el8 mariadb-main 1.7 M
liburing x86_64 1.0.7-3.el8 server2 24 k
socat x86_64 1.7.4.1-1.el8 server1 323 k
Installing weak dependencies:
MariaDB-client-compat noarch 11.5.2-1.el8 mariadb-main 11 k
MariaDB-server-compat noarch 11.5.2-1.el8 mariadb-main 8.9 k
Transaction Summary
============================================================================================================================================================================================================
Install 9 Packages
Total download size: 46 M
Installed size: 239 M
Is this ok [y/N]: y
Downloading Packages:
(1/9): MariaDB-client-compat-11.5.2-1.el8.noarch.rpm 3.0 kB/s | 11 kB 00:03
(2/9): MariaDB-common-11.5.2-1.el8.x86_64.rpm 17 kB/s | 88 kB 00:05
(3/9): MariaDB-server-compat-11.5.2-1.el8.noarch.rpm 6.5 kB/s | 8.9 kB 00:01
(4/9): MariaDB-shared-11.5.2-1.el8.x86_64.rpm 42 kB/s | 131 kB 00:03
(5/9): galera-4-26.4.19-1.el8.x86_64.rpm 290 kB/s | 1.7 MB 00:06
(6/9): socat-1.7.4.1-1.el8.x86_64.rpm 2.1 MB/s | 323 kB 00:00
(7/9): liburing-1.0.7-3.el8.x86_64.rpm 11 MB/s | 24 kB 00:00
(8/9): MariaDB-client-11.5.2-1.el8.x86_64.rpm 312 kB/s | 17 MB 00:55
(9/9): MariaDB-server-11.5.2-1.el8.x86_64.rpm 131 kB/s | 27 MB 03:32
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 220 kB/s | 46 MB 03:36
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : MariaDB-shared-11.5.2-1.el8.x86_64 1/9
Running scriptlet: MariaDB-shared-11.5.2-1.el8.x86_64 1/9
Installing : MariaDB-common-11.5.2-1.el8.x86_64 2/9
Installing : liburing-1.0.7-3.el8.x86_64 3/9
Installing : MariaDB-client-compat-11.5.2-1.el8.noarch 4/9
Installing : MariaDB-client-11.5.2-1.el8.x86_64 5/9
Installing : socat-1.7.4.1-1.el8.x86_64 6/9
Running scriptlet: galera-4-26.4.19-1.el8.x86_64 7/9
Installing : galera-4-26.4.19-1.el8.x86_64 7/9
Running scriptlet: galera-4-26.4.19-1.el8.x86_64 7/9
Installing : MariaDB-server-compat-11.5.2-1.el8.noarch 8/9
Running scriptlet: MariaDB-server-11.5.2-1.el8.x86_64 9/9
Installing : MariaDB-server-11.5.2-1.el8.x86_64 9/9
Running scriptlet: MariaDB-server-11.5.2-1.el8.x86_64 9/9
2024-11-06 11:35:16 0 [Warning] mariadbd: io_uring_queue_init() failed with ENOSYS: check seccomp filters, and the kernel version (newer than 5.1 required)
2024-11-06 11:35:16 0 [Warning] InnoDB: liburing disabled: falling back to innodb_use_native_aio=OFF
Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo
See the MariaDB Knowledgebase at https://mariadb.com/kb
Please report any problems at https://mariadb.org/jira
The latest information about MariaDB is available at https://mariadb.org/.
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
Verifying : MariaDB-client-11.5.2-1.el8.x86_64 1/9
Verifying : MariaDB-client-compat-11.5.2-1.el8.noarch 2/9
Verifying : MariaDB-common-11.5.2-1.el8.x86_64 3/9
Verifying : MariaDB-server-11.5.2-1.el8.x86_64 4/9
Verifying : MariaDB-server-compat-11.5.2-1.el8.noarch 5/9
Verifying : MariaDB-shared-11.5.2-1.el8.x86_64 6/9
Verifying : galera-4-26.4.19-1.el8.x86_64 7/9
Verifying : socat-1.7.4.1-1.el8.x86_64 8/9
Verifying : liburing-1.0.7-3.el8.x86_64 9/9
Installed products updated.
Installed:
MariaDB-client-11.5.2-1.el8.x86_64 MariaDB-client-compat-11.5.2-1.el8.noarch MariaDB-common-11.5.2-1.el8.x86_64 MariaDB-server-11.5.2-1.el8.x86_64 MariaDB-server-compat-11.5.2-1.el8.noarch
MariaDB-shared-11.5.2-1.el8.x86_64 galera-4-26.4.19-1.el8.x86_64 liburing-1.0.7-3.el8.x86_64 socat-1.7.4.1-1.el8.x86_64
Complete!
[root@zabbix yum.repos.d]#
[root@zabbix yum.repos.d]# systemctl enable mariadb
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@zabbix yum.repos.d]# systemctl start mariadb
在安装完mariadb数据库之后,执行以下命令对数据库进行安全初始化:
[root@zabbix yum.repos.d]# /usr/bin/mariadb-secure-installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.'
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] y
New password: abcd@2024
Re-enter new password: abcd@2024
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@zabbix yum.repos.d]#
2.2.4 安装MySQL依赖
为了使zabbix支持MySQL数据库,需要进行以下依赖组件的安装。
[root@zabbix ~]# dnf install zabbix-server-mysql zabbix-sql-scripts
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Last metadata expiration check: 0:15:35 ago on Wed 06 Nov 2024 11:42:31 AM CST.
Dependencies resolved.
============================================================================================================================================================================================================
Package Architecture Version Repository Size
============================================================================================================================================================================================================
Installing:
zabbix-server-mysql x86_64 6.0.35-release1.el8 zabbix 1.8 M
zabbix-sql-scripts noarch 6.0.35-release1.el8 zabbix 8.3 M
Installing dependencies:
OpenIPMI-libs x86_64 2.0.31-3.el8 server2 509 k
fping x86_64 5.1-1.el8 zabbix-non-supported 37 k
unixODBC x86_64 2.3.7-1.el8 server1 458 k
Transaction Summary
============================================================================================================================================================================================================
Install 5 Packages
Total download size: 11 M
Installed size: 20 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): unixODBC-2.3.7-1.el8.x86_64.rpm 11 MB/s | 458 kB 00:00
(2/5): OpenIPMI-libs-2.0.31-3.el8.x86_64.rpm 11 MB/s | 509 kB 00:00
(3/5): fping-5.1-1.el8.x86_64.rpm 34 kB/s | 37 kB 00:01
(4/5): zabbix-sql-scripts-6.0.35-release1.el8.noarch.rpm 2.3 MB/s | 8.3 MB 00:03
(5/5): zabbix-server-mysql-6.0.35-release1.el8.x86_64.rpm 169 kB/s | 1.8 MB 00:10
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.0 MB/s | 11 MB 00:10
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
Zabbix Official Repository (non-supported) - x86_64 1.3 MB/s | 1.3 kB 00:00
Importing GPG key 0x79EA5ED4:
Userid : "Zabbix SIA <packager@zabbix.com>"
Fingerprint: FBAB D5FB 2025 5ECA B22E E194 D13D 58E4 79EA 5ED4
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
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-5.1-1.el8.x86_64 1/5
Installing : OpenIPMI-libs-2.0.31-3.el8.x86_64 2/5
Installing : unixODBC-2.3.7-1.el8.x86_64 3/5
Running scriptlet: unixODBC-2.3.7-1.el8.x86_64 3/5
Running scriptlet: zabbix-server-mysql-6.0.35-release1.el8.x86_64 4/5
Installing : zabbix-server-mysql-6.0.35-release1.el8.x86_64 4/5
Running scriptlet: zabbix-server-mysql-6.0.35-release1.el8.x86_64 4/5
Installing : zabbix-sql-scripts-6.0.35-release1.el8.noarch 5/5
Running scriptlet: zabbix-sql-scripts-6.0.35-release1.el8.noarch 5/5
Verifying : unixODBC-2.3.7-1.el8.x86_64 1/5
Verifying : OpenIPMI-libs-2.0.31-3.el8.x86_64 2/5
Verifying : zabbix-server-mysql-6.0.35-release1.el8.x86_64 3/5
Verifying : zabbix-sql-scripts-6.0.35-release1.el8.noarch 4/5
Verifying : fping-5.1-1.el8.x86_64 5/5
Installed products updated.
Installed:
OpenIPMI-libs-2.0.31-3.el8.x86_64 fping-5.1-1.el8.x86_64 unixODBC-2.3.7-1.el8.x86_64 zabbix-server-mysql-6.0.35-release1.el8.x86_64 zabbix-sql-scripts-6.0.35-release1.el8.noarch
Complete!
[root@zabbix ~]#
2.2.5 创建zabbix数据库
要想安装zabbix server,还要为zabbix创建数据库,执行以下命令登入mariadb数据库:
在输入密码后,进入到mariadb数据库的命令行界面,使用下面命令来创建zabbix数据库,但是不要忘记在第二行命令中更改password(密码):
create database zabbix character set utf8mb4 collate utf8mb4_bin;
create user zabbix@localhost identified by 'Oracle123';
grant all privileges on zabbix.* to 'zabbix'@'localhost';
flush privileges;
quit;
[root@zabbix ~]# /usr/bin/mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 11.5.2-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> create user zabbix@localhost identified by 'Oracle123';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+--------------------+
5 rows in set (0.001 sec)
MariaDB [(none)]> select host,user from mysql.user;
+-----------+-------------+
| Host | User |
+-----------+-------------+
| | PUBLIC |
| localhost | mariadb.sys |
| localhost | mysql |
| localhost | root |
| localhost | zabbix |
+-----------+-------------+
5 rows in set (0.002 sec)
MariaDB [(none)]>
提示
zabbix 现在也支持utf8mb4字符集。在上面的命令中,zabbix已将之前所使用的utf8字符集更改为utf8mb4字符集。
2.2.6 导入数据
现在将zabbix初始化数据库结构和数据导入新创建的zabbix数据库中,这包含了数据库的表结构和一些初始化数据,比如初始账号、密码,以及开箱即用的模板,导入密令如下:
zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | /usr/bin/mariadb -uzabbix -pOracle123 zabbix
[root@zabbix ~]# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | /usr/bin/mariadb -uzabbix -pOracle123 zabbix
[root@zabbix ~]# /usr/bin/mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 20
Server version: 11.5.2-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+--------------------+
5 rows in set (0.001 sec)
MariaDB [(none)]> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| auditlog |
| autoreg_host |
| conditions |
| config |
| config_autoreg_tls |
| corr_condition |
| corr_condition_group |
| corr_condition_tag |
| corr_condition_tagpair |
| corr_condition_tagvalue |
| corr_operation |
| correlation |
| dashboard |
| dashboard_page |
| 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 |
| ha_node |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| host_tag |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| hstgrp |
| httpstep |
| httpstep_field |
| httpstepitem |
| httptest |
| httptest_field |
| httptest_tag |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| interface_snmp |
| item_condition |
| item_discovery |
| item_parameter |
| item_preproc |
| item_rtdata |
| item_tag |
| items |
| lld_macro_path |
| lld_override |
| lld_override_condition |
| lld_override_opdiscover |
| lld_override_operation |
| lld_override_ophistory |
| lld_override_opinventory |
| lld_override_opperiod |
| lld_override_opseverity |
| lld_override_opstatus |
| lld_override_optag |
| lld_override_optemplate |
| lld_override_optrends |
| maintenance_tag |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| media |
| media_type |
| media_type_message |
| media_type_param |
| module |
| 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 |
| report |
| report_param |
| report_user |
| report_usrgrp |
| rights |
| role |
| role_rule |
| script_param |
| scripts |
| service_alarms |
| service_problem |
| service_problem_tag |
| service_status_rule |
| service_tag |
| services |
| services_links |
| sessions |
| sla |
| sla_excluded_downtime |
| sla_schedule |
| sla_service_tag |
| sysmap_element_trigger |
| sysmap_element_url |
| sysmap_shape |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_element_tag |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| tag_filter |
| task |
| task_acknowledge |
| task_check_now |
| task_close_problem |
| task_data |
| task_remote_command |
| task_remote_command_result |
| task_result |
| timeperiods |
| token |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| trigger_queue |
| trigger_tag |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemap |
| valuemap_mapping |
| widget |
| widget_field |
+----------------------------+
173 rows in set (0.001 sec)
提示
在数据导入的过程中,由于数据量较大,可能需要等待数十秒,在这段时间屏幕可能显示空白,或者系统没有任何反应。不用担心,这属于正常情况。
现在完成了mariadb数据库的准备工作,接下来配置zabbix server。
2.2.7 配置启动zabbix server
zabbix server通过使用配置文件进行配置。此文件位于/etc/zabbix/目录中。这里通过vi 命令编辑此文件。
使用以下参数配置zabbix server与数据库的连接,包含DBName(数据库名称),DBUser(数据库用户名),DBPassword(数据库用户密码)。
提示
在启动zabbix之前,你应该配置selinux和防火墙以便允许zabbix启动和使用。如果这是一台测试主机,那么建议禁用selinux和防火墙。
以下命令分别是禁用selinux、禁用防火墙、关闭开机启动防火墙的命令:
在以上配置完毕后,可以通过以下命令启动zabbix server:
可以通过以下命令,检测zabbix server是否正常启动
[root@zabbix ~]# systemctl enable zabbix-server
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /usr/lib/systemd/system/zabbix-server.service.
[root@zabbix ~]# systemctl start zabbix-server
[root@zabbix ~]# systemctl status zabbix-server
● zabbix-server.service - Zabbix Server
Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2024-11-06 14:53:51 CST; 15s ago
Process: 58254 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS)
Main PID: 58256 (zabbix_server)
Tasks: 48 (limit: 102119)
Memory: 51.4M
CGroup: /system.slice/zabbix-server.service
├─58256 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
├─58258 /usr/sbin/zabbix_server: ha manager
├─58259 /usr/sbin/zabbix_server: service manager #1 [processed 0 events, updated 0 event tags, deleted 0 problems, synced 0 service updates, idle 5.005291 sec during 5.005407 sec]
├─58260 /usr/sbin/zabbix_server: configuration syncer [synced configuration in 0.156126 sec, idle 60 sec]
├─58264 /usr/sbin/zabbix_server: alert manager #1 [sent 0, failed 0 alerts, idle 5.003761 sec during 5.003835 sec]
├─58265 /usr/sbin/zabbix_server: alerter #1 started
├─58266 /usr/sbin/zabbix_server: alerter #2 started
├─58268 /usr/sbin/zabbix_server: alerter #3 started
├─58269 /usr/sbin/zabbix_server: preprocessing manager #1 [queued 0, processed 1 values, idle 5.004279 sec during 5.004353 sec]
├─58270 /usr/sbin/zabbix_server: preprocessing worker #1 started
├─58271 /usr/sbin/zabbix_server: preprocessing worker #2 started
├─58272 /usr/sbin/zabbix_server: preprocessing worker #3 started
├─58273 /usr/sbin/zabbix_server: lld manager #1 [processed 0 LLD rules, idle 5.001769sec during 5.001845 sec]
├─58274 /usr/sbin/zabbix_server: lld worker #1 started
├─58275 /usr/sbin/zabbix_server: lld worker #2 started
├─58276 /usr/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
├─58277 /usr/sbin/zabbix_server: timer #1 [updated 0 hosts, suppressed 0 events in 0.000973 sec, idle 59 sec]
├─58280 /usr/sbin/zabbix_server: http poller #1 [got 0 values in 0.000807 sec, idle 5 sec]
├─58282 /usr/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.000493 sec, idle 60 sec]
├─58283 /usr/sbin/zabbix_server: history syncer #1 [processed 0 values, 0 triggers in 0.000022 sec, idle 1 sec]
├─58284 /usr/sbin/zabbix_server: history syncer #2 [processed 0 values, 0 triggers in 0.000021 sec, idle 1 sec]
├─58287 /usr/sbin/zabbix_server: history syncer #3 [processed 0 values, 0 triggers in 0.000020 sec, idle 1 sec]
├─58289 /usr/sbin/zabbix_server: history syncer #4 [processed 0 values, 0 triggers in 0.000023 sec, idle 1 sec]
├─58290 /usr/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.001804 sec, idle 3 sec]
├─58292 /usr/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000016 sec, idle 5 sec]
├─58293 /usr/sbin/zabbix_server: self-monitoring [processed data in 0.000037 sec, idle 1 sec]
├─58294 /usr/sbin/zabbix_server: task manager [processed 0 task(s) in 0.000770 sec, idle 5 sec]
├─58295 /usr/sbin/zabbix_server: poller #1 [got 0 values in 0.000027 sec, idle 1 sec]
├─58299 /usr/sbin/zabbix_server: poller #2 [got 0 values in 0.000037 sec, idle 1 sec]
├─58300 /usr/sbin/zabbix_server: poller #3 [got 0 values in 0.000017 sec, idle 1 sec]
├─58301 /usr/sbin/zabbix_server: poller #4 [got 0 values in 0.000027 sec, idle 1 sec]
├─58302 /usr/sbin/zabbix_server: poller #5 [got 0 values in 0.000039 sec, idle 1 sec]
├─58303 /usr/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000017 sec, idle 1 sec]
├─58304 /usr/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection]
├─58305 /usr/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting for connection]
├─58306 /usr/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection]
├─58308 /usr/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection]
├─58310 /usr/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection]
├─58311 /usr/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000031 sec, idle 5 sec]
├─58314 /usr/sbin/zabbix_server: alert syncer [queued 0 alerts(s), flushed 0 result(s) in 0.000531 sec, idle 1 sec]
├─58316 /usr/sbin/zabbix_server: history poller #1 [got 1 values in 0.000086 sec, idle 5 sec]
├─58318 /usr/sbin/zabbix_server: history poller #2 [got 0 values in 0.000028 sec, idle 5 sec]
├─58320 /usr/sbin/zabbix_server: history poller #3 [got 0 values in 0.000027 sec, idle 5 sec]
├─58321 /usr/sbin/zabbix_server: history poller #4 [got 0 values in 0.000019 sec, idle 5 sec]
├─58323 /usr/sbin/zabbix_server: history poller #5 [got 0 values in 0.000033 sec, idle 5 sec]
├─58325 /usr/sbin/zabbix_server: availability manager #1 [queued 0, processed 1 values, idle 5.003752 sec during 5.005121 sec]
├─58328 /usr/sbin/zabbix_server: trigger housekeeper [startup idle for 60 second(s)]
└─58330 /usr/sbin/zabbix_server: odbc poller #1 [got 0 values in 0.000018 sec, idle 5 sec]
Nov 06 14:53:50 zabbix systemd[1]: Starting Zabbix Server...
Nov 06 14:53:51 zabbix systemd[1]: Started Zabbix Server.
也可以通过查看日志的方式确认zabbix server是否启动,zabbix server提供了详细的启动过程的记录。
[root@zabbix ~]# tail -100f /var/log/zabbix/zabbix_server.log
58256:20241106:145350.994 Starting Zabbix Server. Zabbix 6.0.35 (revision 8a9017e52e7).
58256:20241106:145350.995 ****** Enabled features ******
58256:20241106:145350.995 SNMP monitoring: YES
58256:20241106:145350.995 IPMI monitoring: YES
58256:20241106:145350.995 Web monitoring: YES
58256:20241106:145350.995 VMware monitoring: YES
58256:20241106:145350.995 SMTP authentication: YES
58256:20241106:145350.995 ODBC: YES
58256:20241106:145350.995 SSH support: YES
58256:20241106:145350.995 IPv6 support: YES
58256:20241106:145350.995 TLS support: YES
58256:20241106:145350.995 ******************************
58256:20241106:145350.995 using configuration file: /etc/zabbix/zabbix_server.conf
58256:20241106:145351.004 current database version (mandatory/optional): 06000000/06000054
58256:20241106:145351.004 required mandatory version: 06000000
58258:20241106:145351.008 starting HA manager
58258:20241106:145351.012 HA manager started in active mode
58256:20241106:145351.013 server #0 started [main process]
58259:20241106:145351.014 server #1 started [service manager #1]
58260:20241106:145351.014 server #2 started [configuration syncer #1]
58264:20241106:145351.174 server #3 started [alert manager #1]
58265:20241106:145351.174 server #4 started [alerter #1]
58266:20241106:145351.175 server #5 started [alerter #2]
58268:20241106:145351.175 server #6 started [alerter #3]
58269:20241106:145351.176 server #7 started [preprocessing manager #1]
58271:20241106:145351.176 server #9 started [preprocessing worker #2]
58272:20241106:145351.177 server #10 started [preprocessing worker #3]
58273:20241106:145351.177 server #11 started [lld manager #1]
58274:20241106:145351.177 server #12 started [lld worker #1]
58275:20241106:145351.178 server #13 started [lld worker #2]
58276:20241106:145351.178 server #14 started [housekeeper #1]
58277:20241106:145351.179 server #15 started [timer #1]
58280:20241106:145351.179 server #16 started [http poller #1]
58282:20241106:145351.180 server #17 started [discoverer #1]
58283:20241106:145351.180 server #18 started [history syncer #1]
58284:20241106:145351.180 server #19 started [history syncer #2]
58287:20241106:145351.181 server #20 started [history syncer #3]
58290:20241106:145351.182 server #22 started [escalator #1]
58292:20241106:145351.182 server #23 started [proxy poller #1]
58293:20241106:145351.183 server #24 started [self-monitoring #1]
58294:20241106:145351.184 server #25 started [task manager #1]
58295:20241106:145351.184 server #26 started [poller #1]
58299:20241106:145351.185 server #27 started [poller #2]
58300:20241106:145351.186 server #28 started [poller #3]
58301:20241106:145351.186 server #29 started [poller #4]
58302:20241106:145351.187 server #30 started [poller #5]
58303:20241106:145351.187 server #31 started [unreachable poller #1]
58304:20241106:145351.188 server #32 started [trapper #1]
58305:20241106:145351.188 server #33 started [trapper #2]
58306:20241106:145351.189 server #34 started [trapper #3]
58308:20241106:145351.189 server #35 started [trapper #4]
58310:20241106:145351.190 server #36 started [trapper #5]
58311:20241106:145351.190 server #37 started [icmp pinger #1]
58314:20241106:145351.191 server #38 started [alert syncer #1]
58316:20241106:145351.191 server #39 started [history poller #1]
58318:20241106:145351.192 server #40 started [history poller #2]
58320:20241106:145351.192 server #41 started [history poller #3]
58321:20241106:145351.193 server #42 started [history poller #4]
58323:20241106:145351.193 server #43 started [history poller #5]
58325:20241106:145351.194 server #44 started [availability manager #1]
58328:20241106:145351.194 server #45 started [trigger housekeeper #1]
58330:20241106:145351.194 server #46 started [odbc poller #1]
58289:20241106:145351.195 server #21 started [history syncer #4]
58270:20241106:145351.276 server #8 started [preprocessing worker #1]
58295:20241106:145352.186 Zabbix agent item "system.localtime" on host "Zabbix server" failed: first network error, wait for 15 seconds
58289:20241106:145355.204 item "Zabbix server:zabbix[vmware,buffer,pused]" became not supported: No "vmware collector" processes started.
58289:20241106:145358.216 item "Zabbix server:zabbix[process,report writer,avg,busy]" became not supported: No "report writer" processes started.
58289:20241106:145359.218 item "Zabbix server:zabbix[process,report manager,avg,busy]" became not supported: No "report manager" processes started.
58303:20241106:145407.205 Zabbix agent item "system.swap.size[,pfree]" on host "Zabbix server" failed: another network error, wait for 15 seconds
58303:20241106:145422.220 Zabbix agent item "vm.memory.size[available]" on host "Zabbix server" failed: another network error, wait for 15 seconds
58303:20241106:145437.236 temporarily disabling Zabbix agent checks on host "Zabbix server": interface unavailable
58289:20241106:145441.246 item "Zabbix server:zabbix[process,ipmi poller,avg,busy]" became not supported: No "ipmi poller" processes started.
58289:20241106:145442.249 item "Zabbix server:zabbix[process,java poller,avg,busy]" became not supported: No "java poller" processes started.
58289:20241106:145447.257 item "Zabbix server:zabbix[process,snmp trapper,avg,busy]" became not supported: No "snmp trapper" processes started.
58289:20241106:145447.257 item "Zabbix server:zabbix[process,ipmi manager,avg,busy]" became not supported: No "ipmi manager" processes started.
58289:20241106:145448.260 item "Zabbix server:zabbix[process,vmware collector,avg,busy]" became not supported: No "vmware collector" processes started.
2.2.8 安装和配置zabbix agent
- 安装zabbix agent
安装zabbix agent,需要在主机上执行以下命令:
[root@zabbix ~]# dnf install -y zabbix-agent2
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Last metadata expiration check: 0:31:01 ago on Fri 15 Nov 2024 01:47:10 PM CST.
Dependencies resolved.
====================================================================================================================================================================================================
Package Architecture Version Repository Size
====================================================================================================================================================================================================
Installing:
zabbix-agent2 x86_64 6.0.35-release1.el8 zabbix 5.7 M
Installing dependencies:
zabbix-agent2-plugin-mongodb x86_64 6.0.35-release1.el8 zabbix 3.6 M
zabbix-agent2-plugin-postgresql x86_64 6.0.35-release1.el8 zabbix 2.9 M
Transaction Summary
====================================================================================================================================================================================================
Install 3 Packages
Total download size: 12 M
Installed size: 39 M
Downloading Packages:
(1/3): zabbix-agent2-plugin-postgresql-6.0.35-release1.el8.x86_64.rpm 30 kB/s | 2.9 MB 01:40
(2/3): zabbix-agent2-plugin-mongodb-6.0.35-release1.el8.x86_64.rpm 28 kB/s | 3.6 MB 02:12
(3/3): zabbix-agent2-6.0.35-release1.el8.x86_64.rpm 27 kB/s | 5.7 MB 03:39
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 57 kB/s | 12 MB 03:39
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : zabbix-agent2-plugin-postgresql-6.0.35-release1.el8.x86_64 1/3
Installing : zabbix-agent2-plugin-mongodb-6.0.35-release1.el8.x86_64 2/3
Running scriptlet: zabbix-agent2-6.0.35-release1.el8.x86_64 3/3
Installing : zabbix-agent2-6.0.35-release1.el8.x86_64 3/3
Running scriptlet: zabbix-agent2-6.0.35-release1.el8.x86_64 3/3
Verifying : zabbix-agent2-6.0.35-release1.el8.x86_64 1/3
Verifying : zabbix-agent2-plugin-mongodb-6.0.35-release1.el8.x86_64 2/3
Verifying : zabbix-agent2-plugin-postgresql-6.0.35-release1.el8.x86_64 3/3
Installed products updated.
Installed:
zabbix-agent2-6.0.35-release1.el8.x86_64 zabbix-agent2-plugin-mongodb-6.0.35-release1.el8.x86_64 zabbix-agent2-plugin-postgresql-6.0.35-release1.el8.x86_64
Complete!
[root@zabbix ~]#
- 配置agent
在zabbix agent2安装完后,执行以下命令打开配置文件进行编辑
通过编辑此文件,可以配置zabbix agent2所需的配置参数。
编辑并配置以下参数,将server
等号右边的值修改为zabbix server的IP地址。将hostname
的值修改为被监控主机的主机名
- 启动zabbix agent2
执行以下命令配置开机启动,并重启zabbix agent2
- 在web前端配置
接下来,访问zabbix的web前端,并添加此主机进行监控。
单机“Configuration”->“host”选项,然后单机页面右上角的“create host”,打开如图所示的页面
配置说明
host name:被监控主机的主机名,作为被监控对象的唯一标识。
Groups:对被监控主机作为逻辑分组。
interface:配置特定的监控接口,也就是被监控主机的IP地址及端口(默认为10050),被监控主机通过接口进行通信。zabbix 6.0允许被监控主机不配置接口,但是如果使用zabbix agent2进行监控,就必须配置一个接口。
2.3.工作原理
zabbix server是整个zabbix架构的核心组件之一,主要负责收集监控数据,判断问题,发送告警信息等。一个完整的zabbix server架构由以下几项构成:
- 一台数据库(MySQL、postgresql或者oracle)主机
- 一台zabbix server主机
- 一台用于运行zabbix前端(zabbix forntend)的web主机
web主机可以选择apche或者nginx,php版本至少高于7.2,从zabbix6.0.6已经开始支持php 8.0和php 8.1版本。
刚刚已经安装了zabbix server和数据库,当启动这2个核心服务后,基本上就可以开始进行监控了。
现在zabbix server已经将监控数据写进了zabbix数据库,接下来需要通过zabbix前端进行相关的配置管理,下面介绍如何安装zabbix前端。