智能
助手
最大化  清空记录 停止  历史记录
翻译选中文本
选中一段文本后进行翻译
名词解释
选中一段文本后进行名词解释
知识图谱生成
通过图谱展示知识信息
登录用户在知识浏览页面可用
答案生成
AI自动回答一个问答功能中的问题
登录用户在问答浏览页面,且问题开放回答中可用
知识摘要
自动为当前知识生成摘要
知识浏览页面可用
知识问答
针对当前知识进行智能问答
知识浏览面可用
2025-11-24 16:28:40 版本 : 7.9 创建maven项目-03-搭建Nexus私服
作者: 文艺范儿 于 2025年11月24日 发布在分类 / DevOps / maven 下,并于 2025年11月24日 编辑
 历史版本

备注 修改日期 修改人
创建版本 2025-11-24 16:28:40[当前版本] 文艺范儿

7.9 创建maven项目

6. 搭建Nexus私服

官网:https://www.sonatype.com/

下载地址:https://links.sonatype.com/products/nxrm3/download-unix-x86

a. 环境准备

# 系统要求
操作系统: CentOS 7.x/8.x 或 Ubuntu 18.04+
内存: 至少4GB
磁盘: 至少50GB可用空间
Java: JDK 8+

# 创建专用用户
[root@202-nexus ~]# groupadd nexus
[root@202-nexus ~]# useradd -g nexus -s /bin/bash -d /home/nexus -m nexus


b. 安装Java环境

# 此处不做描述
##验证java
[root@202-nexus ~]# java -version
java version "21.0.9" 2025-10-21 LTS
Java(TM) SE Runtime Environment (build 21.0.9+7-LTS-338)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.9+7-LTS-338, mixed mode, sharing)


c. 下载并安装Nexus

# 创建安装目录
[root@202-nexus ~]# mkdir /home/deploy/nexus
[root@202-nexus ~]# chown -R nexus:nexus /home/deploy/nexus
# 切换用户
[root@202-nexus ~]# su - nexus
# 下载Nexus(最新版本)
[nexus@202-nexus ~]$ cd /home/deploy/nexus/
[nexus@202-nexus nexus]$ wget  https://download.sonatype.com/nexus/3/nexus-3.86.2-01-linux-x86_64.tar.gz

# 解压
[nexus@202-nexus nexus]$ tar xf nexus-3.86.2-01-linux-x86_64.tar.gz
[nexus@202-nexus nexus]$ ln -s nexus-3.86.2-01 nexus

# 创建数据目录
[nexus@202-nexus nexus]$ mkdir /home/deploy/nexus/data


d. 配置Nexus

# 编辑Nexus配置文件
[nexus@202-nexus nexus]$ vim /home/deploy/nexus/nexus/etc/nexus-default.properties
...
## 数据目录
nexus.data=/home/deploy/nexus/data
...


e. 创建系统服务


# 创建systemd服务文件
[root@202-nexus ~]# vim /etc/systemd/system/nexus.service
[root@202-nexus ~]# cat /etc/systemd/system/nexus.service
[Unit]
Description=nexus service
After=network.target

[Service]
Type=forking
LimitNOFILE=65536
User=nexus
Group=nexus
ExecStart=/home/deploy/nexus/nexus/bin/nexus start
ExecStop=/home/deploy/nexus/nexus/bin/nexus stop
Restart=on-abort
TimeoutSec=600

[Install]
WantedBy=multi-user.target


f. 启动Nexus服务

# 设置权限
[root@202-nexus ~]# chown -R nexus:nexus /home/deploy/nexus

# 重新加载systemd
[root@202-nexus ~]# systemctl daemon-reload

# 启动服务
[root@202-nexus ~]# systemctl start nexus
[root@202-nexus ~]# systemctl enable nexus

# 检查状态
[root@202-nexus ~]# systemctl status nexus

# 查看启动日志
[root@202-nexus ~]# tail -f /home/deploy/nexus/sonatype-work/nexus3/log/nexus.log


j. 初始配置

# 访问Nexus Web界面
# 地址: http://your-server-ip:8081

# 获取初始管理员密码
[root@202-nexus ~]# cat /home/deploy/nexus/sonatype-work/nexus3/admin.password

# 初始配置步骤:
# 1. 使用admin和上面获取的密码登录
# 2. 修改管理员密码
# 3. 配置匿名访问(根据安全需求)


k. 配置Maven仓库

在Nexus中创建以下仓库:

代理仓库(Proxy Repositories)

这里只配置代理仓库即可,在页面操作

# 常用代理仓库
- maven-central: https://repo1.maven.org/maven2/
- aliyun-maven: https://maven.aliyun.com/repository/public/
- jcenter: https://jcenter.bintray.com/


托管仓库(Hosted Repositories)

# 发布版本仓库
- maven-releases (Version policy: Release)

# 快照版本仓库  
- maven-snapshots (Version policy: Snapshot)

# 第三方库仓库
- maven-3rdparty (Version policy: Mixed)


仓库组(Repository Groups)

# 创建仓库组,包含所有需要的仓库
- maven-public (包含: maven-central, aliyun-maven, maven-releases, maven-snapshots)

l. Maven项目配置

在项目的pom.xmlsettings.xml中配置:

settings.xml配置示例

#已经去掉所有注释,修改前先备份

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <pluginGroups>
  </pluginGroups>


  <proxies>
  </proxies>

  <servers>
     <server>   
     <id>my-nexus-releases</id>   
     <username>admin</username>   
     <password>dong123456</password>   
     </server>   
     <server>   
     <id>my-nexus-snapshot</id>   
     <username>admin</username>   
     <password>dong123456</password>   
     </server>
  </servers>

  <mirrors>
    <mirror>
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <url>http://10.0.0.202:8081/repository/maven-public/</url>
    </mirror>
  </mirrors>


  <profiles>

<profile>
  <id>nexus</id>
  <repositories>
    <repository>
      <id>central</id>
      <url>http://10.0.0.202:8081/repository/maven-public/</url>
      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
    </repository>
  </repositories>
 <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <url>http://10.0.0.202:8081/repository/maven-public/</url>
      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
    </pluginRepository>
  </pluginRepositories>
</profile>

  </profiles>


<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>





历史版本-目录  [回到顶端]
    文艺知识分享平台 -V 5.2.5 -wcp