CentOS 7 下安装和配置 Sonatype Nexus 3
原文地址:http://blog.sina.com.cn/s/blog_704836f40102x06j.html
稍稍做了一点修改。
前言
CentOS 7 下安装 Sonatype Nexus OSS 3.3 ,因为 3.1 以后,相比 3.0 配置文件发生了一些变化,记录一下大致的安装和配置过程。
Sonatype Nexus 一直是 Maven 仓库管理工具,Nexus 3.1 之后新增了很多功能。
安装参考 How To Install Latest Sonatype Nexus 3 On Linux
配置参考 Configuration and Data Directory Changes for Nexus Repository Manager 3.1.0
本例操作系统为 CentOS 7,命令基本一致。
环境说明
CentOS 7(Minimal Install)
安装和配置步骤
1.更新系统
$ sudo yum update
版本如下
$ cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
2.安装 JDK 1.8
$ curl -L -C - -b "oraclelicense=accept-securebackup-cookie" -O http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.rpm
$ sudo yum localinstall jdk-8u151-linux-x64.rpm
检验一下
$ java -version
java version "1.8.0_151"
SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
3.创建目录,并且 cd 进入这个目录
$ cd /opt
4.下载 Sonatype Nexus OSS 3(请根据实际情况下载最新版本)
$ sudo curl -O https://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.3.1-01-unix.tar.gz
5.解压
$ sudo tar -xzvf nexus-3.3.1-01-unix.tar.gz
6.创建链接
$ sudo ln -s nexus-3.3.1-01 nexus
7.创建 nexus 用户
$ sudo useradd nexus -M -s /sbin/nologin
8.授权
$ sudo chown -R nexus:nexus /opt/nexus
$ sudo chown -R nexus:nexus /opt/sonatype-work/
9.打开 /opt/nexus/bin/nexus.rc 文件, 去掉 run_as_user 变量的注释
$ sudo vi /opt/nexus/bin/nexus.rc
run_as_user="nexus"
10.设置环境变量
~/.bashrc添加NEXUS_HOME
NEXUS_HOME=/opt/nexus
10.安装服务(本例以 systemd 为例)
创建服务文件
$ sudo vi /etc/systemd/system/nexus.service
添加如下内容
[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=nexus
Restart=on-abort
[Install]
WantedBy=multi-user.target
其中LimitNOFILE=65536用于调整文件描述符数量。
安装并启动服务
$ sudo systemctl daemon-reload
$ sudo systemctl enable nexus
$ sudo systemctl start nexus
11.查看服务
$ sudo systemctl status nexus
12.添加防火墙规则
$ sudo firewall-cmd --zone=public --permanent --add-port=8081/tcp
$ sudo firewall-cmd --reload
13.访问测试
访问地址: http://ip:8081/
访问凭证(默认的用户名和密码):
username: admin
password: admin123
14.更改 nexus 的 context path
如需修改路径,编辑 /opt/sonatype-work/nexus3/etc/nexus.properties 文件即可
$ sudo vi /opt/nexus/nexus/etc/nexus.properties
nexus-context-path=/nexus
重启服务
$ sudo systemctl restart nexus
访问测试
地址 http://ip:8081/nexus
结束语
本例安装和配置 Sonatype Nexus 3.3,步骤比较简单。但是版本更新还是个问题,因为每次都手动安装就比较费时了,如果能 yum 安装就比较方便了。
参考资料
How To Install Latest Sonatype Nexus 3 On Linux
Nexus Repository OSS Server Installation
Configuration and Data Directory Changes for Nexus Repository Manager 3.1.0
Chapter 2. Installation and Running
问题:
https://www.cnblogs.com/sunilsun/p/5718306.html
1.nexus需要安装Jdk才能运行
打开 /opt/nexus/bin/nexus
将INSTALL4J_JAVA_HOME_OVERRIDE前面的#去掉,并添加自己的Java目录
该INSTALL4J_JAVA_HOME_配置仅仅针对命令行启动nexus才起作用,当nexus作为服务启动时,该配置不起作用,服务搜索jvm的路径是基本nexus启动文件中的common_jvm_locations设置的路径来查找的。
# Uncomment the following line to override the JVM search sequence
# when nexus start as a service, the below java home setting is invalid as it only follows the common_jvm_locations settings below.
# INSTALL4J_JAVA_HOME_OVERRIDE only take effect when nexus is started by command instead of service
INSTALL4J_JAVA_HOME_OVERRIDE=/opt/java
2.服务启动失败
Jobfornexus.service failed because the control process exited with error code. See"systemctl status nexus.service"and"journalctl -xe"fordetails.
$ journalctl -xe
Apr1910:35:32ubuntu nexus[3252]: No suitable Java Virtual Machine could be found on your system.
Apr 1910:35:32ubuntu nexus[3252]: The version of the JVM must be at least1.8and at most1.8.Apr 1910:35:32ubuntu nexus[3252]: Please define INSTALL4J_JAVA_HOME to point to a suitable JVM.
Apr 1910:35:32ubuntu systemd[1]: nexus.service: Control process exited, code=exited status=83Apr 1910:35:32ubuntu systemd[1]: Failed to start nexus service.
提示找不到JVM,上文配置的INSTALL4J_JAVA_HOME_OVERRIDE在服务启动模式下不启作用,暂不清楚原因。
查找nexus中JVM查找路径如下
common_jvm_locations="/opt/i4j_jres/* /usr/local/i4j_jres/* $HOME/.i4j_jres/* /usr/bin/java* /usr/bin/jdk* /usr/bin/jre* /usr/bin/j2*re* /usr/bin/j2sdk* /usr/java* /usr/java*/jre /usr/jdk* /usr/jre* /usr/j2*re* /usr/j2sdk* /usr/java/j2*re* /usr/java/j2sdk* /opt/java* /usr/java/jdk* /usr/java/jre* /usr/lib/java/jre /usr/local/java* /usr/local/jdk* /usr/local/jre* /usr/local/j2*re* /usr/local/j2sdk* /usr/jdk/java* /usr/jdk/jdk* /usr/jdk/jre* /usr/jdk/j2*re* /usr/jdk/j2sdk* /usr/lib/jvm/* /usr/lib/java* /usr/lib/jdk* /usr/lib/jre* /usr/lib/j2*re* /usr/lib/j2sdk* /System/Library/Frameworks/JavaVM.framework/Versions/1.?/Home /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home /Library/Java/JavaVirtualMachines/*.jdk/Contents/Home/jre"
笔者原JAVA_HOME位于/usr/lib/jdk/jdk1.8.0_74,多了一层
$sudomv/usr/lib/jdk/jdk1.8.0_74/ /usr/local/java/
同时修改JAVA_HOME
$ nano ~/.profile
$ source ~/.profile
$ java -version
重新启动