暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

两分钟快速安装 ShardingSphere-Proxy(5.2.1)

原创 代野(Tank) 2022-11-12
2490

借本地虚机环境安装 ShardingSphere-Proxy 5.2.1 机会,记录了安装过程,供大家参考。

ShardingSphere 支持多种安装方式,如通过二进制包、使用 Docker使用 Helm。本文档介绍如何通过二进制包快速构建 ShardingSphere-Proxy 测试环境,使用版本为 5.2.1。更详细的安装说明,请参考用户手册:使用二进制发布包安装 ShardingSphere-Proxy。

Table of Contents

环境要求

  • 操作系统:Linux,Windows
  • Java JRE:8 或以上版本

安装 ShardingSphere-Proxy

通过 5 个步骤完成快速安装:

  1. 下载产品包
  2. 解压产品包
  3. 修改配置文件(server.yaml)
  4. 引入数据库驱动
  5. 启动服务

环境信息如下:

  • 配置:1c/2g
  • 操作系统:CentOS 7.6
  • Java:1.8.0

下载产品包

可通过 wget 方式直接下载到测试机,或点此下载 apache-shardingsphere-5.2.1-shardingsphere-proxy-bin.tar.gz 软件包后,手动上传至测试机。

# cd /opt # wget https://archive.apache.org/dist/shardingsphere/5.2.1/apache-shardingsphere-5.2.1-shardingsphere-proxy-bin.tar.gz

解压产品包

# pwd /opt # tar xf apache-shardingsphere-5.2.1-shardingsphere-proxy-bin.tar.gz # cd apache-shardingsphere-5.2.1-shardingsphere-proxy-bin # ls LICENSE NOTICE README.txt bin conf lib licenses

修改配置文件(server.yaml)

先对初始配置文件拷贝备份。

# pwd /opt/apache-shardingsphere-5.2.1-shardingsphere-proxy-bin # cp ./conf/server.yaml ./conf/server.yaml.bak

默认的配置文件将不能被直接使用,需要对运行模式权限配置进行修改。

# pwd /opt/apache-shardingsphere-5.2.1-shardingsphere-proxy-bin # vi ./conf/server.yaml --可将如下内容追加至 server.yaml 末尾 mode: type: Standalone repository: type: JDBC rules: - !AUTHORITY users: - root@%:root - sharding@:sharding provider: type: ALL_PERMITTED

引入数据库驱动(可选)

ShardingSphere 产品包内包含了 PostgreSQL 和 openGauss 数据库驱动。如需引入其他数据库驱动,如 MySQL,则需要单独处理。

# pwd /opt/apache-shardingsphere-5.2.1-shardingsphere-proxy-bin # mkdir ext-lib # wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.11/mysql-connector-java-8.0.11.jar -P ./ext-lib/ # ls ext-lib/ mysql-connector-java-8.0.11.jar

启动服务

通过 bin 目录下的启动脚本启动服务。

# pwd /opt/apache-shardingsphere-5.2.1-shardingsphere-proxy-bin # ls ./bin start.bat start.sh stop.sh # ./bin/start.sh # tail -100f ./logs/stdout.log [INFO ] 2022-11-12 16:13:16.307 [main] o.a.s.d.p.c.l.PipelineContextManagerLifecycleListener - mode type is not Cluster, mode type='Standalone', ignore [INFO ] 2022-11-12 16:13:16.797 [main] o.a.s.p.frontend.ShardingSphereProxy - ShardingSphere-Proxy Standalone mode started successfully

启动成功后,查看服务对应的进程信息。

# ps -ef|grep shardingsphere|grep -v grep root 30911 1 13 16:13 pts/1 00:00:10 /usr/local/jdk1.8.0_141/bin/java -Djava.awt.headless=true -server -Xmx2g -Xms2g -Xmn1g -Xss1m -XX:AutoBoxCacheMax=4096 -XX:+UseNUMA -XX:+DisableExplicitGC -XX:LargePageSizeInBytes=128m -XX:+UseConcMarkSweepGC -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 -Dio.netty.leakDetection.level=DISABLED -classpath /opt/apache-shardingsphere-5.2.1-shardingsphere-proxy-bin/conf:/opt/apache-shardingsphere-5.2.1-shardingsphere-proxy-bin/conf:.:/opt/apache-shardingsphere-5.2.1-shardingsphere-proxy-bin/lib/*:/opt/apache-shardingsphere-5.2.1-shardingsphere-proxy-bin/ext-lib/* org.apache.shardingsphere.proxy.Bootstrap -1 /opt/apache-shardingsphere-5.2.1-shardingsphere-proxy-bin/conf 0.0.0.0 false

使用数据库客户端访问

# mysql -uroot -p -h127.0.0.1 -P3307 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.22-ShardingSphere-Proxy 5.2.1 Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> SHOW DATABASES; +--------------------+ | schema_name | +--------------------+ | shardingsphere | | information_schema | | performance_schema | | mysql | | sys | +--------------------+ 5 rows in set (0.02 sec) mysql> mysql> SELECT version(); +-----------------------------------+ | version() | +-----------------------------------+ | 5.7.22-ShardingSphere-Proxy 5.2.1 | +-----------------------------------+ 1 row in set (0.02 sec) mysql> \q Bye

启动与关闭

ShardingSphere-Proxy 服务启动和关闭的脚本位于 ./bin 路径下。

启动

使用以下脚本启动后,服务端口为 ShardingSphere-Proxy 的 3307 缺省端口。

./bin/start.sh

关闭

./bin/stop.sh

总结

ShardingSphere-Prxoy 安装过程比较简单,准备好 Java 环境,获取安装包、解包、修改配置文件后即可启动服务。如果对接的数据库是 MySQL,建议在启动服务前引入 MySQL 驱动,否则需在重启服务后可识别驱动。

最后修改时间:2022-11-13 22:00:21
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论