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


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

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

    环境要求

    • 操作系统: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
    
    • 1
    • 2

    解压产品包

    # 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    修改配置文件(server.yaml)

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

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

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

    # 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    引入数据库驱动(可选)

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    启动服务

    通过 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

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

    # 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
    
    • 1
    • 2

    使用数据库客户端访问

    # 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    启动与关闭

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

    启动

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

    ./bin/start.sh
    
    • 1

    关闭

    ./bin/stop.sh
    
    • 1

    总结

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

  • 相关阅读:
    快速入门C++第四天——继承与派生
    DataCon 【签到题】物联网安全
    linux放开8080端口
    pycharm安装汉化包失败解决方法
    最长回文子串&最长子串&第K大的数字&atoi
    MySQL8新特性窗口函数详解
    【服务器数据恢复】linux ext3下mysql数据库数据恢复案例
    碳中和大潮惊涛拍岸,科技企业如何迈入这条大江大河?
    iPhone 14 Pro/Max出大问题:从旧款机型传输数据后卡死黑屏无法开机!
    Elastic Stack 8.11:引入一种新的强大查询语言 ES|QL
  • 原文地址:https://blog.csdn.net/daiyejava/article/details/127826975