Centos7下nexus3私有maven仓库的安装、配置和使用

1、安装jdk1.8
# rpm -ivh jdk-8u172-linux-x64.rpm
# vi /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/jdk1.8.0_172-amd64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

# source /etc/profile
# java -version

2、安装maven
# wget http://mirrors.shu.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
# tar -zxvf apache-maven-3.5.4-bin.tar.gz -C /home/centyun/
# cd /home/centyun/
# mv apache-maven-3.5.4/ maven
# vi /etc/profile.d/maven.sh
export MAVEN_HOME=/home/centyun/maven
export PATH=$MAVEN_HOME/bin:$PATH

3、安装nexus
# mkdir /home/centyun/nexus
# wget https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.13.0-01-unix.tar.gz
# tar -zxvf nexus-3.13.0-01-unix.tar.gz -C /home/centyun/nexus/
# cd /home/centyun/nexus/
在该目录下有两个目录,nexus-3.13.0-01 nexus程序目录,sonatype-work 数据目录
# cd nexus-3.13.0-01/
这个目录的 etc/nexus-default.properties 的默认端口8081,但是如果需要改端口不建议修改这个文件。
# cd /home/centyun/nexus/nexus-3.13.0-01/bin/
这个目录下 nexus.vmoptions 指定了log目录和data目录
./nexus start     可以启动nexus
如果需要修改启动nexus的jdk, vi nexus, 修改 INSTALL4J_JAVA_HOME_OVERRIDE=/home/centyun/jdk1.8.0_172
# ./nexus status  查看启动状态
# ./nexus stop    停止
如果需要nexus的端口, 修改 /home/centyun/nexus/sonatype-work/nexus3/etc/nexus.properties 的 application-port=8081

4、开放防火墙端口
systemctl status firewalld   查看防火墙状态
firewall-cmd --zone=public --list-ports    查看端口开放情况
firewall-cmd --zone=public --add-port=8081/tcp --permanent
firewall-cmd --reload      刷新防火墙设置
firewall-cmd --zone=public --list-ports

5、nexus配置管理
5.1 配置阿里代理仓库
Configuration > Repository > Repositories ,选择 Create repository 按钮,Select Recipe 选择 maven2(proxy),
Name 填写 aliyun, URL输入 http://maven.aliyun.com/nexus/content/groups/public/  其他值默认。
Configuration > Repository, 双击 maven-public, 在Group区域将aliyun移到右侧Members, 上移到maven-central的上面, 点击 Save

5.2 管理maven仓库中没有的jar
通过 Upload > maven-releases 上传jar,再填写其他参数,即可管理maven中心仓库中不存在的jar依赖


5.3 其他配置
访问 http://192.168.100.181:8081/
登录的默认密码 admin / admin123
页面左上角提示 System Requirement: max file descriptors [4096] likely too low, increase to at least [65536]. 解决办法
vi /etc/security/limits.conf
*  soft  nofile  65536
*  hard  nofile  131072
*  soft  nproc   2048
*  hard  nproc   4096
vi /etc/sysctl.conf
fs.file-max=65535
sysctl -p生效,设置后用 ulimit -a 可以看到open files为65535,如果显示不是65535 则可能需要 reboot
然后重启 nexus

6、使用nexus私有仓库
6.1 maven环境中使用
将maven/conf/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">
    <mirrors>
        <mirror>
            <id>nexus</id>
            <mirrorOf>*</mirrorOf>
            <url>http://192.168.100.181:8081/repository/maven-public/</url>
        </mirror>
    </mirrors>
    <servers>
        <server>
            <id>nexus</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>
</settings>

6.2 eclipse中使用
将6.1中的settings.xml文件配置到eclipse的Window > Preferences > Maven > User Settings 的 User Settings 输入框里选择上一步下载的 settings.xml,然后点击 Update Settings 按钮
然后创建Maven项目,nexus私有仓库就会有内容,可以通过nexus页面的Browse > maven-public中搜索到相应的maven资源
如果需要将项目发布到nexus中,则maven项目的pom.xml文件中加入类似下面的内容,运行 maven deploy 即可将项目发布到nexus仓库
<distributionManagement>
    <repository>
        <id>nexus</id>
        <name>Nexus Release Repository</name>
        <url>http://192.168.100.181:8081/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>nexus</id>
        <name>Nexus Snapshot Repository</name>
        <url>http://192.168.100.181:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

本文内容到此结束,更多内容可关注公众号

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值