错误分析
SharidngSphere-Proxy启动时对服务器内存的大小有一定的要求,大概需要1GB的内存空间供JVM运行。
如果内容空间过小,会报以下错误:
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c56a0000, 982908928, 0) failed; error='Not enough space' (errno=12)
[root@wuqiong conf]# docker run --name tmp -p 3311:3307 apache/shardingsphere-proxy:5.5.1
we find java version: java21, full_version=21.0.4, full_path=/opt/java/openjdk/bin/java
unadapted java version, please notice...
The classpath is /opt/shardingsphere-proxy/conf:/opt/shardingsphere-proxy/conf:.:/opt/shardingsphere-proxy/lib/*:/opt/shardingsphere-proxy/ext-lib/*
main class org.apache.shardingsphere.proxy.Bootstrap -1 /opt/shardingsphere-proxy/conf 0.0.0.0 false
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c56a0000, 982908928, 0) failed; error='Not enough space' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 982908928 bytes. Error detail: committing reserved memory.
# An error report file with more information is saved as:
# /opt/shardingsphere-proxy/hs_err_pid7.log
这时候给虚拟机分配更大的内存或者更换服务器就可以了。
补充
在网上有些教程提出设置JVM的运行内容大小,就可以让JVM正常启动了。这种方法可以让容器启动,但是在客户端连接的时候,日志会打印错误信息,导致客户端一直连接不上。建议更换更大内存的服务器,毕竟ShardingSphere-Proxy用于生产环境下,需要使用集群模式。
# 设置JVM的初始内存大小
[root@wuqiong logs]# docker run -e ES_JAVA_OPTS="-Xmx256m -Xms256m -Xmn128m" -p 3321:3307 --name server-proxy-c apache/shardingsphere-proxy:5.1.1
we find java version: java8, full_version=1.8.0_312
Starting the ShardingSphere-Proxy ...
The classpath is /opt/shardingsphere-proxy/conf:.:/opt/shardingsphere-proxy/lib/*:/opt/shardingsphere-proxy/ext-lib/*
Please check the STDOUT file: /opt/shardingsphere-proxy/logs/stdout.log
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000080000000, 1073741824, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1073741824 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /opt/shardingsphere-proxy/hs_err_pid39.log# 虽然报错,但是可以正常启动了
[root@wuqiong ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
43c65f44fe2e apache/shardingsphere-proxy:5.1.1 "/bin/sh -c '${LOCAL…" 43 seconds ago Up 41 seconds 0.0.0.0:3321->3307/tcp, :::3321->3307/tcp server-proxy-c# 进入容器内部,查看输出的日志信息
root@e9be5bb96378:/opt/shardingsphere-proxy# tail logs/stdout.log
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000080000000, 1073741824, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1073741824 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /opt/shardingsphere-proxy/hs_err_pid39.log