docker快速搭建私有仓库nexus

10 篇文章 0 订阅
4 篇文章 0 订阅

1、创建数据存储路径并授权 

mkdir /home/nexus-data && chown -R 200 /home/nexus-data

2、直接运行docker命令

docker run -d -p 8889:8081 --restart=always  --name nexus -v /home/nexus-data:/nexus-data
 -v /etc/localtime:/etc/localtime sonatype/nexus3

3、nginx域名解析,用域名去访问nexus

server {
	listen 80;
	server_name nexus.zymreal.com;
	access_log /usr/local/nginx/logs/nginx.log combined;
	index index.html index.htm index.php;
	root /opt/nginx/html;
		
	location / {
		proxy_buffering 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;
		proxy_pass http://localhost:8889/;
		client_max_body_size    1000m;  
	}

}

4、登陆nexus.zymreal.com 或者 <ip>:8889/    帐号:admin 密码:admin123

登录后建立nexus-releases(host仓)nexus-snapshots(host仓)nexus-central(Proxy仓)nexus-public(group仓)

nexus-central,代理阿里云中央仓库

http://maven.aliyun.com/nexus/content/groups/public/   

nexus-public ,组合nexus-releases(host仓)nexus-snapshots(host仓)nexus-central(Proxy仓)

5、修改nexus-releases仓库配置,允许直接通过命令推送jar包,如下图,将最下方策略改成 allow redeploy 

6、此时可以推送自己私有的jar包到私有仓库 

打开windows cmd命令 ,推送一个jar包,jar包地址在F盘

mvn deploy:deploy-file -DgroupId=com.stylefeng -DartifactId=guns-generator
 -Dversion=1.0.0 -Dpackaging=jar -Dfile=F:\nexus-pom\guns-generator-1.0.0.jar
 -Durl=http://nexus.zymreal.com/repository/nexus-releases/  -DrepositoryId=nexus

参数解释:

DgroupId、DartifactId、Dversion——表示的是构建的基本坐标,你需要根据你上次的jar包自行改变

Dpackaging——表示的是上传的包的类型,一般为jar,不用改变,根据你的实际情况来改变。

Dfile——表示的是你需要上传的包的地址

Durl——表示的是你要上传到的私有仓库的地址

DrepositoryId——表示你的身份信息。

推送成功后,在nexus页面下Browse  nexus-releases下就能看见刚刚推送的包了

7、最后,修改一下maven的配置文件,引入私有仓库

<?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">


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

  <mirrors>

     <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://nexus.zymreal.com/repository/nexus-public/</url>
    </mirror>

    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
    
    
    <mirror>
      <id>CN</id>
      <name>OSChina Central</name>
      <!--<url>http://maven.oschina.net/content/groups/public/</url>-->
      <url>https://repo1.maven.org/maven2/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>nexus</id>
          <url>http://nexus</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true></enabled></snapshots>
        </repository>
      </repositories>
      <pluginRepositories>    
		<pluginRepository>    
		  <id>nexus</id>    
          <url>http://nexus</url>  
          <releases><enabled>true</enabled></releases>    
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>    
      </pluginRepositories>    
    </profile>
  </profiles>
  
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

   <localRepository>G:\ruanjian\apache-maven-3.3.9\repository</localRepository>
  
</settings>

注意 <localRepository> 改成自己存放的仓库地址

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值