业务背景:
Zabbix3.0.4是业务的主要监控,部署在一台单机中,为避免数据丢失先对其做数据主从同步,因主数据库已经运行了一段时间,数据量大概有10G左右为快速实现主从,使用percona-xtrabackup工具进行备份和恢复。
master db:
操作系统: CentOS7.2 x86_64
mysql: mariadb 5.5.47
通过yum安装的mariadb(yum -y install mariadb mariadb-server php php-mysql httpd)
具体的过程参考:Zabbix系列教程:CentOS 7搭建Zabbix3.0.4服务端及配置详解
slave db:
操作系统:centos6.5
1.在slave中安装mariadb
因之前安装过mysql5.7需要卸载
rpm -e --nodeps mysql*
删除残留文件,否则会无法启动mariadb
rm -rf /var/lib/mysql
rm -f /etc/my.cnf
rm -rf /etc/my.cnf.d
先创建关于mariadb的yum源
vi /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl =
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
yum安装
yum install MariaDB-server MariaDB-client
编辑my.cnf文件
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d
2.主从服务器均开启binlog日志,从服务器开启relay-log:
log-bin=/data/binlog/mysql-bin
binlog-do-db=zabbix
binlog-ignore-db = mysql
expire_logs_day=15
max_binlog_size = 200M
binlog_format=mixed
server-id = 1
验证:
MariaDB [(none)]> show binary logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 396365 |
+------------------+-----------+
1 row in set (0.00 sec)
从服务器配置,开启中继日志:
vim /etc/my.cnf.d/server.cnf
[mariadb]
log-bin=/data/binlog/mysql-bin
relay-log = /data/relaylog/relay-bin
binlog_format=mixed
server-id=10
replicate_wild_do_table=zabbix.%
replicate_wild_ignore_table=mysql.%
改变权限
chown -R mysql.mysql /data/
3.备份主服务器的数据库zabbix
在master和slave两台服务器中都安装percona-xtrabackup
方法:
上传文件percona-toolkit-2.2.4-1.noarch.rpm、percona-xtrabackup-2.1.8-733.rhel6.x86_64.rpm 到服务器中
yum localinstall percona-*.rpm
备份zabbix
/usr/bin/innobackupex --user=root --password=root#$!#140341@ --databases="zabbix" /data/
报错如下:
161114 13:53:03 innobackupex: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/etc/my.cnf;mysql_read_default_group=xtrabackup;host=localhost' as 'root' (using password: YES).
innobackupex: Error: Failed to connect to MySQL server: DBI connect(';mysql_read_default_file=/etc/my.cnf;mysql_read_default_group=xtrabackup;host=localhost','root',...) failed: Access denied for user 'root'@'localhost' (using password: YES) at /usr/bin/innobackupex line 2945.
原因分析:
1.在相同的centos7.2的mariadb5.5.47其他环境是可以的,排除操作系统和数据库与xtrabackup的兼容性问题
2.使用zabbix账户可以进入命令行,但是后面权限不足报错,排除软件本身安装的问题
3.以前碰到过mysql密码复杂以后无法修改数据库的问题,于是把root密码修改成简单的root
并flush privileges后,发现问题解决
可能是命令行工具的bug,当密码配置复杂以后,特别是有特殊符号后命令行工具不能正确识别
继续报错:
xtrabackup_55: Error writing file '/data/2016-11-14_15-00-33/ibdata1' (Errcode: 28)
[01] xtrabackup: Error: xtrabackup_copy_datafile() failed.
[01] xtrabackup: Error: failed to copy datafile.
innobackupex: Error: The xtrabackup child process has died at /usr/bin/innobackupex line 2622.解决办法:
将文件夹/data/2016-11-14_15-00-33删除,重新执行备份即可
成功提示:
>> log scanned up to (130775113381)
xtrabackup: Creating suspend file '/data/2016-11-14_15-08-34/xtrabackup_suspended_2' with pid '5883'
161114 15:10:04 innobackupex: Continuing after ibbackup has suspended
161114 15:10:04 innobackupex: Starting to lock all tables...
161114 15:10:04 innobackupex: All tables locked and flushed to disk
161114 15:10:04 innobackupex: Starting to backup non-InnoDB tables and files
innobackupex: in subdirectories of '/var/lib/mysql'
innobackupex: Backing up files '/var/lib/mysql/zabbix/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (114 files)
>> log scanned up to (130775124431)
161114 15:10:04 innobackupex: Finished backing up non-InnoDB tables and files
161114 15:10:04 innobackupex: Waiting for log copying to finish
xtrabackup: The latest check point (for incremental): '130773362503'
xtrabackup: Stopping log copying thread.
.>> log scanned up to (130775124431)