MySQL-5.6+MySQL-Proxy构建主从复制与读写分离(五)

2014-11-24 17:24:55 · 作者: · 浏览: 4
_User: repl


Master_Port: 3306


Connect_Retry: 60


Master_Log_File: sql-bin.000001


Read_Master_Log_Pos: 120


Relay_Log_File: node2-relay-bin.000002


Relay_Log_Pos: 281


Relay_Master_Log_File: sql-bin.000001


Slave_IO_Running: Yes #为Yes说明成功


Slave_SQL_Running: Yes #为Yes说明成功


Replicate_Do_DB:


Replicate_Ignore_DB:


Replicate_Do_Table:


Replicate_Ignore_Table:


Replicate_Wild_Do_Table:


Replicate_Wild_Ignore_Table:


Last_Errno: 0


Last_Error:


Skip_Counter: 0


Exec_Master_Log_Pos: 120


Relay_Log_Space: 454


Until_Condition: None


Until_Log_File:


Until_Log_Pos: 0


Master_SSL_Allowed: No


Master_SSL_CA_File:


Master_SSL_CA_Path:


Master_SSL_Cert:


Master_SSL_Cipher:


Master_SSL_Key:


Seconds_Behind_Master: 0


Master_SSL_Verify_Server_Cert: No


Last_IO_Errno: 0


Last_IO_Error:


Last_SQL_Errno: 0


Last_SQL_Error:


Replicate_Ignore_Server_Ids:


Master_Server_Id: 10


Master_UUID: 8c55a12b-cd22-11e3-bc81-0050563f4084


Master_Info_File: /usr/local/mysql/data/master.info


SQL_Delay: 0


SQL_Remaining_Delay: NULL


Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it


Master_Retry_Count: 86400


Master_Bind:


Last_IO_Error_Timestamp:


Last_SQL_Error_Timestamp:


Master_SSL_Crl:


Master_SSL_Crlpath:


Retrieved_Gtid_Set:


Executed_Gtid_Set:


Auto_Position: 0


1 row in set (0.05 sec)


ERROR:


No query specified



——测试


1)在master创建一个数据表


mysql> create database user;


Query OK, 1 row affected (0.10 sec)


mysql> create table user.test1(id int);


Query OK, 0 rows affected (0.80 sec)


mysql> insert into user.test1 values(1);


Query OK, 1 row affected (0.12 sec)


mysql> insert into user.test1 values(2);


Query OK, 1 row affected (0.15 sec)


mysql> select * from user.test1;


+------+


| id |


+------+


| 1 |


| 2 |


+------+


2 rows in set (0.02 sec)



2)检测slave是否同步。


mysql> show databases;


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


| Database |


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


| information_schema |


| mysql |


| performance_schema |


| test |


| user |


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


5 rows in set (0.34 sec)


mysql> select * from user.test1;


+------+


| id |


+------+


| 1 |


| 2 |


+------+


2 rows in set (0.04 sec)


#说明同步完成。



——配置读写分离


1)创建相关用户和组


[root@Proxy ~]# groupadd -g 3306 mysql-proxy


[root@Proxy ~]# useradd -u 3306 -g mysql-proxy -s /sbin/nologin -M mysql-proxy



2)编译安装mysql-proxy


[root@Proxy ~]# cd /Linux/


[root@Proxy Linux]# tar zfvx mysql-proxy-0.8.3-linux-rhel5-x86-64bit.tar.gz -C /usr/local/


[root@Proxy local]# mv mysql-proxy-0.8.3-linux-rhel5-x86-64bit/ mysql-proxy


[root@Proxy local]# cd mysql-proxy/


[root@Proxy mysql-proxy]# chown -R root:mysql-proxy .



3)设置mysql-proxy环境变量


[root@Proxy mysql-proxy]# vi /etc/profile.d/mysql-proxy.sh


export PATH=$PATH:/usr/local/mysql-proxy/bin


[root@Proxy mysql-proxy]# source /etc/profile



4)启动mysql-proxy


[root@Proxy mysql-proxy]# mysql-proxy --daemon --log-level=debug \


--log-file=/var/log/mysql-proxy.log --plugins="proxy" \


--proxy-backend-addresses="192.168.1.10:3306" \


--proxy-read-only-backend-addresses="192.168.1.11:3306"



5)查看是否启动[默认端口4040]


[root@Proxy mysql-