Amoeba框架是居于JDK1.5开发的,采用了JDK1.5的特性,所以还需要安装java环境,建议使用javaSE1.5以上的JDK版本. 1)安装java环境 安装参考:http: //www .cnblogs.com /kevingrace/p/5870814 .html [root@amoeba-node ~] # yum -y install java-1.7.0-openjdk* 设置java的环境变量 [root@amoeba-node ~] # vim /etc/profile ....... export JAVA_HOME= /usr/lib/jvm/java-1 .7.0-openjdk.x86_64 export CLASSPATH=.:$JAVA_HOME /jre/lib/rt .jar:$JAVA_HOME /lib/dt .jar:$JAVA_HOME /lib/tools .jar export PATH=$PATH:$JAVA_HOME /bin 使之生效 [root@amoeba-node ~] # source /etc/profile [root@amoeba-node ~] # java -version java version "1.7.0_141" OpenJDK Runtime Environment (rhel-2.6.10.1.el6_9-x86_64 u141-b02) OpenJDK 64-Bit Server VM (build 24.141-b02, mixed mode) 2)安装Amoeba 下载地址:https: //sourceforge .net /projects/amoeba/ 百度云盘下载:https: //pan .baidu.com /s/1c1FRsbe 提取密码:xav2 Amoeba安装非常简单,直接解压即可使用,这里将Amoeba解压到 /usr/local/amoeba 目录下,这样就安装完成了 [root@amoeba-node ~] # unzip amoeba-mysql-3.0.5-RC-distribution.zip [root@amoeba-node ~] # mv amoeba-mysql-3.0.5-RC /usr/local/amoeba [root@amoeba-node ~] # cd /usr/local/amoeba [root@amoeba-node amoeba] # ll 总用量 20 drwxrwxrwx. 2 root root 4096 7月 5 2013 benchmark drwxrwxrwx. 2 root root 4096 7月 5 2013 bin drwxrwxrwx. 2 root root 4096 7月 5 2013 conf -rwxrwxrwx. 1 root root 728 7月 5 2013 jvm.properties drwxrwxrwx. 2 root root 4096 7月 5 2013 lib 3)配置Amoeba Amoeba的配置文件位于 /usr/local/amoeba/conf 目录下。配置文件比较多,但是仅仅使用读写分离功能,只需配置两个文件即可,分别是dbServers.xml和amoeba.xml, 如果需要配置ip访问控制,还需要修改access_list.conf文件,下面首先介绍dbServers.xml的配置: [root@amoeba-node amoeba] # cat conf/dbServers.xml <?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= "connectionManager" >${defaultManager}< /property > <property name= "sendBufferSize" >64< /property > <property name= "receiveBufferSize" >128< /property > <!-- mysql port --> <property name= "port" >3306< /property > // 设置Amoeba要连接的mysql数据库的端口,默认是3306 <!-- mysql schema --> <property name= "schema" >huanqiutest< /property > // 设置缺省的数据库,当连接amoeba时,操作表必须显式的指定数据库名,即采用dbname.tablename的方式,不支持 use dbname指定缺省库,因为操作会调度到各个后端dbserver <!-- mysql user --> <property name= "user" >wang< /property > // 设置amoeba连接后端数据库服务器的账号,因此需要在所有后端数据库上创建该用户,并授权amoeba服务器可连接 <property name= "password" >wang123456< /property > // 设置amoeba连接后端数据库服务器的密码 < /factoryConfig > <poolConfig class= "com.meidusa.toolkit.common.poolable.PoolableObjectPool" > <property name= "maxActive" >500< /property > // 最大连接数,默认500 <property name= "maxIdle" >500< /property > // 最大空闲连接数 <property name= "minIdle" >1< /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= "masterdb" parent= "abstractServer" > // 设置一个后端可写的dbServer,这里定义为masterdb,这个名字可以任意命名,后面在amoeba.xml文件里会用到 <factoryConfig> <!-- mysql ip --> <property name= "ipAddress" >182.48.115.236< /property > // 设置后端可写dbserver的ip < /factoryConfig > < /dbServer > <dbServer name= "slavedb" parent= "abstractServer" > // 设置后端可读dbserver(如果是多个slave从节点,这里就配置多个<dbServer ... < /dbServer >,然后加入到后面第一的可读的组内) <factoryConfig> <!-- mysql ip --> <property name= "ipAddress" >182.48.115.238< /property > // 设置后端可读dbserver的ip < /factoryConfig > < /dbServer > <dbServer name= "myslave" virtual= "true" > // 设置定义一个虚拟的dbserver,实际上相当于一个dbserver组,这里将可读的数据库ip统一放到一个组中,将这个组的名字命名为myslave <poolConfig class= "com.meidusa.amoeba.server.MultipleServerPool" > <!-- Load balancing strategy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA--> <property name= "loadbalance" >1< /property > // 选择调度算法,1表示复制均衡,2表示权重,3表示HA, 这里选择1 <!-- Separated by commas,such as: server1,server2,server1 --> <property name= "poolNames" >slavedb< /property > //myslave 组成员 < /poolConfig > < /dbServer > < /amoeba :dbServers> 另一个配置文件amoeba.xml [root@amoeba-node amoeba] # cat conf/amoeba.xml <?xml version= "1.0" encoding= "gbk" ?> <!DOCTYPE amoeba:configuration SYSTEM "amoeba.dtd" > <amoeba:configuration xmlns:amoeba= "http://amoeba.meidusa.com/" > <proxy> <!-- service class must implements com.meidusa.amoeba.service.Service --> <service name= "Amoeba for Mysql" class= "com.meidusa.amoeba.mysql.server.MySQLService" > <!-- port --> <property name= "port" >8066< /property > // 设置amoeba监听的端口,默认是8066 <!-- bind ipAddress --> // 下面配置监听的接口,如果不设置,默认监听所以的IP <!-- <property name= "ipAddress" >127.0.0.1< /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= "authenticateProvider" > <bean class= "com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator" > <property name= "user" >root< /property > // 提供客户端连接amoeba时需要使用这里设定的账号 (这里的账号密码和amoeba连接后端数据库服务器的密码无关) <property name= "password" >123456< /property > <property name= "filter" > <bean class= "com.meidusa.toolkit.net.authenticate.server.IPAccessController" > <property name= "ipFile" >${amoeba.home} /conf/access_list .conf< /property > < /bean > < /property > < /bean > < /property > < /service > <runtime class= "com.meidusa.amoeba.mysql.context.MysqlRuntimeContext" > <!-- proxy server client process thread size --> <property name= "executeThreadSize" >128< /property > <!-- per connection cache prepared statement size --> <property name= "statementCacheSize" >500< /property > <!-- default charset --> <property name= "serverCharset" >utf8< /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= "defaultManager" class= "com.meidusa.toolkit.net.MultiConnectionManagerWrapper" > <property name= "subManagerClassName" >com.meidusa.toolkit.net.AuthingableConnectionManager< /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" >masterdb< /property > // 设置amoeba默认的池,这里设置为masterdb(这个是在dbServers.xml文件里定义的) <property name= "writePool" >masterdb< /property > // 这两个选项默认是注销掉的,一定要取消注释!否则读写分离无效,这里用来指定前面定义好的写池 <property name= "readPool" >myslave< /property > // 取消注释,这个是前面在dbServers.xml文件里定义的读池 <property name= "needParse" > true < /property > < /queryRouter > < /amoeba :configuration> 4)在masterdb上(即master节点机182.48.115.236上)创建数据库huanqiutest mysql> create database huanqiutest; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | huanqiutest | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec) 然后在slavedb上(即slave节点182.48.115.238上)查看是否复制成功 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | huanqiutest | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec) 分别在masterdb和slavedb上为amoedb授权 mysql> GRANT ALL ON huanqiutest.* TO 'wang' @ '182.48.115.237' IDENTIFIED BY 'wang123456' ; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 启动amoeba [root@amoeba-node ~] # /usr/local/amoeba/bin/launcher .................................................................................... 报错1: The stack size specified is too small, Specify at least 228k Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit . 解决办法: 从错误文字上看,应该是由于stack size太小,导致JVM启动失败,要如何修改呢? 其实Amoeba已经考虑到这个问题,并将JVM参数配置写在属性文件里,可以通过该属性文件修改JVM参数。 修改jvm.properties文件JVM_OPTIONS参数。 [root@amoeba-node ~] # vim /usr/local/amoeba/jvm.properties 将内容 JVM_OPTIONS= "-server -Xms256m -Xmx1024m -Xss196k -XX:PermSize=16m -XX:MaxPermSize=96m" 修改为 JVM_OPTIONS= "-server -Xms1024m -Xmx1024m -Xss256k -XX:PermSize=16m -XX:MaxPermSize=96m" 再次启动Amoeba就ok了 [root@amoeba-node ~] # nohup /usr/local/amoeba/bin/launcher & //将amoeba放在后台执行。该命令执行后,按ctrl+c [root@amoeba-node ~] # ps -ef|grep amoeba root 19079 1 1 15:01 pts /0 00:00:02 /usr/lib/jvm/java-1 .7.0-openjdk.x86_64 /bin/java -server -Xms1024m -Xmx1024m -Xss256k -XX:PermSize=16m -XX:MaxPermSize=96m -Dproject.home= /usr/local/amoeba -Damoeba.home= /usr/local/amoeba -Dproject.name=Amoeba-MySQL -Dproject.output= /usr/local/amoeba/logs -Dignore.signals=1,2 -Dclassworlds.conf= /usr/local/amoeba/bin/launcher .classpath -classpath /usr/local/amoeba/lib/plexus-classworlds-2 .4.2-HEXNOVA.jar org.codehaus.classworlds.Launcher root 19103 19009 0 15:02 pts /0 00:00:00 /bin/bash /usr/local/amoeba/bin/launcher root 19109 19103 0 15:02 pts /0 00:00:00 tail -f /usr/local/amoeba/logs/console .log root 19172 19009 0 15:04 pts /0 00:00:00 grep amoeba [root@amoeba-node ~] # lsof -i:8066 COMMAND PID USER FD TYPE DEVICE SIZE /OFF NODE NAME java 19079 root 64u IPv6 2705157 0t0 TCP *:8066 (LISTEN) .................................................................................. |