nexus在linux上搭建

摘要:
Maven仓库的分类:1.本地仓库2.远程仓库。在远程仓库中,有三种类型:2.1中央仓库2.2专用服务器2.3其他公共库有一个Maven专用服务器,可以轻松管理jar包并将其发布到远程仓库。本文介绍如何在Linux中使用nexus逐步构建Maven私有服务器。首先,安装jdk和maven。此处安装的JDK和maven版本如下:[html]viewplaincopy[root@localhostbin]#java版本javaversion“1.7.0_79”JavaSERuntimeEnvironmentJavaHotSpot64 BitServerVM[root@localhostbin]#mvn-vApacheMaven3.3.9 Mavenhome:/home/data/mavenJavaversion:1.7.0_79,供应商:OracleCorporationJavahome:/home/cuan/soft/jdk1.7.0_79/jreDefaultlocale:en_US,平台编码:UTF-8OSname:“linux”,版本:“3.10.0-327.el7.x86_64”,arch:“amd64”,系列:“unix”附于此处,环境配置:[html]viewplaincopy#javaexportJAVA_HOME=/HOME/data/javaexportPATH=$JAVA_HOME/bin:$PATHexportCLASSPATH=.:$JAVA_ HOME/lib/dt。jar:$JAVA_HOME/lib/tools。jar#mavenexportMAVEN_HOME=/HOME/data/mavenexportMAFEN_HOMEexportPATH=${PATH}:${MAVEN_HHOME}/bin#nextxportRUN_AS_USER=root下载安装nexus下载地址:http://www.sonatype.org/nexus/go解压缩后,对等目录中将出现两个文件夹:nexus-oss-webapp-1.8.0和sonatype work。前者包含nexus的运行环境和应用程序,后者包含您自己的配置和数据。

Maven 仓库的分类:(maven的仓库只有两大类)

1.本地仓库 

2.远程仓库,在远程仓库中又分成了3种:

2.1 中央仓库 

2.2 私服 

2.3 其它公共库

有个maven私服可以很方便地管理我们的jar包和发布构建到远程仓库,本文就介绍了如何在linux下一步步使用nexus搭建maven私服。

私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。

nexus在linux上搭建第1张 nexus在linux上搭建第2张

 

首先安装好jdk 、maven

我这里安装的JDK 、maven版本信息如下:

 

[html] view plain copy
  1. [root@localhost bin]# java -version  
  2. java version "1.7.0_79"  
  3. Java(TM) SE Runtime Environment (build 1.7.0_79-b15)  
  4. Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)  
  5. [root@localhost bin]# mvn -v  
  6. Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T08:41:47-08:00)  
  7. Maven home: /home/data/maven  
  8. Java version: 1.7.0_79, vendor: Oracle Corporation  
  9. Java home: /home/xuan/soft/jdk1.7.0_79/jre  
  10. Default locale: en_US, platform encoding: UTF-8  
  11. OS name: "linux", version: "3.10.0-327.el7.x86_64", arch: "amd64", family: "unix"  

这里附上,环境配置:

 

[html] view plain copy
  1. #java  
  2. export JAVA_HOME=/home/data/java  
  3. export PATH=$JAVA_HOME/bin:$PATH  
  4. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar  
  5.   
  6. #maven  
  7. export MAVEN_HOME=/home/data/maven  
  8. export MAVEN_HOME  
  9. export PATH=${PATH}:${MAVEN_HOME}/bin  
  10.   
  11. #nexus  
  12. export RUN_AS_USER=root  



 


下载安装


nexus下载地址:http://www.sonatype.org/nexus/go

解压后会在同级目录中,出现两个文件夹:nexus-oss-webapp-1.8.0和sonatype-work,前者包含了nexus的运行环境和应用程序,后者包含了你自己的配置和数据。

 

nexus-2.12.0-01-bundle.tar.gz

 

[html] view plain copy
  1. tar -zxvf nexus-2.12.1-01-bundle.tar.gz -C /home/xuan/soft/nexus  
  2. [root@localhost soft]# tar -zxvf nexus-2.12.1-01-bundle.tar.gz  
  3. nexus-2.12.1-01/  
  4. nexus-2.12.1-01/nexus/  


为了方便更新和切换版本,创建链接,更新或者切换版本只需更新链接即可:

 

 

[html] view plain copy
  1. tar -zxvf nexus-2.12.1-01-bundle.tar.gz -C /home/xuan/soft/nexus  
  2.   
  3.   
  4. [root@localhost nexus]# pwd  
  5. /home/xuan/soft/nexus  
  6. [root@localhost nexus]# ls  
  7. nexus-2.12.1-01  sonatype-work  
  8. [root@localhost nexus]#   
  9.   
  10. ln -s /home/xuan/soft/nexus /home/data/nexus  



 

 

