Linux 安装配置maven3.2 以及搭建nexus私服

一、软件准备
1、apache-maven-3.0-bin.tar.gz 下载地址:http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-3.0-bin.tar.gz

2、nexus-3.2.0-01-unix.tar.gz
下载地址:http://nexus.sonatype.org/downloads/

二、maven安装配置
1、创建需要操作maven的用户组以及用户(如果用root用户安装不用创建)
#groupadd configer //创建用户组
#useradd -g configer configer //创建用户并指定用户组
#passwd configer //为用户分配密码

2、创建解压目录,并将apache-maven-3.0-bin.tar.gz文件解压到指定目录

#cd /opt
#mkdir maven
#chown -R configer:configer /opt/maven
#chmod 755 /opt/maven
#su -l configer
#tar -zvxf apache-maven-3.0-bin.tar.gz

2、配置环境变量

#vi /home/configer/.bash_profile

在文件中添加如下行:

M2_HOME=/opt/maven/apache-maven-3.0
export M2_HOME
PATH=$PATH:$M2_HOME/bin
export PATH

3、查看版本

#cd /opt/maven/apache-maven-3.0/bin
#mvn --version


如果显示版本信息,应该会在${user}目录下创建.m2目录

4、查看.m2目录
#cd /home/configer/.m2
如果没有.m2目录,则可以手动添加一个
#mkdir .m2

5、如果需要把maven的repository目录指定到其他目录,则修改maven安装目录下conf中的配置文件settings.xml文件

#vi /opt/maven/apache-maven-3.0/conf/settings.xml
将文件中<localRepository>....</localRepository>的注释打开

或者在文件中增加 在这个注释下增加
<localRepository>your repository path</localRepository>


二、搭建nexus私服
1、解压 nexus-3.2.0-01-unix.tar.gz 文件到指定目录

#tar -zvxf nexus-3.2.0-01-unix.tar.gz

解压后有两个目录:
nexus-3.2.0-01 -- nexus服务目录
sonatype-work -- nexus工作目录

2、自定义配置
1) 修改端口号
# vi nexus-3.2.0-01/etc/nexus-default.properties
修改 application-port=8081 改成自定义的端口即可

2) 开发端口
iptables -I INPUT -p tcp --dport 8081 -j ACCEPT

3)修改用户及密码
在 security->Users-> More ->Change Password

2、启动nexus
#cd /opt/maven/nexus-3.2.0-01/bin

#./nexus start

重启:
#./nexus restart

停止:
#./nexus stop

3、运行nexus
在浏览器中输入:http://localhost:8081/nexus
就可以看到nexus 的主页,点击右上角Log in
默认用户名和密码是:admin/admin123

运行后会自动生成一个nexus工作目录sonatype-work,nexus下载的jar包会存放在
sonatype-work/nexus/storage中

4、配置
1)点击左侧菜单Repositories
分别将右侧列表中

Apache Snapshots
Codehaus Snapshots
Maven Central


三个repository 的Download Remote Index 配置改为True,并保存设置,
然后在列表中分别右键点击三个Repository,点击ReIndex

2)增加新的Repository,有一些比较常用jar包在nexus提供的repository中可能找不到,
一般比较常用的有

JBOSS的两个:
http://repository.jboss.org/maven2/
http://repository.jboss.org/nexus/content/repositories/releases/

SUN的:
http://download.java.net/maven/2/

K-INT的:
http://developer.k-int.com/maven2/

因为找juel:juel-impl:2.2.1 这个jar包,所以我还添加了一个自己找的:
http://repository.exoplatform.org/content/groups/public/

添加步骤:

点击Add->Proxy Repository->填写Repository ID, Repository Name, 以及Remote Storage Location 其他的默认即可。

3) 将新增的Repository添加到Public Repositories中
在Public Repositories 的Configuration中,将多选Select中的项全部添加到左边,然后保存。

4) 添加自己的jar包

在repository列表中有一个3rd party,也就是第三方jar包,点击会看到一个Artifact Upload选项卡,点击后,填写相应的信息。
GAV Definition 一般选择 GAV Parameters
然后添加Group:Artifact:Version:Package
示例 juel:juel-impl:2.2.1:jar


然后选择要上传的jar包,保存即可

5) nexus中设置代理服务器
选择左侧administrator菜单中的Server选项,在右侧打开的页面的中下部,有一个选择项:Default HTTP Proxy Settings(optional) 将复选框选中,填写相应的代理服务器信息即可。

