【原创】Ubuntu 22安装nexus私服

发布于:2025-02-21 ⋅ 阅读:(19) ⋅ 点赞:(0)

Nexus Repository Manager 是由 Sonatype 公司开发的一款非常流行的 Maven 私服解决方案。Nexus 提供了多种类型的仓库管理,包括代理远程仓库、托管内部构件的仓库以及用于快照版本和发布版本的仓库。

下载

官网地址:https://www.sonatype.com/
下载地址:https://www.sonatype.com/thanks/repo-community-edition

安装

建议安装Linux系统,CPU四核以上。

解压程序包

tar zxvf nexus-3.77.1-01-unix.tar.gz

启动

cd nexus-3.77.1-01
cd bin/
./nexus start

如果启动不起来,则因该检查JAVA的问题,要求JAVA17

apt-cache search java
apt-get install openjdk-17-jre-zero -y

然后再启动nexus,应该能正常

测试nexus

查看本机IP

ip a

打开URL http://192.168.1.111:8081
记得端口8081,使用http协议

打开后登录,按照提示重设管理员密码

启用https

在IDE中往往要用https协议下载,如果有域名,可以申请一个SSL证书,如果没有域名那么创建一个自签名证书,步骤如下

切换目录

cd nexus-3.77.1-01/etc/ssl

创建证书

在创建证书的时候,需要设置密码,记得密码哦

openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
openssl req -x509 -days 3650 -key server.key -in server.csr > server.crt
openssl rsa -in server.key -out server.key.unsecure
openssl pkcs12 -export -out keystore.pkcs12 -inkey server.key -in server.crt
keytool -v -importkeystore -srckeystore keystore.pkcs12 -srcstoretype PKCS12 -destkeystore keystore.jks -deststoretype JKS
root@ubuntu22:~/nexus-3.77.1-01/etc/ssl# ll
total 32
drwxr-xr-x 2 root root 4096 Feb 19 05:50 ./
drwxr-xr-x 7 root root 4096 Feb 19 06:02 ../
-rw-r--r-- 1 root root    0 Feb  6 23:24 .placeholder
-rw-r--r-- 1 root root 1382 Feb 19 05:39 keystore.jks
-rw------- 1 root root 1779 Feb 19 05:38 keystore.pkcs12
-rw-r--r-- 1 root root  891 Feb 19 05:38 server.crt
-rw-r--r-- 1 root root  635 Feb 19 05:37 server.csr
-rw------- 1 root root 1062 Feb 19 05:37 server.key
-rw------- 1 root root  916 Feb 19 05:38 server.key.unsecure

修改配置

切换目录

vi nexus-3.77.1-01/etc/jetty/jetty-https.xml

三个地方填写你的密码

  <New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory$Server">
    <Set name="KeyStorePath"><Property name="ssl.etc"/>/keystore.jks</Set>
    <Set name="KeyStorePassword">**密码**</Set>
    <Set name="KeyManagerPassword">**密码**</Set>
    <Set name="TrustStorePath"><Property name="ssl.etc"/>/keystore.jks</Set>
    <Set name="TrustStorePassword">**密码**</Set>
    <Set name="EndpointIdentificationAlgorithm"></Set>
    <Set name="NeedClientAuth"><Property name="jetty.ssl.needClientAuth" default="false"/></Set>
    <Set name="WantClientAuth"><Property name="jetty.ssl.wantClientAuth" default="false"/></Set>
    <Set name="IncludeProtocols">
      <Array type="java.lang.String">
        <Item>TLSv1.2</Item>
      </Array>
    </Set>
  </New>

修改属性文件

vi nexus-3.77.1-01/etc/nexus-default.properties

添加application-port-ssl参数
修改application-port 参数
nexus-args参数末尾添加,${jetty.etc}/jetty-https.xml,启用https

## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
##
# Jetty section
application-port-ssl=443
application-port=80
application-host=0.0.0.0
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml,${jetty.etc}/jetty-https.xml
nexus-context-path=/

# Nexus section
nexus-edition=nexus-pro-edition
nexus-features=\
 nexus-pro-feature

重启 nexus

cd nexus-3.77.1-01/bin
./nexus restart

测试

http://192.168.1.111
https://192.168.1.111