Amoeba for mysql
Amoeba for mysql的搭建
192.168.56.102 master1
192.168.56.103 slave1
192.168.56.104 amoeba
1. 安裝java環境
[root@amoeba ~]# tar zxvf jdk-7u79-linux-x64.tar.gz -C /usr/local/java/
[root@amoeba ~]# vi /etc/profile
新增java和amoeba環境變數:
PATH=$PATH:$HOME/bin:/usr/local/amoeba/bin:/usr/local/java/jdk1.7.0_79/bin
JAVA_HOME=/usr/local/java/jdk1.7.0_79
export JAVA_HOME
export PATH
[root@amoeba ~]# source /etc/profile
[root@amoeba ~]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
2. 安裝amoeba
[root@amoeba ~]# tar zxvf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/
[root@amoeba local]# mv amoeba-mysql-binary-2.2.0 amoeba
3. amoeba配置檔案
Amoeba有哪些主要的配置檔案?
-
想象Amoeba作為資料庫代理層,它一定會和很多資料庫保持通訊,因此它必須知道由它代理的資料庫如何連線,比如最基礎的:主機IP、埠、Amoeba使用的使用者名稱和密碼等等。這些資訊儲存在$AMOEBA_HOME/conf/dbServers.xml中。
二.Amoeba為了完成資料切分提供了完善的切分規則配置,為了瞭解如何分片資料、如何將資料庫返回的資料整合,它必須知道切分規則。與切分規則相關的資訊儲存在$AMOEBA_HOME/conf/rule.xml中。
三.當我們書寫SQL來運算元據庫的時候,常常會用到很多不同的資料庫函式,比如:UNIX_TIMESTAMP()、SYSDATE()等等。這些函式如何被Amoeba解析呢?$AMOEBA_HOME/conf/functionMap.xml描述了函式名和函式處理的關係。
四.對$AMOEBA_HOME/conf/rule.xml進行配置時,會用到一些我們自己定義的函式,比如我們需要對使用者ID求HASH值來切分資料,這些函式在$AMOEBA_HOME/conf/ruleFunctionMap.xml中定義。
五.Amoeba可以制定一些可訪問以及拒絕訪問的主機IP地址,這部分配置在$AMOEBA_HOME/conf/access_list.conf中
六.Amoeba允許使用者配置輸出日誌級別以及方式,配置方法使用log4j的檔案格式,檔案是$AMOEBA_HOME/conf/log4j.xml。
DbServers.xml配置檔案:
[root@amoeba conf]# more dbServers.xml <?xml version="1.0" encoding="gbk"?>
<!DOCTYPE amoeba:dbServers SYSTEM "dbserver.dtd"> <amoeba:dbServers xmlns:amoeba="
<!-- Each dbServer needs to be configured into a Pool, If you need to configure multiple dbServer with load balancing that can be simplified by the following configuration: add attribute with name virtual = "true" in dbServer, but the configuration does not allow the element with name factoryConfig such as 'multiPool' dbServer -->
<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>
<!-- mysql port --> <property name="port">3306</property>
<!-- mysql schema --> <property name="schema">test</property>
<!-- mysql user --> <property name="user">amoeba</property>
<!-- mysql password --> <property name="password">111111</property> </factoryConfig>
<poolConfig class="com.meidusa.amoeba.net.poolable.PoolableObjectPool"> <property name="maxActive">500</property> <property name="maxIdle">500</property> <property name="minIdle">10</property> <property name="minEvictableIdleTimeMillis">600000</property> <property name="timeBetweenEvictionRunsMillis">600000</property> <property name="testOnBorrow">true</property> <property name="testOnReturn">true</property> <property name="testWhileIdle">true</property> </poolConfig> </dbServer>
<dbServer name="master1" parent="abstractServer"> <factoryConfig> <!-- mysql ip --> <property name="ipAddress">192.168.56.102</property> </factoryConfig> </dbServer>
<dbServer name="slave1" parent="abstractServer"> <factoryConfig> <!-- mysql ip --> <property name="ipAddress">192.168.56.103</property> </factoryConfig> </dbServer>
<dbServer name="multiPool" virtual="true"> <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool"> <!-- Load balancing strategy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA--> <property name="loadbalance">1</property>
<!-- Separated by commas,such as: server1,server2,server1 --> <property name="poolNames">slave1</property> </poolConfig> </dbServer>
</amoeba:dbServers> |
Amoeba.xml配置檔案:
[root@amoeba conf]# more amoeba.xml <?xml version="1.0" encoding="gbk"?>
<!DOCTYPE amoeba:configuration SYSTEM "amoeba.dtd"> <amoeba:configuration xmlns:amoeba="
<proxy>
<!-- service class must implements com.meidusa.amoeba.service.Service --> <service name="Amoeba for Mysql" class="com.meidusa.amoeba.net.ServerableConnectionManager"> <!-- port --> <property name="port">8066</property>
<!-- bind ipAddress --> <!-- --> <property name="ipAddress">192.168.56.104</property>
<property name="manager">${clientConnectioneManager}</property>
<property name="connectionFactory"> <bean class="com.meidusa.amoeba.mysql.net.MysqlClientConnectionFactory"> <property name="sendBufferSize">128</property> <property name="receiveBufferSize">64</property> </bean> </property>
<property name="authenticator"> <bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">
<property name="user">amoeba</property>
<property name="password">111111</property>
<property name="filter"> <bean class="com.meidusa.amoeba.server.IPAccessController"> <property name="ipFile">${amoeba.home}/conf/access_list.conf</property> </bean> </property> </bean> </property>
</service>
<!-- server class must implements com.meidusa.amoeba.service.Service --> <service name="Amoeba Monitor Server" class="com.meidusa.amoeba.monitor.MonitorServer"> <!-- port --> <!-- default value: random number --> <property name="port">9066</property> <!-- bind ipAddress --> <property name="ipAddress">192.168.56.104</property> <property name="daemon">true</property> <property name="manager">${clientConnectioneManager}</property> <property name="connectionFactory"> <bean class="com.meidusa.amoeba.monitor.net.MonitorClientConnectionFactory"></bean> </property>
</service>
<runtime class="com.meidusa.amoeba.mysql.context.MysqlRuntimeContext"> <!-- proxy server net IO Read thread size --> <property name="readThreadPoolSize">20</property>
<!-- proxy server client process thread size --> <property name="clientSideThreadPoolSize">30</property>
<!-- mysql server data packet process thread size --> <property name="serverSideThreadPoolSize">30</property>
<!-- per connection cache prepared statement size --> <property name="statementCacheSize">500</property>
<!-- query timeout( default: 60 second , TimeUnit:second) --> <property name="queryTimeout">60</property> </runtime>
</proxy>
<!-- Each ConnectionManager will start as thread manager responsible for the Connection IO read , Death Detection --> <connectionManagerList> <connectionManager name="clientConnectioneManager" class="com.meidusa.amoeba.net.MultiConnectionManagerWrapper"> <property name="subManagerClassName">com.meidusa.amoeba.net.ConnectionManager</property> <!-- default value is avaliable Processors <property name="processors">5</property> --> </connectionManager> <connectionManager name="defaultManager" class="com.meidusa.amoeba.net.MultiConnectionManagerWrapper"> <property name="subManagerClassName">com.meidusa.amoeba.net.AuthingableConnectionManager</property>
<!-- default value is avaliable Processors <property name="processors">5</property> --> </connectionManager> </connectionManagerList>
<!-- default using file loader --> <dbServerLoader class="com.meidusa.amoeba.context.DBServerConfigFileLoader"> <property name="configFile">${amoeba.home}/conf/dbServers.xml</property> </dbServerLoader>
<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">master1</property>
<!— --> <property name="writePool">master1</property> <property name="readPool">slave1</property> <property name="needParse">true</property> </queryRouter> </amoeba:configuration> |
需要在主從節點新增使用者amoeba及其許可權:
Grant all on *.* to ‘amoeba’@’192.168.56.104’ identified by ‘111111’;
4. 啟動amoeba
[root@amoeba conf]# nohup amoeba start & --後臺啟動
[root@amoeba conf]# amoeba start ---前臺啟動
log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml
2015-06-19 03:10:38,351 INFO context.MysqlRuntimeContext - Amoeba for Mysql current versoin=5.1.45-mysql-amoeba-proxy-2.2.0
log4j:WARN ip access config load completed from file:/usr/local/amoeba/conf/access_list.conf
2015-06-19 03:10:38,683 INFO net.ServerableConnectionManager - Amoeba for Mysql listening on /192.168.56.104:8066.
2015-06-19 03:10:38,689 INFO net.ServerableConnectionManager - Amoeba Monitor Server listening on /192.168.56.104:9066.
[root@amoeba conf]# mysql -uamoeba -p111111 -h192.168.56.104 -P8066
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 899565349
Server version: 5.1.45-mysql-amoeba-proxy-2.2.0 Source distribution
Copyright (c) 2000, 2013, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
| xx |
+--------------------+
4 rows in set (0.01 sec)
登入成功。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/637517/viewspace-1766822/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Amoeba for MySQL 基本介紹MySql
- Amoeba for mysql的優劣MySql
- MySQL Amoeba讀寫分離MySql
- Amoeba for mysql讀寫分離MySql
- Amoeba for MySQL讀寫分離配置MySql
- Amoeba 實現 MySQL 讀寫分離MySql
- mysql讀寫分離Amoeba的部署MySql
- 透過Amoeba連線mysql報錯MySql
- Amoeba+Mysql 實現讀寫分離MySql
- Amoeba for MySQL學習研究之注意事項MySql
- Mysql讀寫分離方案-Amoeba環境部署記錄MySql
- MySQL使用Amoeba作為Proxy時的注意事項MySql
- Amoeba實現MySQL的負載均衡、故障轉移MySql負載
- Amoeba實現讀寫分離
- Amoeba -阿里的開源專案阿里
- 解決在使用Amoeba遇到的問題
- mysql5.6.13通用二進位制格式安裝並使用amoeba實現對mysql5.6資料庫讀寫分離MySql資料庫
- 啟動Amoeba報The stack size specified is too small解決方法
- 【Mysql】MySQL管理工具MySQL UtilitiesMySql
- MySQL - 初識MySQLMySql
- 【MySQL】MySQL基礎MySql
- 【MySQL】MySQL 5.7 初探MySql
- mysql 索引( mysql index )MySql索引Index
- 【MySQL】mysql optimize tableMySql
- 「MySQL」 MySQL執行流程MySql
- MySQL入門--mysql命令MySql
- MySQL入門--MySQL安全MySql
- 【Mysql】修改mysql時區MySql
- 【MySQL】MySQL中的鎖MySql
- [mysql]ubuntu安裝mysqlMySqlUbuntu
- MySQL(六):MySQL之MVCCMySqlMVC
- Warning:The /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql'MySql
- MySQL入門系列:MySQL概述MySql
- mysql + nodejs mysql篇(2)MySqlNodeJS
- 【MySQL(2)| MySQL索引機制】MySql索引
- 重返MySQL之MySQL基礎MySql
- 安裝mysql和mysql workbenchMySql
- 【MySQL】九、MySQL與IO.MySql