linux centos7安装配置nexus,并搭建maven私服

1、目的

      搭建nexus实现制品库的作用,保存发行版项目包。

2、下载nexus

      从官网下载免费版 https://www.sonatype.com/download-oss-sonatype

3、安装配置

3.1 安装nexus需要依赖java环境,需要先安装jdk8

# 这里使用nexus-3.26.1-02-unix.tar.gz版本
# 将压缩包放入服务器的指定文件夹
# 移动压缩包到指定目录
mkdir /usr/local/nexus
cp nexus-3.26.1-02-unix.tar.gz /usr/local/nexus

# 解压 nexus
cd /usr/local/nexus
tar -zxvf nexus-3.26.1-02-unix.tar.gz

# 解压之后会产生两个文件夹

nexus-3.26.1-02  #安装目录,nexus的启动文件及配置

sonatype-work  #数据目录,存放默认数据,日志、私服的jar


# 测试的服务器实力有限,需要把内存改小,启动参数配置在文件中./nexus-3.26.1-02/bin/nexus.vmoptions
# 修改 大小 2703m to 512m
# sed -i 's/2703/512/' ./nexus-3.26.1-02/bin/nexus.vmoptions

./nexus-3.26.1-02/bin/nexus start

# 到这里nexus就启动了

# 可以使用命令查看启动状态
./nexus-3.26.1-02/bin/nexus status

# 显示以下信息表示正在运行,启动日志在./sonatype-work/nexus3/log文件夹中

警告是启动用户为root,百度一下 修改启动用户 解决warning
########
WARNING: ************************************************************
WARNING: Detected execution as "root" user.  This is NOT recommended!
WARNING: ************************************************************
nexus is running.
########

# 也可以使用查看nexus的启动进程判断服务启动情况
ps -ef | grep nexus

# 显示以下信息表示进程正常
########
root     24376     1 99 11:43 pts/0    00:00:26 /home/tools/jdk1.8.0_241/bin/java -server -Dinstall4j.jvmDir=/home/tools/jdk1.8.0_241 -Dexe4j.moduleName=/usr/local/nexus/nexus-3.26.1-02/bin/nexus -XX:+UnlockDiagnosticVMOptions -Dinstall4j.launcherId=245 -Dinstall4j.swt=false -Di4jv=0 -Di4jv=0 -......
########

   

3.2  nexus默认端口为8081,配置文件在 /nexus-3.26.1-02/etc/nexus-default.properties

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

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

nexus.hazelcast.discovery.isEnabled=true

4、nexus功能

4.1 系统地址

http://ip:port

##### 3.26版本的nexus初始密码是在./sonatype-work/nexus3/admin.password文件中的一串随机字符串,之前版本的默认密码为:admin123

账号:admin

密码:*********

3.26版本使用初始密码登陆之后会提示重新设置密码,修改之后原初始密码文件就被自动删除了。

4.2 nexus功能的大概介绍

  1. blob缓存数据块

    默认的blob块是default,初始化的数据块是默认保存在./sonatype-work/nexus3/blobs/default

    可以新建一个数据块,保存在其他目录下,这样备份数据目录的时候会容易很多。(下面会说到备份的问题)

2. 仓库介绍

    1、四种仓库类型介绍

默认仓库介绍

   1)maven-central:      maven中央库,默认从https://repo1.maven.org/maven2/拉取jar

   2)maven-releases:   私库发行版jar

   3)maven-snapshots:私库快照(调试版本)jar

   4)maven-public:     仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml中使用。

Nexus默认的仓库类型有以下四种:(上面的名字可以随便取,关键是它对应的是什么仓库类型)

   1)group(仓库组类型):又叫组仓库,用于方便开发人员自己设定的仓库;

   2)hosted(宿主类型):内部项目的发布仓库(内部开发人员,发布上去存放的仓库);

   3)proxy(代理类型):  从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage Location属性的值即被代理的远程仓库的路径);

   4)virtual(虚拟类型): 虚拟仓库(这个基本用不到,重点关注上面三个仓库的使用);

Policy(策略):表示该仓库为发布(Release)版本仓库还是快照(Snapshot)版本仓库;

4.3 搭建maven私服

      1. 新建一个代理仓库,代理地址填写阿里的maven地址 http://maven.aliyun.com/nexus/content/groups/public/

          选择maven2(proxy)

    2. 新建一个host类型仓库,存放第三方不能下载的包,比如oracle驱动包

    3. 将创建好的仓库放入group类型的仓库管理,能查看组内所有的仓库包

     

5、上传jar文件到nexus存放

5.1 项目打包到nexus

首先需要在maven的setting.xml中配置上传使用的账号和密码

	<server>
		<id>emp-release</id>
		<username>admin</username>
		<password>admin123</password>
	</server>
	<server>
		<id>emp-snapshot</id>
		<username>admin</username>
		<password>admin123</password>
	</server>

在项目的pom.xml中配置打包上传的地址

    <distributionManagement>
        <repository>
            <id>emp-release</id>
            <name>emp-vaadin-component-release</name>
            <url>http://ip:port/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>emp-snapshot</id>
            <name>emp-vaadin-component-snapshot</name>
            <url>http://ip:port/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

pom文件和setting文件的id相对应

使用maven的deploy命令可以将打包好的jar文件上传到nexus仓库中,上传时会根据项目名后缀判断上传到具体的仓库

maven-snapshots快照仓库只接受项目版本后缀带有-SNAPSHOT的jar包,其他的包都会上传到maven-releases发行版仓库
mvn deploy

5.2 第三方包安装到nexus

#mvn deploy:deploy-file -DgroupId=包名 -DartifactId=文件名 -Dversion=版本 -Dpackaging=文件类型 -Dfile=文件路径 -Durl=仓库地址 -DrepositoryId=权限用户对应setting文件的server

mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=8 -Dpackaging=jar -Dfile=D:/ojdbc8-8.jar -Durl=http://ip:port/repository/3rdMaven/ -DrepositoryId=emp-release

6、下载jar包,配置私服地址

在setting文件中配置镜像地址,配置在第一个。maven镜像地址的优先级(maven目录中config/setting.xml>.m2/setting.xml>pom.xml)

私服从代理仓库拉去到jar包会保存在私服中,再下载到本地maven库

    <mirror>
      <id>nexusMaven</id>
      <name>nexus maven</name>
      <url>http://ip:port/repository/maven-public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>

7、nexus备份

备份将数据目录./sonatype-work 整个目录拷贝,恢复的时候在安装目录./nexus-3.26.1-02/bin/nexus.vmoptions文件中指定数据目录到备份文件,就恢复完成了。blob存放路径如果在./sonatype-work 中的话备份起来会比较大。

8、over,介绍完毕

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值