Nexus自建服务使用后续遇到的问题及解决办法

852 阅读3分钟

背景:某天发现云服务器上部署的nexus服务无法访问,看了下服务器在线,但是Nexus 服务没有启动,奇了怪了,因此尝试重启Nexus服务,遇到如下问题需解决:

Native memory allocation (mmap) failed to map 1890254848 bytes for committing reserved memory.

# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1890254848 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=
# This output file may be truncated or incomplete.
#
#  Out of Memory Error (os_linux.cpp:2795), pid=23752, tid=0x00007f5983f4b700
#
# JRE version:  (8.0_322-b06) (build )
# Java VM: OpenJDK 64-Bit Server VM (25.322-b06 mixed mode linux-amd64 compressed oops)
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again

问题日志里面说的很明白了,启动的时候内存不够。

Nexus服务启动内存不够

错误信息:Native memory allocation (mmap) failed to map 1890254848 bytes for committing reserved memory

原因:云服务器是1G RAM,显然不满足Nexus启动所需

解决办法:传送门,跟着这个文章学习吧

最终我采用的是创建swapfile的方法,参考文章:传送门

经过上面步骤之后,重新运行./nexus run,服务启动成功。

云服务器重启之后Nexus无法访问

原因:Nexus服务没有设置开启自启动 解决办法:设置Nexus开机自启动

参考文章:传送门:我主要参考的这个

参考这个文章中,使用的是nexus的start命令,但是经常在启动nexus的时候该命令看起来启动成功了,实际还是无法访问nexus服务,我后来改成run命令了

或者参考文章:传送门

这两个参考的文章有一个让我迷惑的地方,就是第二个文章中提到执行命令chkconfig nexus on设置服务开机自启动,但是我参考第一个文章的时候并没有提到执行该命令,因此可能是因为添加的服务默认就是启动的吧,经测试没有执行该语句重启服务器之后,Nexus服务依然可以访问(建议还是执行下该语句)。

附:自启动服务文件写入的内容

#!/bin/bash
#chkconfig:2345 20 90
#description:nexus
#processname:nexus

export NEXUS_HOME=/usr/local/mysoft/nexus/nexus-3.37.3-02

case $1 in
    start)
        echo "Starting nexus…"
        su superluo $NEXUS_HOME/bin/nexus start
        echo "Starting nexus OK…"
        ;;
    run)
            echo "Running nexus…"
            su superluo $NEXUS_HOME/bin/nexus run
            echo "Running nexus OK…"
            ;;
    stop)
        echo "Stoping nexus…"
        su superluo $NEXUS_HOME/bin/nexus stop
        echo "Stoping nexus OK…"
        ;;
    status)
        su superluo $NEXUS_HOME/bin/nexus status
        ;;
    restart)
        echo "Restarting nexus…"
        su superluo $NEXUS_HOME/bin/nexus restart
        echo "Restarting nexus OK…"
        ;;
    dump)
        su superluo $NEXUS_HOME/bin/nexus dump
        ;;
    console)
        su superluo $NEXUS_HOME/bin/nexus console
        ;;
    *)
        echo "Usage: nexus {start|stop|run|run-redirect|status|restart|force-reload}"
esac

部分含义解释: 第一行#!/bin/bash 格式标准 第二行#chkconfig:2345 20 90 设置开机启动时候需要, 大致意思如下

chkconfig后面有三个参数2345,20和90告诉chkconfig程序,需要在rc2.d~rc5.d目录下,创建名字为 S20nexus的文件连接,连接到/etc/rc.d/init.d目录下的的nexu脚本。第一个字符是S,系统在启动的时候,运行脚 本nexus,就会添加一个start参数,告诉脚本,现在是启动模式。同时在rc0.d和rc6.d目录下,创建名字为K90nexus的 文件连接,第一个字符为K,个系统在关闭系统的时候,会运行nexus,添加一个stop,告诉脚本,现在是关闭模式。 注意上面的三行中,第二,第三行是必须的,否则在运行chkconfig --add nexus时,会报错。

JAVA_HOME和NEXUS_HOME根据自己本地安装来修改

———————————————— 以上含义解释摘抄自以下博客文章: 原文链接:blog.csdn.net/u011271894/…