日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

MySQL多实例实现半同步复制

發(fā)布時(shí)間:2023/12/31 数据库 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MySQL多实例实现半同步复制 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

MySQL多實(shí)例實(shí)現(xiàn)半同步復(fù)制

MySQL多實(shí)例實(shí)現(xiàn)半同步復(fù)制

主庫(kù)1:192.168.40.150

主庫(kù)2:192.168.40.161

從庫(kù)(2個(gè)MySQL實(shí)例):192.168.40.162

一:分別在192.168.40.161和192.168.40.150使用【show master status;】記錄當(dāng)前的復(fù)制位置

如下所示

mysql> show master status;

+--------------+----------+--------------+------------------+-------------------+

| File?????????| Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+--------------+----------+--------------+------------------+-------------------+

| mysql.000006 | 11426362 |??????????????|??????????????????|???????????????????|

+--------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

二:master(分別在192.168.40.161和192.168.40.150進(jìn)行如下操作)

1.啟用二進(jìn)制日志

log_bin=mysql

log-bin-index=mysql-index

2.為master選擇一個(gè)在當(dāng)前復(fù)制架構(gòu)中惟一的server-id

server-id={0-2^32}

3.創(chuàng)建一個(gè)具有復(fù)制權(quán)限的用戶帳號(hào)

mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repluser'@'192.168.40.162' IDENTIFIED BY 'replpass';

mysql> FLUSH PRIVILEGES;

4.分別master的配置文件中的mysqld段添加如下一行,并重啟服務(wù)

