公司的代码依赖是经过Maven进行管理的,而Maven的私库咱们使用的是Nexus,目前使用的版本是Nexus Repository Manager OSS 2.12.1。css
可是因为以前咱们搭建的Nexus服务器就是在咱们办公室的一台空闲的Linux电脑上,虽然也稳定地使用两年了,可是基于安全性考虑,准备将Nexus服务器迁移到公司的机房服务器去。html
所以我须要在机房从新搭建Nexus服务器,而后将办公室上的Nexus服务器迁移到机房服务器。这一篇博客先来记录下Nexus服务器的安装过程。java
Nexus是基于java语言开发的,全部在安装Nexus2.12.1以前,咱们须要配置Nexus2.12.1运行所须要的jdk环境。Nexus2.12.1须要的JDK版本为JDK7。linux
由于本机环境以及安装过JDK了,正好版本为JDK7,这边就不演示了。web
[root@localhost nexus-2.12.1-01]# java -version
java version "1.7.0_131"
OpenJDK Runtime Environment (rhel-2.6.9.0.el6_8-x86_64 u131-b00)
OpenJDK 64-Bit Server VM (build 24.131-b00, mixed mode)
[root@localhost nexus-2.12.1-01]#
Nexus Repository Manager OSS ,以前叫作 Nexus OS,是开源免费的。【OSS = Open Source Software,开源软件——免费】sql
https://help.sonatype.com/display/NXRM2/Download+Archives+-+Repository+Manager+OSSvim
Nexus Repository Manager,以前叫作 Nexus Professional。只有拥有一个有效的许可证才可使用全部功能【专业版本——收费】浏览器
https://help.sonatype.com/display/NXRM2/Download+Archives+-+Repository+Manager+2缓存
所以咱们首先找到Nexus Repository Manager OSS 的下载地址,以下所示:安全
https://help.sonatype.com/display/NXRM2/Download+Archives+-+Repository+Manager+OSS
而后向下滑动,找到与咱们已经安装好的对应的版本 Nexus Repository Manager OSS 2.12.1
而后咱们下载 nexus-2.12.1-01-bundle.tar.gz 压缩包,右键复制好相应的下载地址为
https://download.sonatype.com/nexus/oss/nexus-2.12.1-01-bundle.tar.gz
而后咱们在机房的Linux服务器(咱们的服务器为CenterOS)上下载该压缩包,使用以下命令便可下载。
wget https://download.sonatype.com/nexus/oss/nexus-2.12.1-01-bundle.tar.gz
等待几分钟便可下载好压缩包。这一次用时10m 41s下载好了nexus-2.12.1-01-bundle.tar.gz
将nexus-2.12.1-01-bundle.tar.gz压缩包解压到/usr/local目录下,使用以下命令
tar -xf nexus-2.12.1-01-bundle.tar.gz -C /usr/local/
上面命令执行完后,nexus-2.12.1-01-bundle.tar.gz就解压到了/url/local目录下,使用以下命令便可查看
cd /usr/local/
ll
而后咱们进入到 nexus-2.12.1-01/ 目录下
[root@localhost local]# cd nexus-2.12.1-01/
[root@localhost nexus-2.12.1-01]# ll
总用量 40
drwxr-xr-x 3 1001 1001 4096 12月 13 16:27 bin
drwxr-xr-x 2 1001 1001 4096 12月 13 16:27 conf
drwxr-xr-x 2 1001 1001 4096 12月 13 16:27 lib
-rw-r--r-- 1 1001 1001 11006 3月 3 2016 LICENSE.txt
drwxr-xr-x 2 1001 1001 4096 3月 3 2016 logs
drwxr-xr-x 4 1001 1001 4096 12月 13 16:27 nexus
-rw-r--r-- 1 1001 1001 782 3月 3 2016 NOTICE.txt
drwxr-xr-x 2 1001 1001 4096 3月 3 2016 tmp
[root@localhost nexus-2.12.1-01]#
使用以下的命令,将nexus2.12.1加入到系统服务中
[root@localhost nexus-2.12.1-01]# cp bin/nexus /etc/init.d/nexus2
//添加到开机启动
[root@localhost nexus-2.12.1-01]# chkconfig --add nexus2
//设置nexus服务开机自启动
[root@localhost nexus-2.12.1-01]# chkconfig nexus2 on
关于 chkconfig能够参考连接:
使用vim命令,修改/etc/init.d/nexus2文件
vim /etc/init.d/nexus2
这里须要修改两个变量值
#-----------------------------------------------------------------------------
# These settings can be modified to fit the needs of your application
# Set this to the root of the Nexus installation #NEXUS_HOME=".." #修改成真正的Nexus目录 NEXUS_HOME="/usr/local/nexus-2.12.1-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= #将运行时的用户改成root RUN_AS_USER=root
在 /usr/local/nexus-2.12.1-01 目录下执行下面的命令
[root@localhost nexus-2.12.1-01]# vim bin/jsw/conf/wrapper.conf
须要将wrapper.java.command 设置为 java的真实路径,咱们先使用 cat /etc/profile命令,获取到java的安装目录为 /usr/bin/java
JAVA_HOME=/usr/java
PATH=$PATH:%JAVA_HOME%/bin CLASSPATH=%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar
[root@localhost nexus-2.12.1-01]# ls /usr/java/bin/
appletviewer idlj java javafxpackager javapackager jcmd jdb jinfo jmc jrunscript jstat keytool pack200 rmid serialver unpack200 xjc
ControlPanel jar javac javah java-rmi.cgi jconsole jdeps jjs jmc.ini jsadebugd jstatd native2ascii policytool rmiregistry servertool wsgen
extcheck jarsigner javadoc javap javaws jcontrol jhat jmap jps jstack jvisualvm orbd rmic schemagen tnameserv wsimport
[root@localhost nexus-2.12.1-01]#
所以wrapper.java.command 的值咱们得设置为 /usr/java/bin/java
# Set the JSW working directory (used as base for resolving relative paths) wrapper.working.dir=../../.. # Set the JVM executable # (modify this to absolute path if you need a Java that is not on the OS path) #wrapper.java.command=java #设置好Java执行文件所处的位置 wrapper.java.command=/usr/java/bin/java
以上修改完毕后,咱们再来修改nexus2.12.1监听的端口,以及仓库的存储位置,以下:
经过vim命令修改 conf/nexus.properties文件
[root@localhost nexus-2.12.1-01]# pwd
/usr/local/nexus-2.12.1-01
[root@localhost nexus-2.12.1-01]# ll
总用量 40
drwxr-xr-x 3 1001 1001 4096 12月 13 16:27 bin
drwxr-xr-x 2 1001 1001 4096 12月 13 16:27 conf
drwxr-xr-x 2 1001 1001 4096 12月 13 16:27 lib
-rw-r--r-- 1 1001 1001 11006 3月 3 2016 LICENSE.txt
drwxr-xr-x 2 1001 1001 4096 3月 3 2016 logs
drwxr-xr-x 4 1001 1001 4096 12月 13 16:27 nexus
-rw-r--r-- 1 1001 1001 782 3月 3 2016 NOTICE.txt
drwxr-xr-x 2 1001 1001 4096 3月 3 2016 tmp
[root@localhost nexus-2.12.1-01]# vim conf/nexus.properties
将application-port设置为8081,将nexus-work设置为${bundleBasedir}/../sonatype-work/nexus,以下所示
# 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
好了,Nexus的安装初步设置操做,完毕!
在启动Nexus以前,咱们先看看 Nexus有哪些命令?
敲以下的命令,能够看到nexus有的命令有 console | start | stop | restart | status | dump
[root@localhost nexus-2.12.1-01]# /etc/init.d/nexus2
Usage: /etc/init.d/nexus2 { console | start | stop | restart | status | dump }
[root@localhost nexus-2.12.1-01]#
使用以下命令启动Nexus
/etc/init.d/nexus2 start
以下所示
[root@localhost nexus-2.12.1-01]# /etc/init.d/nexus2 start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.
[root@localhost nexus-2.12.1-01]#
经过日志咱们能够看到 Nexus OSS 已经正常启动了。
Nexus服务启动以后,咱们就能够经过浏览器来访问Nexus了,在浏览器进行访问。
地址为 http://ip:端口/nexus
以下所示,在浏览器输入地址 http://ip地址:8081/nexus 而后就出现了以下所示的画面。
经过上图,咱们能够很明显的看到Nexus2.12.1已经正常启动。
如今咱们登陆到Nexus2.12.1管理后台。
Nexus管理后台默认的管理员用户名和密码为admin/admin123
填好用户名和密码,点击LogIn,而后咱们就能够看到以下所示的界面
点击左侧菜单栏的Responsitories
而后就能够展开目前拥有的Responsitories
关于仓库的截图,放大部分以下所示:
通常用到的仓库种类是hosted、proxy。
Hosted表明宿主仓库,用来发布一些第三方不容许的组件,好比Oracle驱动、好比商业软件jar包。
Proxy表明代理远程的仓库,最典型的就是Maven官方中央仓库、JBoss仓库等等。若是构建的Maven项目本地仓库没有依赖包,那么就会去这个代理站点去下载,那么若是代理站点也没有此依赖包,就回去远程中央仓库下载依赖,这些中央仓库就是proxy。代理站点下载成功后再下载至本机。
默认状况下Nexus为咱们建立了如下主要的Repository:
Public Repositories,这是一个Repository Group,它所对应的URL为http://localhost:8080/nexus-2.5/content/groups/public/,该Repository Group包含了多个Repository,其中包含了Releases、Snapshots、Third Party和Central。Repository Group的做用是咱们只须要在本身的项目中配置该Repository Group就好了,它将自动从其所包含的Repository中下载依赖,好比若是咱们声明对Spring的依赖,那么根据Repository Group中各个Repository的顺序(能够配置),Nexus将首先从Releases中下载Spring,发现没有,再从Snapshots中下载(极大可能也没有,由于它是个Snapshots的Repository),依次查找,最后可能在Central Repository中找到。在配置项目的Repository时,咱们应该首先考虑Public Repositories。
3rd party,该Repository便是存放你公司所购买的第三方软件库的地方,它是一个由Nexus本身维护的一个Repository。
Apache Snapshots,看名字你就应该知道这是个什么样的Repository,这是一个代理Repository,即最终的依赖仍是得在Apache官网上去下载,而后缓存在Nexus中。
Central,这就是代理Maven Central Repository的Repository。
Releases,你本身的项目要发布时,就应该发布在这个Repository,他也是Nexus本身维护的Repository,而不是代理。
Snapshots,你本身项目Snapshot的Repository。
做者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/78793038
本文同步发表在阿里云栖:https://yq.aliyun.com/articles/282205?spm=5176.blogshare282205.0.0.xLalTm若是以为本文对您有所帮助,欢迎您扫码下图所示的支付宝和微信支付二维码对本文进行随意打赏。您的支持将鼓励我继续创做!