Foreword
We installed the lamp environment on one server during zabbix installation, but the capacity of mysql is related to the lifeblood of zabbix. If the capacity is not enough, no amount of detection data can be stored, which seriously limits the performance of zabbix, just like This is equivalent to putting a "tight spell" on zabbix. In view of this situation, it is necessary to separate the mysql database.
surroundings:
device | description |
---|---|
192.168.10.7 (zabbix server) | lamp all in one zabbix |
192.168.10.4 (msyql database) | Separated database |
192.168.10.8 (agent side) | Agent side for monitoring |
1> // Prepare mysql database by yourself. Reference: https://blog.csdn.net/weixin_43815140/article/details/105163108
2> // Open the database, create a database and user with the same name
创建数据库,添加支持中文字符集:
mysql> create database zabbix character set utf8 collate utf8_bin;
给zabbix赋权:
mysql> grant all on zabbix.* to zabbix@'%' identified by '123.com';
3> // Backup and export the zabbix database on the zabbix server
在zabbix服务器上备份数据库文件:
mysqldump -uroot -p123.com --databases zabbix > `date +%F%H`_zabbix.sql
Copy the scp database file on 192.168.10.4
[[email protected] ~]# scp [email protected]:/root/2020-04-2115_zabbix.sql ./
4> // Import the backup database file on the 192.168.10.4mysql database
mysql -uroot -p < 2020-04-2115_zabbix.sql
Enter password: #密码123.com
It is not finished yet, the database is just transferred, but the original database connection information is still on the zabbix-server, zabbix_server.conf
and /web/zabbix.conf.php
all need to be changed. Web / zabbix.conf.php is the mysql-related file generated when the installation is complete. ,
Note the bottom line
5> // Modify the database connection information on zabbix-server
[root@localhost ~]# grep -Ev '^$|#' /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=192.168.10.4
DBName=zabbix
DBUser=zabbix
DBPassword=123.com
DBPort=3306
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
6> // Modify /etc/zabbix/web/zabbix.conf.php
[root@localhost ~]# grep -Ev '^$|#' /etc/zabbix/web/zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB;
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = '192.168.10.4';
$DB['PORT'] = '0';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = '123.com';
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';
$ZBX_SERVER = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'lzj_zabbix';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
7> // Restart zabbix and httpd on the server side, close mysql, verify
systemctl restart zabbix-server httpd
systemctl stop mariadb.service
No problem, it can still be accessed, and here, the database is successfully transferred.