启动nexus

 

[html] view plain copy
  1. [root@localhost bin]# pwd  
  2. /home/data/nexus/nexus-2.12.1-01/bin  
  3. [root@localhost bin]# ./nexus  
  4. Usage: ./nexus { console | start | stop | restart | status | dump }  


[html] view plain copy
  1. $ ./nexus start  
  2. Starting Nexus OSS...  
  3. Started Nexus OSS.  


启动成功:

 

nexus在linux上搭建第3张

查看控制台:

 

[html] view plain copy
  1. [root@localhost bin]# ./nexus console  
  2. ****************************************  
  3. WARNING - NOT RECOMMENDED TO RUN AS ROOT  
  4. ****************************************  
  5. Running Nexus OSS...  
  6. Nexus OSS is already running.  

 



查看nexus日志:

[html] view plain copy
  1. [root@localhost logs]# pwd  
  2. /home/data/nexus/nexus-2.12.1-01/logs  
  3. [root@localhost logs]# tail -f ./wrapper.log  
  4. jvm 1    | 2016-05-20 06:50:10,655-0700 INFO  [qtp1294005448-58] anonymous org.apache.http.impl.execchain.RetryExec - I/O exception (java.net.SocketException) caught when processing request to {s}->https://sonatype-download.global.ssl.fastly.net:443: Connection reset  



配置nexus


访问网址:http://yourhostname:8081/nexus

访问网址:http://192.168.140.128:8081/nexus

右上角以admin登陆,默认用户名/密码:admin/admin123。

nexus在linux上搭建第4张

 

安装过程中可能遇到的错误:

1、进入启动目录,启动时不成功  提示

****************************************
WARNING – NOT RECOMMENDED TO RUN AS ROOT
****************************************
If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.


大概意思就是要在环境配置export RUN_AS_USER=root,临时配置

也可以在vi /etc/profile 文件末尾里添加export RUN_AS_USER=root  永久配置


2、访问不了虚拟机的,需要关闭防火墙
centos从7开始默认用的是firewalld,这个是基于iptables的,虽然有iptables的核心,但是iptables的服务是没安装的。

所以你只要停止firewalld服务即可:
sudo systemctl stop firewalld.service && sudo systemctl disable firewalld.service


如果你要改用iptables的话,需要安装iptables服务:
sudo yum install iptables-services
sudo systemctl enable iptables && sudo systemctl enable ip6tables
sudo systemctl start iptables && sudo systemctl start ip6tables

 

下一步进行Maven 与私服的测试:

~/.m2/settings.xml

在maven的setting.xml文件增加使用nexus私服配置:

maven 私服地址 http://192.168.1.102:8081/nexus/content/groups/public/

maven 中央仓库地址:http://repo1.maven.org/maven2  (没有私服镜像可以中央仓库的)

 

[html] view plain copy
  1. <settings>  
  2.   <mirrors>   
  3.   
  4.     <mirror>  
  5.       <!--This sends everything else to /public -->  
  6.       <id>nexus</id>  
  7.       <mirrorOf>*</mirrorOf>  
  8.       <url>http://192.168.1.102:8081/nexus/content/groups/public/</url>  
  9.     </mirror>  
  10.   </mirrors>  
  11.   <profiles>   
  12.   
  13.     <profile>  
  14.       <id>nexus</id>  
  15.       <!--Enable snapshots for the built in central repo to direct -->  
  16.       <!--all requests to nexus via the mirror -->  
  17.       <repositories>  
  18.         <repository>  
  19.           <id>central</id>  
  20.           <url>http://central</url>  
  21.           <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>  
  22.           <snapshots><enabled>true</enabled></snapshots>  
  23.         </repository>  
  24.         <repository>  
  25.             <id>spring-release</id>  
  26.             <name>Spring Maven Release Repository</name>  
  27.             <url>http://repo.springsource.org/libs-release</url>  
  28.             <snapshots>  
  29.                 <enabled>false</enabled>  
  30.             </snapshots>  
  31.         </repository>  
  32.       </repositories>  
  33.      <pluginRepositories>  
  34.         <pluginRepository>  
  35.           <id>central</id>  
  36.           <url>http://central</url>  
  37.           <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>  
  38.           <snapshots><enabled>true</enabled></snapshots>  
  39.         </pluginRepository>  
  40.       </pluginRepositories>  
  41.     </profile>  
  42.   </profiles>  
  43.   <activeProfiles>  
  44.     <!--make the profile active all the time -->  
  45.     <activeProfile>nexus</activeProfile>  
  46.   </activeProfiles>  
  47.   
  48.   <!-- deploy artifacts to repository. -->  
  49.   <servers>  
  50.     <server>  
  51.       <id>releases</id>  
  52.       <username>admin</username>  
  53.       <password>admin123</password>  
  54.     </server>  
  55.     <server>  
  56.       <id>snapshots</id>  
  57.       <username>admin</username>  
  58.       <password>admin123</password>  
  59.     </server>  
  60.   </servers>  
  61.   
  62. </settings>  


