shardingsphere配置读写分离集群(1主2从结构)

第一章、shardingsphere的安装

1、使用ftp将离线安装包放到/opt

2、进入opt目录,解压,移动到/usr/local,重命名

cd /opt
tar -xzvf mysql-5.7,29-linux-glibc2.12-x86_64.tar.gz
mv apache-shardingsphere-4.1.1-sharding-proxy-bin /usr/local
cd /usr/local
mv apache-shardingsphere-4.1.1-sharding-proxy-bin shardingsphere

3、安装mysql连接器

tar -xzvf mysql-connector-java-5.1.48.tar.gz
mv /usr/local/shardingphere/lib

4、启动和停止

cd shrdingsphere/bin 
./start.sh 
./stop.sh

第二章、配置读写分离多用户集群

1、集群结构

在这里插入图片描述

2、config-master_slave.yaml

cd .. 
cd shardingsphere/conf 
vi config-master_slave.yaml

配置如下内容:

schemaName:demo #数据库名 demo
dataSources:
    master_ds: # 主库配置
        url:jdbc:mysql://主库ip:3306/demo?serverTimezone=UTC&useSSL=false
        username:demo # 数据库用户,
        password:demo # 数据库密码
        connectionTimeoutMilliseconds:30000
        idleTimeoutMillisecond:60000
        maxLifetimeMillliseconds:1800000
        maxPoolSize:50
    slave_ds_0: # 从库1配置
        url:jdbc:mysql://从库ip1:3306/demo?serverTimezone=UTC&useSSL=false
        username:demo # 数据库用户,
        password:demo # 数据库密码
        connectionTimeoutMilliseconds:30000
        idleTimeoutMillisecond:60000
        maxLifetimeMillliseconds:1800000
        maxPoolSize:50
     slave_ds_1: # 从库2配置
        url:jdbc:mysql://从库ip2:3306/demo?serverTimezone=UTC&useSSL=false
        username:demo # 数据库用户,
        password:demo # 数据库密码
        connectionTimeoutMilliseconds:30000
        idleTimeoutMillisecond:60000
        maxLifetimeMillliseconds:1800000
        maxPoolSize:50

masterSlaveRule:
    name:ms_ds
    masterDataSourceName:master_ds
    slaveDataSourceNames:
        - slave_ds_0
        - slave_ds_1

3、配置数据库2

在另外复制一个config-master_slave.yaml配置文件,改个名称即可。

cp config-master_slave.yaml 
config-master_slave-2.yaml 
vi config-master_slave-2.yaml

按如下配置

schemaName:demo #数据库名 demo
dataSources:
    master_ds: # 主库配置
        url:jdbc:mysql://主库ip:3306/demo1?serverTimezone=UTC&useSSL=false
        username:demo # 数据库用户,
        password:demo # 数据库密码
        connectionTimeoutMilliseconds:30000
        idleTimeoutMillisecond:60000
        maxLifetimeMillliseconds:1800000
        maxPoolSize:50
    slave_ds_0: # 从库1配置
        url:jdbc:mysql://从库ip1:3306/demo1?serverTimezone=UTC&useSSL=false
        username:demo # 数据库用户,
        password:demo # 数据库密码
        connectionTimeoutMilliseconds:30000
        idleTimeoutMillisecond:60000
        maxLifetimeMillliseconds:1800000
        maxPoolSize:50
     slave_ds_1: # 从库2配置
        url:jdbc:mysql://从库ip2:3306/demo1?serverTimezone=UTC&useSSL=false
        username:demo # 数据库用户,
        password:demo # 数据库密码
        connectionTimeoutMilliseconds:30000
        idleTimeoutMillisecond:60000
        maxLifetimeMillliseconds:1800000
        maxPoolSize:50

masterSlaveRule:
    name:ms_ds
    masterDataSourceName:master_ds
    slaveDataSourceNames:
        - slave_ds_0
        - slave_ds_1

3、server.xml

在server.xml中配置如下内容

authentication:
    user:
        demo: # demo数据库
            password:demo
            authorizedSchemas:demo
        demo1: # demo1数据库
            password:demo1
            authorizedSchemas:demo1
    sharding:
        password:sharding
        authorizedSchemas:sharding_db

props:
    executor.size:16
    sql.show:false

4、重启

cd shrdingsphere/bin 
./stop.sh
./start.sh 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值