• Amoeba实现Mysql读写分离


    在mysql主库、从库执行:
    grant all on mxyc.* to 'mxycuser'@'192.168.12.71' identified by '123456' with grant option;
    Amoeba安装
    1、安装jdk环境
    ./jdk-6u29-linux-x64-rpm.bin
    ln -s /usr/java/jdk1.6.0_29/ /usr/java/jdk1.6
    vi /etc/profile
    export JAVA_HOME=/usr/java/jdk1.6
    export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
    source /etc/profile
    2、安装Amoeba
    unzip amoeba-mysql-3.0.5-RC-distribution.zip
    mv amoeba-mysql-3.0.5-RC /usr/local/amoeba
    cd /usr/local/amoeba/conf
    vi amoeba.xml
    <property name="ipAddress">192.168.12.71</property>
    设置登陆amoeba的帐号密码

    设置登陆amoeba的帐号密码
    <property name="user">root</property>

    <property name="password">123qwe</property>

    设置读写(这个两行是注释掉的,记得把<!--去掉)
    <property name="writePool">server1</property>
    <property name="readPool">server2</property>

    vi dbServers.xml

    修改dbServers.xml,设置数据库端口、登陆MySQL的帐号和密码。

    <!-- mysql port -->
    <property name="port">3306</property>

    <!-- mysql schema -->
    <property name="schema">mxyc</property>

    <!-- mysql user -->
    <property name="user">mxycuser</property>

    <property name="password">123456</property>

    修改dbServers.xml,设置数据库服务器的别名和服务器IP

    <dbServer name="server1" parent="abstractServer">
    <factoryConfig>
    <!-- mysql ip -->
    <property name="ipAddress">192.168.12.28</property>
    </factoryConfig>
    </dbServer>

    <dbServer name="server2" parent="abstractServer">
    <factoryConfig>
    <!-- mysql ip -->
    <property name="ipAddress">192.168.12.29</property>
    </factoryConfig>
    </dbServer>

    修改dbServers.xml,设置ROUNDROBIN(轮询策略):

    <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">server1,server2</property>
    </poolConfig>
    </dbServer>

    启动amoeba
    /usr/local/amoeba/bin/launcher &
    测试登陆:
    mysql -uroot -p123456 -h 192.168.12.71 --port 8066

  • 相关阅读:
    高并发编程之基础概念
    使用JAXB实现Bean与Xml相互转换
    python语法(五)—函数
    2018年终总结
    python语法(四)— 文件操作
    excel开发
    spring 常用注解,@primary注解
    spring中InitializingBean和@Bean的初始化,bean初始化
    @PostConstruct 注解
    LocalDateTime java8
  • 原文地址:https://www.cnblogs.com/zclzhao/p/4917444.html
Copyright © 2020-2023  润新知