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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Percona Server 5.6 Master-Slave Replication测试

發布時間:2023/12/20 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Percona Server 5.6 Master-Slave Replication测试 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為什么80%的碼農都做不了架構師?>>> ??

MySQL的Master-Slave Replication是一個異步的復制過程,從一個 MySQL instance(Master)復制到另一個 instance(Slave)。在Master與Slave之間的實現整個復制過程主要由三個線程來完成,其中兩個線程(SQL線程和IO線程)在 Slave 端,另外一個線程(IO線程)在Master端。 在MySQL Multi-Master興起的今天,Master-Slave依然有著不少應用場景。
MySQL 復制的基本過程如下(http://machael.blog.51cto.com/829462/239112/):
1. Slave上面的IO線程連接上 Master,并請求從指定日志文件的指定位置(或者從最開始的日志)之后的日志內容;
2. Master 接收到來自 Slave 的 IO 線程的請求后,通過負責復制的 IO 線程根據請求信息讀取指定日志指定位置之后的日志信息,返回給 Slave 端的 IO 線程。返回信息中除了日志所包含的信息之外,還包括本次返回的信息在 Master 端的 Binary Log 文件的名稱以及在 Binary Log 中的位置;
3. Slave 的 IO 線程接收到信息后,將接收到的日志內容依次寫入到 Slave 端的Relay Log文件(mysql-relay-bin.xxxxxx)的最末端,并將讀取到的Master端的bin-log的文件名和位置記錄到master-
info文件中,以便在下一次讀取的時候能夠清楚的高速Master“我需要從某個bin-log的哪個位置開始往后的日志內容,請發給我”
?4. Slave 的 SQL 線程檢測到 Relay Log 中新增加了內容后,會馬上解析該 Log 文件中的內容成為在 Master 端真實執行時候的那些可執行的 Query 語句,并在自身執行這些 Query。這樣,實際上就是在 Master 端和 Slave 端執行了同樣的 Query,所以兩端的數據是完全一樣的。
下面就在CentOS 6.5 兩節點的環境中配置一個簡單的Percona Server 5.6.16 Master-Slave復制:
OStack01 ?192.168.46.132
OStack02 ?192.168.46.133

1. 安裝Percona

在Master, Slave安裝Percona Server

[root@localhost Desktop]# rpm -ivh http://www.percona.com/downloads/Percona-Server-5.6/LATEST/binary/redhat/6/x86_64/Percona-Server-shared-56-5.6.16-rel64.2.el6.x86_64.rpm Retrieving http://www.percona.com/downloads/Percona-Server-5.6/LATEST/binary/redhat/6/x86_64/Percona-Server-shared-56-5.6.16-rel64.2.el6.x86_64.rpm Preparing... ########################################### [100%]1:Percona-Server-shared-5########################################### [100%] [root@localhost Desktop]# rpm -ivh http://www.percona.com/downloads/Percona-Server-5.6/LATEST/binary/redhat/6/x86_64/Percona-Server-client-56-5.6.16-rel64.2.el6.x86_64.rpm Retrieving http://www.percona.com/downloads/Percona-Server-5.6/LATEST/binary/redhat/6/x86_64/Percona-Server-client-56-5.6.16-rel64.2.el6.x86_64.rpm Preparing... ########################################### [100%]1:Percona-Server-client-5########################################### [100%] [root@localhost Desktop]# rpm -ivh http://www.percona.com/downloads/Percona-Server-5.6/LATEST/binary/redhat/6/x86_64/Percona-Server-server-56-5.6.16-rel64.2.el6.x86_64.rpm Retrieving http://www.percona.com/downloads/Percona-Server-5.6/LATEST/binary/redhat/6/x86_64/Percona-Server-server-56-5.6.16-rel64.2.el6.x86_64.rpm Preparing... ########################################### [100%]1:Percona-Server-server-5########################################### [100%] 2014-04-30 00:39:07 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2014-04-30 00:39:07 19100 [Note] InnoDB: Using atomics to ref count buffer pool pages 2014-04-30 00:39:07 19100 [Note] InnoDB: The InnoDB memory heap is disabled 2014-04-30 00:39:07 19100 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2014-04-30 00:39:07 19100 [Note] InnoDB: Compressed tables use zlib 1.2.3 2014-04-30 00:39:07 19100 [Note] InnoDB: Using Linux native AIO 2014-04-30 00:39:07 19100 [Note] InnoDB: Using CPU crc32 instructions 2014-04-30 00:39:07 19100 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2014-04-30 00:39:07 19100 [Note] InnoDB: Completed initialization of buffer pool 2014-04-30 00:39:07 19100 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2014-04-30 00:39:07 19100 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2014-04-30 00:39:07 19100 [Note] InnoDB: Database physically writes the file full: wait... 2014-04-30 00:39:07 19100 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2014-04-30 00:39:07 19100 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2014-04-30 00:39:07 19100 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2014-04-30 00:39:07 19100 [Warning] InnoDB: New log files created, LSN=45781 2014-04-30 00:39:07 19100 [Note] InnoDB: Doublewrite buffer not found: creating new 2014-04-30 00:39:07 19100 [Note] InnoDB: Doublewrite buffer created 2014-04-30 00:39:07 19100 [Note] InnoDB: 128 rollback segment(s) are active. 2014-04-30 00:39:08 19100 [Warning] InnoDB: Creating foreign key constraint system tables. 2014-04-30 00:39:08 19100 [Note] InnoDB: Foreign key constraint system tables created 2014-04-30 00:39:08 19100 [Note] InnoDB: Creating tablespace and datafile system tables. 2014-04-30 00:39:08 19100 [Note] InnoDB: Tablespace and datafile system tables created. 2014-04-30 00:39:08 19100 [Note] InnoDB: Waiting for purge to start 2014-04-30 00:39:08 19100 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.6.16-64.2 started; log sequence number 0 2014-04-30 00:39:08 19100 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work. 2014-04-30 00:39:08 19100 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work. 2014-04-30 00:39:08 19100 [Note] Binlog end 2014-04-30 00:39:08 19100 [Note] InnoDB: FTS optimize thread exiting. 2014-04-30 00:39:08 19100 [Note] InnoDB: Starting shutdown... 2014-04-30 00:39:10 19100 [Note] InnoDB: Shutdown completed; log sequence number 16259772014-04-30 00:39:10 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2014-04-30 00:39:10 19125 [Note] InnoDB: Using atomics to ref count buffer pool pages 2014-04-30 00:39:10 19125 [Note] InnoDB: The InnoDB memory heap is disabled 2014-04-30 00:39:10 19125 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2014-04-30 00:39:10 19125 [Note] InnoDB: Compressed tables use zlib 1.2.3 2014-04-30 00:39:10 19125 [Note] InnoDB: Using Linux native AIO 2014-04-30 00:39:10 19125 [Note] InnoDB: Using CPU crc32 instructions 2014-04-30 00:39:10 19125 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2014-04-30 00:39:10 19125 [Note] InnoDB: Completed initialization of buffer pool 2014-04-30 00:39:10 19125 [Note] InnoDB: Highest supported file format is Barracuda. 2014-04-30 00:39:10 19125 [Note] InnoDB: 128 rollback segment(s) are active. 2014-04-30 00:39:10 19125 [Note] InnoDB: Waiting for purge to start 2014-04-30 00:39:10 19125 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.6.16-64.2 started; log sequence number 1625977 2014-04-30 00:39:10 19125 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work. 2014-04-30 00:39:10 19125 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work. 2014-04-30 00:39:10 19125 [Note] Binlog end 2014-04-30 00:39:10 19125 [Note] InnoDB: FTS optimize thread exiting. 2014-04-30 00:39:10 19125 [Note] InnoDB: Starting shutdown... 2014-04-30 00:39:12 19125 [Note] InnoDB: Shutdown completed; log sequence number 1625987PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands:/usr/bin/mysqladmin -u root password 'new-password'/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'Alternatively you can run:/usr/bin/mysql_secure_installationwhich will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers.See the manual for more instructions.Please report any problems at http://bugs.mysql.com/The latest information about MySQL is available on the web athttp://www.mysql.comSupport MySQL by buying support/licenses at http://shop.mysql.comWARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the serverPercona Server is distributed with several useful UDF (User Defined Function) from Maatkit. Run the following commands to create these functions: mysql -e "CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME 'libfnv1a_udf.so'" mysql -e "CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so'" mysql -e "CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so'" See http://code.google.com/p/maatkit/source/browse/trunk/udf for more details

2. 配置Master,Slave的數據庫參數文件

master: # vi /etc/my.cnf #在[mysqld]中添加 explicit_defaults_for_timestamp=true log_bin = mysql-bin server_id = 1 innodb_buffer_pool_size = 128M join_buffer_size = 128M sort_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

log-bin is the binary log basename to generate binary log file names.
server-id option is used in replication to enable master and slave servers to identify themselves uniquely. On the master and each slave, you must use the server-id option to establish a unique replication ID in the range from 1 to 231.
explicit_defaults_for_timestamp是5.6關于timestamp默認行為的設置,請參考:http://www.williamsang.com/archives/818.html
sqlmode – STRICT_TRANS_TABLES – 為事務引擎啟用嚴格模式
sqlmode – NO_ENGINE_SUBSTITUTION 如果需要的存儲引擎被禁用或未編譯,可以防止自動替換存儲引擎。

slave:

vi /etc/my.cnf #在[mysqld]中添加 explicit_defaults_for_timestamp=true log_bin = mysql-bin server_id = 2 relay_log = /var/lib/mysql/mysql-relay-bin log_slave_updates = 1 read_only =1 innodb_buffer_pool_size = 128M join_buffer_size = 128M sort_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

Out of the settings described above, the only essential one is the server-id part, but I have enabled log-bin too and named it similar to the one on master, so that slave can be promoted to master if and when required.
relay-log specifies the location and name of the relay log
log-slave-updates makes the slave log the replicated events to its binary log
read-only prevents data changes on the slaves, because slave is really usually used for reads

3. 啟動并配置數據庫

分別啟動master、slave數據庫:

<SHELL># service mysql start Starting MySQL (Percona Server)......[ OK ]

檢查監聽端口

<SHELL># netstat -nat # netstat -lnap | grep 3306 tcp 0 0 :::3306 :::* LISTEN 20771/mysqld

設置root密碼

<SHELL># /usr/bin/mysqladmin -u root password 'debugo' <SHELL># mysql -u root

登錄并檢查:

# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 2 Server version: 5.6.16-64.2-56-log Percona Server (GPL), Release 64.2, Revision 569 ......mysql> show master status-> G *************************** 1. row ***************************File: mysql-bin.000001Position: 262Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: 1 row in set (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec)

下面做一個test數據庫的完整備份,并復制到slave所在的節點中:

<SHELL># mysqldump -uroot -pdebugo --master-data=2 test > /root/dbdump.db

Note the user of master-data option. Use this option to dump a master replication server to produce a dump file that can be used to set up another server as a slave of the master. With the master-data value set to 2, the“change master” to statement (that indicates binlog name and position) is written as a comment at the start of the dump file for information purposes. The master-data option also turns on lock-all-tables option, which acquires a global read lock across all tables which ensures that the dump is consistent.
拷貝并導入到slave中:

<SHELL># scp /root/dbdump.db OStack02:/root dbdump.db 100% 203 0.2KB/s 00:00 <SHELL># mysql -uroot -p test < dbdump.db Enter password:

配置master數據庫用戶:

mysql> grant replication slave,replication client on *.* to rep@'192.168.46.%' identified by 'debugo'; Query OK, 0 rows affected (0.05 sec) mysql> grant all on test.* to rep@'192.168.46.%'; Query OK, 0 rows affected (0.00 sec) mysql> commit; Query OK, 0 rows affected (0.00 sec)mysql> show master status G *************************** 1. row ***************************File: mysql-bin.000003Position: 349Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: 1 row in set (0.00 sec)

slave數據庫:

[root@localhost ~]# mysql -u root ... mysql> grant replication slave,replication client on *.* to rep@'192.168.46.%' identified by 'debugo'; Query OK, 0 rows affected (0.05 sec) mysql> grant all on test.* to rep@'192.168.46.%'; Query OK, 0 rows affected (0.00 sec) mysql> commit; Query OK, 0 rows affected (0.00 sec)mysql> change master to master_host='192.168.46.132', master_user='rep',master_password='debugo',master_log_file='mysql-bin.000001',master_log_pos=0; Query OK, 0 rows affected, 2 warnings (0.05 sec) mysql> start slave; Query OK, 0 rows affected (0.04 sec)

4. 測試

在master端的test數據庫中,創建test.t表并插入數據。

mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 623 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)mysql> use test Database changedmysql> create table t (name varchar(10)); Query OK, 0 rows affected (0.02 sec)mysql> insert into t values ('debugo'); Query OK, 1 row affected (0.00 sec)mysql> commit; Query OK, 0 rows affected (0.00 sec)mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 945 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)

slave端,檢查數據

mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 1126 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)mysql> use test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed mysql> show tables; +----------------+ | Tables_in_test | +----------------+ | t | +----------------+ 1 row in set (0.00 sec)mysql> select * from t; +--------+ | name | +--------+ | debugo | +--------+ 1 row in set (0.00 sec)mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 1448 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)

可見兩邊binlog的position增量是一致的,數據被成功傳送過來。

轉載于:https://my.oschina.net/boltwu/blog/719838

總結

以上是生活随笔為你收集整理的Percona Server 5.6 Master-Slave Replication测试的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。