部署Zabbix4.0服务
简介
测试部署zabbix 4.0,zabbix服务需要用到zabbix-server,zabbix-proxy,zabbix-agent,zabbix-web组件和mysql数据库;
参考链接:1 Red Hat Enterprise Linux/CentOS (zabbix.com)
环境
主机名 | 系统 | IP | 功能 | 备注 |
---|---|---|---|---|
test | CentOS7.9 | 172.17.91.179 | zabbix服务器 | |
Harbor | CentOS7.9 | 172.17.80.82 | zabbix测试用客户端 |
部署并配置mariadb
使用mariadb为zabbix提供数据存储服务,yum方式安装;
安装
yum -y install mariadb-server mariadb-client
创建数存储目录并配置权限
mkdir -p /mnt/mariadb_data
chown -R mysql:mysql /mnt/mariadb_data
编辑配置文件
vim /etc/my.cnf
[mysqld]
# datadir=/var/lib/mysql
datadir=/mnt/mariadb_data # 修改默认的数据存储路径,已保证存储空间足够;
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
collation-server = utf8_bin
init-connect='SET NAMES utf8'
character-set-server = utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
注意以下配置,目的是保证新建的数据库编码格式为“utf8”,并且collation-server要为utf8_bin,因为zabbix前端安装时有编码格式要求;
.
.
collation-server = utf8_bin
init-connect='SET NAMES utf8'
character-set-server = utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
.
.
启动服务测试并确认服务状态
systemctl start mariadb
[root@test ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2023-06-06 09:35:18 CST; 4h 14min ago
Process: 1943 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 1858 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 1942 (mysqld_safe)
Tasks: 20
Memory: 110.7M
CGroup: /system.slice/mariadb.service
├─1942 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─2167 /usr/libexec/mysqld --basedir=/usr --datadir=/mnt/mariadb_data --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mar...
Jun 06 09:35:15 test mariadb-prepare-db-dir[1858]: MySQL manual for more instructions.
Jun 06 09:35:15 test mariadb-prepare-db-dir[1858]: Please report any problems at http://mariadb.org/jira
Jun 06 09:35:15 test mariadb-prepare-db-dir[1858]: The latest information about MariaDB is available at http://mariadb.org/.
Jun 06 09:35:15 test mariadb-prepare-db-dir[1858]: You can find additional information about the MySQL part at:
Jun 06 09:35:15 test mariadb-prepare-db-dir[1858]: http://dev.mysql.com
Jun 06 09:35:15 test mariadb-prepare-db-dir[1858]: Consider joining MariaDB's strong and vibrant community:
Jun 06 09:35:15 test mariadb-prepare-db-dir[1858]: https://mariadb.org/get-involved/
Jun 06 09:35:16 test mysqld_safe[1942]: 230606 09:35:16 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Jun 06 09:35:16 test mysqld_safe[1942]: 230606 09:35:16 mysqld_safe Starting mysqld daemon with databases from /mnt/mariadb_data
Jun 06 09:35:18 test systemd[1]: Started MariaDB database server.
初始化数据库
运行mysql_secure_installation来进行数据库初始化,以下截取网上的相关介绍;
.
.
Enter current password for root (enter for none): # 初次运行直接回车
.
Set root password? [Y/n] # 是否设置root用户密码,输入y并回车或直接回车
New password: # 设置root用户的密码
Re-enter new password: # 再输入一次你设置的密码
.
Remove anonymous users? [Y/n] # 是否删除匿名用户,生产环境建议删除,所以直接回车
.
Disallow root login remotely? [Y/n] # 是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
.
Remove test database and access to it? [Y/n] # 是否删除test数据库,直接回车
.
.
登录测试
mysql -u root -p
创建zabbix数据库用户,并赋权
不保证语句书写完全无误,请自行确认。并且zabbix-server配置文件中不支持带特殊符号的数据库密码,所以在创建zabbix用户密码时需要注意;
MariaDB [(none)]> CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'zabbix123';
MariaDB [(none)]> GRANT ALL ON *.* TO 'zabbix'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
登录测试
mysql -u zabbix -p
为zabbix服务创建数据库
需要保证zabbix-server和zabbix-proxy使用单独数据库;
MariaDB [(none)]> CREATE DATABASE zabbix_server;
MariaDB [(none)]> CREATE DATABASE zabbix_proxy;
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| zabbix_proxy |
| zabbix_server |
+--------------------+
5 rows in set (0.00 sec)
查询数据库编码格式
MariaDB [(none)]> USE zabbix_server
Database changed
MariaDB [zabbix_server]> show variables like "%character%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
MariaDB [zabbix_server]> USE zabbix_proxy;
Database changed
MariaDB [zabbix_proxy]> show variables like "%character%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
部署zabbix 4.0服务端
配置yum源
rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum-config-manager --enable rhel-7-server-optional-rpms
yum clean all
安装 Zabbix Server/proxy/前端
yum -y install zabbix-server-mysql
yum -y install zabbix-proxy-mysql
yum -y install zabbix-web-mysql
导入数据库
导入zabbix-server数据库
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -u zabbix -p zabbix_server
导入zabbix-proxy数据库
zcat /usr/share/doc/zabbix-proxy-mysql*/schema.sql.gz | mysql -u zabbix -p zabbix_proxy
编辑zabbix_server.conf
vim /etc/zabbix/zabbix_server.conf
.
.
DBName=zabbix_server # zabbix-server所用数据库名称;
.
DBUser=zabbix # 登录数据库用户;
.
DBPassword=zabbix123 # 登录数据库密码;
.
ExportDir=/mnt/zabbix_data
.
.
编辑zabbix_proxy.conf
注意:可以不适用proxy代理直接启用server,涉及字段与zabbix_server.conf配置基本相同;
zabbix-server/proxy启动测试
systemctl start zabbix-server
systemctl start zabbix-proxy
安装zabbix前端
vim /etc/httpd/conf.d/zabbix.conf
.
.
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value max_input_vars 10000
php_value always_populate_raw_post_data -1
# php_value date.timezone Europe/Riga
php_value date.timezone Asia/Shanghai # 主要修改这行,配置时区;
.
.
修改配置文件后,访问:http://172.17.91.179/zabbix会跳转到安装界面(具体步骤后续补全);
部署zabbix-agent客户端
zabbix-agent启用在被监控设备上,用来和服务进行通信并获取数据;
配置yum源
rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum-config-manager --enable rhel-7-server-optional-rpms
yum clean all
安装客户端文件
yum -y install zabbix-agent
编辑配置文件
vim /etc/zabbix/zabbix_agentd.conf
.
.
SourceIP=172.17.80.82 # 填写本机IP地址;
.
Server=172.17.91.179 # 指定Server或proxy的ip(主备指定VIP),公网访问需要指定公网ip和对应端口;
.
ServerActive=172.17.91.179 # 主动模式 同Server=ip保持一致;
.
Hostname=harbor # 填写本机主机名即可;
.
.
启动agent服务
systemctl start zabbix-agent
服务启动后默认通信端口为10050,如果开启防火墙需要开放端口;
访问测试
链接地址:http://172.17.91.179/
默认用户:Admin
默认密码:zabbix
网友评论