Sonatype Nexus 私服的安裝(MacOS 篇)

本文是針對 Sonatype Nexus Repository OSS MacOS 綠色版的安裝指引乍钻。

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

當(dāng)前(2020-02-02)最新版為 3.20.1-01铭腕,MacOS 版的直接下載地址為:https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.20.1-01-mac.tgz

官網(wǎng)下載速度在國內(nèi)非常的慢银择,已下載緩存到網(wǎng)盤: https://pan.baidu.com/s/1QeW-RH5YtV8MV3gkDqYKVg 提取碼: v2mi

一)nexus 安裝步驟

  1. 解壓下載的 nexus-3.20.1-01-mac.tgz 到目錄 /path/to/nexus/累舷,得到如下目錄結(jié)構(gòu):

    /path/to/nexus/
    |--nexus-3.20.1-01
    |  |--bin/
    |  |  |--contrib/
    |  |  |--nexus
    |  |  |--nexus.rc
    |  |  |--nexus.vmoptions
    |  |--deploy/...
    |  |--etc/...
    |  |--lib/...
    |  |--public/...
    |  |--system/...
    |  |--...
    |--sonatype-work/
    |  |--nexus3/
    |  |  |--log/
    |  |  |--orient/
    |  |  |  |--plugins/
    |  |  |  |  |--studio.zip
    |  |  |--tmp/
    |  |  |--clean_cache
    

    目錄 /path/to/nexus/ 需根據(jù)自身需要設(shè)置為實(shí)際的磁盤目錄浩考,下同。

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

    $ ln -s /path/to/nexus/nexus-3.20.1-01 /path/to/nexus/nexus-latest
    
  3. /path/to/nexus/nexus-latest/bin 添加到系統(tǒng)環(huán)境變量 PATH 內(nèi)

    # 執(zhí)行如下命令修改 ~/.profile 文件
    $ vi ~/.profile
    
    # 往 ~/.profile 文件添加如下兩行
    export NEXUS_HOME=/path/to/nexus/nexus-latest
    PATH=$PATH:$NEXUS_HOME/bin
    
    # 執(zhí)行如下命令使添加到 ~/.profile 文件的配置生效
    $ source ~/.profile
    
  4. 執(zhí)行 nexus start 啟動 nexus 服務(wù)

    $ nexus start
    Starting nexus
    

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

    $ nexus help
    Usage: /path/to/nexus/nexus-latest/bin/nexus {start|stop|run|run-redirect|status|restart|force-reload}
    

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

    nexus-main-page.png

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

    nexus-change-password.png

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

    nexus-enable-anonymous-access.png
  5. 添加第三方 maven 倉庫的代理配置到 nexus
    以管理員賬號 admin 登陸 nexus袜瞬,打開 Repositories 配置界面,
    默認(rèn)情況下 nexus 僅配置了 maven 中心倉庫的代理 maven-central身堡。
    maven-public 為所有代理倉庫的自定義匯集邓尤,用于控制 nexus 按特定順序分別從配置的第三方倉庫中下載依賴包。
    按照個人習(xí)慣贴谎,我一共配置了如下幾個第三方 maven 倉庫的代理配置:

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

    詳細(xì)可參考官方配置文檔 《Repository Management》

  6. 【可選配置】自定義 nexus 相關(guān)配置參數(shù)(特殊情況才需要修改,一般不建議修改):
    創(chuàng)建文件 /path/to/nexus/sonatype-work/nexus3/etc/nexus.properties赴精,添加如下配置:

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

    參考 /path/to/nexus/nexus-latest/etc/nexus-default.properties 文件內(nèi)的配置參數(shù)進(jìn)行配置即可。

    如果要遷移數(shù)據(jù)目錄 sonatype-work/nexus3 到其它地方蕾哟,需要修改文件 nexus-latest/bin/nexus.vmoptions一忱,這個不建議修改。

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

    $ nexus restart
    
  7. 【可選配置】升級 nexus

    1. 執(zhí)行 nexus stop 命令停止當(dāng)前已啟動的 nexus 服務(wù)
      $ nexus stop
      Shutting down nexus
      Stopped.
      
    2. 下載最新版的 nexus 包谭确,解壓后僅保留 nexus-3.{new-version} 目錄帘营,并移動到 /path/to/nexus/ 目錄下,然后重新創(chuàng)建軟鏈接 nexus-latest逐哈,指向新版本的 nexus 目錄即可:
      $ cd /path/to/nexus
      $ rm nexus-latest
      $ ln -s /path/to/nexus/nexus-3.{new-version} /path/to/nexus/nexus-latest
      
    3. 執(zhí)行 nexus start 重新啟動 nexus 服務(wù)芬迄。

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

