买了个2核2G的云服务器,在部署seata服务的时候,老是报内存不足的错误,经过一番折腾,最后实践可行,着急的可以直接划到文章最后面看成果
问题:
apm-skywalking not enabled
JMX disabled
Affected JVM parameters: -Dlog.home=/root/logs/seata -server -Dloader.path=/lib -Xmx2048m -Xms2048m -Xss640k -XX:SurvivorRatio=10 -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:MaxDirectMemorySize=1024m -XX:-OmitStackTraceInFastThrow -XX:-UseAdaptiveSizePolicy -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/root/logs/seata/java_heapdump.hprof -XX:+DisableExplicitGC -Xloggc:/root/logs/seata/seata_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -Dio.netty.leakDetectionLevel=advanced -Dapp.name=seata-server -Dapp.pid=1 -Dapp.home=/ -Dbasedir=/
OpenJDK 64-Bit Server VM warning: Cannot open file /root/logs/seata/seata_gc.log due to No such file or directory
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2147483648 bytes for committing reserved memory.
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000080000000, 2147483648, 0) failed; error='Cannot allocate memory' (errno=12)
# An error report file with more information is saved as:
# /seata-server/hs_err_pid1.log
寻找解决方法
问了ChatGPT说是通过启动命令
这几种方式都没有效果
# 没有效果
docker run --memory=256m --memory-swap=256m [其他参数] seata:latest
#或者
docker run -e JAVA_OPTS="-Xmx256m -Xms256m" -d --name seata seataio/seata-server
然后建议我通过修改seata-server.sh(或.bat)文件中的JAVA_OPT变量来实现。
我下载个windows运行版,发现bat的命令如下:
成功解决
所以docker启动命令时,修改的应该是JMX_OPTS这个参数,稍作修改后得到最后的启动命令:
docker run -e JMX_OPTS="-Xmx256m -Xms256m" -d --name seata2 seataio/seata-server
对应的seata日志也显示成功启动了
最后得出的结论是在启动命令中加入
-e JMX_OPTS="-Xmx256m -Xms256m"
可以修改seata的内存占用,而不是JAVA_OPTS