首页 > 代码库 > mysql读写分离
mysql读写分离
root@bogon ~]# yum -y install gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libmcrypt* libtool* flex* pkgconfig*
libevent* glib* readline-devel
[root@bogon ~]# mkdir /opt/install/
[root@bogon ~]# cd /opt/install/
[root@bogon install]# wget http://www.lua.org/ftp/lua-5.1.4.tar.gz
[root@bogon install]# tar zxvf lua-5.2.3.tar.gz
[root@bogon install]# cd lua-5.2.3
[root@bogon install]# make linux
此时如果出现
lua.c:67:31: fatal error: readline/readline.h: No such file or directory
说明缺少libreadline-dev依赖包
[plain] view plain copy print?在CODE上查看代码片派生到我的代码片
[root@bogon install]# make install
[root@bogon install]# export LUA_CFLAGS="-I/usr/local/include" LUA_LIBS="-L/usr/local/lib -llua -ldl" LDFLAGS="-lm"
这行代码我也不知道啥作用,好像是的指定环境变量。
下面开始安装mysql-proxy
安装之前先看一下自己机器是否是64位系统
查看centos内核的版本
[plain] view plain copy print?在CODE上查看代码片派生到我的代码片
[root@bogon install]# cat /etc/issue
查看linux版本
[plain] view plain copy print?在CODE上查看代码片派生到我的代码片
[root@bogon install]# cat /proc/version
[root@bogon install]# lsb_release -a
载地址:http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-Proxy/
[plain] view plain copy print?在CODE上查看代码片派生到我的代码片
[root@bogon install]# cd /opt/install
[root@bogon install]# wget http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-Proxy/mysql-proxy-0.8.4-linux-rhel5-x86-32bit.tar.gz
[root@bogon install]# tar zxvf mysql-proxy-0.8.4-linux-rhel5-x86-32bit.tar.gz
[root@bogon install]# mkdir /opt/mysql-proxy/
[root@bogon install]# cp /opt/install/mysql-proxy-0.8.4-linux-rhel5-x86-32bit/* /opt/mysql-proxy/
[root@bogon install]# cd /opt/mysql-proxy/
[root@bogon install]# export PATH=$PATH:/opt/mysql-proxy/bin/
mysql-proxy.conf配置
[mysql-proxy]
#[aemon = tru]
#keepalive = true
pid-file = /var/run/mysql-proxy.pid
#log-file = /var/log/mysql-proxy.log
#log-level = debug
#max-open-files = 1024
plugins = admin,proxy
#user = mysql-proxy
#
#Proxy Configuration
#proxy-address = 0.0.0.0:3307
proxy-backend-addresses = 192.168.1.144:3306 读写权限mysql
proxy-read-only-backend-addresses = 192.168.1.106:3306 只读mysql
proxy-lua-script =/usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua
proxy-skip-profiling = true
#
# Admin Configuration
admin-address = 192.168.1.144:4041 这个是mysql-proxy的管理端口和ip
admin-lua-script = /usr/local/mysql-proxy/share/doc/mysql-proxy/admin.lua
admin-username = porxy1 这个是mysql-proxy的用户密码
admin-password = 123456
启动/usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/usr/local/mysql-proxy/mysql-proxy.conf
2016-08-19 17:23:18: (critical) plugin admin 0.8.3 started
2016-08-19 17:23:18: (critical) plugin proxy 0.8.3 started
后会看到这两的lua脚本被启动
测试/usr/local/mysql/bin/mysql -uporxy1 -p123456 -P4041 -h192.168.1.144 这是登入mysql-proxy的管理端口用的proxy的用户密码
在这个下面无法实现mysql的命令
SELECT * FROM backends 用这个命令查看mysql的连接情况
backend_ndx | address | state | type | uuid | connected_clients |
+-------------+--------------------+-------+------+------+-------------------+
| 1 | 192.168.1.144:3306 | up | rw | NULL | 0 |
| 2 | 192.168.1.106:3306 | up | ro | NULL | 0
/usr/local/mysql/bin/mysql -uproxy1 -p123456 -h192.168.1.144 -P4040 是用户端口这个用户密码必须是mysql的用户
mysql读写分离