Amoeba(變形蟲(chóng))項(xiàng)目是一個(gè)開(kāi)源框架,于2008年開(kāi)始發(fā)布一款 Amoeba for Mysql軟件;
這個(gè)軟件致力于MySQL的分布式數(shù)據(jù)庫(kù)前端代理層,它主要在應(yīng)用層訪問(wèn)MySQL的時(shí)候充當(dāng)SQL路由功能,專(zhuān)注于分布式數(shù)據(jù)庫(kù)代理層(Database Proxy)開(kāi)發(fā);位于 Client、DB Server(s)之間,對(duì)客戶端透明;
===================================================================
1 簡(jiǎn)介
2 準(zhǔn)備
? ?2.1 時(shí)間同步
? ?2.2 配置MySQL主從復(fù)制架構(gòu)
3 ameoba安裝配置
? ?3.1 安裝配置JDK
? ?3.2 安裝ameoba
? ?3.3 配置ameoba
? ?3.4 使用驗(yàn)證
? ?3.5 后期擴(kuò)展
4 問(wèn)題記錄
===================================================================
?
1 簡(jiǎn)介
Amoeba(變形蟲(chóng))項(xiàng)目是一個(gè)開(kāi)源框架,于2008年開(kāi)始發(fā)布一款 Amoeba for Mysql軟件;
這個(gè)軟件致力于MySQL的分布式數(shù)據(jù)庫(kù)前端代理層,它主要在應(yīng)用層訪問(wèn)MySQL的時(shí)候充當(dāng)SQL路由功能,專(zhuān)注于分布式數(shù)據(jù)庫(kù)代理層(Database Proxy)開(kāi)發(fā);位于 Client、DB Server(s)之間,對(duì)客戶端透明;
具有負(fù)載均衡、高可用性、SQL 過(guò)濾、讀寫(xiě)分離、可路由相關(guān)的請(qǐng)求到目標(biāo)數(shù)據(jù)庫(kù)、可并發(fā)請(qǐng)求多臺(tái)數(shù)據(jù)庫(kù)并合并結(jié)果;
通過(guò)Amoeba你能夠完成多數(shù)據(jù)源的高可用、負(fù)載均衡、數(shù)據(jù)切片的功能,目前Amoeba已在很多企業(yè)的生產(chǎn)線上面使用;
?
2 準(zhǔn)備
2.1 時(shí)間同步
# crontab - e # Dscrip: Time Sync # CTime: 2014.03 . 23 */ 5 * * * * /usr/sbin/ntpdate 172.16 . 0.1 &>/dev/ null
2.2 配置MySQL主從復(fù)制架構(gòu)
詳見(jiàn)博文" MariaDB 主從復(fù)制 "
?
3 ameoba安裝配置
3.1 安裝配置JDK
chmod +x jdk-6u31-linux-x64- rpm.bin vi /etc/profile.d/java. sh # 采用bin文件安裝jdk export JAVA_HOME =/usr/java/ latest export PATH =$JAVA_HOME/bin:$PATH
3.2 安裝ameoba
mkdir /usr/local/ amoeba tar xf amoeba-mysql-binary- 2.2 . 0 . tar .gz -C /usr/local/ amoeba # 使用二進(jìn)制程序文件安裝amoeba cd /usr/local/ amoeba bin / amoeba start # 前臺(tái)運(yùn)行 nohup /usr/local/amoeba/bin/amoeba start & # 后臺(tái)運(yùn)行 mysql -h127. 0.0 . 1 -uroot -p -P8066 # amoeba默認(rèn)監(jiān)聽(tīng)端口為8066
3.3 配置ameoba
cd /usr/local/amoeba/ conf vi ameoba.xml # 前端定義配置文件 # 修改ameoba前端監(jiān)聽(tīng)端口 <service name= " Amoeba for Mysql " class= " com.meidusa.amoeba.net.ServerableConnectionManager " > <property name= " port " > 3306 </property> # 默認(rèn)端口是8066,修改為3306,便于實(shí)現(xiàn)前端程序連接數(shù)據(jù)庫(kù)的透明性 # 修改連接amoeba接口的認(rèn)證信息 <property name= " authenticator " > <bean class= " com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator " > <property name= " user " >root</property> <property name= " password " >mypass</property> # 添加登錄密碼 # 查詢路由設(shè)置 <queryRouter class= " com.meidusa.amoeba.mysql.parser.MysqlQueryRouter " > <property name= " ruleLoader " > <bean class= " com.meidusa.amoeba.route.TableRuleFileLoader " > <property name= " ruleFile " >${amoeba.home}/conf/rule.xml</property> <property name= " functionFile " >${amoeba.home}/conf/ruleFunctionMap.xml</property> </bean> </property> <property name= " sqlFunctionFile " >${amoeba.home}/conf/functionMap.xml</property> <property name= " LRUMapSize " > 1500 </property> <property name= " defaultPool " >master</property> # 設(shè)定默認(rèn)節(jié)點(diǎn) <property name= " writePool " >master</property> # 設(shè)定可寫(xiě)節(jié)點(diǎn),節(jié)點(diǎn)定義見(jiàn)dbServers.xml文件 <property name= " readPool " >readservers</property> # 設(shè)定只讀池,可配置多個(gè)slave節(jié)點(diǎn) <property name= " needParse " > true </property> </queryRouter> vi dbServers.xml # 后端節(jié)點(diǎn)配置文件 # 定義抽象服務(wù)器,為每個(gè)后端MySQL服務(wù)器提供默認(rèn)連接配置 <dbServer name= " abstractServer " abstractive= " true " > <factoryConfig class= " com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory " > <property name= " manager " >${defaultManager}</property> <property name= " sendBufferSize " > 64 </property> <property name= " receiveBufferSize " > 128 </property> <property name= " port " > 3406 </property> <property name= " schema " >test</property> <property name= " user " >root</property> <property name="password"> magedu </property> </factoryConfig> # 定義后端MySQL的IP地址,一個(gè)master,一個(gè)slave <dbServer name= " master " parent= " abstractServer " > <factoryConfig> <property name= " ipAddress " > 192.168 . 0.45 </property> </factoryConfig> </dbServer> <dbServer name= " slave " parent= " abstractServer " > <factoryConfig> <property name= " ipAddress " > 192.168 . 0.46 </property> </factoryConfig> </dbServer> # 定義虛擬服務(wù)器組,即只讀池readservers <dbServer name= " readservers " virtual= " true " > <poolConfig class= " com.meidusa.amoeba.server.MultipleServerPool " > <property name= " loadbalance " > 1 </property> <property name= " poolNames " >master,slave</property> </poolConfig> </dbServer>
3.4 使用驗(yàn)證
在主庫(kù)上授權(quán):
MariaDB [(none)]> grant all on *.* to ' root ' @ ' 172.16.%.% ' identified by ' magedu ' ; Query OK, 0 rows affected ( 0.00 sec) MariaDB [(none)] > grant all on *.* to ' root ' @ ' %mysql.com ' identified by ' magedu ' ; # 這里的密碼應(yīng)該與dbServer.xml中的數(shù)據(jù)庫(kù)密碼一致 Query OK, 0 rows affected ( 0.00 sec) MariaDB [(none)] > flush privileges; Query OK, 0 rows affected ( 0.00 sec)
# 登錄驗(yàn)證 [root@mysql conf]# mysql -h127. 0.0 . 1 -uroot -p - P3306 Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 2097086015 Server version: 5.1 . 45 -mysql-amoeba-proxy- 2.2 . 0 Source distribution Copyright (c) 2000 , 2014 , Oracle, SkySQL Ab and others. Type ' help; ' or ' \h ' for help. Type ' \c ' to clear the current input statement. MySQL [(none)] > show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin. 000030 | 326 | | | +------------------+----------+--------------+------------------+ 1 row in set ( 0.00 sec) MySQL [(none)] > # 讀寫(xiě)驗(yàn)證 [root@mysql conf]# mysql -h127. 0.0 . 1 -uroot -p - P3306 Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 2097086015 Server version: 5.1 . 45 -mysql-amoeba-proxy- 2.2 . 0 Source distribution Copyright (c) 2000 , 2014 , Oracle, SkySQL Ab and others. Type ' help; ' or ' \h ' for help. Type ' \c ' to clear the current input statement. MySQL [(none)] > create database amoeba_test; Query OK, 1 row affected ( 0.04 sec) MySQL [(none)] > [root@mysql bin]# mysql -h127. 0.0 . 1 -uroot -p - P3406 Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 33 Server version: 10.0 . 10 -MariaDB- log Source distribution Copyright (c) 2000 , 2014 , Oracle, SkySQL Ab and others. Type ' help; ' or ' \h ' for help. Type ' \c ' to clear the current input statement. MariaDB [(none)] > show databases; +--------------------+ | Database | +--------------------+ | amoeba_test | | information_schema | | mysql | | performance_schema | | test | +--------------------+ 9 rows in set ( 0.01 sec) MariaDB [(none)] > # 從amoeba接口登錄創(chuàng)建數(shù)據(jù)庫(kù)amoeba_test后,再?gòu)闹鲙?kù)的接口中去查詢數(shù)據(jù)庫(kù)已創(chuàng)建,說(shuō)明寫(xiě)入確實(shí)是落在了主庫(kù)節(jié)點(diǎn)上; # 若要驗(yàn)證ameoba對(duì)于讀操作的調(diào)度,則需要暫時(shí)停止從庫(kù)的復(fù)制操作,然后在主庫(kù)上更新數(shù)據(jù),這樣從ameoba讀取數(shù)據(jù)將出現(xiàn)不一致的情況;
3.5 后期擴(kuò)展
利用MMM雙主復(fù)制架構(gòu)+Amoeba代理,可以實(shí)現(xiàn)對(duì)MySQL的高可用性和高性能;
關(guān)于MMM的內(nèi)容參加博文" MySQL Scale Out "
4 問(wèn)題記錄
現(xiàn)象 :使用mysql -uroot -p -P8066命令始終無(wú)法連接進(jìn)入ameoba的配置接口,一直都是進(jìn)入mysql數(shù)據(jù)庫(kù)的配置接口
原因 :在測(cè)試環(huán)境下,ameoba和mysql的主庫(kù)都部署在同一臺(tái)主機(jī)上,當(dāng)啟動(dòng)ameoba服務(wù)后,即使指定-P8066連接,mysql客戶端還是默認(rèn)采用可被識(shí)別的socket文件(/tmp/mysql.sock)連接,同樣指定-hlocalhost也是一樣的;
當(dāng)使用mysql命令連接mysqld時(shí):
-
連接主機(jī)為localhost或不指定時(shí),mysql會(huì)采用Unix Socket的連接方式;
-
連接主機(jī)為127.0.0.1時(shí),mysql會(huì)采用TCP的方式連接;
解決方法 :指定-h127.0.0.1連接即可,即mysql -h127.0.0.1 -uroot -p -P8066
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
