如何在centos上搭建自己maven仓库

来源:互联网 发布:java发牌器 编辑:程序博客网 时间:2024/05/01 21:05

转载:http://www.linuxidc.com/Linux/2016-11/136954.htm


注:Nexus依赖JDKnexus-2.11.*需要JDK1.7版本及以上

一。安装JDK

步骤:

第一步:下载 jdk-7u55-linux-i586.tar.gz (如果有网可以使用wget http://Oracle官网的下载地址)

第二步:上传压缩包到linux系统。

第三步:解压缩(将源文件压缩包解压至/usr/local下的jdk文件夹)。

[root@localhost zhoujianxu]# mkdir -p /usr/local/jdk

[root@localhost zhoujianxu]# tar -zxvf jdk-7u55-linux-i586.tar.gz -C /usr/local/jdk

CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服

......
jdk1.7.0_55/man/man1/javadoc.1
jdk1.7.0_55/man/man1/jar.1
[root@localhost zhoujianxu]#

使用java -version 查看是否安装成功!

[root@localhost zhoujianxu]# java -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) Client VM (build 24.55-b03, mixed mode)
[root@localhost zhoujianxu]#
CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服

第四步:配置环境变量(vi编辑器使用:按i进入编辑模式,修改完成后按ESC键进入命令模式输入:wq命令保存并退出:q!强制退出)。

[root@localhost zhoujianxu]# vi /etc/profile

修改/etc/profile,在文件中添加如下内容:

1
2
3
4
5
6
#set java environment
JAVA_HOME=/usr/local/jdk/jdk1.7.0_55
JRE_HOME=/usr/local/jdk/jdk1.7.0_55/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH

 如下图
CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服

第五步:source /etc/profile或者重启。

[root@localhost zhoujianxu]# source /etc/profile

—————————————————————————————————————————————————

二。安装Nexus步骤:

第一步:Nexus官网下载地址:http://www.sonatype.org/nexus/go/

使用wget命令下载 wget 想要下载nexus版本的地址

[root@localhost nexus]# wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.2-03-bundle.tar.gz

[root@localhost nexus]# ls
nexus-2.11.2-03-bundle.tar.gz
[root@localhost nexus]#

CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服

第二步:解压

[root@localhost nexus]# mkdir /usr/local/nexus

[root@localhost nexus]# tar -zxvf nexus-2.11.2-03-bundle.tar.gz  -C /usr/local/nexus/

[root@localhost nexus]# cd /usr/local/nexus

[root@localhost nexus]# ls
nexus-2.11.2-03 sonatype-work
(一个 nexus 服务,一个私有库目录)

第三步:编辑 Nexus 的 nexus.properties 文件,配置端口和 work 目录信息(保留默认)
[root@localhost nexus]# cd nexus-2.11.2-03
[root@localhost nexus-2.11.2-03]# ls
bin conf lib LICENSE.txt logs nexus NOTICE.txt tmp
查看目录结构,jetty 运行
[root@localhost nexus-2.11.2-03]# cd conf
[root@localhost conf]# vi nexus.properties

1
2
3
4
5
6
7
8
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus
# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF

 如下图

CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服
第四步:编辑 nexus 脚本, 配置 RUN_AS_USER 参数
[root@localhost conf]# vi /usr/nexus/nexus-2.11.2-03/bin/nexus

NEXUS_HOME=".."
改为(不修改默认也可以):
NEXUS_HOME="nexus安装目录"

#RUN_AS_USER=
改为:
RUN_AS_USER=root

CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服

第五步:防火墙中打开 8081 端口 [etc目录通常放一些零散的配置文件]
[root@localhost conf]# vi /etc/sysconfig/iptables
添加:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT

CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服
保存后重启防火墙(即使防火墙开着也可以访问,作为服务器安全第一)
[root@localhost conf]# service iptables restart
第六步:启动 nexus [nexus的bin目录下的可以执行文件可以进入bin查看]
[root@localhost conf]# /usr/nexus/nexus-2.11.2-03/bin/nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.
[root@localhost conf]#
—————————————————————————————————————————————————

浏览器输入地址 http://192.168.174.128:8081/nexus

CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服

登录,默认用户名 admin 默认密码 admin123

到此,Nexus 已安装完成。

Nexus的访问权限模型

Nexus是基于权限做访问控制的,服务器的每一个资源都有对应的权限来控制,因此用户执行特定的操作时就必须拥有必要的权限。管理员必须以角色的方式将权限赋予Nexus用户。用户可以被赋予一个或者多个角色,角色可以包含一个或多个权限,角色还可以包含一个或者多个其他角色。

Nexus上预定义了三个用户,用admin登录后,单击页面左边的User链接,看到如下图列表:

CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服

admin:该用户拥有Nexus的全部权限,默认密码为admin123。
deployment:该用户能够访问Nexus,浏览仓库内容、搜索、上传部署构件,但是不能对Nexus进行任何配置,默认密码为deployment123。
anonymous:该用户对应了所有未登录的匿名用户,它们可以浏览仓库并进行搜索。

添加新用户并授予登录访问权限

CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服

添加第三方jar默认情况下Nexus为我们创建了以下主要的Repository
1、Public Repositories,这是一个Repository Group,该Repository  Group包含了多个Repository,其中包含了Releases、Snapshots、ThirdParty和Central。
2、3rd party,该Repository即是存放你公司所购买的第三方软件库的地方,它是一个由Nexus自己维护的一个Repository。 
3、Apache Snapshots,看名字你就应该知道这是个什么样的Repository,这是一个代理Repository,即最终的依赖还是得在Apache官网上去下载,然后缓存在Nexus中。
4、Central,这就是代理Maven Central Repository的Repository。
5、Releases,你自己的项目要发布时,就应该发布在这个Repository,他也是Nexus自己维护的Repository,而不是代理。
6、Snapshots,你自己项目Snapshot的Repository。

使用3rd party上传第三方jar包

在Repository列表中,选中 3rd party,选中artifact upload,

选择GAV Defini3ion: GAV Parameters,Auto Guess 打钩。

在下方输入JAR包对应的Group、Artifact、Version,Packaging选择JAR格式。

点击select Artifact(s) to upload 按钮,选择要上传的JAR包

如下图所示

CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服

 然后

CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服

CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服

CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服

OK上传成功!

输入pinyin4j点击搜索

如下图:

CentOS安装Nexus(Maven私有库)详细配置及上传本地jar到私服

Nexus安装与配置  http://www.linuxidc.com/Linux/2016-09/135084.htm

Maven使用入门 http://www.linuxidc.com/Linux/2012-11/74354.htm

Ubuntu 下 搭建Nexus Maven私服中央仓库  http://www.linuxidc.com/Linux/2016-08/133936.htm

Linux下使用Nexus搭建Maven私服详解 http://www.linuxidc.com/Linux/2016-08/134630.htm

Linux下使用Nexus搭建Maven私服 http://www.linuxidc.com/Linux/2016-08/134617.htm

Linux下安装配置Nexus http://www.linuxidc.com/Linux/2016-09/135083.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-11/136954.htm


settings.xml文件配置

 <servers><server>      <id>releases</id>      <username>liuxxxx</username>      <password>xxxx</password>    </server>  </servers>  <!-- mirrors   | This is a list of mirrors to be used in downloading artifacts from remote repositories.   |   | It works like this: a POM may declare a repository to use in resolving certain artifacts.   | However, this repository may have problems with heavy traffic at times, so people have mirrored   | it to several places.   |   | That repository definition will have a unique id, so we can create a mirror reference for that   | repository, to be used as an alternate download site. The mirror site will be the preferred   | server for that repository.   |-->  <mirrors>    <mirror>      <id>public</id>      <mirrorOf>central</mirrorOf>      <name>my maven</name>      <url>http://xx.xx.xxx.xxx:8081/nexus/content/groups/public/</url>    </mirror>      </mirrors>



0 0
原创粉丝点击