当前位置:   article > 正文

CentOS7搭建maven私服-nexus_centos7 sonatype nexus repository

centos7 sonatype nexus repository

1,下载nexus安装包

1)直接去官网下载,链接如下:

https://www.sonatype.com/products/nexus-repository?topnav=true

2)去百度网盘拉取(此处为nexus-3.19.1-01-unix.tar.gz):

链接: https://pan.baidu.com/s/1mUPM0u-LOJSs7xH2FByOQg 提取码: bw7p

2,nexus安装

1)创建nexus组以及用户,命令如下:

[root@localhost ~]# groupadd nexus
[root@localhost ~]# useradd -g nexus -d /home/nexus -m nexus

参数说明:

-c comment 指定一段注释性描述。
-d 目录 指定用户主目录,如果此目录不存在,则同时使用-m选项,可以创建主目录。
-g 用户组 指定用户所属的用户组。
-G 用户组,用户组 指定用户所属的附加组。
-s Shell文件 指定用户的登录Shell。
-u 用户号 指定用户的用户号,如果同时有-o选项,则可以重复使用其他用户的标识号。

2)切换到nexus用户,通过文件上传工具将nexus安装包上传到nexus用户目录,并解压,操作如下:

[root@localhost ~]# su - nexus

[nexus@localhost ~]$ ls
nexus-3.19.1-01-unix.tar.gz
[nexus@localhost ~]$ tar -zxvf nexus-3.19.1-01-unix.tar.gz 

3)配置修改

进入nexus配置目录,修改项目名和端口号,命令如下:

[nexus@localhost ~]$ cd /home/nexus/nexus-3.19.1-01/etc

[nexus@localhost etc]$ vim nexus-default.properties

  1. ## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
  2. ##
  3. # Jetty section
  4. #8081端口号
  5. application-port=8081
  6. application-host=0.0.0.0
  7. nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
  8. #nexus为项目名
  9. nexus-context-path=/nexus
  10. # Nexus section
  11. nexus-edition=nexus-pro-edition
  12. nexus-features=\
  13. nexus-pro-feature
  14. nexus.hazelcast.discovery.isEnabled=true

4)启动nexus并查看状态,命令如下:

[nexus@localhost nexus-3.19.1-01]$ cd /home/nexus/nexus-3.19.1-01
[nexus@localhost nexus-3.19.1-01]$ ./bin/nexus start
Starting nexus
[nexus@localhost nexus-3.19.1-01]$ ./bin/nexus status
nexus is running.

5)访问nexus

浏览器输入地址,如:http://172.30.20.56:8081/nexus/

说明:172.30.20.56为部署nexus服务器ip,8081位nexus启动端口。

注意:需要关闭防火墙或者开放8081访问端口

6)修改nexus登录密码

点击登录,用户名为admin,默认密码在指定文件里面,如图:

登录完成,按提示修改密码,如图:

3,基于nexus的maven私服搭建 

用admin账号登录,依次点击Server administration and configuration-->Repository-->Repositories,界面显示如下:

 1)创建代理proxy

代理用来指向远程仓库的,如中央仓库,阿里云仓库。这里新建一个代理仓库。点击Create Repository,步骤如下:

拉到页面底端,点击Create Repository按钮,创建代理仓库完成,如下图:

 2)创建宿主host

宿主仓库管理项目打出来的包,分为发布Release和快照Snapshot两种。

创建Snapshot仓库,步骤如下:

拉到页面底端,点击Create Repository按钮,创建Snapshot仓库完成,如下图:

创建Release仓库,步骤如下:

 拉到页面底端,点击Create Repository按钮,创建Release仓库完成,如下图:

3)创建仓库组

仓库组好比数据库的视图,可以把多个仓库聚合起来用。

注:把aliyun放在maven-central上面,这样才能优先找阿里云的构件 

仓库组创建,步骤如下:

创建结果如下:

 4)nexus3.19的默认用户有两种:admin(能配置仓库、查询和上传构件)和 anonymous(只能查构件),此处为了权限可控,创建开发角色与用户(查询和上传构件)。

创建开发角色,步骤如下:

拉到最后面点击Create role按钮,创建开发角色完成,如下图:

创建开发用户,步骤如下:

开发用户创建完成,如下图:

5)sttings文件配置

  1. <!--配置localRepository本地存储位置-->
  2. <localRepository>/Users/dev/m2/repository</localRepository>
  3. <!--配置servers-->
  4. <servers>
  5. <server>
  6. <id>nexus-snapshots</id>
  7. <username>dev</username>
  8. <password>dev@ab23</password>
  9. </server>
  10. <server>
  11. <id>nexus-releases</id>
  12. <username>dev</username>
  13. <password>dev@ab23</password>
  14. </server>
  15. </servers>
  16. <!--配置mirrors-->
  17. <mirrors>
  18. <mirror>
  19. <id>thirdparty</id>
  20. <mirrorOf>Authorized thirdparty resources by CMBC</mirrorOf>
  21. <name>thirdpartyMirror</name>
  22. <url>http://192.168.14.200:2510/nexus/repository/nexus-snapshots</url>
  23. </mirror>
  24. </mirrors>
  25. <!--配置profiles-->
  26. <profiles>
  27. <profile>
  28. <id>nexus</id>
  29. <repositories>
  30. <repository>
  31. <id>snapshots</id>
  32. <name>nexus snapshot repository</name>
  33. <url>http://192.168.14.200:2510/nexus/repository/nexus-snapshots</url>
  34. <releases>
  35. <enabled>true</enabled>
  36. </releases>
  37. <snapshots>
  38. <enabled>true</enabled>
  39. </snapshots>
  40. </repository>
  41. </repositories>
  42. </profile>
  43. </profiles>

6)pom.xml配置

  1. <distributionManagement>
  2. <snapshotRepository>
  3. <id>nexus-snapshots</id>
  4. <name>nexus snapshot repository</name>
  5. <url>http://192.168.14.200:2510/nexus/repository/nexus-snapshots</url>
  6. </snapshotRepository>
  7. </distributionManagement>

 至此,基于nexus的maven私服搭建完成。

感谢阅读,有什么问题,欢迎各位指正。 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/490743
推荐阅读
相关标签
  

闽ICP备14008679号