日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

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

發布時間:2024/1/1 数据库 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 2014 log

bin目錄下放的都是可執行文件

1. “encrypt”是用來生成MySQL密碼加密的,在配置的時候會用到

2. “mysql-proxy”是MySQL自己的讀寫分離代理

3. “mysql-proxyd”是360弄出來的,后面有個“d”,服務的啟動、重啟、停止。都是用他來執行的

conf目錄下放的是配置文件

1. “test.cnf”只有一個文件,用來配置代理的,可以使用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 test.cnf

進入后,可以在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, 2013, 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, 2013, 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*/ 就可以將讀請求強制發往主庫。

總結

以上是生活随笔為你收集整理的360 mysql读写分离_基于360的Atlas中间件实现MySQL的读写分离的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。