您的位置:首页 > 运维架构 > Linux

Linux下搭建maven 私服

2016-02-20 22:00 441 查看
最近研究了一下,mven的私服搭建以及,eclipse开发配置,在这里写一下,免得以后还得到处百度,也供大家学习吧

一般公司都会搭建自己的maven私服,同意管理jar文件

环境 

centos6.6  

nexus-2.12.0-01

java 1.7.0_79

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


点击红色箭头的地方进行下载,点击以后会弹出个框 如下图



这个弹出框会自动关闭,我这边自动关闭以后,无法下载如下图



我这里就是这样,但是浏览器的地址栏 会有下载链接,大家可以把连接复制一下,放到迅雷下载就行

为了方便大家我把下载地址贴出来
https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-latest-bundle.tar.gz
我会把资源放到百度云盘供大家下载

资源下载地址

有疑问的直接加我 QQ 695438455,不经常登录博客

下载完以后,就是安装和启动

我把nexus文件放到了 /usr 下面解压的,里面会有两个文件,nexus-2.12.0-01和sonatype-work

为了防止 没有权限的问题,我直接把这两个文件的权限改为 777了

chmod -R 777 nexus-2.12.0-01

chmod -R 777 sonatype-work

nexus-2.12.0-01:启动文件和配置文件

sonatype-work:nexus的日志什么的都在这个里面

解压完以后,我们进入到下面的目录

/usr/nexus-2.12.0-01/bin

下面有三个文件

lsw    nexus    nexus.bat

输入 ./nexus start 就启动了

会出现以下提示

Starting Nexus OSS...

Started Nexus OSS.

接下来访问一下看看是否启动成功,默认端口是8081
http://localhost:8081/nexus或者http://127.0.0.1:8081/nexus

[b]如果看到下面的页面那么恭喜你,安装成功了,在这里需要注意一下,启动的时候会出一个错误,需要指定启动用户

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

自己把 这个目录 /usr/nexus-2.12.0-01/bin 下的 nexus 修改一下就可以了,修改root或者其他,然后重启启动
[/b]



看到这个页面以后,右上角有个 log in 需要登录,点击然后输入用户名和密码登录即可 

用户名:admin 密码admin123

设置开机启动

以centos为例:

cp /opt/nexus-2.12.0-01/bin/nexus /etc/init.d/

打开/etc/init.d/nexus 修改

# Set this to the root of the Nexus installation

NEXUS_HOME="/opt/nexus-2.12.0-01"

chkconfig nexus on   即可

注意配置防火墙规则:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT
添加完重启防火墙,这样其他机器才可以访问

配置nexus

我们下载的是一个空的库,所以需要我们配置一下,从中央库下载下来

点击左边views/repository菜单下面的Repositories,如下图



找到右边仓库列表中的三个仓库Apache Snapshots,Codehaus Snapshots和Maven Central,然后再没有仓库的configuration下把Download Remote Indexes修改为true。然后在这三个仓库上分别右键,选择Repari Index,这样Nexus就会去下载远程的索引文件,可能有点慢。
等到如下图就说明下载完了



关于仓库的类型介绍  

  hosted 类型的仓库,内部项目的发布仓库

  releases 内部的模块中release模块的发布仓库

  snapshots 发布内部的SNAPSHOT模块的仓库

  3rd party 第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去

  proxy 类型的仓库,从远程中央仓库中寻找数据的仓库

  group 类型的仓库,组仓库用来方便我们开发人员进行设置的仓库

执行完以上内容,以后,
但是需要将其他几个代理的库配置映射到Public中,选中public 我这个已经移动完毕了,默认的是 在右边 avaliable reposi...是有几个的,把右边的

挪到左边,然后 点击 save就行了,然后再 public 鼠标右键 选择Repari Index,同样出现
browse index下面有内容就说明成功了




到此安装就差不多了,接下来说一下项目中的应用

首先修改,settings.xml,可以直接把我的复制过去,然后把我打"0.0.0.0"的地方修改为你自己的访问地址,局域网就是ip地址,本地就是localhost和127.0.0.1

<?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"> <pluginGroups></pluginGroups>
<proxies></proxies>
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>

<mirrors>
<mirror>
<id>nexus-releases</id>
<mirrorOf>*</mirrorOf>
<url>http://0.0.0.0:8081/content/groups/public</url>
</mirror>
<mirror>
<id>nexus-snapshots</id>
<mirrorOf>*</mirrorOf>
<url>http://0.0.0.0:8081/content/groups/public</url>
</mirror>
</mirrors>

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

</settings>
<localRepository> 这个地方是 我们从私服下载的jar文件的存放地址
这个文件修改完以后,就可以给其他开发人员共用了,保证统一管理jar文件

暂时就配置这些了,当然还有其他功能,比如发布什么的就先不说了

剩下的就是 eclipse的配置了,留在下一篇文章吧

关于仓库的类型介绍  

  hosted 类型的仓库,内部项目的发布仓库

  releases 内部的模块中release模块的发布仓库

  snapshots 发布内部的SNAPSHOT模块的仓库

  3rd party 第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去

  proxy 类型的仓库,从远程中央仓库中寻找数据的仓库

  group 类型的仓库,组仓库用来方便我们开发人员进行设置的仓库
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  maven 私服 nexus