6) 编写自己的settings.xml,文件内容如下:

<settings>
<proxies>
<proxy>
<id>normal</id>
<active>true</active>
<protocol>http</protocol>
<username>deployment</username>
<password>deploy</password>
<host>localhost:8081/nexus</host>
<port>80</port>
<nonProxyHosts>localhost:8081/nexus</nonProxyHosts>
</proxy>
</proxies>

<mirrors>
<mirror>
<!--This is used to direct the public snapshots repo in the
profile below over to a different nexus group -->
<id>nexus-public-snapshots</id>
<mirrorOf>public-snapshots</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
</mirror>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>

<profiles>
<profile>
<id>development</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<!--this profile will allow snapshots to be searched when activated-->
<id>public-snapshots</id>
<repositories>
<repository>
<id>public-snapshots</id>
<url>http://public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
--------------------------------------------------------------------------------

遇到这种警告:
****************************************
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,临时配置
在命令行下输入:

export RUN_AS_USER=root

然后执行,就不会再提示了
./nexus start

---------------------------------------------------------------

Linux在启动时,会自动执行/etc/rc.d目录下的初始化程序,因此我们可以把启动任务放到该目录下:

1、因为其中的rc.local是在完成所有初始化之后执行,因此可以把启动脚本写到里面;
2、用root账号登陆Linux,vi /etc/rc.d/rc.local编辑文件,在最后加入需要执行的脚本程序:
su -l $username -c "/nexus/nexus-2.8.0-05/bin/nexus start"


****注意下面几点说明****
1.component name的一些说明:
1)maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar
2)maven-releases:私库发行版jar
3)maven-snapshots:私库快照(调试版本)jar
4)maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml中使用。
2.Nexus默认的仓库类型有以下四种:
1)group(仓库组类型):又叫组仓库,用于方便开发人员自己设定的仓库;
2)hosted(宿主类型):内部项目的发布仓库(内部开发人员,发布上去存放的仓库);
3)proxy(代理类型):从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage Location属性的值即被代理的远程仓库的路径);
4)virtual(虚拟类型):虚拟仓库(这个基本用不到,重点关注上面三个仓库的使用);
3.Policy(策略):表示该仓库为发布(Release)版本仓库还是快照(Snapshot)版本仓库;
4.Public Repositories下的仓库
1)3rd party: 无法从公共仓库获得的第三方发布版本的构件仓库,即第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去;
2)Apache Snapshots: 用了代理ApacheMaven仓库快照版本的构件仓库
3)Central: 用来代理maven中央仓库中发布版本构件的仓库
4)Central M1 shadow: 用于提供中央仓库中M1格式的发布版本的构件镜像仓库
5)Codehaus Snapshots: 用来代理CodehausMaven 仓库的快照版本构件的仓库
6)Releases: 内部的模块中release模块的发布仓库,用来部署管理内部的发布版本构件的宿主类型仓库;release是发布版本;
7)Snapshots:发布内部的SNAPSHOT模块的仓库,用来部署管理内部的快照版本构件的宿主类型仓库;snapshots是快照版本,也就是不稳定版本
所以自定义构建的仓库组代理仓库的顺序为:Releases,Snapshots,3rd party,Central。也可以使用oschina放到Central前面,下载包会更快。
5.Nexus默认的端口是8081,可以在etc/nexus-default.properties配置中修改。
6.Nexus默认的用户名密码是admin/admin123
7.当遇到奇怪问题时,重启nexus,重启后web界面要1分钟左右后才能访问。
8.Nexus的工作目录是sonatype-work(路径一般在nexus同级目录下)
# pwd
/usr/local
# ls nexus/
bin deploy etc lib LICENSE.txt NOTICE.txt public system
# ls sonatype-work/
nexus3
# ls sonatype-work/nexus3/
backup blobs cache db elasticsearch etc generated-bundles health-check instances keystores lock log orient port tmp

Nexus仓库分类的概念:
1)Maven可直接从宿主仓库下载构件,也可以从代理仓库下载构件,而代理仓库间接的从远程仓库下载并缓存构件
2)为了方便,Maven可以从仓库组下载构件,而仓库组并没有时间的内容(下图中用虚线表示,它会转向包含的宿主仓库或者代理仓库获得实际构件的内容)

转自:http://www.cnblogs.com/dingyingsi/p/3776560.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值