Nexus centos 安裝

搭建nexus服務的意義
做爲內網的統一代理,團隊合做開發時不用每人都去外網下載一次;
解決部分變態公司內網管制沒法訪問外網的問題,選一臺有外網權限的機器搭建服務器,其他人直接內網訪問此服務;
團隊合做開發時解決maven項目依賴問題;ios

你們nexus以後使用情形以下圖
nginx

一、安裝nexus

在安裝以前 兄弟們要搞清楚是環境的jdk版本,兄弟我2018/8/20直接下了最新的版本,結果悲劇,配置到一半,報錯,以下:web

#高版本要求jdk8以上
[root@227 nexus]# ./bin/nexus console
No suitable Java Virtual Machine could be found on your system.
The version of the JVM must be at least 1.8 and at most 1.8.
Please define INSTALL4J_JAVA_HOME to point to a suitable JVM.

退而求其次nexus-2.11.4-01-bundle.tar.gzshell

  • 雲下載

wget http://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.4-01-bundle.tar.gzapache

wget  http://mirrors.cnnic.cn/apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.tar.gzbootstrap

[root@227 ~]# wget http://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.4-01-bundle.tar.gz
--2018-08-20 15:55:29--  http://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.4-01-bundle.tar.gz
Resolving sonatype-download.global.ssl.fastly.net... 151.101.73.194
Connecting to sonatype-download.global.ssl.fastly.net|151.101.73.194|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 70938260 (68M) [application/x-gzip]
Saving to: 「nexus-2.11.4-01-bundle.tar.gz」

100%[============================================================================>] 70,938,260   121K/s   in 9m 14s  

Last-modified header invalid -- time-stamp ignored.
2018-08-20 16:04:44 (125 KB/s) - 「nexus-2.11.4-01-bundle.tar.gz」 saved [70938260/70938260]
  • 解壓到/usr/local
[root@227 ~]# ll
total 69396
-rw-------. 1 root root     2362 Feb 28 18:39 anaconda-ks.cfg
drwxr-xr-x. 2 root root     4096 Feb 28 10:46 Desktop
drwxr-xr-x. 2 root root     4096 Feb 28 10:46 Documents
drwxr-xr-x. 2 root root     4096 Aug 20 15:41 Downloads
-rw-r--r--. 1 root root    68509 Feb 28 18:39 install.log
-rw-r--r--. 1 root root    11969 Feb 28 18:37 install.log.syslog
drwxr-xr-x. 2 root root     4096 Feb 28 10:46 Music
-rw-r--r--. 1 root root 70938260 Aug 20 16:04 nexus-2.11.4-01-bundle.tar.gz
drwxr-xr-x. 2 root root     4096 Feb 28 10:46 Pictures
drwxr-xr-x. 2 root root     4096 Feb 28 10:46 Public
drwxr-xr-x. 2 root root     4096 Feb 28 10:46 Templates
drwxr-xr-x. 2 root root     4096 Feb 28 10:46 Videos
[root@227 ~]# tar -zxvf nexus-2.11.4-01-bundle.tar.gz -C /usr/local/

注意:vim

  必定要解壓到這個目錄下,具體緣由我也不知道,文檔裏是這麼作的,咱們也不必本身找麻煩。瀏覽器

  • 創建軟連接服務器

  • 查看/usr/local目錄,結果以下:

[root@227 ~]# cd /usr/local/
[root@227 local]# ln -s nexus-2.11.4-01 nexus
[root@227 local]# ll
total 92
drwxr-xr-x.  2 root root  4096 Sep 23  2011 bin
drwxr-xr-x.  2 root root  4096 Sep 23  2011 etc
drwxr-xr-x.  2 root root  4096 Sep 23  2011 games
drwxr-xr-x.  2 root root  4096 Sep 23  2011 include
drwxr-xr-x.  2 root root  4096 Apr 11 15:43 key
drwxr-xr-x.  2 root root  4096 Sep 23  2011 lib
drwxr-xr-x.  2 root root  4096 Sep 23  2011 lib64
drwxr-xr-x.  2 root root  4096 Sep 23  2011 libexec
drwxr-xr-x.  2 root root 32768 Aug 20 00:10 logs
lrwxrwxrwx.  1 root root    15 Aug 20 16:09 nexus -> nexus-2.11.4-01
drwxr-xr-x.  8 root root  4096 Jul 10  2015 nexus-2.11.4-01
drwxr-xr-x. 11 root root  4096 May 21 17:15 nginx
drwxr-xr-x.  2 root root  4096 Apr  4 16:30 RSA-KeyPair
drwxr-xr-x.  2 root root  4096 Sep 23  2011 sbin
drwxr-xr-x.  5 root root  4096 Feb 28 18:29 share
drwxr-xr-x.  4 root root  4096 Jul 10  2015 sonatype-work
drwxr-xr-x.  2 root root  4096 Sep 23  2011 src
  • 設置環境變量(按官網文檔的說法是可選,不過仍是配上吧)