测试效果图:

 

1、在项目的pom.xml文件  加入maven依赖测试

nexus在linux上搭建第5张

2、私服上的依赖

nexus在linux上搭建第6张

3、项目本地的依赖

nexus在linux上搭建第7张

 

参考文档:

http://tianweili.github.io/blog/2015/03/17/linux-nexus-maven-private-server/

maven 使用私服的参考文档:

http://blog.csdn.net/liujiahan629629/article/details/39272321

本地上传依赖到nexus服务器的两种方式:

1、通过网页上传
2、通过maven的方式depoly

在项目的pom.xml 加入如下配置 (这里不做详细介绍,可以参考上面的资料)

 

[html] view plain copy
  1. <distributionManagement>  
  2.   <repository>  
  3.       <id>releases</id>  
  4.       <name>Nexus Release Repository</name>  
  5.       <url>http://192.168.1.102:8081/nexus/content/repositories/releases/</url>  
  6.   </repository>  
  7.   <snapshotRepository>  
  8.       <id>snapshots</id>  
  9.       <name>Nexus Snapshot Repository</name>  
  10.       <url>http://192.168.1.102:8081/nexus/content/repositories/snapshots/</url>  
  11.   </snapshotRepository>  
  12. </distributionManagement>  


 

运行命令:mvn package deploy 它会根据项目的pom.xml文件的配置如下  在私服生成些war包 (暂不知道在那些场景应用)

<groupId>com.xuan</groupId>

<artifactId>spring</artifactId>

<packaging>war</packaging>

<version>0.0.1-SNAPSHOT</version>

<name>springmvc_hibernate</name>

在私服生成 

/com/xuan/spring/xxxxx.pom

/com/xuan/springxxxxx.war


免责声明:文章转载自《nexus在linux上搭建》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇微慕WordPress小程序专业版v2.0【Jenkins+Ansible+Gitlab 自动化部署三剑客】学习笔记-第五章 5-1~5-5 Freestyle Job实战下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

linux系统上nginx配置按天生成日志文件

nginx日志默认把日志都写到一个文件中,这样不方便管理,而且文件容量会越来越大,所以为了方便管理分析日志把日志按天切割,即每天生成一个新的日志文件。 实现步骤 1. 找到nginx日志文件 我的文件在/usr/local/nginx/logs这个路径下,有个access.log文件就是nginx的日志文件 2. 进入该路径创建个sh文件(称为批处理日志...

dmalloc arm-linux平台使用

话说“工欲善其事,必先得其器”,用C语言写程序,最怕遇到个什么内存泄漏,内存越界访问了,心里那个急啊。。。 如果在i368-linlux上,valgrind工具是首选,但在arm-linux平台上,如何呢,dmalloc就是一个不错的选择。当然,IBM的purify是另外一个级别的选手,不提也罢。 1. 到官方网站下载dmalloc: www.dmallo...

Linux网络编程 select/epoll得知socket有数据可读,如何判断数据全部被读取完毕?

补充一点:只有在使用epoll ET(Edge Trigger)模式的时候,才需要关注数据是否读取完毕了。使用select或者epoll的LT模式,其实根本不用关注数据是否读完了,select/epoll检测到有数据可读去读就OK了。 这里有两种做法: 1. 针对TCP,调用recv方法,根据recv方法的返回值,如果返回值小于我们指定的recv buf...

PostgreSQL:在Linux系统上面安装PostgreSQL数据库

一、准备工作 这里使用的Linux操作系统是Centos7,选择在虚拟机上面装Centos7系统,然后在虚拟机上面安装PostgreSQL。 二、安装PostgreSQL 2.1、选择版本 进入PostgreSQL官网下载界面,找到Centos相关下载信息。官网下载地址:https://www.postgresql.org/download/linux/r...

Linux中最大进程数和最大文件数

前言 Linux系统中可以设置关于资源的使用限制,比如:进程数量,文件句柄数,连接数等等。在日常的工作中应该遇到过: -bash: fork: retry: Resource temporarily unavailable 或者 too many open files 这些类似的操作错误,前者是由于当前用户的进程数超出限制,后者由于当前用户的文件打开数超出...

ubuntu和centos操作命令对比

ubuntu和centos操作命令对比 1,安装软件,比如安装jdk CentOS : rpm -i jdk-XXX_linux-x64_bin.rpm 进行安装, Ubuntu : dpkg -i jdk-XXX_linux-x64_bin.deb 进行安装。 其中 -i 就是 install 的意思。 2,管理软件 查询已安装的软件 rpm -qa...