Sonatype Nexus 私服的安裝(Windows 篇)

本文是針對 Sonatype Nexus Repository OSS Windows 綠色版的安裝指引封断。

注:Nexus Repository OSS 只支持 64 位的 Windows 操作系統(tǒng)牺氨,32 位的不支持影晓。

官方最新版下載地址為:https://www.sonatype.com/nexus-repository-oss
歷史版本下載地址為:https://help.sonatype.com/repomanager3/download/download-archives---repository-manager-3

當前(2020-02-02)最新版為 3.20.1-01奸晴,Windows 版的直接下載地址為:https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.20.1-01-win64.zip

官網下載速度在國內非常的慢魁兼,已下載緩存到網盤: https://pan.baidu.com/s/1QeW-RH5YtV8MV3gkDqYKVg 提取碼: v2mi氯迂。

一)nexus 安裝步驟

  1. 解壓下載的 nexus-3.20.1-01-win64.zip 到目錄 D:\path\to\nexus\屯碴,得到如下目錄結構:

    D:\path\to\nexus\
    |--nexus-3.20.1-01
    |  |--bin\
    |  |  |--contrib\...
    |  |  |--nexus.exe
    |  |  |--nexus.vmoptions
    |  |--deploy\...
    |  |--etc\...
    |  |--jre\...
    |  |--lib\...
    |  |--public\...
    |  |--system\...
    |  |--...
    |--sonatype-work\
    |  |--nexus3\
    |  |  |--log\
    |  |  |--orient\
    |  |  |  |--plugins\
    |  |  |  |  |--studio.zip
    |  |  |--tmp\
    |  |  |--clean_cache
    

    目錄 D:\path\to\nexus\ 需根據自身需要設置為實際的磁盤目錄描睦,下同。

  2. 在與 nexus-3.20.1-01 同級目錄下創(chuàng)建軟鏈接 nexus-latest 并鏈接到此目錄以方便日后的升級

    > cd D:\path\to\nexus\
    > mklink /D nexus-latest nexus-3.20.1-01
    為 nexus-latest <<===>> nexus-3.20.1-01 創(chuàng)建的符號鏈接
    

    mklink 命令需要在以管理員身份打開的 CMD 中才支持导而。

  3. D:\path\to\nexus\nexus-latest\bin 添加到系統(tǒng)環(huán)境變量 Path

    這樣才能保證在命令行中直接使用 nexus 命令。

  4. 執(zhí)行 nexus /start 啟動 nexus 服務

    > nexus /start
    Starting nexus
    

    執(zhí)行 nexus /? 命令可查看可用的命令清單:

    > nexus /?
    Usage: D:\path\to\nexus\nexus-latest\bin\nexus {start|stop|run|run-redirect|status|restart|force-reload}
    

    啟動后訪問 http://localhost:8081 打開 nexus 主頁:

    nexus-main-page.png

    點擊右上角的 Sign in 可以 admin 賬號登陸進行相關配置隔崎,首次點擊 Sign in今艺,會提示管理員 admin 賬號的初始密碼已自動生成在文件 sonatype-work/nexus3/admin.password 內,以此密碼登陸后會繼續(xù)彈出對話框要求修改為新的密碼:

    nexus-change-password.png

    之后會再彈出一個對話框設置是否允許匿名瀏覽爵卒、下載倉庫中的包:(建議勾選)

    nexus-enable-anonymous-access.png
  5. 添加第三方 maven 倉庫的代理配置到 nexus
    以管理員賬號 admin 登陸 nexus虚缎,打開 Repositories 配置界面,
    默認情況下 nexus 僅配置了 maven 中心倉庫的代理 maven-central钓株。
    maven-public 為所有代理倉庫的自定義匯集实牡,用于控制 nexus 按特定順序分別從配置的第三方倉庫中下載依賴包。
    按照個人習慣轴合,我一共配置了如下幾個第三方 maven 倉庫的代理配置:

    nexus-repositories.png
    nexus-maven-public.png

    詳細可參考官方配置文檔 《Repository Management》

  6. 【可選配置】如果要安裝為系統(tǒng)服務,以管理員身份執(zhí)行 nexus /install 即可受葛。

    卸載服務則執(zhí)行 nexus /uninstall

  7. 【可選配置】自定義 nexus 相關配置參數(特殊情況才需要修改题涨,一般不建議修改):
    創(chuàng)建文件 D:\path\to\nexus\sonatype-work\nexus3\etc\nexus.properties,添加如下配置:

    # 自定義 web 訪問端口
    application-port=8081
    
    # 自定義 Web 上下文路徑 (以 / 開頭总滩,不要以 / 結尾)
    nexus-context-path=/
    

    參考 D:\path\to\nexus\nexus-latest\etc\nexus-default.properties 文件內的配置參數進行配置即可纲堵。

    如果要遷移數據目錄 sonatype-work\nexus3 到其它地方,需要修改文件 nexus-latest\bin\nexus.vmoptions闰渔,這個不建議修改席函。

    注:配置文件修改后必須重新啟動 nexus 服務才能生效:

    > nexus /restart
    
  8. 【可選配置】升級 nexus

    1. 執(zhí)行 nexus /stop 命令停止當前已啟動的 nexus 服務:
      > nexus /stop
      Shutting down nexus
      Stopped.
      
    2. 下載最新版的 nexus 包,解壓后僅保留 nexus-3.{new-version} 目錄冈涧,并移動到 D:\path\to\nexus\ 目錄下茂附,然后重新創(chuàng)建軟鏈接 nexus-latest蝌以,指向新版本的 nexus 目錄即可:
      > cd D:\path\to\nexus\
      > md nexus-latest
      > mklink /D nexus-latest nexus-3.{new-version}
      
    3. 執(zhí)行 nexus /start 重新啟動 nexus 服務。

    以上升級方法適用于從 nexus-3.1.0+ 升級到 nexus3 的最新版本何之,官方文檔為《Upgrading Nexus Repository Manager 3.1.0 and Newer