較低版本 nexus3 的默認(rèn)管理員賬號是 admin昂秃,密碼是 admin123(如 nexus-3.14)禀梳,如果從較低版本升級到當(dāng)前最新版(如 nexus-3.20)杜窄,使用 admin 賬號首次登陸后,系統(tǒng)會提示你更新密碼一次及設(shè)置是否允許匿名瀏覽算途、下載倉庫中的包塞耕。類似于上面步驟 4 的相關(guān)截圖。

二)maven 相關(guān)配置

  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>
    

    詳細(xì)可參考官方指引文檔 《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 私服扫外。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市廓脆,隨后出現(xiàn)的幾起案子筛谚,更是在濱河造成了極大的恐慌,老刑警劉巖停忿,帶你破解...
    沈念sama閱讀 218,284評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件驾讲,死亡現(xiàn)場離奇詭異,居然都是意外死亡席赂,警方通過查閱死者的電腦和手機(jī)蝎毡,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,115評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來氧枣,“玉大人,你說我怎么就攤上這事别垮”慵啵” “怎么了?”我有些...
    開封第一講書人閱讀 164,614評論 0 354
  • 文/不壞的土叔 我叫張陵碳想,是天一觀的道長烧董。 經(jīng)常有香客問我,道長胧奔,這世上最難降的妖魔是什么逊移? 我笑而不...
    開封第一講書人閱讀 58,671評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮龙填,結(jié)果婚禮上胳泉,老公的妹妹穿的比我還像新娘。我一直安慰自己岩遗,他們只是感情好扇商,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,699評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著宿礁,像睡著了一般案铺。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上梆靖,一...
    開封第一講書人閱讀 51,562評論 1 305
  • 那天控汉,我揣著相機(jī)與錄音笔诵,去河邊找鬼。 笑死姑子,一個胖子當(dāng)著我的面吹牛乎婿,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播壁酬,決...
    沈念sama閱讀 40,309評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼次酌,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了舆乔?” 一聲冷哼從身側(cè)響起岳服,我...
    開封第一講書人閱讀 39,223評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎希俩,沒想到半個月后吊宋,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,668評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡颜武,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,859評論 3 336
  • 正文 我和宋清朗相戀三年璃搜,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片鳞上。...
    茶點(diǎn)故事閱讀 39,981評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡这吻,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出篙议,到底是詐尸還是另有隱情唾糯,我是刑警寧澤,帶...
    沈念sama閱讀 35,705評論 5 347
  • 正文 年R本政府宣布鬼贱,位于F島的核電站移怯,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏这难。R本人自食惡果不足惜舟误,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,310評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望姻乓。 院中可真熱鬧嵌溢,春花似錦、人聲如沸蹋岩。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,904評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽星澳。三九已至疚顷,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背腿堤。 一陣腳步聲響...
    開封第一講書人閱讀 33,023評論 1 270
  • 我被黑心中介騙來泰國打工阀坏, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人笆檀。 一個月前我還...
    沈念sama閱讀 48,146評論 3 370
  • 正文 我出身青樓忌堂,卻偏偏與公主長得像,于是被迫代替她去往敵國和親酗洒。 傳聞我的和親對象是個殘疾皇子士修,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,933評論 2 355

推薦閱讀更多精彩內(nèi)容