美文网首页
使用 Nexus 3搭建 maven 私服 - 安装篇

使用 Nexus 3搭建 maven 私服 - 安装篇

作者: 泡水鱼干 | 来源:发表于2021-05-15 16:13 被阅读0次

本文参照官网:https://help.sonatype.com/repomanager3

简介

私服是一种特殊的远程仓库,建立在局域网内,主要作用:

  • 代理远程仓库及部署第三方构件
  • 管理公司自己的私有jar

常用来搭建私服的软件:

安装

下载:https://www.sonatype.com/products/repository-oss-download

按照需求下载对应系统版本

# 解压
[root@localhost ~]# tar -xzvf nexus-3.30.1-01-unix.tar.gz 
[root@localhost ~]# mv nexus-3.30.1-01 /usr/local/nexus
[root@localhost ~]# cd /usr/local/

# 创建用户
[root@localhost local]# groupadd nexus
[root@localhost local]# useradd -g nexus -s /sbin/nologin nexus

# 修改权限
[root@localhost local]# chown -R nexus:nexus nexus

# 指定启动用户
[root@localhost local]# vim nexus/bin/nexus.rc
run_as_user="nexus"

# 环境变量配置
[root@localhost local]# vim /etc/profile
export PLEXUS_NEXUS_WORK=/home/nexus/sonatype-work
[root@localhost local]# source /etc/profile

# 修改工作目录
[root@localhost bin]# cd /usr/local/nexus/bin
[root@localhost bin]# vim nexus.vmoptions
-XX:LogFile=/home/nexus/sonatype-work/nexus3/log/jvm.log
-Dkaraf.data=/home/nexus/sonatype-work/nexus3
-Dkaraf.log=/home/nexus/sonatype-work/nexus3/log
-Djava.io.tmpdir=/home/nexus/sonatype-work/nexus3/tmp

# 启动 nexus {start|stop|run|run-redirect|status|restart|force-reload}
# 以 nexus 用户启动
[root@localhost nexus]# sudo -u nexus /usr/local/nexus/bin/nexus run

# 当出现下列信息表示启动成功
-------------------------------------------------

Started Sonatype Nexus OSS 3.30.1-01

-------------------------------------------------
# 停止
[root@localhost bin]# sudo -u nexus /usr/local/nexus/bin/nexus stop

# 查看状态

验证安装,在浏览器输入地址访问,

http://IP地址:8081/
012.png

点击 Sign in 登陆,首次登陆需要获得admin密码,密码在nexus工作目录下。输入密码成功后,系统提示重置admin密码,按照提示操作即可

# 获取密码
[root@localhost bin]# vim /home/nexus/sonatype-work/nexus3/admin.password

配置

配置nexus启动用户

最好以仅具有所需访问权限的特定用户身份运行该服务或守护程序

[root@localhost bin]# vim nexus.rc
run_as_user="nexus"

以服务运行

在生产环境中我们需要配置nexus以服务运行,保证服务器重新启动后nexus可以启动。

[root@localhost system]# cd /etc/systemd/system
[root@localhost system]# vim nexus.service
[Unit]
Description=nexus service
After=network.target
  
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/usr/local/nexus/bin/nexus start
ExecStop=/usr/local/nexus/bin/nexus stop
User=nexus
Restart=on-abort
TimeoutSec=600
  
[Install]
WantedBy=multi-user.target

