鍍金池/ 教程/ Linux/ Nexus 安裝和配置
Linux 下常用壓縮文件的解壓、壓縮
  • 1.
Maven 安裝和配置
  • 1.
CentOS 網(wǎng)絡設置
  • 1.
  • 1.
  • 1.
TeamCity 安裝和配置
Zsh 入門
  • 1.
  • 1.
Bash 其他常用命令
Bash 常用命令
  • 1.
  • 1.
  • 1.
Ubuntu 介紹
Ubuntu 網(wǎng)絡相關設置問題
Nginx 安裝和配置
  • 1.
  • 1.
  • 1.
  • 1.
Linux-Tutorial
Nexus 安裝和配置
  • 1.
黑客入侵檢查
Yum 下載安裝包及對應依賴包
  • 1.
  • 1.
Tomcat 8 安裝和配置、優(yōu)化
  • 1.
Ubuntu 安裝和分區(qū)

Nexus 安裝和配置

Nexus 安裝

  • Nexus 安裝

    • 官網(wǎng):http://www.sonatype.org/nexus/
    • 官網(wǎng)下載:http://www.sonatype.org/nexus/archived/
    • 此時(20160207) Nexus 最新版本為:2.12.0-01
    • JDK 要求是 JDK 7,官網(wǎng)要求 7u6 或之后版本,包括 JDK 8
    • 官網(wǎng)幫助說明 1:http://books.sonatype.com/nexus-book/2.11/reference/install.html
    • 官網(wǎng)幫助說明 2:http://books.sonatype.com/sonatype-clm-book/html/clm-book/installation-configuration.html
    • 我個人習慣 /opt 目錄下創(chuàng)建一個目錄 setups 用來存放各種軟件安裝包;在 /usr 目錄下創(chuàng)建一個 program 用來存放各種解壓后的軟件包,下面的講解也都是基于此習慣
    • 我個人已經(jīng)使用了第三方源:EPEL、RepoForge,如果你出現(xiàn) yum install XXXXX 安裝不成功的話,很有可能就是你沒有相關源,請查看我對源設置的文章
    • 壓縮包下載(由于國內(nèi)網(wǎng)絡的原因不排除你下載不了):wget http://download.sonatype.com/nexus/oss/nexus-2.12.0-01-bundle.tar.gz
    • 如果地址下載不了,那是因為你需要開 VPN,你也可以選擇降低要求下載 2.11.4-01 版本:http://pan.baidu.com/s/1mgSNJtA

      • 解壓壓縮包:tar zxvf nexus-2.11.4-01-bundle.tar.gz
        • 解壓出來有兩個文件夾:
        • 這是程序目錄:nexus-2.11.4-01
        • 這是倉庫目錄:sonatype-work
      • 移到目錄到我的安裝目錄下:mv nexus-2.11.4-01/ /usr/program/
      • 進入安裝目錄:cd /usr/program/
      • 把目錄名字改為更好看點:mv nexus-2.11.4-01/ nexus2.11.4/
      • 編輯系統(tǒng)配置文件:vim /etc/profile
      • 在文件的尾巴增加下面內(nèi)容:

          # Nexus
          NEXUS_HOME=/usr/program/nexus2.11.4
          export NEXUS_HOME
          RUN_AS_USER=root
          export RUN_AS_USER
      • 刷新配置:source /etc/profile
      • 由于目錄 sonatype-work 以后是做倉庫用的,會存儲很多 jar,所以這個目錄一定要放在磁盤空間大的區(qū)內(nèi),目前我們還沒第一次啟動 Nexus,所以這里還是空文件
        • 我個人習慣把這類目錄放在 /opt 下,所以你要特別注意,下面有內(nèi)容對這個文件夾進行操作的都是基于 opt 目錄的:mv /opt/setup/sonatype-work/ /opt/
        • 設置配置文件:vim /usr/program/nexus2.11.4/conf/nexus.properties
          • 把文件中該值:nexus-work=${bundleBasedir}/../sonatype-work/nexus
          • 改為:nexus-work=/opt/sonatype-work/nexus
      • 默認情況下如果你的 JDK 等系統(tǒng)變量設置好的是無需編輯 Nexus 的配置文件,但是這里還是給大家一下配置文件路徑:vim /usr/program/nexus2.11.4/bin/jsw/conf/wrapper.conf
      • 開放防火墻端口:
        • 添加規(guī)則:sudo iptables -I INPUT -p tcp -m tcp --dport 8081 -j ACCEPT
        • 保存規(guī)則:sudo /etc/rc.d/init.d/iptables save
        • 重啟 iptables:sudo service iptables restart
    • 測試安裝結果:
      • 啟動 Nexus:/usr/program/nexus2.11.4/bin/nexus start
      • 查看啟動日志:tail -200f /usr/program/nexus2.11.4/logs/wrapper.log
      • 關閉 Nexus:/usr/program/nexus2.11.4/bin/nexus stop
      • 訪問:http://192.168.0.110:8081/nexus
      • 登錄賬號密碼:
        • 賬號密碼:admin
        • 密碼:admin123

