Maven学习—Nexus2私服搭建

本文详细介绍了如何在Ubuntu环境下配置JDK环境变量,并逐步指导安装和配置Sonatype Nexus私服,包括端口设置、防火墙配置及通过Nginx实现外网域名访问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、Nexus搭建环境

环境:Ubuntu 16.04.4、JDK8、Sonatype Nenux、Maven

二、搭建步骤

1、配置JDK环境变量

解压JDK安装包,修改 vi /etc/profile配置文件,增加环境变量配置。修改完,保存后执行source /etc/profile命令,让新修改的环境变量生效。

JAVA_HOME=/usr/local/java/jdk1.8.0_181;
PATH=$JAVA_HOME/bin:/bin:$PATH;
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar;

三、安装私服Nexus

1、Nexus资源包下载

Nexus官方下载地址:https://www.sonatype.com/download-oss-sonatype
Nexus官方文档地址:https://help.sonatype.com/repomanager2/download

2、Nexus 资源包解压

2.1、在 /usr/local目录中创建子目录 nexus

mdkir /usr/local/nexus

2.2、解压Nexus到指定目录

tar -zxvf  nexus-2.14.10-01-bundle.tar.gz -C /usr/local/nexus

Nexus压缩包中包含两个子目录:nexus-2.14.10-01 和 sonatype-work
nexus-2.14.10-01 是具体的私服应用内容;
sonatype-work 是Nexus私服下载的构件存放工作目录。

Nexus 目录结构

Nexus 各个目录结构说明

目录名称

目录说明

nexus-2.14.10-01/binnexus 启动相关文件
nexus-2.14.10-01/confnexus配置文件
nexus-2.14.10-01/libnexus依赖的包文件
nexus-2.14.10-01/logsnexus日志文件
nexus-2.14.10-01/nexusnexus web界面工程文件,使用Jetty启动项目
nexus-2.14.10-01/tmpnexus 临时文件
sonatype-work/nexusnexus 运行工作下载的文件

3、检查私服端口和工作目录

nexus-2.14.10-01 目录中有子目录 conf,其中保存私服应用的配置信息。查看nexus.properties文件,确定私服访问端口和工作目录。如果没有端口相关冲突,该配置文件不做任何内容修改。配置文件内容如下:

# Sonatype Nexus
# ==============
# This is the most basic configuration of Nexus.

# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus

# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF

# orientdb buffer size in megabytes
storage.diskCache.bufferSize=4096

4、修改Nexus运行用户

Nexus私服启动后,私服应用需要访问Linux的文件系统,所以需要有足够的权限。Nexus的启动脚本文件中,可以指定应用的访问用户,此信息在nexus-2.14.10-01/bin/nexus脚本文件中定义。需修改如下信息:

# IMPORTANT - Make sure that the user has the required privileges to write into the Nexus installation directory.

# NOTE - This will set the user which is used to run the Wrapper as well as
#  the JVM and is not useful in situations where a privileged resource or
#  port needs to be allocated prior to the user being changed.
RUN_AS_USER=root  # 修改后的内容,代表Nexus私服使用root用户权限

一般不建议使用root用户权限启动,可以新建一个nexus用户,启动Nexus。

5、修改防火墙,开放Nexus私服端口访问

修改防火墙配置文件,开放Nexus私服的访问端口 8081

vi /etc/sysconfig/iptables  # 注意centOS系统环境
增加如下配置:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8081 -j ACCEPT

iptables status # 查看端口状态
service iptables restart # 重启防火墙

阿里云服务器,需要在阿里云管理后台,设置服务器的端口规则。不在iptables中限制端口的访问

6、启动并测试访问

启动Nexus私服
`/usr/local/nexus/nexus-2.14.10-01/bin/nexus start`

启动成功日志

常用的命令

nexus start  # 启动
nexus stop  # 停止
nexus status  # 查看状态
nexus restart  # 重启

启动成功访问:http://[你的IP]:8081/nexus

四、阿里云服务外网域名访问

阿里云服务器配置外网域名可以访问,配置域名解析,通过Nginx配置访问nexus服务。

1、添加阿里云域名解析,如 nexus.[你的域名] 为例。

2、配置阿里云服务器的Nginx配置文件

  server {
       listen       80;
       server_name nexus.[你的域名];

        charset utf-8;
        access_log  logs/nexus_access.log main;
        include proxy.conf;

        location / {
            proxy_pass http://127.0.0.1:8081;
        }

        location ~ ^/(WEB-INF)/ {
            deny all;
        }

        location ~ \.(php|asp|aspx) {
            deny all;
        }
    }

其中 proxy.conf 的内容为

proxy_redirect          off;
proxy_set_header        Host            $host;
proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        RealIP          $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

client_max_body_size    100m;
proxy_connect_timeout   3s;
proxy_send_timeout      1m;
proxy_read_timeout      1m;
proxy_temp_file_write_size 1024m;
proxy_buffer_size         32k;
proxy_buffers             4 32k;
proxy_busy_buffers_size 64k;
proxy_ignore_client_abort on;
proxy_next_upstream error timeout invalid_header http_503;

2、配置好,Nginx重新reload下,使配置生效。

3、通过域名测试访问是否生效。

特别注意:nexus2 的访问域名为:http://nexus.[你的域名]/nexus

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飞鸽FlyGo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值