在公司开发项目的时候,使用到了maven,但刚开始的时候,只有我一个人开发,所以也没有搭建maven私服,后来增加了几个开发人员,因为考虑到maven更新包的问题,决定搭建一个maven私服,在此做一下记录
nexus私服的作用是相当于在maven库和本地maven中间的一个中转站,当我们需要下载jar的时候,eclipse会现在本地maven寻找,如果找不到,再在nexus上寻找,如果还是没有,则会到maven库里面下载,先下载到nexus,然后,本地maven再从nexus下载到本地,这样可以提高本地开发的效率,好了,转正题
1、准备工作
CentOS 6.8 :操作系统
nexus-2.12.0-01-bundle.tar.gz,这儿提供一个 下载地址:
http://www.sonatype.com/download-oss-sonatype
,可以下载最新的nexus。
2、安装过程
(1)先把安装包拷到指定的目录下,我自己是在/usr/nexus下
(2)解压安装包,解压命令是:
# tar -zxfv nexus-2.12.0-01-bundle.tar.gz
(3)解压完成以后,目录下会出现两个子目录,分别是:sonatype-work、nexus-2.12.0-01
nexus-2.12.0-01:文件执行目录,包括日志文件的目录,
sonatype-work:jar在nexus下的存放目录(在此建议为nexus选择一个空间比较大的目录,因为以后会存很多的包)
(4)配置nexus端口信息:nexus默认使用的端口是8081,如果该端口有其他的用处,可以在/nexus-2.12.0-01/conf/nexus.properties下修改端口,
# Jetty section
#配置端口信息,可以修改为其他端口,我这儿选的是9037
#application-port=8081application-port=9037
application-host=0.0.0.0#访问nexus的地址:localhost:8081/nexus
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus# Nexus section
#配置work目录地址,Maven仓库JAR缓存地址,可修改其他地址eg:${bundleBasedir}/nexus-work/nexus
nexus-work=${bundleBasedir}/../sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF
(5)配置 /nexus-2.12.0-01/bin/nexus
# Set this to the root of the Nexus installation
#配置nexus根目录,用绝对地址
NEXUS_HOME="/usr/nexus/nexus-2.12.0-01"# If specified, the Wrapper will be run as the specified user.
# IMPORTANT - Make sure that the user has the required privileges to write into the Nexus installation directory.
# NOTE - This will set the user which is used to run the Wrapper as well as
# the JVM and is not useful in situations where a privileged resource or
# port needs to be allocated prior to the user being changed.
#RUN_AS_USER=#运行用户,nexus推荐不用root,但是我只有这个用户
RUN_AS_USER=root
(6)完成了,保存,退出
(7)运行./nexus会出现下面的提示
Usage: ./nexus { console | start | stop | restart | status | dump }
(8)输入命令,启动nexus
#./nexus start
(9)打开浏览器输入地址,即可访问nexus
至此,nexus安装成功!
注意:我在安装过程中遇到一个问题,卡了我一天,而且找了半天帖子,答案还是是而非,就是提示我localhost:unkown error,最后在一个关于tomcat的帖子看到这个问题,是说我们系统的hosts里面没有配置localhost,最后我在hosts文件里面配置了localhost,完美解决。hosts文件位置:/etc/hosts