Nexus 配置

  • 修改默認端口:vim /usr/program/nexus2.11.4/conf/nexus.properties,修改該值:application-port=8081
  • 下載遠程中央庫的索引到服務器
    • http://wiki.jikexueyuan.com/project/linux-in-eye-of-java/images/Nexus-Install-And-Settings-a-1.jpg" alt="Nexus 配置" />
    • 如上圖標注 4 所示,把默認是 False 改為 True
    • http://wiki.jikexueyuan.com/project/linux-in-eye-of-java/images/Nexus-Install-And-Settings-a-2.gif" alt="Nexus 配置" />
    • 如上圖 gif 所示,創(chuàng)建任務開始進行索引下載。需要特別提醒的是,如果你的私服是虛擬機,那得保證你分配的硬盤足夠大,別像我一樣吝嗇只給 10 G(現(xiàn)在還剩下 1.9 G),結果報:設備上沒有空間
  • 項目上配置鏈接連接私服(下面內(nèi)容涉及到 maven 的基礎知識,請自行私下學習):
    • 對項目獨立設置:
      • 打開項目的 pom.xml 文件:
      • 添加下面內(nèi)容:
          <repositories>
              <repository>
                  <id>Nexus</id>
                  <name>虛擬機-192.168.0.110-Nexus</name>
                  <url>http://192.168.0.110:8081/nexus/content/groups/public/</url>
              </repository>
          </repositories>
    • 對全局配置進行設置:
      • 打開 maven 的 settings.xml 文件:
      • 添加下面內(nèi)容:
          <mirrors>
              <mirror>
                  <id>YouMeekNexus</id>
                  <name>YouMeek Nexus</name>
                  <mirrorOf>*</mirrorOf>
                  <url>http://192.168.0.110:8081/nexus/content/groups/public/</url>
              </mirror>
          </mirrors>

持續(xù)集成自動構建后發(fā)布到 Nexus 上

  • 在 Maven 的 settings.xml 加上連接服務器信息:
<!--設置私庫認證信息,用戶名和密碼我就用默認的,如果你們有權限控制的需求可以創(chuàng)建對應的一些賬號-->  
<servers>  
    <server>  
        <id>nexus-releases</id>  
        <username>admin</username>  
        <password>admin123</password>  
    </server>  
    <server>  
        <id>nexus-snapshots</id>  
        <username>admin</username>  
        <password>admin123</password>  
    </server>  
</servers>  
  • 在項目的 pom.xml 文件加上:
<!-- nexus-releases nexus-snapshots 與 Maven 的配置文件 settings.xml 中 server 下的 id 對應 -->  
<distributionManagement>  
    <repository>  
        <id>nexus-releases</id>  
        <name>Nexus Releases Repository</name>  
        <url>http://192.168.0.110:8081/nexus/content/repositories/releases/</url>  
    </repository>  
    <snapshotRepository>  
        <id>nexus-snapshots</id>  
        <name>Nexus Snapshots Repository</name>  
        <url>http://192.168.0.110:8081/nexus/content/repositories/snapshots/</url>  
    </snapshotRepository>  
</distributionManagement>

Nexus 手動更新索引文件

  • 手動更新索引
    • 關閉 Nexus:/usr/program/nexus2.11.4/bin/nexus stop
    • 命令:cd /opt/sonatype-work/nexus/indexer/central-ctx
      • 刪除里面默認的文件:rm -rf *
    • 訪問官網(wǎng)索引:http://repo.maven.apache.org/maven2/.index/
      • 下載文件:nexus-maven-repository-index.gzwget http://repo.maven.apache.org/maven2/.index/nexus-maven-repository-index.gz
      • 下載文件:nexus-maven-repository-index.propertieswget http://repo.maven.apache.org/maven2/.index/nexus-maven-repository-index.properties
      • 下載索引解壓工具:wget https://repo1.maven.org/maven2/org/apache/maven/indexer/indexer-cli/5.1.1/indexer-cli-5.1.1.jar
      • 執(zhí)行解壓命令(該命令執(zhí)行需要4分鐘左右):java -jar indexer-cli-5.1.0.jar -u nexus-maven-repository-index.gz -d ./
      • 刪除解壓前文件:rm -rf indexer-cli-5.1.0.jar nexus-maven-repository-index.gz nexus-maven-repository-index.properties
      • 重啟服務:/usr/program/nexus2.11.4/bin/nexus start

資料

上一篇:下一篇: