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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

amoba读写分离

發布時間:2025/3/15 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 amoba读写分离 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原文出自?http://www.abcdocker.com/abcdocker/81


1.AMOEBA是什么

Amoeba(變形蟲)項目,該開源框架于2008年 開始發布一款 Amoeba for Mysql軟件。這個軟件致力于MySQL的分布式數據庫前端代理層,它主要在應用層訪問MySQL的 時候充當SQL路由功能,專注于分布式數據庫代理層(Database Proxy)開發。座落與 Client、DB Server(s)之間,對客戶端透明。具有負載均衡、高可用性、SQL 過濾、讀寫分離、可路由相關的到目標數據庫、可并發請求多臺數據庫合并結果。 通過Amoeba你能夠完成多數據源的高可用、負載均衡、數據切片的功能,目前Amoeba已在很多 企業的生產線上面使用。

2.AMOBA不能做什么

???目前還不支持事務 ???暫時不支持存儲過程(近期會支持) ???不適合從amoeba導數據的場景或者對大數據量查詢的query并不合適(比如一次請求返回10w以上甚至更多數據的場合) ???暫時不支持分庫分表,amoeba目前只做到分數據庫實例,每個被切分的節點需要保持庫表結構一致

3.安裝AMOBA

安裝JDK

  • [root@db01 ~]# tar -xf jdk-8u91-linux-i586.tar.gz -C /usr/lib/
  • [root@db01 ~]# ln -s /usr/lib/jdk1.8.0_91/ /usr/lib/java
  • [root@db01 ~]# cat >> /etc/profile <<EOF
  • [root@db01 ~]# echo '
  • export JAVA_HOME=/usr/lib/java
  • export JRE_HOME=${JAVA_HOME}/jre
  • export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
  • export PATH=${JAVA_HOME}/bin:$PATH' >> /etc/profileEOF
  • [root@db01 ~]# source /etc/profile
  • [root@db01 ~]# java -version
  • java version "1.8.0_91"
  • Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
  • Java HotSpot(TM) Client VM (build 25.91-b14, mixed mode)
  • 安裝amoeba

  • [root@db01 ~]# wget http://ncu.dl.sourceforge.net/project/amoeba/Amoeba%20for%20mysql/2.x/amoeba-mysql-binary-2.1.0-RC5.tar.gz
  • [root@db01 ~]# mkdir -p /application/amoeba-2.1.0-rc5
  • [root@db01 ~]# tar -xf amoeba-mysql-binary-2.1.0-RC5.tar.gz /application/amoeba-2.1.0-rc5/
  • [root@db01 ~]# ln -s /application/amoeba-2.1.0-rc5/ /application/amoeba
  • [root@db01 ~]# echo 'PATH=/application/amoeba/bin/:$PATH' >> /etc/profile
  • [root@db01 ~]# source /etc/profile
  • 4.AMOEBA基礎配置介紹

    Amoeba主要配置文件
  • dbServers.xml #主機IP,端口,Amoeba的用戶名密碼
  • rule.xml ??????? #切分規則相關
  • functionMap.xml #描述了函數名和函數處理的關系
  • ruleFunctionMap.xml #自定義函數
  • access_list.conf #可以訪問和拒絕訪問的列表
  • log4j.xml ??????? #日志文件相關配置
  • 5.配置AMOEBA對一個數據庫實例進行操作

    測試mysql是否可以正常連接
  • [root@db01 ~]# mysql -uroot -poldboy123 -S /data/3306/mysql.sock?
  • Welcome to the MySQL monitor. ?Commands end with ; or \g.
  • Your MySQL connection id is 5
  • Server version: 5.5.49-log Source distribution
  • Copyright (c) 2000, 2016, 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>
  • ?配置一個DB節點

  • <?xml version="1.0" encoding="gbk"?>
  • <!DOCTYPE amoeba:dbServers SYSTEM "dbserver.dtd">
  • <amoeba:dbServers xmlns:amoeba="http://amoeba.meidusa.com/">
  • ? ? ? ? ? ? ? ? <!--?
  • ? ? ? ? ? ? ? ? ? ? ? ? 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">oldboy</property>
  • ? ? ? ? ? ? ? ? ? ? ? ? <!-- ?mysql password -->
  • ? ? ? ? ? ? ? ? ? ? ? ? <property name="password">123456</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="testWhileIdle">true</property>
  • ? ? ? ? ? ? ? ? </poolConfig>
  • ? ? ? ? </dbServer>
  • ? ? ? ? <dbServer name="server1" ?parent="abstractServer">
  • ? ? ? ? ? ? ? ? <factoryConfig>
  • ? ? ? ? ? ? ? ? ? ? ? ? <!-- mysql ip -->
  • ? ? ? ? ? ? ? ? ? ? ? ? <property name="ipAddress">127.0.0.1</property>
  • ? ? ? ? ? ? ? ? </factoryConfig>
  • ? ? ? ? </dbServer>
  • ? ? ? ? <dbServer name="multiPool" virtual="true">
  • ? ? ? ? ? ? ? ? <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">
  • ? ? ? ? ? ? ? ? ? ? ? ? <!-- Load balancing strategy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=H
  • A-->
  • ? ? ? ? ? ? ? ? ? ? ? ? <property name="loadbalance">1</property>
  • ? ? ? ? ? ? ? ? ? ? ? ? <!-- Separated by commas,such as: server1,server2,server1 -->
  • ? ? ? ? ? ? ? ? ? ? ? ? <property name="poolNames">server1</property>
  • ? ? ? ? ? ? ? ? </poolConfig>
  • ? ? ? ? </dbServer>
  • </amoeba:dbServers>
  • 6.AMOEBA讀寫分離

  • 創建授權用戶bzjxs
  • GRANT ALL ON *.* TO 'bzjxs'@'172.16.1.%' IDENTIFIED BY '123456'
  • 配置dbServer.xml
  • <?xml version="1.0" encoding="gbk"?>
  • <!DOCTYPE amoeba:dbServers SYSTEM "dbserver.dtd">
  • <amoeba:dbServers xmlns:amoeba="http://amoeba.meidusa.com/">
  • ...
  • ?<dbServer name="Master" ?parent="abstractServer">
  • ? <factoryConfig>
  • ? ?<!-- mysql ip -->
  • ? ?<property name="ipAddress">192.168.0.1</property>
  • ? </factoryConfig>
  • ?</dbServer>
  • <--配置mysql節點master-->
  • ?
  • ?<dbServer name="Slave1" ?parent="abstractServer">
  • ? <factoryConfig>
  • ? ?<!-- mysql ip -->
  • ? ?<property name="ipAddress">192.168.0.2</property>
  • ? </factoryConfig>
  • ?</dbServer>
  • <--配置mysql節點slave1-->
  • ?<dbServer name="Slave2" ?parent="abstractServer">
  • ? <factoryConfig>
  • ? ?<!-- mysql ip -->
  • ? ?<property name="ipAddress">192.168.0.3</property>
  • ? </factoryConfig>
  • ?</dbServer>
  • <--配置mysql節點slave2-->
  • ??
  • ?<dbServer name="virtualSlave" virtual="true">
  • <--配置mysql節點池-->
  • ? <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">
  • ? ?<!-- Load balancing strategy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->
  • ? ?<property name="loadbalance">1</property>
  • <--1代表輪詢-->
  • ? ?
  • ? ?<!-- Separated by commas,such as: server1,server2,server1 -->
  • ? ?<property name="poolNames">Slave1,Slave1,Slave2</property>
  • <--配置權重 代表輪詢兩次Slave1,輪詢1Slave2-->
  • ? </poolConfig>
  • ?</dbServer>
  • ...
  • </amoeba:dbServers>
  • 配置amoeba.xml直接配置讀寫分離

  • <?xml version="1.0" encoding="gbk"?>
  • <!DOCTYPE amoeba:configuration SYSTEM "amoeba.dtd">
  • <amoeba:configuration xmlns:amoeba="http://amoeba.meidusa.com/">
  • ...
  • <queryRouter class=”com.meidusa.amoeba.mysql.parser.MysqlQueryRouter”> ?
  • ? ?<property name="LRUMapSize">1500</property>
  • <--amoeba緩存的語句的條數-->
  • ? ?<property name="defaultPool">Master</property>?
  • <--默認訪問的mysql節點 一些除了SELECT\UPDATE\INSERT\DELETE的語句都會在defaultPool執行-->
  • ? ?<property name="writePool">Master</property>
  • <--寫入的服務器-->
  • ? ?<property name="readPool">virtualSlave</property>
  • <--讀取的服務器可以是節點名也可以是節點池名-->
  • ? ?<property name="needParse">true</property> ?
  • </queryRouter> ?
  • ...
  • </amoeba:configuration>
  • AMOEBA官方文檔 http://docs.hexnova.com/amoeba/rw-splitting.html 本文轉載老男孩28期李佳豪同學分享 喜歡本作者請關注我們的博客!

    總結

    以上是生活随笔為你收集整理的amoba读写分离的全部內容,希望文章能夠幫你解決所遇到的問題。

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