一)双主环境配置
MairDB1 | 192.168.1.122 | mariadb-10.0.10.tar.gz |
maridb2 | 192.168.1.120 | mariadb-10.0.10.tar.gz |
二)操作系统版本
[root@localhost ~]# cat /etc/issue CentOS release 6.4 (Final) Kernel \r on an \m Mage Education Learning Services http://www.magedu.com [root@localhost ~]# uname -r 2.6.32-358.el6.x86_64
三)主服务器1配置
1)修改不同的ID
2)双主各都启动二进制日志和中继日志
3)双主各自建立授权账号
4)确定双主的位置一样
vim /etc/my.cnf thread_concurrency = 8 datadir = /mydata/data数据存放目录 log-bin=/mydata/binlogs/mysql-bin二进制目录 server-id = 1 relay_log = /mydata/relaylogs/relay-bin中继日志目录 auto_increment_increment = 1自动增长步长 auto_increment_offset = 1自动增长类型的初始值
授权账号
MariaDB [(none)]> grant replication slave,replication client on *.* to 'Andy'@'192.168.%.%' identified by 'Andy.com'; MariaDB [(none)]> flush privileges;
查看服务器的起始位置
MariaDB [(none)]> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000002 | 636 | | | +------------------+----------+--------------+------------------+
四)主服务器2的配置
thread_concurrency = 2 datadir = /mydata/data log-bin=/mydata/binlogs/mysql-bin server-id = 10 relay-log = /mydata/relaylogs/relay-bin auto_increment_increment = 2 auto_increment_offset = 2
授权账号
MariaDB [(none)]> grant replication slave,replication client on *.* to 'Andy'@'192.168.%.%' identified by 'Andy.com'; Query OK, 0 rows affected (0.18 sec) MariaDB [(none)]> flush privilges; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'privilges' at line 1 MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.04 sec) MariaDB [(none)]> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000002 | 636 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
五)各服务器分别建立连接
主一建立连接
MariaDB [(none)]> change master to master_host='192.168.1.120',master_user='Andy',master_password='Andy.com',master_log_file='mysql-bin.000002',master_log_pos=636; Query OK, 0 rows affected (0.08 sec)
主二建立连接
MariaDB [(none)]> change master to master_host='192.168.1.122',master_user='Andy',master_password='Andy.com',master_log_file='mysql-bin.000002',master_log_pos=636; Query OK, 0 rows affected (0.11 sec)
六)测试
主1上创建数据库,主2查看是否同步 mysql> create database Andy; Query OK, 1 row affected (0.08 sec) mysql> show databases; +---------------------+ | Database | +---------------------+ | information_schema | | Andy | | benet | | #mysql50#lost+found | | mysql | | performance_schema | | test | +---------------------+
主2查看发现已同步 mysql> show databases; +---------------------+ | Database | +---------------------+ | information_schema | | Andy | | #mysql50#lost+found | | mysql | | performance_schema | | test | +---------------------+
主2创建,去主1查看 mysql> create database benet; Query OK, 1 row affected (0.12 sec) mysql> show databases; +---------------------+ | Database | +---------------------+ | information_schema | | Andy | | benet | | #mysql50#lost+found | | mysql | | performance_schema | | test |
mysql> show databases; +---------------------+ | Database | +---------------------+ | information_schema | | Andy | | benet | | #mysql50#lost+found | | mysql | | performance_schema | | test | +---------------------+
PS:
同步完成,需要注意的地方,二进制文件目录需要设置权限,不然启动服务会报错。