时间:2021-07-01 10:21:17 帮助过:27人阅读
##安装mysql-server主服务端(192.168.10.25)
service firewalld stop
chkconfig firewalld off
setenforce 0
getenforce
sed -i ‘s/^SELINUX=enforcing/SELINUX=permissive/‘ /etc/selinux/config
yum install -y mariadb mariadb-server
service mariadb restart
chkconfig mariadb on
sed -i ‘1aserver_id=25‘ /etc/my.cnf
sed -i ‘2alog-bin=mysql-bin‘ /etc/my.cnf
service mariadb restart
mysql -uroot -e "grant all on *.* to admin@‘%‘ identified by ‘01‘;flush privileges;"
mysql -uroot -e "grant replication slave on *.* to rep@‘%‘ identified by ‘01‘;flush privileges;"
mysql -uroot -e "select user,host,password from mysql.user;"
mysql -uroot -e "reset master;show master status;"
##安装mysql-server主服务端(192.168.10.26)
service firewalld stop
chkconfig firewalld off
setenforce 0
getenforce
sed -i ‘s/^SELINUX=enforcing/SELINUX=permissive/‘ /etc/selinux/config
yum install -y mariadb mariadb-server
service mariadb restart
chkconfig mariadb on
sed -i ‘1aserver_id=26‘ /etc/my.cnf
sed -i ‘2alog-bin=mysql-bin‘ /etc/my.cnf
service mariadb restart
mysql -uroot -e "grant all on *.* to admin@‘%‘ identified by ‘01‘;flush privileges;"
mysql -uroot -e "grant replication slave on *.* to rep@‘%‘ identified by ‘01‘;flush privileges;"
mysql -uroot -e "select user,host,password from mysql.user;"
mysql -uroot -e "change master to master_host=‘192.168.100.11‘,master_user=‘rep‘,master_password=‘01‘,master_port=3306,master_log_file=‘mysql-bin.000001‘,master_log_pos=245;"
sleep 30s
mysql -uroot -e "start slave;show slave status\G"
##安装配置atlas读写分离(192.168.10.28)
service iptables stop
chkconfig iptables off
setenforce 0
getenforce
sed -i ‘s/^SELINUX=enforcing/SELINUX=permissive/‘ /etc/selinux/config
grep ‘^SELINUX=‘ /etc/selinux/config
安装和配置atlas软件
rpm -ivh Atlas-2.2.1.el6.x86_64.rpm
echo "PATH=$PATH:/usr/local/mysql-proxy/bin/" >> /etc/profile
source /etc/profile
ll /usr/local/mysql-proxy/
##mysql-proxy文件功能说明:
bin目录下放的都是可执行文件
1. “encrypt”是用来生成MySQL密码加密的,在配置的时候会用到
2. “mysql-proxy”是MySQL自己的读写分离代理
3. “mysql-proxyd”是360弄出来的,后面有个“d”,服务的启动、重启、停止。都是用他来执行的
conf目录下放的是配置文件
1. “test.cnf”只有一个文件,用来配置代理的,可以使用vim来编辑
lib目录下放的是一些包,以及Atlas的依赖
log目录下放的是日志,如报错等错误信息的记录
进入bin目录,使用encrypt来对数据库的密码进行加密,我的MySQL数据的用户名是admin,密码是01,我需要对密码进行加密
cd /usr/local/mysql-proxy/bin/
./encrypt 01 生成加密密码,并复制此密码
cd /usr/local/mysql-proxy/conf/
cp -v test.cnf test.cnf.bak //备份test.cnf配置文件
vi test.conf 修改后的读写分享的完整配置文件内容
[mysql-proxy]
admin-username = user
admin-password = pwd
proxy-backend-addresses = 192.168.100.11:3306
pwds = admin:VFnEp9P4Vu4=, rep:VFnEp9P4Vu4=
daemon = true
keepalive = true
event-threads = 8
log-level = message
log-path = /usr/local/mysql-proxy/log
proxy-address = 0.0.0.0:3306
admin-address = 0.0.0.0:2345
test.cnf读写分离配置文件功能说明:
1:[mysql-proxy] //读写分离代理配置
6:admin-username = user //管理接口的用户名
9:admin-password = pwd //管理接口的密码
12:proxy-backend-addresses = 192.168.100.11:3306 //主数据库的IP地址和端口号(可读可写)
18:pwds = admin:VFnEp9P4Vu4=, rep:VFnEp9P4Vu4= //后端MYSQL的用户名和encrypt命令生成的加密密码
21:daemon = true //设置为守护进程模式(后台运行)
24:keepalive = true //允许keepalive
27:event-threads = 8 //工作线程数为8
30:log-level = message //日志等级为message消息
33:log-path = /usr/local/mysql-proxy/log //日志文件路径
45:proxy-address = 0.0.0.0:3306 //Atlas监听的管理接口IP和端口
48:admin-address = 0.0.0.0:2345 //Atlas监听的管理接口IP和端口
重启atlas服务:/usr/local/mysql-proxy/bin/mysql-proxyd test start
查状态:./etc/init.d/mysqld status
设置mysql-proxyd开机启动:
echo "/usr/local/mysql-proxy/bin/mysql-proxyd test start" >> /etc/profile
source /etc/profile
登录测试:mysql -uadmin -p01 -h 192.168.10.28 -P3306
登录到atlas管理端:mysql -uuser -ppwd -h 192.168.10.28 -P2345
采用Atlas实现MySQL读写分离
标签:采用atlas实现mysql读写分离