Nexus 安装运维手册

1. Nexus 安装与配置

1.1 下载Nexus

  登录https://www.sonatype.com/download-oss-sonatype,下载最新的Nexus版本。 我这里使用的是nexus-3.16.1-02版本;

1.2 安装Nexus

#将tar包上传到服务器/usr/local/目录下解压,这个时候会出现 nexus-3.16.1-02、sonatype-work 两个文件夹

tar -zxvf nexus-3.16.1-02-unix.tar.gz  

#修改配置文件,eg:端口号

cd /usr/local/nexus-3.16.1-02/etc

vim nexus-default.properties

1.3 启动Nexus

  启动用户是root的时候会出现下面的警告,可以通过修改/usr/local/nexus-3.16.1-02/bin/nexus.rc文件解决;

       

#修改启动用户run_as_user,建议不要使用root

vim /usr/local/nexus-3.16.1-02/bin/nexus.rc

#
cd /usr/local/nexus-3.16.1-02/bin

./nexus start --后台启动

./nexus run --前台启动,显示日志

1.4 登录Nexus

  服务启动完以后,输入Ip地址+端口访问(8081),Nexus默认的账户名和密码是是 admin/admin123

 

1.5 配置私有库

  将私有库添加到http://192.168.209.128:8081/repository/maven-public/中。

 

1.6 导入jar包

  一般私服都是存在内网环境,Nexus3.0以后需要通过命令命令将具体的jar包打到私服中;

#将下面的脚本丢到需要上传jar包的文件目录下
chmod u+x mavenimport.sh
./mavenimport.sh -u admin -p admin123 -r http://192.168.209.128:8081/repository/lingan/

 

#!/bin/bash
# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is important
# Get command line params

while getopts ":r:u:p:" opt; do
	case $opt in
		r) REPO_URL="$OPTARG"
		;;
		u) USERNAME="$OPTARG"
		;;
		p) PASSWORD="$OPTARG"
		;;
	esac
done

find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' 
-not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;

1.7 设置登录用户权限

  建议将admin注销,重新定义一个登录用户。在Nexus 3.0 这个版本中我直接删除admin会报错,但是设置为不可用没有问题;

 

2. Maven 安装与配置

2.1 下载Maven

      登录http://maven.apache.org 下载最新的maven版本,我这里使用的是apache-maven-3.6.1版本。

2.2 安装Maven

将tar包上传到服务器/usr/local/目录下解压
tar -zxvf apache-maven-3.6.1-bin.tar.gz 

2.3 配置Maven

#配置release、snapshot的用户信息;
#配置mirror指向私服的nexus-public;
vim /usr/local/maven/apache-maven-3.6.1/conf/setting.xml

 

3. 工作空间配置

3.1 修改本地Maven配置

  配置release、snapshot的用户信息;

  配置mirror指向私服的nexus-public;

3.2 修改工程中的pom文件

<repositories>

    <repository>

        <id>nexus-public</id>

        <url>http://192.168.11.23:8180/repository/maven-public/</url>

        <snapshots>

            <enabled>true</enabled>

        </snapshots>

    </repository>

</repositories>

<distributionManagement>

    <repository>

        <id>release</id>

        <url>http://192.168.11.23:8180/repository/maven-releases/</url>

    </repository>

    <snapshotRepository>

        <id>snapshot</id>

        <url>http://192.168.11.23:8180/repository/maven-snapshots/</url>

    </snapshotRepository>

</distributionManagement>

 

<build>

    <plugins>

        <plugin>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-compiler-plugin</artifactId>

            <version>3.8.0</version>

            <configuration>

                <source>1.7</source>

                <target>1.7</target>

                <encoding>UTF-8</encoding>

            </configuration>

        </plugin>

 

        <plugin>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-war-plugin</artifactId>

            <version>3.2.2</version>

        </plugin>

    </plugins>

</build>

  

 

转载于:https://www.cnblogs.com/jiangyaxiong1990/p/10813110.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值