[root@227 local]# vim /etc/profile

unset i
unset -f pathmunge
JAVA_HOME=/usr/jdk1.7.0_79
JRE_HOME=$JAVA_HOME/jre
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME JRE_HOME CLASSPATH PATH
export NEXUS_HOME=/usr/local/nexus-2.11.4-01

[root@227 local]#
[root@227 local]# source /etc/profile
[root@227 local]# echo $NEXUS_HOME
/usr/local/nexus-2.11.4-01

二、啓動nexus

2.1啓動服務器

  前臺啓動:好了,咱們來前臺啓動一下。咦,沒起來,提示:

[root@227 local]# cd /usr/local/nexus
[root@227 nexus]# ./bin/nexus console
****************************************
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.
[root@227 nexus]# vim /etc/profile
#結尾加上 export RUN_AS_USER=root
[root@227 nexus]# source /etc/profile
[root@227 nexus]# ./bin/nexus console
#運行結果以下
wrapper  | Launching a JVM...
jvm 1    | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
jvm 1    |   Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.
jvm 1    | 
jvm 1    | 2018-08-20 16:15:57,678+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.jsw.JswLauncher - Starting with arguments: [./conf/jetty.xml, ./conf/jetty-requestlog.xml]
jvm 1    | 2018-08-20 16:15:57,682+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.jsw.JswLauncher - JVM ID: 1, JVM PID: 16148, Wrapper PID: 16146, User: root
jvm 1    | 2018-08-20 16:15:57,699+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder - Properties:
jvm 1    | 2018-08-20 16:15:57,700+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder -   application-conf='/usr/local/nexus-2.11.4-01/../sonatype-work/nexus/conf'
jvm 1    | 2018-08-20 16:15:57,700+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder -   application-host='0.0.0.0'
jvm 1    | 2018-08-20 16:15:57,700+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder -   application-port='8081'
jvm 1    | 2018-08-20 16:15:57,700+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder -   bundleBasedir='/usr/local/nexus-2.11.4-01'
jvm 1    | 2018-08-20 16:15:57,700+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder -   java.awt.headless='true'
jvm 1    | 2018-08-20 16:15:57,700+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder -   networkaddress.cache.ttl='3600'
jvm 1    | 2018-08-20 16:15:57,700+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder -   nexus-app='/usr/local/nexus-2.11.4-01/nexus/WEB-INF'
jvm 1    | 2018-08-20 16:15:57,700+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder -   nexus-webapp='/usr/local/nexus-2.11.4-01/nexus'
jvm 1    | 2018-08-20 16:15:57,700+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder -   nexus-webapp-context-path='/nexus'
jvm 1    | 2018-08-20 16:15:57,700+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder -   nexus-work='/usr/local/sonatype-work/nexus'
jvm 1    | 2018-08-20 16:15:57,700+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder -   org.eclipse.ecf.provider.filetransfer.retrieve.readTimeout='30000'
jvm 1    | 2018-08-20 16:15:57,700+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder -   runtime='/usr/local/nexus-2.11.4-01/nexus/WEB-INF'
jvm 1    | 2018-08-20 16:15:57,700+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.ConfigurationBuilder -   security-xml-file='/usr/local/nexus-2.11.4-01/../sonatype-work/nexus/conf/security.xml'
jvm 1    | 2018-08-20 16:15:57,701+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.Launcher - Java: 1.7.0_79, Java HotSpot(TM) 64-Bit Server VM, Oracle Corporation, 24.79-b02
jvm 1    | 2018-08-20 16:15:57,701+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.Launcher - OS: Linux, 2.6.32-431.el6.x86_64, amd64
jvm 1    | 2018-08-20 16:15:57,701+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.Launcher - User: root, en, /root
jvm 1    | 2018-08-20 16:15:57,701+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.Launcher - CWD: /usr/local/nexus-2.11.4-01
jvm 1    | 2018-08-20 16:15:57,711+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.Launcher - TMP: /usr/local/nexus-2.11.4-01/tmp
jvm 1    | 2018-08-20 16:15:57,713+0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer - Starting