rpl_semi_sync_master_enabled=ON?(或者:mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';)

mysql> SHOW GLOBAL VARIABLES LIKE '%semi%';

mysql> SET GLOBAL rpl_semi_sync_master_enabled=ON;

mysql> SET GLOBAL rpl_semi_sync_master_timeout=1000;

5.配置主從復(fù)制時(shí)的事務(wù)安全:

在主服務(wù)器上mysqld段配置:sync_binlog=1

6.重啟mysql服務(wù)

二、slave(在192.168.40.162的兩個(gè)mysql實(shí)例中進(jìn)行如下操作)

1.在192.168.40.162配置兩個(gè)實(shí)例:socket端口分別為3306和3307,具體配置請(qǐng)參考配置文件。

2.創(chuàng)建所需要的目錄

mkdir -p /data/{mysql3306,mysql3307}

3.分別對(duì)192.168.40.161和192.168.40.150的數(shù)據(jù)目錄打包,然后分別上傳至192.168.40.162的/data/mysql3306和/data/mysql3307目錄下

例如:

# cd /data/mysql/

# tar zcf mysql_162.tar.gz ./*

# scp mysql_162.tar.gz 192.168.40.162:/data/mysql3306/

4.啟用中繼日志(并關(guān)閉二進(jìn)制日志)

relay-log=/data/mysql3306/relay-3306.log

relay-log-index=/data/mysql3306/relay-log-index-3306.log

5.為slave選擇一個(gè)在當(dāng)前復(fù)制架構(gòu)中惟一的server-id

server-id={0-2^32}

6.為slave選擇一個(gè)在當(dāng)前復(fù)制架構(gòu)中惟一的server-uuid

修數(shù)據(jù)目錄下的auto.cnf?修數(shù)據(jù)目錄下的auto.cnf?的server-uuid

如將

server-uuid=3fd1f0a1-b34e-11e4-996a-000c29b1b59d

修改為

server-uuid=3fd1f0a1-b34e-11e4-996a-000c29b1b52d

5、復(fù)制過(guò)濾器

slave:

replicate-ignore-db=mysql

replicate-ignore-db=information_schema

replicate-ignore-db=performance_schema

8.重啟mysql服務(wù)

9.開(kāi)啟半同步復(fù)制

從服務(wù)器:

mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';

mysql> SET GLOBAL rpl_semi_sync_slave_enabled=ON;

在主服務(wù)器驗(yàn)正半同步復(fù)制是否生效:

mysql> SHOW GLOBAL STATUS LIKE '%semi%';

9.連接至主服務(wù)器

mysql> CHANGE MASTER TO MASTER_HOST='192.168.40.161', MASTER_USER='repluser',??MASTER_PASSWORD='replpass',??MASTER_PORT=3306,??MASTER_LOG_FILE='mysql.000006', MASTER_LOG_POS=11426362;

mysql> START SLAVE;??????

10.檢查主從是否成功

mysql> show slave status;


主服務(wù)器配置文件: [root@db_peizi1?~]#?more?/etc/my.cnf [client] port=3306 socket?=?/usr/local/mysql/mysql.sock[mysql] default-character-set=utf8[mysqld] port????????????=?3306 socket??????????=?/usr/local/mysql/mysql.sock basedir=/usr/local/mysql datadir=/data/mysql server_id=1 user=mysql skip-name-resolve log_bin=mysql expire_logs_days?=?30sync_binlog=1 rpl_semi_sync_master_enabled=ON#slow_log slow-query-log=On slow_query_log_file=/data/logs/mysql/peizi-slow.log long_query_time=1#?Disabling?symbolic-links?is?recommended?to?prevent?assorted?security?risks symbolic-links=0character-set-server=utf8 default-storage-engine=InnoDB explicit_defaults_for_timestamp=trueskip-external-lockingmax_connections=300 query_cache_size=1048576 performance_schema_max_table_instances=600 table_definition_cache=400 table_open_cache=256 tmp_table_size=64M max_heap_table_size=64M thread_cache_size=16myisam_max_sort_file_size=16G myisam_sort_buffer_size=32M key_buffer_size=25M read_buffer_size=128K read_rnd_buffer_size=256K sort_buffer_size=256K join_buffer_size=16M max_allowed_packet=4Minnodb_file_per_table=1 innodb_flush_log_at_trx_commit=1 innodb_log_buffer_size=2M innodb_buffer_pool_size=64M innodb_log_file_size=16M innodb_thread_concurrency=8sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"[mysqld_safe] log-error=/data/logs/mysql/mysqld.log pid-file=/usr/local/mysql/tmp/mysqld.pid多實(shí)例從服務(wù)器配置文件: [mysqld_multi] mysqld?=?/usr/local/mysql/bin/mysqld_safe mysqladmin?=?/usr/local/mysql/bin/mysqladmin[mysql] default-character-set=utf8[mysqld1] port????????????=?3306 socket??????????=?/usr/local/mysql/mysql-3306.sock basedir=/usr/local/mysql datadir=/data/mysql3306 pid-file=/var/lock/subsys/mysql3306/mysq-3306.pid server_id=11 user=mysql skip-name-resolve expire_logs_days?=?30master-info-file=/data/mysql3306/master-3306.info read-only relay-log=/data/mysql3306/relay-3306.log relay-log-index=/data/mysql3306/relay-log-index-3306.log replicate-ignore-db=mysql replicate-ignore-db=information_schema replicate-ignore-db=performance_schema#?Disabling?symbolic-links?is?recommended?to?prevent?assorted?security?risks symbolic-links=0character-set-server=utf8 default-storage-engine=InnoDB explicit_defaults_for_timestamp=trueskip-external-lockingmax_connections=300 query_cache_size=1048576 performance_schema_max_table_instances=600 table_definition_cache=400 table_open_cache=256 tmp_table_size=64M thread_cache_size=16myisam_max_sort_file_size=16G myisam_sort_buffer_size=32M key_buffer_size=25M read_buffer_size=128K read_rnd_buffer_size=256K sort_buffer_size=256K join_buffer_size=16M max_allowed_packet=4Minnodb_file_per_table=1 innodb_flush_log_at_trx_commit=1 innodb_log_buffer_size=2M innodb_buffer_pool_size=64M innodb_log_file_size=8M innodb_thread_concurrency=8lower_case_table_names=1 sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"[mysqld2] port????????????=?3307 socket??????????=?/usr/local/mysql/mysql-3307.sock basedir=/usr/local/mysql datadir=/data/mysql3307 pid-file=/var/lock/subsys/mysql3307/mysql-3307.pid server_id=6 user=mysql skip-name-resolve expire_logs_days?=?30master-info-file=/data/mysql3307/master-3307.info read-only relay-log=/data/mysql3307/relay-3307.log relay-log-index=/data/mysql3307/relay-log-index-3307.log replicate-ignore-db=mysql replicate-ignore-db=information_schema replicate-ignore-db=performance_schema#?Disabling?symbolic-links?is?recommended?to?prevent?assorted?security?risks symbolic-links=0character-set-server=utf8 default-storage-engine=InnoDB explicit_defaults_for_timestamp=trueskip-external-lockingmax_connections=300 query_cache_size=1048576 performance_schema_max_table_instances=600 table_definition_cache=400 table_open_cache=256 tmp_table_size=64M thread_cache_size=16myisam_max_sort_file_size=16G myisam_sort_buffer_size=32M key_buffer_size=25M read_buffer_size=128K read_rnd_buffer_size=256K sort_buffer_size=256K join_buffer_size=16M max_allowed_packet=4Minnodb_file_per_table=1 innodb_flush_log_at_trx_commit=1 innodb_log_buffer_size=2M innodb_buffer_pool_size=64M innodb_log_file_size=8M innodb_thread_concurrency=8lower_case_table_names=1 sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"


轉(zhuǎn)載于:https://blog.51cto.com/openlinuxfly/1643835

總結(jié)

以上是生活随笔為你收集整理的MySQL多实例实现半同步复制的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。