【Nexus笔记】安装配置

1.下载解压

wget http://download.sonatype.com/nexus/3/nexus-3.21.1-01-unix.tar.gz
tar -zxf nexus-3.21.1-01-unix.tar.gz 

2.配置

2.1端口及上下文路径

vim nexus/nexus-3.21.1-01/etc/ nexus-default.properties

application-port=8081
application-host=192.168.1.129
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
nexus-context-path=/nexus

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

 2.2使用root运行

vim nexus/nexus-3.21.1-01/bin/nexus.rc

run_as_user=root #使用root运行

2.3JVM参数

vim nexus/nexus-3.21.1-01/bin/nexus.vmoptions

-Xms256m
-Xmx1024m
-XX:MaxDirectMemorySize=2703m
-XX:+UnlockDiagnosticVMOptions
-XX:+LogVMOutput
-XX:LogFile=../sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=../sonatype-work/nexus3
-Dkaraf.log=../sonatype-work/nexus3/log
-Djava.io.tmpdir=../sonatype-work/nexus3/tmp
-Dkaraf.startLocalConsole=false
#
# additional vmoptions needed for Java9+
#
# --add-reads=java.xml=java.logging
# --add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=../sonatype-work/nexus3
-Dkaraf.log=../sonatype-work/nexus3/log
-Djava.io.tmpdir=../sonatype-work/nexus3/tmp
-Dkaraf.startLocalConsole=false
#
# additional vmoptions needed for Java9+
#
# --add-reads=java.xml=java.logging
# --add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED
# --patch-module=java.base=lib/endorsed/org.apache.karaf.specs.locator-4.2.6.jar
# --patch-module=java.xml=lib/endorsed/org.apache.karaf.specs.java.xml-4.2.6.jar
# --add-opens=java.base/java.security=ALL-UNNAMED
# --add-opens=java.base/java.net=ALL-UNNAMED
# --add-opens=java.base/java.lang=ALL-UNNAMED
# --add-opens=java.base/java.util=ALL-UNNAMED
# --add-opens=java.naming/javax.naming.spi=ALL-UNNAMED
# --add-opens=java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED
# --add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED
# --add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED
# --add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED
# --add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED
# --add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED
#
# comment out this vmoption when using Java9+
#

2.4修改环境变量

vim /etc/profile

export NEXUS_HOME=/alidata/server/nexus/nexus-3.21.1-01

export PATH=$PATH:$NEXUS_HOME/bin

source /etc/profile

2.5设置开机自启动 

ln -s /alidata/server/nexus/nexus-3.21.1-01/bin/nexus /etc/init.d/nexus3 
chkconfig --add nexus3 
chkconfig nexus3 on 

2.6修改 nexus3 启动时要使用的 jdk 版本

vim /alidata/server/nexus/nexus-3.21.1-01/bin

第 14 行: 
INSTALL4J_JAVA_HOME_OVERRIDE=/alidata/server/jdk1.8.0_152

2.7修改 nexus3 数据以及相关日志的存储位置 (可选):

vim nexus/nexus-3.21.1-01/bin/nexus.vmoptions

-XX:LogFile=./sonatype-work/nexus3/log/jvm.log 
-Dkaraf.data=./sonatype-work/nexus3 
-Djava.io.tmpdir=./sonatype-work/nexus3/tmp 

2.8启动

bin/nexus start

2.9服务器开放Nexus私服端口

(1)firewall-cmd --zone=public --add-port=8081/tcp --permanent

(2)阿里云服务器安全组配置

3.nginx代理nexus

server {
    listen 80;
    server_name 域名;

    location /nexus {
        proxy_pass http://127.0.0.1:8081;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size 300M;
    }
}
# 重启nginx
./nginx -s reload

4.配置仓库

安装成功后有两个默认账号admin、anonymous,其中admin具有全部权限;anonymous作为匿名用户,只具有查看权限。

pepositories name属性说明

  • maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar
  • maven-releases:私库发行版jar
  • maven-snapshots:私库快照(调试版本)jar
  • maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml中使用。

pepositories type属性说明

  • group(仓库组类型):又叫组仓库,用于方便开发人员自己设定的仓库
  • hosted(宿主类型):内部项目的发布仓库(内部开发人员,发布上去存放的仓库)
  • proxy(代理类型):从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage Location属性的值即被代理的远程仓库的路径)
  • virtual(虚拟类型):虚拟仓库(这个基本用不到,重点关注上面三个仓库的使用)

一般,访问我们使用maven-public
http://域名/nexus/repository/maven-public/

由于访问中央仓库有时候会比较慢,这里我添加一个阿里云的代理仓库,然后优先级放到默认中央库之前, 阿里云的maven仓库url为http://maven.aliyun.com/nexus/content/groups/public

然后再public组里面讲这个aliyun-proxy仓库加入,排在maven-central之前即可。 

创建Blob Stores

文件存储的地方,创建一个目录的话,对应文件系统的一个目录,可供仓库上传文件使用,如图所示:

 

5. 本地Maven使用私服

在maven的默认配置settings.xml中修改如下:

<servers>
	<server>
        <id>nexus</id>
        <username>admin</username>
        <password>123456</password>
    </server>
</servers>

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

<profiles>
    <profile>  
      <id>nexus</id>
      <repositories>
        <repository>
          <id>Nexus</id>
          <url>http://域名/nexus/repository/maven-public/</url>
          <releases>
            <enabled>true</enabled>
			<updatePolicy>always</updatePolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
      <activation>
        <activeByDefault>true</activeByDefault>      
        <jdk>1.8</jdk>
      </activation>
      <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
      </properties>
    </profile>
</profiles>

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

6.修改工程的pom.xml

如果要发布自己的jar到私服,就需要修改工程的pom.xml,添加如下内容,否则什么都不用做:

<distributionManagement>
    <repository>
        <id>nexus</id>
        <name>Releases</name>
        <url>http://域名/nexus/repository/maven-releases</url>
    </repository>
    <snapshotRepository>
        <id>nexus</id>
        <name>Snapshot</name>
        <url>http://域名/nexus/repository/maven-snapshots</url>
    </snapshotRepository>
</distributionManagement>

注意:上面的repository的id值一定要跟settings.xml文件中配置的server一致。上传到Nexus上,使用 mvn deploy 即可,开发的时候请使用snapshot版本,也就是version的后缀必须是-SNAPSHOT

引用:

1.阿里云 ECS服务器(CentOS 7)安装和使用Nexus教程

2.maven私服nexus3.x环境配置

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值