700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 360 mysql读写分离_基于360的Atlas中间件实现MySQL的读写分离

360 mysql读写分离_基于360的Atlas中间件实现MySQL的读写分离

时间:2022-11-26 11:57:49

相关推荐

360 mysql读写分离_基于360的Atlas中间件实现MySQL的读写分离

Atlas配置

下载Atlas会有两个版本,其中有个分表的版本,但是这个需要其他的依赖,我这边不需要分表这种需求,所以安装普通的版本

首先进入Linux的Home目录下,下载非分表的安装包

下载好了之后,进行安装

[root@localhost home]# rpm -ivh Atlas-2.2.1.el6.x86_64.rpm

Preparing... ########################################### [100%]1:Atlas ########################################### [100%]

安装好了,它会默认在”/usr/local/mysql-proxy”下给你生成4个文件夹,以及需要配置的文件,如下:

[root@localhost home]# ll /usr/local/mysql-proxy/total16drwxr-xr-x. 2 root root 4096 Dec 28 10:47bin

drwxr-xr-x. 2 root root 4096 Dec 28 10:47conf

drwxr-xr-x. 3 root root 4096 Dec 28 10:47lib

drwxr-xr-x. 2 root root 4096 Dec 17 log

bin目录下放的都是可执行文件

1. “encrypt”是用来生成MySQL密码加密的,在配置的时候会用到

2. “mysql-proxy”是MySQL自己的读写分离代理

3. “mysql-proxyd”是360弄出来的,后面有个“d”,服务的启动、重启、停止。都是用他来执行的

conf目录下放的是配置文件

1. “f”只有一个文件,用来配置代理的,可以使用vim来编辑

lib目录下放的是一些包,以及Atlas的依赖

log目录下放的是日志,如报错等错误信息的记录

进入bin目录,使用encrypt来对数据库的密码进行加密,我的MySQL数据的用户名是buck,密码是hello,我需要对密码进行加密

[root@localhost bin]# ./encrypt hello

RePBqJ+5gI4=

配置Atlas,使用vim进行编辑

[root@localhost conf]# cd /usr/local/mysql-proxy/conf/[root@localhost conf]# vim f

进入后,可以在Atlas进行配置,360写的中文注释都很详细,根据注释来配置信息,其中比较重要,需要说明的配置如下:

这是用来登录到Atlas的管理员的账号与密码,与之对应的是“#Atlas监听的管理接口IP和端口”,也就是说需要设置管理员登录的端口,才能进入管理员界面,默认端口是2345,也可以指定IP登录,指定IP后,其他的IP无法访问管理员的命令界面。方便测试,我这里没有指定IP和端口登录。

#管理接口的用户名

admin-username =user

#管理接口的密码

admin-password = pwd

这是用来配置主数据的地址与从数据库的地址,这里配置的主数据库是135,从数据库是134

#Atlas后端连接的MySQL主库的IP和端口,可设置多项,用逗号分隔

proxy-backend-addresses = 192.168.246.134:3306#Atlas后端连接的MySQL从库的IP和端口,@后面的数字代表权重,用来作负载均衡,若省略则默认为1,可设置多项,用逗号分隔

proxy-read-only-backend-addresses = 192.168.246.135:3306@1

这个是用来配置MySQL的账户与密码的,我的MySQL的用户是buck,密码是hello,刚刚使用Atlas提供的工具生成了对应的加密密码

#用户名与其对应的加密过的MySQL密码,密码使用PREFIX/bin目录下的加密程序encrypt加密,下行的user1和user2为示例,将其替换为你的MySQL的用户名和加密密码!

pwds= buck:RePBqJ+5gI4=

这是设置工作接口与管理接口的,如果ip设置的”0.0.0.0”就是说任意IP都可以访问这个接口,当然也可以指定IP和端口,方便测试我这边没有指定,工作接口的用户名密码与MySQL的账户对应的,管理员的用户密码与上面配置的管理员的用户密码对应。

#Atlas监听的工作接口IP和端口

proxy-address = 0.0.0.0:3307#Atlas监听的管理接口IP和端口

admin-address = 0.0.0.0:3308

启动Atlas

[root@localhost bin]# ./mysql-proxyd test start

OK: MySQL-Proxy of test is started

测试一下Atlas服务器的MySQL状态,要确认它是关闭状态,并且使用mysql命令,进不去数据库

[root@localhost bin]# /etc/init.d/mysqld status

mysqldisstopped

[root@localhost bin]# mysql

ERROR2002 (HY000): Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock'(2)

确认系统中自带的MySQL进不去了,使用如下命令,进入Atlas的管理模式“mysql -h127.0.0.1-P2345 -uuser -ppwd”,能进去说明Atlas正常运行着呢,因为它会把自己当成一个MySQL数据库,所以在不需要数据库环境的情况下,也可以进入到MySQL数据库模式。

[root@localhost bin]# mysql -h127.0.0.1 -P3308 -uuser -ppwd

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection idis 1Server version:5.0.99-agent-admin

Copyright (c)2000, , Oracle and/or its affiliates. All rights reserved.

Oracleis a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type'help;' or '\h' for help. Type '\c'to clear the current input statement.

mysql>

可以访问“help”表,来看MySQL管理员模式都能做些什么。可以使用SQL语句来访问

mysql> select * fromhelp;+----------------------------+---------------------------------------------------------+

| command | description |

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

| SELECT * FROM help | shows this help |

| SELECT * FROM backends | lists the backends and their state |

| SET OFFLINE $backend_id | offline backend server, $backend_id is backend_ndx's id |

| SET ONLINE $backend_id | online backend server, ... |

| ADD MASTER $backend | example: "add master 127.0.0.1:3306", ... |

| ADD SLAVE $backend | example: "add slave 127.0.0.1:3306", ... |

| REMOVE BACKEND $backend_id | example: "remove backend 1", ... |

| SELECT * FROM clients | lists the clients |

| ADD CLIENT $client | example: "add client 192.168.1.2", ... |

| REMOVE CLIENT $client | example: "remove client 192.168.1.2", ... |

| SELECT * FROM pwds | lists the pwds |

| ADD PWD $pwd | example: "add pwd user:raw_password", ... |

| ADD ENPWD $pwd | example: "add enpwd user:encrypted_password", ... |

| REMOVE PWD $pwd | example: "remove pwd user", ... |

| SAVE CONFIG | save the backends to config file |

| SELECT VERSION | display the version of Atlas |

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

16 rows in set (0.00sec)

mysql>

也可以使用工作接口来访问,使用命令“mysql -h127.0.0.1 -P3307 -ubuck -phello”

[root@localhost bin]# mysql -h127.0.0.1 -P3307 -ubuck -phello

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection idis 1Server version:5.0.81-log

Copyright (c)2000, , Oracle and/or its affiliates. All rights reserved.

Oracleis a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type'help;' or '\h' for help. Type '\c'to clear the current input statement.

mysql>

如果工作接口可以进入了,就可以在Windows平台下,使用Navicat来连接数据库,填写对应的host,Port,用户名,密码就可以

为了解决读写分离存在写完马上就想读而这时可能存在主从同步延迟的情况,Altas中可以在SQL语句前增加 /*master*/ 就可以将读请求强制发往主库。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。