[102]$ vim /etc/my.cnf
[mysqld]
log-bin
server_id=1
skip_name_resolve=1 #忽略名字解析
创建连接需要的帐号
[102]$ mysql
#创建复制用帐号
mysql> grant replication slave on *.* to repluser@'%' identified by '123';
#创建管理用帐号
mysql> grant all on *.* to mhauser@'%'identified by'123';
slave主机:192.168.99.103
修改mariadb配置文件
[103]$ vim /etc/my.cnf
[mysqld]
server_id=2 #不同节点此值各不相同
log-bin
read_only
relay_log_purge=0
skip_name_resolve=1
这里:关闭relay_log_purge是为了不让mysql自动清除中继日志,官方就有这么一句话 'Disabling purging of relay logs when using the --relay-log-recovery option risks data consistency and is therefore not crash-safe.'
连接到主服务器
[103]$ mysql
MariaDB [(none)]> CHANGE MASTER TO
MASTER_HOST='192.168.99.102',
MASTER_PORT=3306,
MASTER_USER='repluser',
MASTER_PASSWORD='123',
MASTER_LOG_FILE='mariadb-bin.000001',
MASTER_LOG_POS=245;
#启动
MariaDB [(none)]> start slave ;
#查看下成功了没
MariaDB [(none)]> show slave status\G;
#看看帐号同步来了没
MariaDB [(none)]> select user from mysql.user;
+----------+
| user |
+----------+
| mhauser |
| repluser |
...
另一个slave主机:192.168.99.104
修改mariadb配置文件
[104]$ vim /etc/my.cnf
[mysqld]
server_id=2 #不同节点此值各不相同
log-bin
read_only
relay_log_purge=0
skip_name_resolve=1
连接到主服务器
[104]$ mysql
MariaDB [(none)]> CHANGE MASTER TO
MASTER_HOST='192.168.99.102',
MASTER_PORT=3306,
MASTER_USER='repluser',
MASTER_PASSWORD='123',
MASTER_LOG_FILE='mariadb-bin.000001',
MASTER_LOG_POS=245;
#启动
MariaDB [(none)]> start slave ;
#查看下成功了没
MariaDB [(none)]> show slave status\G;
#看看帐号同步来了没
MariaDB [(none)]> select user from mysql.user;
+----------+
| user |
+----------+
| mhauser |
| repluser |
...