vlambda博客
学习文章列表

Mycat 集群配置同步

使用zookeeper统一存储分发配置

版本信息

名称 版本号 备注
mysql 5.7 数据库
mycat 1.6.5 mycat server 中间件
zookeeper 3.4.14 提供mycat集群全局配置

部署情况

主机名 IP 角色
node1 192.168.114.129 Mycat ,Zookeeper, MySql
node2 192.168.114.133 Zookeeper,Mysql
node3 192.168.114.136 Zookeeper,Mysql
node4 192.168.114.137 Mycat,Mysql

zookeeper 集群安装

zookeepr 依赖 java环境,所以机器上必须提取安装jdk
#node1
wget https://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
scp zookeeper-3.4.14.tar.gz [email protected]:/www/soft
scp zookeeper-3.4.14.tar.gz [email protected]:/www/soft
#node1 node2 node3
tar -zxvf zookeeper-3.4.14.tar.gz
mv zookeeper-3.4.14 /usr/local
mv zookeeper-3.4.14 zookeeper
cd conf
cp zoo_sample.cfg zoo.cfg

cd /usr/local/zookeeper
mkdir data

#node1 > 0 node2 >1 node3 > 2
echo 0 > ./data/myid #每个zk配置一个id
echo 1 > ./data/myid
echo 2 > ./data/myid

#node1 node2 node3
vim conf/zoo.cfg
dataDir=/usr/local/zookeeper/data
server.0=192.168.114.129:2888:3888
server.1=192.168.114.133:2888:3888
server.2=192.168.114.136:2888:3888

#启动
./bin/skServer.sh start

#dataDir 设置zk目录
#server 设置集群目录

配置mycat 从 zookeeper获取配置

#node1
vim /usr/local/mycat/conf/myid.properties
loadZk=true
zkURL=192.168.114.129:2181,192.168.114.133:2181,192.168.114.133:2181
clusterId=mycat-cluster-1
myid=mycat_01
clusterSize=2
clusterNodes=mycat_01,mycat_02
#server booster ; booster install on db same server,will reset all minCon to 2
type=server
boosterDataHosts=dataHost1
#node4


初始mycat配置到zookeeper

cd /usr/local/mycat/conf
cp schema.xml server.xml rule.xml sequence_db_conf.properties zkconf
cd ..
./bin/init_zk_data.sh

进入到zk中查看是否同步成功

./bin/zkCli.sh
ls /mycat/mycat-cluster-1
...
get /mycat/mycat-cluster-1/schema/dataHost

启动mycat 验证配置是否同步成功

#node1 node4
mycat stop
mycat start