MYCAT+MySQL双主实现负载均衡和故障转移

2018-06-09 80次浏览 发表评论

下面是介绍mycat的配置,MySQL的双主配置参考:http://1987.name/1094.html

软件下载安装:http://dl.mycat.io/

配置JAVA环境

wget http://dl.mycat.io/jdk-8u20-linux-x64.tar.gz
tar zxvf jdk-8u20-linux-x64.tar.gz
mv jdk1.8.0_20 /usr/local/jdk

添加以下内容到/etc/profile

#Add JDK
export JAVA_HOME=/usr/local/jdk
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib

然后执行. /etc/profile使其生效。

安装mycat

cd /usr/local/src/
wget http://dl.mycat.io/1.6.5/Mycat-server-1.6.5-release-20180122220033-linux.tar.gz
tar zxvf http://dl.mycat.io/1.6.5/Mycat-server-1.6.5-release-20180122220033-linux.tar.gz -C /usr/local

添加环境变量到/etc/profile

export MYCAT_HOME=/usr/local/mycat

. /etc/profile

新建一个系统用户用于启动mycat:

useradd mycat
chown -R mycat:mycat /usr/local/mycat

配置schema.xml文件:

vim /usr/local/mycat/conf/schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
        <schema name="USERDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1"></schema>
        <dataNode name="dn1" dataHost="node1" database="testdb" />
        <dataHost name="node1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql"
                  dbDriver="native" switchType="1" slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                <writeHost host="192.168.0.30" url="192.168.0.30:3306" user="testdb" password="123456">
                        <readHost host="192.168.0.40" url="192.168.0.40:3306" user="testdb" password="123456" />
                </writeHost>
                <writeHost host="192.168.0.40" url="192.168.0.40:3306" user="testdb" password="123456" />
        </dataHost>
</mycat:schema>

配置server.xml文件:

vim /usr/local/mycat/conf/server.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
        <system>
        <property name="nonePasswordLogin">0</property>
        <property name="useHandshakeV10">1</property>
        <property name="useSqlStat">0</property>
        <property name="useGlobleTableCheck">0</property>
        <property name="sequnceHandlerType">2</property>
        <property name="subqueryRelationshipCheck">false</property>
        <property name="processorBufferPoolType">0</property>
        <property name="serverPort">8066</property>
        <property name="managerPort">9066</property> 
        <property name="handleDistributedTransactions">0</property>
        <property name="useOffHeapForMerge">1</property>
        <property name="memoryPageSize">64k</property>
        <property name="spillsFileBufferSize">1k</property>
        <property name="useStreamOutput">0</property>
        <property name="systemReserveMemorySize">384m</property>
        <property name="useZKSwitch">false</property>
        </system>

        <user name="root" defaultAccount="true">
                <property name="password">1qaz2wsx</property>
                <property name="schemas">USERDB</property>
        </user>

        <user name="user">
                <property name="password">user</property>
                <property name="schemas">USERDB</property>
                <property name="readOnly">true</property>
        </user>

</mycat:server>

评论

随便说点,聊聊天~