Skip to content

Src Install Nexus3

编译安装 Nexus3

一. 安装 Java

$ tar -xf jdk-8u333-linux-x64.tar.gz -C /usr/local/
$ mv /usr/local/jdk1.8.0_333 /usr/local/java

$ cat /etc/profile.d/java8.sh
JAVA_HOME=/usr/local/java
JRE_HOME=/usr/local/java/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH

$ source /etc/profile
$ java -version
java version "1.8.0_333"
Java(TM) SE Runtime Environment (build 1.8.0_333-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.333-b02, mixed mode)

二. 安装 Nexus3

1)到官网下载 Nexus3,并上传至服务器

1
2
3
$ mkdir -p /opt/nexus
$ wget https://download.sonatype.com/nexus/3/nexus-3.41.1-01-unix.tar.gz
$ tar -xf nexus-3.41.1-01-unix.tar.gz -C /opt/nexus

2)创建用户 & 用户组,将授予目录权限

1
2
3
4
5
$ groupadd nexus
$ useradd -g nexus nexus
$ groups nexus
nexus : nexus
$ chown -R nexus. /opt/nexus

3)修改配置文件,按需进行

  • run_as_user:程序启动用户
  • INSTALL4J_JAVA_HOME_OVERRIDE:Java 环境变量
  • application-port:程序启动端口
1
2
3
4
5
6
7
8
9
$ cat ./nexus/nexus-3.41.1-01/bin/nexus.rc
run_as_user="nexus"

$ cat ./nexus/nexus-3.41.1-01/bin/nexus
INSTALL4J_JAVA_HOME_OVERRIDE=/usr/local/java

$ cat ./nexus/nexus-3.41.1-01/etc/nexus-default.properties
# Jetty section
application-port=8081

4)创建自启动脚本

$ vim /usr/lib/systemd/system/nexus.service
[Unit]
Description=nexus
After=network.target

[Service]
Type=forking
ExecStart=/opt/nexus/nexus-3.41.1-01/bin/nexus start
ExecReload=/opt/nexus/nexus-3.41.1-01/bin/nexus restart
ExecStop=/opt/nexus/nexus-3.41.1-01/bin/nexus stop
User=nexus
Restart=on-abort
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

# 启动服务并按提示查看密码进行登录修改
$ systemctl enable --now nexus && systemctl status nexus
$ cat /opt/nexus/sonatype-work/nexus3/admin.password
705683b1-0244-4adb-bf63-7fc3436aa6cb