公司的代碼依賴是經過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若是以爲本文對您有所幫助,歡迎您掃碼下圖所示的支付寶和微信支付二維碼對本文進行隨意打賞。您的支持將鼓勵我繼續創做!