Amoeba(變形蟲)項目是一個開源框架,于2008年開始發布一款 Amoeba for Mysql軟件;
這個軟件致力于MySQL的分布式數據庫前端代理層,它主要在應用層訪問MySQL的時候充當SQL路由功能,專注于分布式數據庫代理層(Database Proxy)開發;位于 Client、DB Server(s)之間,對客戶端透明;
===================================================================
1 簡介
2 準備
? ?2.1 時間同步
? ?2.2 配置MySQL主從復制架構
3 ameoba安裝配置
? ?3.1 安裝配置JDK
? ?3.2 安裝ameoba
? ?3.3 配置ameoba
? ?3.4 使用驗證
? ?3.5 后期擴展
4 問題記錄
===================================================================
?
1 簡介
Amoeba(變形蟲)項目是一個開源框架,于2008年開始發布一款 Amoeba for Mysql軟件;
這個軟件致力于MySQL的分布式數據庫前端代理層,它主要在應用層訪問MySQL的時候充當SQL路由功能,專注于分布式數據庫代理層(Database Proxy)開發;位于 Client、DB Server(s)之間,對客戶端透明;
具有負載均衡、高可用性、SQL 過濾、讀寫分離、可路由相關的請求到目標數據庫、可并發請求多臺數據庫并合并結果;
通過Amoeba你能夠完成多數據源的高可用、負載均衡、數據切片的功能,目前Amoeba已在很多企業的生產線上面使用;
?
2 準備
2.1 時間同步
# crontab -
e
# Dscrip: Time Sync
# CTime:
2014.03
.
23
*/
5
* * * * /usr/sbin/ntpdate
172.16
.
0.1
&>/dev/
null
2.2 配置MySQL主從復制架構
詳見博文" MariaDB 主從復制 "
?
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 # 使用二進制程序文件安裝amoeba
cd
/usr/local/
amoeba
bin
/
amoeba start # 前臺運行
nohup
/usr/local/amoeba/bin/amoeba start &
# 后臺運行
mysql
-h127.
0.0
.
1
-uroot -p -P8066 # amoeba默認監聽端口為8066
3.3 配置ameoba
cd /usr/local/amoeba/
conf
vi
ameoba.xml # 前端定義配置文件
# 修改ameoba前端監聽端口
<service name=
"
Amoeba for Mysql
"
class=
"
com.meidusa.amoeba.net.ServerableConnectionManager
"
>
<property name=
"
port
"
>
3306
</property>
# 默認端口是8066,修改為3306,便于實現前端程序連接數據庫的透明性
# 修改連接amoeba接口的認證信息
<property name=
"
authenticator
"
>
<bean class=
"
com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator
"
>
<property name=
"
user
"
>root</property>
<property name=
"
password
"
>mypass</property>
# 添加登錄密碼
# 查詢路由設置
<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>
# 設定默認節點
<property name=
"
writePool
"
>master</property>
# 設定可寫節點,節點定義見dbServers.xml文件
<property name=
"
readPool
"
>readservers</property>
# 設定只讀池,可配置多個slave節點
<property name=
"
needParse
"
>
true
</property>
</queryRouter>
vi
dbServers.xml # 后端節點配置文件
# 定義抽象服務器,為每個后端MySQL服務器提供默認連接配置
<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地址,一個master,一個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>
# 定義虛擬服務器組,即只讀池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 使用驗證
在主庫上授權:
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
'
; # 這里的密碼應該與dbServer.xml中的數據庫密碼一致
Query OK,
0
rows affected (
0.00
sec)
MariaDB [(none)]
>
flush privileges;
Query OK,
0
rows affected (
0.00
sec)
# 登錄驗證
[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)]
>
# 讀寫驗證
[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接口登錄創建數據庫amoeba_test后,再從主庫的接口中去查詢數據庫已創建,說明寫入確實是落在了主庫節點上;
# 若要驗證ameoba對于讀操作的調度,則需要暫時停止從庫的復制操作,然后在主庫上更新數據,這樣從ameoba讀取數據將出現不一致的情況;
3.5 后期擴展
利用MMM雙主復制架構+Amoeba代理,可以實現對MySQL的高可用性和高性能;
關于MMM的內容參加博文" MySQL Scale Out "
4 問題記錄
現象 :使用mysql -uroot -p -P8066命令始終無法連接進入ameoba的配置接口,一直都是進入mysql數據庫的配置接口
原因 :在測試環境下,ameoba和mysql的主庫都部署在同一臺主機上,當啟動ameoba服務后,即使指定-P8066連接,mysql客戶端還是默認采用可被識別的socket文件(/tmp/mysql.sock)連接,同樣指定-hlocalhost也是一樣的;
當使用mysql命令連接mysqld時:
-
連接主機為localhost或不指定時,mysql會采用Unix Socket的連接方式;
-
連接主機為127.0.0.1時,mysql會采用TCP的方式連接;
解決方法 :指定-h127.0.0.1連接即可,即mysql -h127.0.0.1 -uroot -p -P8066
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

