系在安裝 64位版本的rpm包
wget https://github.com/Qihoo360/Atlas/releases/download/sharding-1.0.1/Atlas-sharding_1.0.1-el6.x86_64.rpm rpm -ivh Atlas-2.2.el6.x86_64_2.rpm Preparing... ########################################### [100%] 1:Atlas ########################################### [100%] [root@dev04 downloads]# ls
rpm包安裝後,修改/usr/local/test.cnf
[mysql-proxy] #帶#號的爲非必需的配置項目 #管理接口的用戶名 admin-username = root #管理接口的密碼 admin-password = 123456 #Atlas後端連接的MySQL主庫的IP和端口,可設置多項,用逗號分隔 proxy-backend-addresses = 10.1.1.102:3306 #Atlas後端連接的MySQL從庫的IP和端口,@後面的數字代表權重,用來作負載均衡,若省略則默認爲1,可設置多項,用逗號分隔 proxy-read-only-backend-addresses = 10.1.1.107:3306@1,10.1.1.108:3306@1 #用戶名與其對應的加密過的MySQL密碼,密碼使用PREFIX/bin目錄下的加密程序encrypt加密,下行的user1和user2爲示例,將其替換爲你的MySQL的用戶名和加密密碼! pwds = repluser:Zm3rwtutc2Qa8s/oWZlMvQ== #設置Atlas的運行方式,設爲true時爲守護進程方式,設爲false時爲前臺方式,一般開發調試時設爲false,線上運行時設爲true,true後面不能有空格。 daemon = true #設置Atlas的運行方式,設爲true時Atlas會啓動兩個進程,一個爲monitor,一個爲worker,monitor在worker意外退出後會自動將其重啓,設爲false時只有worker,沒有monitor,一般開發調試時設爲false,線上運行時設爲true,true後面不能有空格。 keepalive = true #工作線程數,對Atlas的性能有很大影響,可根據情況適當設置 event-threads = 8 #日誌級別,分爲message、warning、critical、error、debug五個級別 log-level = message #日誌存放的路徑 log-path = /usr/local/mysql-proxy/log #SQL日誌的開關,可設置爲OFF、ON、REALTIME,OFF代表不記錄SQL日誌,ON代表記錄SQL日誌,REALTIME代表記錄SQL日誌且實時寫入磁盤,默認爲OFF #sql-log = OFF #慢日誌輸出設置。當設置了該參數時,則日誌只輸出執行時間超過sql-log-slow(單位:ms)的日誌記錄。不設置該參數則輸出全部日誌。 #sql-log-slow = 10 #實例名稱,用於同一臺機器上多個Atlas實例間的區分 #instance = test #Atlas監聽的工作接口IP和端口 proxy-address = 0.0.0.0:1234 #Atlas監聽的管理接口IP和端口 admin-address = 0.0.0.0:2345 #分表設置,此例中person爲庫名,mt爲表名,id爲分表字段,3爲子表數量,可設置多項,以逗號分隔,若不分表則不需要設置該項 #tables = person.mt.id.3 #默認字符集,設置該項後客戶端不再需要執行SET NAMES語句 #charset = utf8 #允許連接Atlas的客戶端的IP,可以是精確IP,也可以是IP段,以逗號分隔,若不設置該項則允許所有IP連接,否則只允許列表中的IP連接 #client-ips = 127.0.0.1, 192.168.1 #Atlas前面掛接的LVS的物理網卡的IP(注意不是虛IP),若有LVS且設置了client-ips則此項必須設置,否則可以不設置 #lvs-ips = 192.168.1.1
運行Atlas
進入/usr/local/mysql-proxy/bin目錄,執行下面的命令啓動、重啓或停止Atlas。
(1). sudo ./mysql-proxyd test start,啓動Atlas。
(2). sudo ./mysql-proxyd test restart,重啓Atlas。
(3). sudo ./mysql-proxyd test stop,停止Atlas。
注意:
(1). 運行文件是:mysql-proxyd(不是mysql-proxy)。
(2). test是conf目錄下配置文件的名字,也是配置文件裏instance項的名字,三者需要統一。
(3). 可以使用ps -ef | grep mysql-proxy查看Atlas是否已經啓動或停止。
執行命令:mysql -h127.0.0.1 -P1234 -u用戶名 -p密碼,如果能連上則證明Atlas初步測試正常,可以再嘗試發幾條SQL語句看看執行結果是否正確。
進入Atlas的管理界面的命令:mysql -h127.0.0.1 -P2345 -uuser -ppwd,進入後執行:select * from help;查看管理DB的各類命令。
管理控制檯:
mysql -uroot -p123456 -h10.1.1.108 -P2345 Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.0.99-agent-admin Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is 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> select * from help; +----------------------------+---------------------------------------------------------+ | 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", ... | | ADD CLIENT $client | example: "add client 192.168.1.2", ... | | REMOVE CLIENT $client | example: "remove client 192.168.1.2", ... | | SAVE CONFIG | save the backends to config file | +----------------------------+---------------------------------------------------------+ 10 rows in set (0.01 sec) mysql> select * from backends; +-------------+-----------------+-------+------+ | backend_ndx | address | state | type | +-------------+-----------------+-------+------+ | 1 | 10.1.1.102:3306 | up | rw | | 2 | 10.1.1.107:3306 | up | ro | | 3 | 10.1.1.108:3306 | up | ro | +-------------+-----------------+-------+------+ 3 rows in set (0.01 sec)
Slave HA 測試
登陸一個slave機器(107)
mysql> stop slave;
然後使用 mysql -urepluser -preplpass -h10.1.1.108 -P1234 登陸後進行插入
再執行查詢,應該是輪訓查詢兩個slave服務器(107和108),由於107關掉了slave同步,所以
結果會顯示不同步,再次查詢會顯示同步(108),這說明負載均衡生效。
更多參考見 https://github.com/Qihoo360/Atlas/blob/master/README_ZH.md