atlas安装
atlas说明
atlas为mysql数据库的中间件,可以实现mysql的读写分离
程序只需要连接atlas入口,无需读写单独指定
程序 -> atlas ->数据库(主库、读库)
mysql读写分离的概念
写在主库,主库一般只有一个
读可以分配在多个从库上,也能把读分配到主库上,如果写压力不大的话
主库+从库 给予atlas读写的权限
grant all privileges on *.* to 'shijiange'@'192.168.237.128' identified by 'pwd666';
atlas连接数据的用户是shijiange,密码是pwd666
Atlas下载地址
https://github.com/Qihoo360/Atlas/releases
Atlas的编译安装
yum install mysql-devel gcc gcc-devel python-devel openssl-devel autoconf glib2 glib2-devel libevent-devel flex-devel flex jemalloc jemalloc-devel loc-devel lua-devel -y
tar -zxvf Atlas-2.2.1.tar.gz
cd Atlas-2.2.1
./bootstrap.sh
make
make install
安装验证
ll -h /usr/local/mysql-proxy/
/usr/local/mysql-proxy/bin/mysql-proxy --version
主库+从库 给予atlas读写的权限
grant all privileges on *.* to 'zxw'@'192.168.126.5' identified by 'zxw';
atlas连接数据的用户是zxw,密码是zxw
配置文件
/usr/local/mysql-proxy/conf/mysql.cnf
[mysql-proxy] #主库地址 proxy-backend-addresses = 192.168.126.6:3306 #从库地址,@后面的数字代表权重,用来负载均衡,默认权重为1。可设置多项,用逗号分隔 proxy-read-only-backend-addresses = 192.168.126.7:3306@1 #用户名和密码,密码需要使用/usr/local/mysql-proxy/bin/encrypt加密 pwds = zxw:s1KPQ9UW5Lw= daemon = true #守护进程 keepalive = true #线程数 event-threads = 1 #日志级别,message、warning、critical、error、debug log-level = warning #日志存放的路径 log-path = /usr/local/mysql-proxy/log #SQL日志的开关,OFF代表不记录SQL日志,ON代表记录SQL日志,REALTIME代表记录SQL日志且实时写入磁盘 sql-log = OFF #慢日志输出设置。单位:ms sql-log-slow = 1000 #Atlas监听端口 proxy-address = 192.168.126.5:3306 #管理监听端口 admin-address = 0.0.0.0:2345 admin-username = zxw admin-password = zxw #客户端连接默认字符集,不设置的话一般还需要使用set names utf8 charset = utf8 #ip白名单 #client-ips = 127.0.0.1, 192.168.3.1
启动
[root@ceph1 bin]# ./mysql-proxyd mysql start OK: MySQL-Proxy of mysql is started