2.2之後臺進程啓動:

[root@227 ~]# cd /usr/local/nexus
######################後臺啓動命令################################

[root@227 nexus]# ./bin/nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.

[root@227 nexus]# ./bin/nexus stop
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Stopping Nexus OSS...
Stopped Nexus OSS.

######################查看日誌################################
[root@227 nexus]# tail -f logs/wrapper.log
jvm 1    | 2018-08-21 09:10:12,782+0800 INFO  [RepositoryStatusChecker-central] *SYSTEM org.sonatype.nexus.proxy.maven.maven2.M2Repository-central - Next attempt to auto-unblock the "Central" (id=central) repository by checking its remote peer health will occur in 40 seconds.
jvm 1    | 2018-08-21 09:10:18,206+0800 INFO  [qtp1235955620-81] *SYSTEM org.apache.shiro.nexus5727.FixedDefaultWebSessionManager - Global session timeout: 1800000 ms
jvm 1    | 2018-08-21 09:10:18,207+0800 INFO  [qtp1235955620-81] *SYSTEM org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler...
jvm 1    | 2018-08-21 09:10:18,208+0800 INFO  [qtp1235955620-81] *SYSTEM org.apache.shiro.cache.ehcache.EhCacheManager - Using existing EHCache named [shiro-activeSessionCache]
jvm 1    | 2018-08-21 09:10:18,264+0800 INFO  [qtp1235955620-81] admin org.sonatype.nexus.velocity.VelocityEngineProvider - Creating Nexus VelocityEngine
jvm 1    | 2018-08-21 09:10:18,869+0800 INFO  [qtp1235955620-81] admin /nexus - nexus: [Noelios Restlet Engine] - Attaching application: org.sonatype.nexus.rest.NexusApplication@228da80f to URI: /nexus/service/local
jvm 1    | 2018-08-21 09:10:18,894+0800 INFO  [qtp1235955620-87] admin org.sonatype.security.model.source.FileModelConfigurationSource - Loading security configuration from: /usr/local/nexus-2.11.4-01/../sonatype-work/nexus/conf/security.xml
jvm 1    | 2018-08-21 09:10:19,243+0800 INFO  [proxy-3-thread-1] admin org.sonatype.nexus.proxy.storage.remote.httpclient.HttpClientRemoteStorage - Initializing remote transport for proxy repository "Apache Snapshots" [id=apache-snapshots]...
jvm 1    | 2018-08-21 09:10:52,665+0800 INFO  [RepositoryStatusChecker-codehaus-snapshots] *SYSTEM org.sonatype.nexus.proxy.maven.maven2.M2Repository-codehaus-snapshots - Next attempt to auto-unblock the "Codehaus Snapshots" (id=codehaus-snapshots) repository by checking its remote peer health will occur in 1 minute 20 seconds.
jvm 1    | 2018-08-21 09:10:52,783+0800 INFO  [RepositoryStatusChecker-central] *SYSTEM org.sonatype.nexus.proxy.maven.maven2.M2Repository-central - Next attempt to auto-unblock the "Central" (id=central) repository by checking its remote peer health will occur in 1 minute 20 seconds.

2.3web訪問

好了,咱們在瀏覽器上看看能不能訪問吧,路徑:

http://192.168.1.227(換成你的ip):8081/nexus.

結果如圖所示:

img

點擊右上角登陸:

默認用戶名爲admin,密碼admin123

3.搭建私服

3.1 界面元素介紹

