在安装好了sonatype nexus之后(我的nexus是安装在/usr/local/下的),我们可以把nexus设置为系统服务,设置步骤如下:
使用超级用户root进行以下4个步骤
1.把nexus复制到/etc/init.d/nexus下或者制作一个链接
#cd /etc/init.d/
#cp /usr/local/nexus2/bin/nexus /etc/init.d/nexus
2.为nexus授权
#chmod 755 /etc/init.d/nexus
3.将nexus设置为系统服务
#update-rd.d nexus defaults
4.进行了以上步骤之后我们还不能直接启动服务,还得修改nexus的配置信息,修改/etc/init.d/nexus,增加或者修改以下变量:
NEXUS_HOME="/usr/local/nexus2"
RUN_AS_USER=dengsilinming
PLATFORM=linux-x86-64
PLATFORM_DIR="${NEXUS_HOME}/bin/jsw/${PLATFORM}"
WRAPPER_CMD="${PALTFORM_DIR}/wrapper"
WRAPPER_CONF="${PLATFORM_DIR}/../conf/wrapper.conf"
PIDDIR="${NEXUS_HOME}" #pid会写在/usr/local/nexus2/nexus.pid文件里
5.退出root,用我们设置的用户启动服务(我这里是dengsilinming,因为我是RUN_AS_USER=dengsilinming)
#service nexus start
启动后你会看到启动成功的提示信息:
Starting Nexus OSS...
Started Nexus OSS.
在设置过程中遇到的问题:
dengsilinming@dengsilinming:~$ service nexus start
Starting Nexus OSS...
Started Nexus OSS.
dengsilinming@dengsilinming:~$ tail -f /usr/local/nexus2/logs/wrapper.log
wrapper | JVM exited while loading the application.
jvm 4 | wrapper | Unable to start JVM: No such file or directory (2)
wrapper | Reloading Wrapper configuration...
wrapper | Launching a JVM...
wrapper | Unable to start JVM: No such file or directory (2)
wrapper | JVM exited while loading the application.
jvm 5 | wrapper | Unable to start JVM: No such file or directory (2)
wrapper | There were 5 failed launches in a row, each lasting less than 300 seconds. Giving up.
wrapper | There may be a configuration problem: please check the logs.
wrapper | <-- Wrapper Stopped
报错了,说找不到jdk的配置信息,但我在Path里面明明有配置,在出现这个问题时如果切换回root用户再启动,可以成功。个人猜想这是权限引起的,但具体是不是不清楚,希望懂的朋友们可以留言告知。
解决方法:把wrapper.conf里面的wrapper.java.command=%JAVA_HOME%/bin/java改成绝对路径--wrapper.java.command=/opt/jdk1.7.0_45/bin/java,保存后再用配置的账户启动,此时OK了。
注:如果使用wrapper.java.command=%JAVA_HOME%/bin/java,直接重启系统后,你会发现nexus服务自动启动了,我们需要的效果达到了,但直接停止服务后再手动调用命令service nexus start同样失败。
参考文章: Configuring Nexus as a Service
http://wrapper.tanukisoftware.com/doc/english/prop-java-command.html