利用MySQL-Proxy進行MySQL資料庫的讀寫分離

來源:互聯網
上載者:User

利用MySQL-Proxy進行MySQL資料庫的讀寫分離

實驗系統:CentOS 6.6_x86_64
實驗前提:防火牆和selinux都關閉
實驗說明:本實驗共有4台主機,IP分配如拓撲
實驗軟體:mariadb-10.0.20  mysql-proxy-0.8.5-linux-el6-x86-64bit

:http://pan.baidu.com/s/1o6EFEQm

MySQL Proxy讀寫分離實戰

在CentOS 5.2下安裝最新的MySQL Proxy

RHEL5.5下MySQL Proxy 安裝

mysql proxy、mysql-mmm實現讀寫分離高可用性

實驗拓撲:

 

一、準備工作:

1.將主機名稱改為如下所示:

2.將hosts檔案添加如下內容:

3.master、slave1和slave2安裝mariadb: 

tar xf mariadb-10.0.20-linux-x86_64.tar.gz  -C /usr/local/
cd /usr/local/
ln -sv mariadb-10.0.20-linux-x86_64 mysql
useradd -r mysql
mkdir -pv /mydata/data
chown -R mysql.mysql /mydata/data/
cd mysql/
chown -R root.mysql .
scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
cp support-files/my-large.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

二、配置主從複製

1.master上配置my.cnf:

[mysqld]
server-id      = 1
datadir = /mydata/data
log-bin = /mydata/data/master-bin
binlog_format = ROW
sync_binlog = 1                        //確保每次事務提交之前都能將二進位日誌同步磁碟上

2.slave1上配置my.cnf:

[mysqld]
#log-bin=mysql-bin
#binlog_format=mixed
server-id      = 2
datadir = /mydata/data
relay_log = /mydata/data/relay-log
read_only = 1
sync_master_info = 1                  //及時同步master檔案
sync_relay_log = 1                    //及時同步relay-log檔案
sync_relay_log_info = 1                //及時同步relay-log-info檔案

3.slave2上配置my.cnf:

[mysqld]
#log-bin=mysql-bin
#binlog_format=mixed
server-id      = 3
datadir = /mydata/data
relay_log = /mydata/data/relay-log
read_only = 1
sync_master_info = 1
sync_relay_log = 1
sync_relay_log_info = 1

4.在master上建立複製使用者:

service mysqld start
/usr/local/mysql/bin/mysql
------------------------------------------->
GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'slave'@'192.168.19.%' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;

5.在master上查看二進位日誌位置:

SHOW MASTER LOGS;

6.兩台slave上操作:

CHANGE MASTER TO MASTER_HOST='master',MASTER_USER='slave',MASTER_PASSWORD='123456',MASTER_LOG_FILE='master-bin.000001',MASTER_LOG_POS=637;
START SLAVE;
SHOW SLAVE STATUS\G

更多詳情見請繼續閱讀下一頁的精彩內容:

  • 1
  • 2
  • 下一頁

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.