docker安装sharding-proxy

文章目录

  • 1. docker安装sharding-proxy
  • 2. 验证
  • 3. 附

1. docker安装sharding-proxy

  1. 获取镜像
docker pull apache/shardingsphere-proxy:5.1.1

这里以5.1.1版本为例,更多版本可参见dockerhub

  1. 启动容器
docker run -d \
-v /atguigu/server/proxy-a/conf:/opt/shardingsphere-proxy/conf \
-v /atguigu/server/proxy-a/ext-lib:/opt/shardingsphere-proxy/ext-lib \
-e ES_JAVA_OPTS="-Xmx256m -Xms256m -Xmn128m" \
-p 3321:3307 \
--name server-proxy-a \
apache/shardingsphere-proxy:5.1.1
  1. mysql驱动上传
    mysql-connector-java-8.0.22.jar驱动上传至/atguigu/server/proxy-a/ext-lib目录下
  2. 修改server.yaml
rules:
  - !AUTHORITY
    users:
      - root@%:root
    provider:
      type: ALL_PRIVILEGES_PERMITTED

props:
  sql-show: true

将配置文件放置在/atguigu/server/proxy-a/conf目录下
(注意:这里的- !AUTHORITY坚决不能删除,我擅自将其删除,导致shardingsphere-proxy总是无法正常启动)

  1. 启动容器
docker restart server-proxy-a

2. 验证

  1. 日志查看
    前往容器内部的/opt/shardingsphere-proxy/logs/stdout.log文件查看日志
......
06:41:10.343 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true
06:41:10.343 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedByteBuffersPerChunk: 1023
06:41:10.384 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.processId: 38 (auto-detected)
06:41:10.386 [main] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.machineId: 02:42:ac:ff:fe:11:00:02 (auto-detected)
06:41:10.430 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled
06:41:10.430 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0
06:41:10.430 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384
06:41:10.456 [epollEventLoopGroup-2-1] INFO io.netty.handler.logging.LoggingHandler - [id: 0xb34a76d5] REGISTERED
06:41:10.459 [epollEventLoopGroup-2-1] INFO io.netty.handler.logging.LoggingHandler - [id: 0xb34a76d5] BIND: 0.0.0.0/0.0.0.0:3307
06:41:10.461 [epollEventLoopGroup-2-1] INFO io.netty.handler.logging.LoggingHandler - [id: 0xb34a76d5, L:/0.0.0.0:3307] ACTIVE
06:41:10.462 [main] INFO org.apache.shardingsphere.proxy.frontend.ShardingSphereProxy - ShardingSphere-Proxy Memory mode started successfully

有打印started successfully则启动成功!

  1. 也可以使用别的mysql的命令行客户端对该ShardingSphere-Proxy进行连接
mysql -h 192.xxx.xxx.xxx -P 3321 -u root -p
show databases;

3. 附

上述多数内容参考自尚硅谷,如有侵权,烦请联系将立刻删除

你可能感兴趣的:(shardingsphere,docker,docker,java,容器,sphere-proxy)