shardingsphere 配置读写分离集群(1 主 2 从结构)
作者:zhengzai7
- 2023-07-18 陕西
本文字数:1732 字
阅读完需:约 6 分钟

第一章、shardingsphere 的安装
1、使用 ftp 将离线安装包放到/opt
2、进入 opt 目录,解压,移动到/usr/local,重命名
cd /opttar -xzvf mysql-5.7,29-linux-glibc2.12-x86_64.tar.gzmv apache-shardingsphere-4.1.1-sharding-proxy-bin /usr/localcd /usr/localmv apache-shardingsphere-4.1.1-sharding-proxy-bin shardingsphere复制代码
3、安装 mysql 连接器
tar -xzvf mysql-connector-java-5.1.48.tar.gzmv /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 #数据库名 demodataSources: 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 #数据库名 demodataSources: 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 复制代码
划线
评论
复制
发布于: 刚刚阅读数: 3
zhengzai7
关注
还未添加个人签名 2023-07-07 加入
还未添加个人简介










评论