img

登陸後,點擊左側Repositories,界面如上圖所示。

右側的列表中,能夠看到nexus預設的幾個倉庫。

第一個public Repositories,類型爲group,這個簡單理解爲倉庫的集合,下面的倉庫就是能夠加入到這個集合的元素。

對外能夠只提供一個單獨的url,如上圖顯示爲:http://192.168.1.227:8081/nexus/content/groups/public/

大部分的終端用戶,只須要配置上面這一個單獨的聚合後的url,而不用單獨配置多個倉庫。用戶也不須要知道某個jar包具體來源於maven 中央倉庫,或者是Apache Snapshots,或者是咱們本身添加的其餘倉庫。

這樣的好處在於:若是咱們要新增某個倉庫(如開源中國、阿里雲),客戶端不須要作任何更改,只須要在nexus上將要新增的倉庫加入到對外提供服務的倉庫 group中就能夠。

第二個3rd party,與倒數第一個和第二個倉庫,Releases和Snapshots同樣,類型爲hosted,意思是由nexus本機管理的倉庫。該倉庫用於商業化的,第三方提供的非開源的依賴倉庫,如oracle jdbc driver。

倒數第二個Releases,用於存放開發團隊內部用的正式版的依賴。

倒數第一個Snapshots,用於存放開發團隊內部平常構建的頻率更新較快的依賴包。

Apache Snapshots和Central類型都是proxy,意思是遠端倉庫的代理。前者包含了Apache Software Foundation 發佈的快照版本(這麼翻譯不知道對不對),後者爲Maven中央倉庫,咱們平時maven默認就是鏈接該倉庫。

Central M1 Shadow類型爲virtual,按官方文檔的意思是,只是已有倉庫的一個不一樣呈現方式的映射。有須要能夠參考官方手冊6.2.3節。

3.2 倉庫集合的界面

img

點擊Configuration,能夠看到當前添加到該集合的倉庫列表及順序(優先級高的在上面,可用鼠標拖拽),當咱們新增了倉庫,將會出如今右側的available Repository,添加到左邊便可。

若是有哪一個倉庫不想加入到該集合,也能夠拖拽到右邊來。

3.3使用本地maven客戶端測試nexus是否成功部署

首先複製倉庫集合的repository url,客戶端配置須要用到。

img

配置maven客戶端:

img

打開settings.xml,按照以下步驟修改:

<mirrors>
    <mirror>
    <!--This sends everything else to /public -->
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <url>http://192.168.1.227:8081/nexus/content/groups/public</url>
    </mirror>
</mirrors>
<profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <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>
  </profiles>
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

接下來在ide中測試下(我我的用maven命令行很少,不熟悉,仍是用intelj idea演示吧)

在idea中依次打開File--Settings--搜索Maven--出現以下界面:

img

保證上述幾項指向正在用的maven目錄和配置文件便可。點擊ok,退出。

打開Maven Projects窗口,勾選Profiles中的nexus。

img

隨便新建一個maven工程,在pom中添加一項本地倉庫中沒有的依賴,應該出現以下圖示:(下圖能夠看出,正在去咱們配置的私服下載maven依賴)

img

至此。大致配置完成。

3.3 經過網頁方式將jar包上傳到nexus

在使用Maven管理項目時,如何將jar包上傳到私有倉庫,下面簡單介紹一下上傳方法。

環境:nexus私有庫
步驟以下:

1.登錄已經安裝好的nexus私有倉庫,如圖:

1

2.點擊左邊菜單「Repositories」,選擇右邊列表「3rd party「

2

3.點擊「3rd party」,選擇artifact Upload,以下圖:

3

4.在artifact Upload界面顯示的有GAV Parameter,groupId,artifactId,Version,Packaging等等參數,界面如圖:

5

5.將以上參數填以後,選擇要上傳的jar包,點擊」add artifact「,最後點擊」save「保存按鈕便可,以下圖所示:

5

7

8

說:這種方法只是上傳了jar包。經過maven引用當前jar,不能取得jar的依賴

img

經過 from pom的方式,選擇pom文件,以及jar。經過maven引入jar時,會自動加載jar的依賴

相關文章
相關標籤/搜索