![如何在具有 1GB RAM 的 Centos7 中运行 XWiki?](https://linux22.com/image/1593589/%E5%A6%82%E4%BD%95%E5%9C%A8%E5%85%B7%E6%9C%89%201GB%20RAM%20%E7%9A%84%20Centos7%20%E4%B8%AD%E8%BF%90%E8%A1%8C%20XWiki%EF%BC%9F.png)
根据 XWiki 文档,1GB 足以运行 XWiki。
https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Performances/#HMemory
适用于 Java 8(即 XWiki >= 8.1)。请注意,Java 8 中不再有 permgen:小型和中型安装:最小 1024MB(-Xmx1024m)
我根据文档安装并配置了 Tomcat。
我有(在conf/tomcat.conf
)
JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx750m -XX:MaxPermSize=125m -XX:+HeapDumpOnOutOfMemoryError"
有时
JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx1024m -XX:MaxPermSize=192m -XX:+HeapDumpOnOutOfMemoryError"
而且它随机崩溃。我甚至无法添加其他用户。这是转储文件的第一部分hs_err_pid11420.log
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 105709568 bytes for committing reserved memory.
# Possible reasons:
# The system is out of physical RAM or swap space
# The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
# JVM is running with Unscaled Compressed Oops mode in which the Java heap is
# placed in the first 4GB address space. The Java Heap base address is the
# maximum limit for the native heap growth. Please use -XX:HeapBaseMinAddress
# to set the Java Heap base and to place the Java Heap above 4GB virtual address.
# This output file may be truncated or incomplete.
#
# Out of Memory Error (os_linux.cpp:2766), pid=11420, tid=0x00007fcd0d720700
#
# JRE version: OpenJDK Runtime Environment (8.0_212-b04) (build 1.8.0_212-b04)
# Java VM: OpenJDK 64-Bit Server VM (25.212-b04 mixed mode linux-amd64 compressed oops)
我没有使用 HSQLDB。我在同一台服务器上使用 Postgresql。
CentOS Linux 版本 7.6.1810(核心)、XWiki 10.11.8
答案1
我通过添加交换文件修复了这个问题。
https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-centos-7
dd if=/dev/zero of=/swapfile count=125 bs=1MiB # 125 MB
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
sysctl vm.swappiness=10
sysctl vm.vfs_cache_pressure=50
我将 Tomcat 缩小到 750MB(对于一个空的 wiki 来说,这个大小似乎太高了)。
conf/tomcat.conf
JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx750m -XX:MaxPermSize=125m -XX:+HeapDumpOnOutOfMemoryError"
现在我的top
节目几乎没有免费的,但它不会崩溃。
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1015008 total, 67244 free, 844308 used, 103456 buff/cache
KiB Swap: 127996 total, 0 free, 127996 used. 18232 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
13409 tomcat 20 0 3065908 741928 3724 S 0.3 73.1 2:30.68 java