我试图进行复制

在CentOS7标准中,使用MariaDB 5.5.40进行操作。

设定

大师的设置

  [mysqld]
  character-set-server = utf8
  innodb_file_per_table = 1

  # show variables like slow;
  slow_query_log=ON
  long_query_time=1
  log-slow-queries=/var/log/mariadb/slow.log

+ # 一意の値を設定
+ server-id = 101
+ # binlog
+ log_bin = /srv/binlog/bin.log
+ binlog_format=MIXED
+ # 1年保管
+ expire_logs_days = 365

在主服务器上创建一个用于复制的账户

MariaDB [(none)]>
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.11.0/255.255.255.0' IDENTIFIED BY 'oida4Wezxa5OSh8V';
MariaDB [(none)]> show master status;
+------------+----------+--------------+------------------+
| File       | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------+----------+--------------+------------------+
| bin.000001 |      245 |              |                  |
+------------+----------+--------------+------------------+
1 row in set (0.00 sec)

记住这个值,因为之后会用到。

从主服务器复制到从服务器

mkdir /opt/{bin,relay}log
chown mysql:mysql /opt/{bin,relay}log

systemctl stop mariadb
cd /var/lib/mysql
tar cpf /tmp/db.tar .
scp /tmp/db.tar dbsrv2:

systemctl restart mariadb

在slave服务器上指定master服务器的binlog位置

  [mysqld]
  character-set-server = utf8
  innodb_file_per_table = 1

  # show variables like slow;
  slow_query_log=ON
  long_query_time=1
  log-slow-queries=/var/log/mariadb/slow.log

+ server-id = 102
+ relay-log=/srv/relaylog/bin
+ relay-log-index=/srv/relaylog/bin
mkdir /opt/{bin,relay}log
chown mysql:mysql /opt/{bin,relay}log

cd /var/lib/mysql
rm -rf *
tar xpf ~/db.tar .

systemctl restart mariadb
MariaDB [(none)]> 
CHANGE MASTER TO
  MASTER_HOST = 'dbsrv1',
  MASTER_USER = 'repl',
  MASTER_PASSWORD = 'oida4Wezxa5OSh8V',
  MASTER_LOG_FILE = 'bin.000001',
  MASTER_LOG_POS = 245;
MariaDB [(none)]> START SLAVE;
MariaDB [(none)]> SHOW SLAVE STATUS \G

确认动作

在师傅的指导下进行执行。

MariaDB [(none)]> use test;
MariaDB [(none)]> CREATE TABLE count1(num INT);
MariaDB [(none)]> INSERT INTO count1 (num) VALUES (1);

在奴隶身份下进行确认

MariaDB [(none)]> use test;
MariaDB [(none)]> show tables;
MariaDB [(none)]> select * from count1;

请留意

当主的Mariadb重新启动后,从属的Mariadb也需要重新启动,否则无法复制吗?

广告
将在 10 秒后关闭
bannerAds