較低版本 nexus3 的默認管理員賬號是 admin跟畅,密碼是 admin123(如 nexus-3.14),如果從較低版本升級到當前最新版(如 nexus-3.20)溶推,使用 admin 賬號首次登陸后徊件,系統(tǒng)會提示你更新密碼一次及設置是否允許匿名瀏覽、下載倉庫中的包蒜危。類似于上面步驟 4 的相關截圖虱痕。

二)maven 相關配置

  1. 配置 maven 使用 nexus 代理所有依賴的下載:
    修改 maven 的用戶配置文件 ~/.m2/settings.xml
    <settings>
      <mirrors>
        <mirror>
          <!--This sends everything else to maven-public -->
          <id>nexus</id>
          <mirrorOf>*</mirrorOf>
          <!-- http://[ip]:[port][/nexus-context-path]/repository/[public-repository-name] -->
          <url>http://localhost:8081/repository/maven-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>
    </settings>
    

    詳細可參考官方指引文檔 《Proxying Maven and npm Quick Start》

  2. 【可選配置】配置將 maven 項目打包發(fā)布到此 nexus 私服:
    1. 修改 ~/.m2/settings.xml 文件,添加如下配置:
      <settings>
        ...
        <servers>
          <!-- account and password for deploy to nexus -->
          <server>
            <id>lan</id>
            <username>admin</username>
            <password>admin123</password>
          </server>
        </servers>
        <profiles>
          <profile>
            <id>lan</id>
            <properties>
              <lan-release-url>http://localhost:8081/repository/maven-releases</lan-release-url>
              <lan-snapshot-url>http://localhost:8081/repository/maven-snapshots</lan-snapshot-url>
            </properties>
          </profile>
        </profiles>
      </settings>
      
    2. 修改 maven 項目的 pom.xml 文件辐赞,添加如下配置:
      <project>
        <profiles>
          <!-- configuration for deploy to nexus repository -->
          <profile>
            <id>lan</id>
            <distributionManagement>
              <repository>
                <id>lan</id>
                <url>${lan-release-url}</url>
              </repository>
              <snapshotRepository>
                <id>lan</id>
                <url>${lan-snapshot-url}</url>
              </snapshotRepository>
            </distributionManagement>
            <build>
              <plugins>
                <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-source-plugin</artifactId>
                </plugin>
                <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-javadoc-plugin</artifactId>
                </plugin>
              </plugins>
            </build>
          </profile>
        </profiles>
      </project>
      

      命令行執(zhí)行 mvn clean deploy -P lan 即可將項目打包發(fā)布到 nexus 私服部翘。

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市响委,隨后出現的幾起案子新思,更是在濱河造成了極大的恐慌,老刑警劉巖赘风,帶你破解...
    沈念sama閱讀 218,386評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件夹囚,死亡現場離奇詭異,居然都是意外死亡邀窃,警方通過查閱死者的電腦和手機荸哟,發(fā)現死者居然都...
    沈念sama閱讀 93,142評論 3 394
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來瞬捕,“玉大人鞍历,你說我怎么就攤上這事》净ⅲ” “怎么了劣砍?”我有些...
    開封第一講書人閱讀 164,704評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長笋轨。 經常有香客問我秆剪,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,702評論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮焕阿,結果婚禮上,老公的妹妹穿的比我還像新娘洁灵。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 67,716評論 6 392
  • 文/花漫 我一把揭開白布徽千。 她就那樣靜靜地躺著苫费,像睡著了一般。 火紅的嫁衣襯著肌膚如雪双抽。 梳的紋絲不亂的頭發(fā)上百框,一...
    開封第一講書人閱讀 51,573評論 1 305
  • 那天,我揣著相機與錄音牍汹,去河邊找鬼铐维。 笑死,一個胖子當著我的面吹牛慎菲,可吹牛的內容都是我干的嫁蛇。 我是一名探鬼主播,決...
    沈念sama閱讀 40,314評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼露该,長吁一口氣:“原來是場噩夢啊……” “哼睬棚!你這毒婦竟也來了?” 一聲冷哼從身側響起解幼,我...
    開封第一講書人閱讀 39,230評論 0 276
  • 序言:老撾萬榮一對情侶失蹤抑党,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后书幕,有當地人在樹林里發(fā)現了一具尸體新荤,經...
    沈念sama閱讀 45,680評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,873評論 3 336
  • 正文 我和宋清朗相戀三年台汇,在試婚紗的時候發(fā)現自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片篱瞎。...
    茶點故事閱讀 39,991評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡苟呐,死狀恐怖,靈堂內的尸體忽然破棺而出俐筋,到底是詐尸還是另有隱情牵素,我是刑警寧澤,帶...
    沈念sama閱讀 35,706評論 5 346
  • 正文 年R本政府宣布澄者,位于F島的核電站笆呆,受9級特大地震影響,放射性物質發(fā)生泄漏粱挡。R本人自食惡果不足惜赠幕,卻給世界環(huán)境...
    茶點故事閱讀 41,329評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望询筏。 院中可真熱鬧榕堰,春花似錦、人聲如沸嫌套。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,910評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至魏蔗,卻和暖如春砍的,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背莺治。 一陣腳步聲響...
    開封第一講書人閱讀 33,038評論 1 270
  • 我被黑心中介騙來泰國打工廓鞠, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人产雹。 一個月前我還...
    沈念sama閱讀 48,158評論 3 370
  • 正文 我出身青樓诫惭,卻偏偏與公主長得像,于是被迫代替她去往敵國和親蔓挖。 傳聞我的和親對象是個殘疾皇子夕土,可洞房花燭夜當晚...
    茶點故事閱讀 44,941評論 2 355

推薦閱讀更多精彩內容