nexus安装与配置

来源:互联网 发布:python获取字符串长度 编辑:程序博客网 时间:2024/05/18 01:04

一.安装nexus前准备
1.先安装jdk,maven
vi /etc/profile
在末尾添加

export JAVA_HOME=/opt/jdk1.7export MAVEN_HOME=/opt/maven-3.3.9export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH

让配置生效
source /etc/profile
java -version
mvn --help
2.配好dns,能ping通外网(比如www.baidu.com)才能下载索引,中央库构件
修改dns
vi /etc/resolv.conf
nameserver 61.128.114.133

二.到http://www.sonatype.com/download-oss-sonatype获取linux包tar.gz的下载连接,假如已下载nexus-2.11.4-01-bundle.tar.gz到/root
三.安装和配置

/usr/sbin/groupadd nexus/usr/sbin/useradd -g nexus nexuscd ~tar xf nexus-2.11.4-01-bundle.tar.gzmv nexus-2.11.4-01 /opt/mv sonatype-work /home/nexus/chmod 777 /home/nexus/sonatype-workchown -R nexus:nexus /home/nexus/sonatype-workvi /opt/nexus-2.11.4-01/conf/nexus.properties###主要修改nexus库的位置nexus-work=/home/nexus/sonatype-work/nexuscp /opt/nexus-2.11.4-01/bin/nexus /etc/init.d/vi /etc/init.d/nexus###主要修改这两行NEXUS_HOME="/opt/nexus-2.11.4-01"RUN_AS_USER=nexuschown -R nexus:nexus /opt/nexus-2.11.4-01###添加到自启动并查看chkconfig --add nexuschkconfig --list|grep nexusservice nexus start###再clone一个终端,并跟踪日志,从日志都可以看出,启动到正常访问,对于机器性能一般都需要1分钟左右tail -f /opt/nexus-2.11.4-01/logs/wrapper.log###回到之前的终端 ps -ef|grep nexus netstat -npl|grep 8081

三.在浏览器打开http://192.168.1.194:8081/nexus,点右上角的Log In,输入admin/admin123(nexus默认的设置就已相当完善,但还是有些配置根据自己的情况要修改)
1.点左侧导航repositories,就可以右边列出已有的默认库(在左侧还有查看日志,定义计划任务等功能,修改密码的入口在右上角profile)
2.Nexus提供了三种不同的仓库:
A.代理仓库.一个代理仓库是对远程仓库的一个代理。默认情况下,Nexus自带了如下配置的
Apache Snapshots:这个仓库包含了来自于Apache软件基金会的快照版本
Codehaus Snapshots:这个仓库包含了来自于Codehaus的快照版本
Central Maven Repository:这是中央Maven仓库(发布版本)
B.宿主仓库.一个宿主仓库是由Nexus托管的仓库.Maven自带了如下配置的宿主仓库
3rd Party:这个宿主仓库应该用来存储在公共Maven仓库中找不到的第三方依赖。这种依赖的样例有:你组织使用的,商业的,私有的类库如Oracle JDBC驱动
Releases:这个宿主仓库是你组织公布内部发布版本的地方
Snapshots:这个宿主仓库是你组织发布内部快照版本的地方
C.虚拟仓库一个虚拟仓库作为Maven 1的适配器存在。Nexus自带了一个central-m1虚拟仓库
3.在列表随便点一个仓库
A.点Configuration,可以查看仓库的ID,名字,类型等信息
B.其中proxy类型才有browse remote选项.以Central库为例,它也是我最关心的,点Configuration,Remote Storage Location是远程仓库的URL(如果网络原因不能通,就要修改),Download Remote Indexes设置是否下载索引,在外网环境应将默认值False改为True,修改后再保存.
4.Public Repositories的仓库类型是group,它就是将几个仓库分成为一个组,点Ordered Group Repositories可以看到加入此组的仓库并排好顺序,默认顺序为Releases,Snapshots,3rd party,Central,这样的顺序是合理的,并且是绝大多数人的需求.如果我们在maven配置使用这个仓库,它查找构件就是按这顺序查找,前三个都找不到时,就会通过代理Central中央仓库去下载
5.除了虚拟仓库Central M1 shadow没有Browse Index,其它仓库都有Browse Index和Browse Storage,当nexus不能为maven项目提供构件,这两个选项的查看是比较重要,Browse Index和Browse Storage正如其名,浏览索引与浏览存储.
6.其中,3rd party和Releases还可以在浏览器添加构件,点Artifact Upload,GAV Definition可以选GAV Parameters,写好gav,选好packaging,选好Select Artifacts(s) to Upload,最后点底部的Upload Artifact(s)

四.在maven使用nexus
1.部署构件到nexus
A.部署发行版.
pom.xml片段

<distributionManagement>    ...    <repository>        <id>releases</id>        <name>Internal Releases</name>        <url>http://192.168.1.194:8081/nexus/content/repositories/releases</url>    </repository>    ...</distributionManagement>

运行mvn deploy
B.部署快照版.

<distributionManagement>    ...    <snapshotRepository>        <id>Snapshots</id>        <name>Internal Snapshots</name>        <url>http://192.168.1.194:8081/nexus/content/repositories/snapshots</url>    </snapshotRepository>    ...</distributionManagement>

运行mvn deploy
C.部署第三方构件
mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.3.0 -Dpackaging=jar -Dfile=ojdbc.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty -DrepositoryId=thirdparty

2.一般maven项目的pom片段

    <pluginRepositories>        <pluginRepository>            <id>Nexus Public Plugin</id>            <name>Nexus Public Plugin</name>            <url>${nexus.url}/content/groups/public</url>            <releases>                <enabled>true</enabled>            </releases>            <snapshots>                <enabled>true</enabled>            </snapshots>        </pluginRepository>    </pluginRepositories>    <distributionManagement>        <repository>            <id>Nexus Releases Repository</id>            <name>Nexus Releases Repository</name>            <url>${nexus.url}/content/repositories/releases</url>        </repository>        <snapshotRepository>            <id>Nexus Snapshot Repository</id>            <name>Nexus Snapshot Repository</name>            <url>${nexus.url}/content/repositories/snapshots</url>        </snapshotRepository>    </distributionManagement>

另:对于已有的maven库,一样应拷到/home/nexus/sonatype-work/nexus/storage/central,因为墙,还有本身通过网络下载也没下载工具下载快,或者内网不能下载,造成下载索引是一件痛苦的事情.下面是一种方法
1.准备工作
a.到http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.apache.maven.indexer%22%20AND%20a%3A%22indexer-cli%22下载indexer-cli
b.到http://repo1.maven.org/maven2/.index/下载nexus-maven-repository-index.gz和nexus-maven-repository-index.properties,并验证一下md5

2.停止nexus,建立索引,拷贝到相应位置,并启动nexus
service nexus stop
mv /home/nexus/sonatype-work/nexus/indexer/central-ctx /tmp/

假如下载的三个文件在~/index,建立索引需要几分钟
cd ~/index
java -jar indexer-cli-5.1.1.jar -u nexus-maven-repository-index.gz -d indexer
mv indexer /home/nexus/sonatype-work/nexus/indexer/central-ctx
chown -R nexus:nexus /home/nexus/sonatype-work/nexus/indexer/central-ctx

service nexus start

0 0