真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

通過amoeba工具實(shí)現(xiàn)配置mysql讀寫分離的方法介紹

下面講講關(guān)于通過amoeba工具實(shí)現(xiàn)配置MySQL讀寫分離的方法,文字的奧妙在于貼近主題相關(guān)。所以,閑話就不談了,我們直接看下文吧,相信看完通過amoeba工具實(shí)現(xiàn)配置mysql讀寫分離的方法這篇文章你一定會(huì)有所受益。

創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括永靖網(wǎng)站建設(shè)、永靖網(wǎng)站制作、永靖網(wǎng)頁制作以及永靖網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,永靖網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到永靖省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

一,背景介紹:

Amoeba(變形蟲)項(xiàng)目,專注 分布式數(shù)據(jù)庫 proxy 開發(fā)。座落與Client、DB Server(s)之間。對(duì)客戶端透明。具有負(fù)載均衡、高可用性、sql過濾、讀寫分離、可路由相關(guān)的query到目標(biāo)數(shù)據(jù)庫、可并發(fā)請(qǐng)求多臺(tái)數(shù)據(jù)庫合并結(jié)果。要想搭建Amoeba讀寫分離,首先需要知道MySQL的主從配置。具體的架構(gòu)圖如下圖:

通過amoeba工具實(shí)現(xiàn)配置mysql讀寫分離的方法介紹

二,配置所需的環(huán)境:

 Amoeba for mysql:192.168.1.28

 Master : 192.168.1.247

 Slave : 192.168.1.245

 database:yazi passwd:root/123456

 JDK1.8.0_51

三,具體的搭建和配置步驟如下:

 1,配置mysql主從復(fù)制,具體參照上篇的mysql主從復(fù)制的配置

 2,安裝配置jdk1.8.0_51以及環(huán)境變量

   (1),安裝jdk命令: rpm -ivh jdk-8u51-linux-x64.rpm

[root@localhost install]# ll
total 481168
-rw-r--r--. 1 root root   8850470 Nov  2 22:43 apache-tomcat-7.0.63.tar.gz
-rw-r--r--. 1 root root 137808216 Jan 13 15:09 jdk-8u51-linux-x64.rpm
-rw-r--r--. 1 root root  33203321 Nov 20 11:31 mysql-5.6.25.tar.gz
-rw-r--r--. 1 root root 312845162 Nov 13 15:19 mysql-5.6.27-linux-glibc2.5-x86_64.tar.gz
[root@localhost install]# rpm -ivh jdk-8u51-linux-x64.rpm 
Preparing...                ########################################### [100%]
   1:jdk1.8.0_51            ########################################### [100%]
Unpacking JAR files...
        rt.jar...
        jsse.jar...
        charsets.jar...
        tools.jar...
        localedata.jar...
        jfxrt.jar...
        plugin.jar...
        javaws.jar...
        deploy.jar...

   (2)配置環(huán)境變量:

[root@localhost install]# vi /etc/profile

# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
pathmunge () {
    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if [ "$2" = "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}
if [ -x /usr/bin/id ]; then
    if [ -z "$EUID" ]; then
        # ksh workaround
        EUID=`id -u`
        UID=`id -ru`
    fi
    USER="`id -un`"
    LOGNAME=$USER
    MAIL="/var/spool/mail/$USER"
fi
# Path manipulation
if [ "$EUID" = "0" ]; then
    pathmunge /sbin
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
    pathmunge /usr/sbin after
    pathmunge /sbin after
fi
HOSTNAME=`/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
    export HISTCONTROL=ignoreboth
else
    export HISTCONTROL=ignoredups
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
    umask 002
else
    umask 022
fi
for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then
            . "$i"
        else
            . "$i" >/dev/null 2>&1
        fi
    fi
done
unset i
unset -f pathmunge

export JAVA_HOME=/usr/java/jdk1.8.0_51
export JRE_HOME=/usr/java/jdk1.8.0_51/jre
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

    (3)配置生效和驗(yàn)證:

[root@FileServerA logs]# source /etc/profile
[root@FileServerA logs]# java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

 3,安裝配置amoeba

   (1)下載amoeba

(http://nchc.dl.sourceforge.net/project/amoeba/Amoeba%20for%20mysql/3.x/amoeba-mysql-3.0.5-RC-distribution.zip)

   (2)壓縮包無需安裝,直接解壓即可

[root@localhost install]# unzip amoeba-mysql-3.0.5-RC-distribution.zip 
Archive:  amoeba-mysql-3.0.5-RC-distribution.zip
   creating: amoeba-mysql-3.0.5-RC/
   creating: amoeba-mysql-3.0.5-RC/lib/
  inflating: amoeba-mysql-3.0.5-RC/lib/amoeba-core-3.0.5-RC.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/log4j-1.2.12.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/commons-lang-2.4.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/commons-logging-1.1.1.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/commons-beanutils-1.8.0.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/commons-collections-3.2.1.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/ognl-3.0.1.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/javassist-3.11.0.GA.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/toolkit-common-pool-1.2.0.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/commons-pool-1.6.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/slf4j-api-1.6.1.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/slf4j-log4j12-1.6.2.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/toolkit-common-bean-1.3.0.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/toolkit-common-util-1.2.0.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/dom4j-1.6.1.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/xml-apis-1.0.b2.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/oro-2.0.8.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/commons-digester-1.8.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/toolkit-net-io-2.2.0.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/commons-cli-1.2.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/toolkit-common-runtime-1.3.0.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/spring-core-3.0.6.RELEASE.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/spring-asm-3.0.6.RELEASE.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/spring-context-3.0.6.RELEASE.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/spring-aop-3.0.6.RELEASE.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/aopalliance-1.0.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/spring-beans-3.0.6.RELEASE.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/spring-expression-3.0.6.RELEASE.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/plexus-classworlds-2.4.2-HEXNOVA.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/toolkit-net-benchmark-1.2.0.jar  
  inflating: amoeba-mysql-3.0.5-RC/lib/amoeba-mysql-3.0.5-RC.jar  
   creating: amoeba-mysql-3.0.5-RC/bin/
  inflating: amoeba-mysql-3.0.5-RC/bin/benchmark  
  inflating: amoeba-mysql-3.0.5-RC/bin/launcher  
  inflating: amoeba-mysql-3.0.5-RC/bin/mkdirhier  
  inflating: amoeba-mysql-3.0.5-RC/bin/shutdown  
  inflating: amoeba-mysql-3.0.5-RC/bin/benchmark.bat  
  inflating: amoeba-mysql-3.0.5-RC/bin/launcher.bat  
  inflating: amoeba-mysql-3.0.5-RC/bin/benchmark.classpath  
  inflating: amoeba-mysql-3.0.5-RC/bin/launcher.classpath  
   creating: amoeba-mysql-3.0.5-RC/conf/
  inflating: amoeba-mysql-3.0.5-RC/conf/access_list.conf  
  inflating: amoeba-mysql-3.0.5-RC/conf/amoeba.dtd  
  inflating: amoeba-mysql-3.0.5-RC/conf/amoeba.xml  
  inflating: amoeba-mysql-3.0.5-RC/conf/dbserver.dtd  
  inflating: amoeba-mysql-3.0.5-RC/conf/dbServers.xml  
  inflating: amoeba-mysql-3.0.5-RC/conf/function.dtd  
  inflating: amoeba-mysql-3.0.5-RC/conf/functionMap.xml  
  inflating: amoeba-mysql-3.0.5-RC/conf/log4j.dtd  
  inflating: amoeba-mysql-3.0.5-RC/conf/log4j.xml  
  inflating: amoeba-mysql-3.0.5-RC/conf/rule.dtd  
  inflating: amoeba-mysql-3.0.5-RC/conf/rule.xml  
  inflating: amoeba-mysql-3.0.5-RC/conf/ruleFunctionMap.xml  
   creating: amoeba-mysql-3.0.5-RC/benchmark/
  inflating: amoeba-mysql-3.0.5-RC/benchmark/context.xml  
  inflating: amoeba-mysql-3.0.5-RC/benchmark/objectMap.dtd  
  inflating: amoeba-mysql-3.0.5-RC/benchmark/query.xml  
  inflating: amoeba-mysql-3.0.5-RC/jvm.properties  
  
[root@localhost install]# mv amoeba-mysql-3.0.5-RC /usr/local/

  (3)amoeba的配置文件詳解:

amoeba.xml:定義前端的控制文件,包括前端的端口,用戶名和密碼

dbServers.xml:定義后端節(jié)點(diǎn)的配置文件。設(shè)置數(shù)據(jù)庫,登錄mysql的賬號(hào)和密碼

    a,配置amoeba.xml文件

[root@FileServerA conf]# vim amoeba.xml


                
                
                        
                        8066             //***端口號(hào)***//

                        
                        

                        
                                
                                        128
                                        64
                                
                        

                        
                                

                                        root

                                        123456
"amoeba.xml" 91L, 3099C                                                                                      30,6-41        8%





        

                
                
                        
                        8066  //設(shè)置其他的端口

                        
                        

                        
                                
                                        128
                                        64
                                
                        

                        
                                

                                        lqb            //***遠(yuǎn)程訪問代理的用戶名和密碼***//

                                        123456          //***用戶名和密碼***//

                                        
                                                
                                                        ${amoeba.home}/conf/access_list.conf
                                                
                                        
                                
                        

                

                

                        
                        128

                        
                        500

                        
                        utf8

                        
                        60
                

        

        
        
                
                        com.meidusa.toolkit.net.AuthingableConnectionManager
                
        

                
        
                ${amoeba.home}/conf/dbServers.xml
        

        
                
                        
                                ${amoeba.home}/conf/rule.xml
                                ${amoeba.home}/conf/ruleFunctionMap.xml
                        
                
                ${amoeba.home}/conf/functionMap.xml
                1500
                master


                master         //***寫的資源池***//
                viplqb          //***寫的資源池***//

                true
        

      b,配置dbServers.xml文件

[root@FileServerA conf]# vim  dbServers.xml



                
        
                
                        ${defaultManager}
                        64
                        128
                        
                        3306     //***設(shè)置mysql訪問端口號(hào)***//          
                        
                        yazi  //***設(shè)置mysql訪問默認(rèn)庫***//
                        
                        root    //***登錄mysql賬號(hào)和密碼***//
                        123456
                
                
                        500
                        500
                        1
                        600000
                        600000
                        true
                        true
                        true
                
        
                  //***設(shè)置master和ip地址***//
                
                        
                        192.168.1.247
                
        
                 //***設(shè)置slave1和ip地址***//
                                     //***如果有多個(gè)slave主機(jī)復(fù)制本配置到下邊繼續(xù)添加ip地址***//
                        
                        192.168.1.245
                
        
        
                
                        
                        1   //***采用輪詢方式***//
                        
                        slave1  //***所有從庫的主機(jī)都要寫上***//
                
        

  (4)啟動(dòng)amoeba并查看是否有報(bào)錯(cuò)。

[root@FileServerA conf]# /usr/local/amoeba-mysql-3.0.5-RC/bin/launcher &
[1] 34774
[root@FileServerA conf]# log4j:WARN ip access config load completed from file:/usr/local/amoeba-mysql-3.0.5-RC/conf/access_list.conf
2016-07-04 13:46:11,874 INFO  net.ServerableConnectionManager - Server listening on 0.0.0.0/0.0.0.0:8066.
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=16m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=96m; support was removed in 8.0
 2016-07-04 13:47:53 [INFO] Project Name=Amoeba-MySQL, PID=32445 , starting...
log4j:WARN log4j config load completed from file:/usr/local/amoeba-mysql-3.0.5-RC/conf/log4j.xml
2016-07-04 13:47:53,604 INFO  context.MysqlRuntimeContext - Amoeba for Mysql current versoin=5.1.45-mysql-amoeba-proxy-3.0.4-BETA
log4j:WARN ip access config load completed from file:/usr/local/amoeba-mysql-3.0.5-RC/conf/access_list.conf
2016-07-04 13:47:53,789 INFO  net.ServerableConnectionManager - Server listening on 0.0.0.0/0.0.0.0:8066.
 2016-07-04 14:22:55 [INFO] ignore signal:HUP
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=16m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=96m; support was removed in 8.0
 2016-07-04 17:31:08 [INFO] Project Name=Amoeba-MySQL, PID=34779 , starting...
log4j:WARN log4j config load completed from file:/usr/local/amoeba-mysql-3.0.5-RC/conf/log4j.xml
2016-07-04 17:31:08,868 INFO  context.MysqlRuntimeContext - Amoeba for Mysql current versoin=5.1.45-mysql-amoeba-proxy-3.0.4-BETA
log4j:WARN ip access config load completed from file:/usr/local/amoeba-mysql-3.0.5-RC/conf/access_list.conf
2016-07-04 17:31:09,128 INFO  net.ServerableConnectionManager - Server listening on 0.0.0.0/0.0.0.0:8066.

    (5)用其他的云服務(wù)器來進(jìn)行登錄:

[root@mysqlmaster ~]# mysql -ulqb -p -h292.168.1.28 -P8066    
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 965356058
Server version: 5.1.45-mysql-amoeba-proxy-3.0.4-BETA MySQL Community Server (GPL)
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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| yazi               |
+--------------------+
5 rows in set (0.01 sec)
mysql>

備注:當(dāng)配置這個(gè)文件時(shí)amoeba.xml ,其他的主機(jī)通過代理就可以訪問,如上說明amoeba.xml配置的沒有問題。

    (6)驗(yàn)證讀寫分離,這個(gè)需要配置dbServers.xml這個(gè)文件了,接下來即為驗(yàn)證讀寫分離。

   

(a)在沒停掉同步之前在主庫247上創(chuàng)建一張表;

mysql> use yazi;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+----------------+
| Tables_in_yazi |
+----------------+
| sxit           |
| test           |
+----------------+
2 rows in set (0.00 sec)
mysql> create table lqb (id int(10) ,name varchar(10),address varchar(20));     
Query OK, 0 rows affected (0.02 sec)

(b)在從庫245上查看,并在slave上停止同步:

mysql> use yazi;
Database changed
mysql> show tables;
+----------------+
| Tables_in_yazi |
+----------------+
| lqb            |
| sxit           |
| test           |
+----------------+
3 rows in set (0.00 sec)
mysql> stop slave
    -> ;
Query OK, 0 rows affected (0.00 sec)

(c)在主從上各插入一條不同的數(shù)據(jù)

在主庫上插入(1,'zhangsan','master');

在從庫上插入(2,’lisi','slave);

在主庫上執(zhí)行以下操作:

mysql> insert into lqb values(1,'zhangsan','master');
Query OK, 1 row affected (0.00 sec)
mysql> select * from lqb;
+------+----------+---------+
| id   | name     | address |
+------+----------+---------+
|    1 | zhangsan | master  |
+------+----------+---------+
1 row in set (0.00 sec)

在從庫上執(zhí)行以下操作:

mysql> insert into lqb values(2,'zhangsan','slave'); 
Query OK, 1 row affected (0.00 sec)
mysql> select * from lqb;
+------+----------+---------+
| id   | name     | address |
+------+----------+---------+
|    2 | zhangsan | slave   |
+------+----------+---------+
1 row in set (0.00 sec)

 (d)登錄amoeba云服務(wù)器查看讀操作:顯示的是245slave云服務(wù)器

mysql> select * from lqb;

+------+----------+---------+

| id   | name     | address |

+------+----------+---------+

|    2 | zhangsan | slave   |

+------+----------+---------+

1 row in set (0.00 sec)

(e)在amoeba云服務(wù)器上測(cè)試以下寫操作,查看還是245從庫上的數(shù)據(jù)。

mysql> insert into lqb values(3,'wanger','test_write');
Query OK, 1 row affected (0.00 sec)
mysql> select * from lqb;
+------+----------+---------+
| id   | name     | address |
+------+----------+---------+
|    2 | zhangsan | slave   |
+------+----------+---------+
1 row in set (0.00 sec)

在主庫247上查詢,可以看到已插入進(jìn)來了

mysql> select * from lqb;
+------+----------+------------+
| id   | name     | address    |
+------+----------+------------+
|    1 | zhangsan | master     |
|    3 | wanger   | test_write |
+------+----------+------------+
2 rows in set (0.00 sec)

在從庫上245查詢,還是剛才查詢

mysql> select * from lqb;
+------+----------+---------+
| id   | name     | address |
+------+----------+---------+
|    2 | zhangsan | slave   |
+------+----------+---------+
1 row in set (0.00 sec)

至此,數(shù)據(jù)庫讀寫分離已經(jīng)配置完成,在正式生產(chǎn)環(huán)境中,需將讀寫主機(jī)的定義更改,因?yàn)閿?shù)據(jù)庫用的最多的還是讀的操作。我們可以將讀或查詢交給從來處理,同樣的,我們也可以添加多個(gè)從主機(jī)。讓其自動(dòng)從不同的從主機(jī)上讀取數(shù)據(jù)庫。

對(duì)于以上通過amoeba工具實(shí)現(xiàn)配置mysql讀寫分離的方法相關(guān)內(nèi)容,大家還有什么不明白的地方嗎?或者想要了解更多相關(guān),可以繼續(xù)關(guān)注我們的行業(yè)資訊板塊。


當(dāng)前文章:通過amoeba工具實(shí)現(xiàn)配置mysql讀寫分離的方法介紹
當(dāng)前鏈接:http://weahome.cn/article/pjshpe.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部