lua-5.0.2-1.el5.rf.i386.rpm mysql-proxy-0.8.0-linux-rhel5-x86-32bit.tar.gz
lua-devel-5.0.2-1.el5.rf.i386.rpm
[root@proxy ~]# rpm -ivh lua-5.0.2-1.el5.rf.i386.rpm
warning: lua-5.0.2-1.el5.rf.i386.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing... ########################################### [100%]
1:lua ########################################### [100%] [root@proxy ~]# rpm -ivh lua-devel-5.0.2-1.el5.rf.i386.rpm
warning: lua-devel-5.0.2-1.el5.rf.i386.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing... ########################################### [100%]
1:lua-devel ########################################### [100%]将mysql-proxy软件包减压到/usr/local/目录并改名为 proxy
[root@proxy ~]# tar xzf mysql-proxy-0.8.0-linux-rhel5-x86-32bit.tar.gz -C /usr/local/
[root@proxy ~]# cd /usr/local
[root@proxy ~]# mv mysql-proxy-0.8.0-linux-rhel5-x86-32bit/ proxy
这个代理软件减压就可以直接用了。 2、开启其他俩台机器的mysqld服务。 [root@MASTER ~]# service mysqld start
启动 MySQL: [确定]
[root@MASTER ~]# [root@BACKUP ~]# service mysqld start
启动 MySQL: [确定]
[root@BACKUP ~]# 3、完成后,在MASTER和BACKUP在准备一张表,分别授权一个用户,查看实验效果。 [root@BACKUP ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.77 Source distributionType 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> use test ;
Database changed
mysql> create table test(id int);
Query OK, 0 rows affected (0.04 sec)mysql> grant all on *.* to zhaoyun@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
[root@MASTER ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.77 Source distributionType 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> use test
Database changed
mysql> create table test(id int);
Query OK, 0 rows affected (0.02 sec)mysql> grant all on *.* to zhaoyun@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into test values(1);
Query OK, 1 row affected (0.00 sec)
现在back数据库插入一条数据,来查看实验效果。
4、准备工作完成,下面配置代理服务。 [root@proxy mysql-proxy]# pwd
/usr/local/proxy/share/doc/mysql-proxy
[root@proxy mysql-proxy]# vi rw-splitting.lua min_idle_connections = 4, 为了验证试验效果将他改成1 .就是当有一个链接的时候,就实现读写分离的功能。
# max_idle_connections = 8, [root@proxy bin]# ./mysql-proxy -P 192.168.0.17:3306 -r 192.168.0.59:3306 -b 192.168.0.193:3306 -s /usr/local/proxy/share/doc/mysql-proxy/rw-splitting.lua
2011-12-09 21:28:39: (critical) chassis-limits.c:81: could not raise RLIMIT_NOFILE to 8192, Invalid argument (22). Current limit still 1024.-P 指定本机地址端口即代理server-r 可读的数据库服务器及端口-b 可写的数据库服务器及端口-s 执行配置文件在第一次执行时会出现文件限制的信息。需要修改一下系统参数使用ulimit命令配置。[root@proxy bin]# ulimit -n 10240完成后再次启动,现在启动没有信息了,将其放在后台运行。后面加&就可以了。[root@proxy bin]# ./mysql-proxy -P 192.168.0.17:3306 -r 192.168.0.59:3306 -b 192.168.0.193:3306 -s /usr/local/proxy/share/doc/mysql-proxy/rw-splitting.lua
& 代理启动后会启动一个端口就是-P指定的 [root@localhost ~]# netstat -antlp |grep 3306
tcp 0 0 192.168.0.17:3306 0.0.0.0:* LISTEN 23560/mysql-proxy
[root@localhost ~]# 5、在客户端进行测试。 [root@client ~]# mysql -h 192.168.0.59 -uzhaoyun -p123456连接后分别对数据表进行读写操作,查看是否能看到读和写不在同一个机器。。 在客户端对数据进行操作时,代理服务会显示信息 server default db: test
client default db:
syncronizing
server default db: test
client default db:
syncronizing
server default db: test
client default db: zhaoyun
syncronizing
本文出自 “技术交流” 博客,请务必保留此出处http://zhaoyun.blog.51cto.com/2090116/738312