Centos 7 搭建 mvn 私服

一、安装

1、下载

链接:https://pan.baidu.com/s/1kziaOKwmnq_FRgHc0KX5Ng 
提取码:kjes

2、创建目录

mkdir /usr/local/nexus

tar -zxvf nexus-3.23.0-03-unix.tar.gz -C /usr/local/nexus/

cd /usr/local/nexus/nexus-3.23.0-03/

3、修改配置文件

vim bin/nexus

# detect if execute as root user
run_as_root=false        # 修改成 flase
user_id=`id -u`
user_name=`id -u -n`
if [ -z "$run_as_user" -a $user_id -ne 0 ]; then
  run_as_root=false
elif [ -n "$run_as_user" -a "$run_as_user" != 'root' ]; then
  run_as_root=false
fi


vim etc/nexus-default.properties

# Jetty section
application-port=8081     # 端口号,根据需要
application-host=0.0.0.0
nexus-context-path=/

4、启动

./bin/nexus start

# 成功
Starting nexus

5、访问

http://192.168.1.86:8081/ 

5、登陆,点击右上角 sign in

# 查看密码
vim /usr/local/nexus/sonatype-work/nexus3/admin.password

二、软件 操作

1、 创建 文件存储目录

2、创建仓库

proxy:是代理,可以设置多个,国内的:华为、阿里,国外的:maven2等等,指的是如果你当前私服没有可用jar,需要去哪下载。
hosted:本地的,指代当前私服。存放你上传的第三方jar、已下载的jar等。
group:管理本地和代理(以上两个),目的是将上述多个仓库聚合,对用户暴露统一的地址。
配置顺序:先配置proxy和hosted,最后配置group管理他们。 

1、创建 maven2(proxy)

阿里云的地址:http://maven.aliyun.com/nexus/content/groups/public/

2、创建 maven2(hosted)

3、创建 maven2(group) 

先从你当前maven私服去找,如果没有去国内的代理源进行下载,如过还没有,则去国外maven总库下载。

三、项目管理 上传 jar 包到私服

1、添加仓库认证,找到 本地电脑的 maven中的 setting,找到servers节点

<server>
        <id>releases</id>
        <username>admin</username>
        <password>admin123</password>
</server>
<server>
        <id>snapshots</id>
        <username>admin</username>
        <password>admin123</password>
</server>

 2、在项目的 pom.xml 添加远程发布的私服仓库地址

<distributionManagement>
    <repository>
    <!--此id要与setting.xml里面server的id对应-->
        <id>releases</id>
        <name>releases Repository</name>
        <url>http://192.168.1.86:8081/repository/rubis-hosted/</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <name>snapshots</name>
        <url>http://192.168.1.86:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

猜你喜欢

转载自blog.csdn.net/mshxuyi/article/details/107681572
今日推荐