[root@localhost system]# chmod +x nexus.service
# 配置自启动
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl enable nexus.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nexus.service to /etc/systemd/system/nexus.service.
# 验证
[root@localhost system]# systemctl start nexus.service
[root@localhost system]# systemctl status nexus.service
 nexus.service - nexus service
   Loaded: loaded (/etc/systemd/system/nexus.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2021-05-15 14:43:40 CST; 12s ago
  Process: 2417 ExecStart=/usr/local/nexus/bin/nexus start (code=exited, status=0/SUCCESS)
 Main PID: 2590 (java)
   CGroup: /system.slice/nexus.service
           └─2590 /usr/local/jdk1.8.0_271/bin/java -server -Dinstall4j.jvmDir=/usr/local/jdk1.8.0_271 -Dexe4j.moduleName=/usr/local/ne...

5月 15 14:43:40 localhost.localdomain systemd[1]: Starting nexus service...
5月 15 14:43:40 localhost.localdomain nexus[2417]: Starting nexus
5月 15 14:43:40 localhost.localdomain systemd[1]: Started nexus service.

注意:nexus启动比较慢当看到 active (running) 时候,访问链接有可能仍看不到界面,稍微等待一会

至此,nexus命令变为如下

# 启动
[root@localhost system]# systemctl start nexus.service
# 状态
[root@localhost system]# systemctl status nexus.service
# 停止
[root@localhost system]# systemctl stop nexus.service

配置文件说明

修改nexux安装目录/bin/nexus.vmoptions文件,调整JVM参数

配置文件目录nexux安装目录/etc

  • fabric

    Ehcache,Elasticsearch和OrientDB的配置文件

  • karaf

    Apache Karaf的配置文件,包括:

    • config.properties

      Apache Karaf运行时的主要配置。此文件不应被修改。

    • custom.properties

      Apache Karaf使用的可定制配置。该文件可用于将其他参数传递给Apache Karaf容器。

    • org.apache.*、org.ops4j.*

      各种Karaf和OSGi相关的配置文件

    • system.properties

      用于JVM和应用程序启动的系统属性

  • jetty

    Eclipse Jetty的配置文件

  • logback

    日志配置文件,有关日志文件名,日志级别,模式布局和rotation规则的默认记录定义。包括:

    • logback.xml:用来定义nexus.log、tasks/*.log

    • logback-access.xml:用来定义 request.log

  • nexus-default.properties

    默认配置样板,不应该被修改。

    如果修改请拷贝nexus-default.properties到工作路径/etc/nexus.properties

    本文工作路径为/home/nexus/sonatype-work/nexus3

    注意:nexus第一次启动会在目录下创建该文件,如果需要在没启动前修改配置,请手动创建相应目录及文件,并注意文件权限(运行nexus使用nexus用户,创建的文件应属于该用户)

  • ssl

    配置HTTPS时放置密钥

JAVA配置

修改安装目录/bin/nexus.vmoptions 文件,比如修改内存

-Xms2703M
-Xmx2703M
-XX:MaxDirectMemorySize=2703M

端口修改

修改工作路径/etc/nexus.properties

application-port=8888

工作/日志 目录修改

修改安装目录/bin/nexus.vmoptions 文件

-XX:LogFile=/home/nexus/sonatype-work/nexus3/log/jvm.log
-Dkaraf.data=/home/nexus/sonatype-work/nexus3
-Dkaraf.log=/home/nexus/sonatype-work/nexus3/log
-Djava.io.tmpdir=/home/nexus/sonatype-work/nexus3/tmp

使用nginx代理

HTTP

http {
  
  proxy_send_timeout 120;
  proxy_read_timeout 300;
  proxy_buffering    off;
  proxy_request_buffering off;
  keepalive_timeout  5 5;
  tcp_nodelay        on;
  
  server {
    listen   *:80;
    server_name  www.example.com;
  
    # allow large uploads of files
    client_max_body_size 1G;
  
    # optimize downloading files larger than 1G
    #proxy_max_temp_file_size 2G;
  
    location / {
      # Use IPv4 upstream address instead of DNS name to avoid attempts by nginx to use IPv6 DNS lookup
      proxy_pass http://127.0.0.1:8081/;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
  }
}

HTTPS

http {
  
  proxy_send_timeout 120;
  proxy_read_timeout 300;
  proxy_buffering    off;
  proxy_request_buffering off;
  keepalive_timeout  5 5;
  tcp_nodelay        on;
  
  server {
    listen   *:443;
    server_name  repo.example.com;
  
    # allow large uploads of files
    client_max_body_size 1G;
  
    # optimize downloading files larger than 1G
    #proxy_max_temp_file_size 2G;
  
    ssl on;
    ssl_certificate      example.pem;
    ssl_certificate_key  example.key;
  
    location / {
      # Use IPv4 upstream address instead of DNS name to avoid attempts by nginx to use IPv6 DNS lookup
      proxy_pass http://127.0.0.1:8081/;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto "https";
    }
  }
}

安装后

API

Nexus提供REST API,完整的文档可以使用admin账号登陆后查看,本文地址:http://192.168.3.113:8888/#admin/system/api,或通过下列步骤查看,登陆系统 》点击齿轮图标 》System 》API

013.png

配置匿名访问

关闭用户匿名访问。登陆系统 》点击齿轮图标 》Security 》Anonymous Access,取消Allow anonymous users to access the server 勾选

014.png

更改管理员电子邮件地址

登陆系统 》点击齿轮图标 》Security 》Users 点击admin账户 出现如下界面

015.png

配置SMTP设置

配置默认的HTTP和HTTPS代理设置

登陆系统 》点击齿轮图标 》System 》HTTP

016.png

为您的服务器设置备份过程

登陆系统 》点击齿轮图标 》System 》Tasks 》Create task 显示如下界面,点击 Admin - Export databases for backup 出现备份配置界面

017.png 018.png

常见错误

Connect to sonatype-download.global.ssl.fastly.net:443

登陆系统》点击齿轮图标》System 》Capabilities 点击“Outreach:Management”

010.png

点击 “Disable”,之后重启 nexus


011.png

相关文章

网友评论

      本文标题:使用 Nexus 3搭建 maven 私服 - 安装篇

      本文链接:https://www.haomeiwen.com/subject/frxkjltx.html