ぺーぺーSEのブログ

備忘録・メモ用サイト。

Nexus入門

Sonatype NEXUS入門。
NEXUSはMavenのパッケージリポジトリサーバ。
今回はOSS版を入れる。

インストール

JDK6以上をあらかじめインストールしておく。
ここからNEXUS OSSをダウンロードして任意の場所(例えば、「C:\nexus」「/data/nexus」)へ展開する。
展開すると2つのディレクトリがでる。

C:\nexus>ls -l
total 0
drwxrwxrwx   1 user     group           0 Jul 14 10:03 nexus-2.11.3-01
drwxrwxrwx   1 user     group           0 Jul 14 10:04 sonatype-work

※UnxUtilsを使用しています。

Linux系の場合は以下のようにバージョンが変わった時用にシンボリックリングの作成とユーザの作成を行う。

$ ln -s nexus-2.11.3-01 nexus # シンボリックリング作成
$ groupadd nexus              # グループ作成
$ useradd nexus -g nexus      # ユーザ作成
$ chown -R nexus. nexus       # nexusディレクトリにnexusユーザの権限付与

起動

bin配下のnexus(もしくはnexus.bat)を実行するとUsageが見れる。

# Windowsの場合
C:\nexus\nexus-2.11.3-01>bin\nexus.bat
Usage: bin\nexus.bat { console : start : stop : restart : install : uninstall }

# Linuxの場合
$/data/nexus/nexus/bin/nexus
Usage: /data/nexus/nexus/bin/nexus { console | start | stop | restart | status | dump }

WindowsLinux共に「nexus(.bat) console」コマンドで標準出力にログをはきつつ起動する。
Linuxの場合は「nexus start」で「logs/wrapper.log」へ標準出力をリダイレクトして起動する。
Windowsの場合は「nexus.bat install」でWindowsサービスとして登録でき、その後「nexus.bat start」で起動できる。
nexus dump」でnexusのスレッドダンプを取得できる。(※NEXUSはJettyで起動している1つのJavaプロセス)
また、Linuxでの起動スクリプトについては以下のページに例がある。

junko.hatenablog.com http://books.sonatype.com/nexus-book/reference/install-sect-service.html

アクセス

デフォルトだと「http://localhost:8081/nexus/」へアクセスすればWeb Consoleが見れる。
管理者権限の「id/password」は「admin/admin123」。

リポジトリ

サイドバーの「Views/Repositories」→「Repository」にデフォルトで以下のようなリポジトリが登録されている。

リポジトリ 説明
Public Repositories 以下のリポジトリへ、1つのURLでアクセスできるようにするグループリポジトリ
3rd party 開発で必要となるサードパーティ製ライブラリ(OJDBC等)を保管するリポジトリ
Central Mavenセントラルリポジトリへのproxyの役割を果たすリポジトリ
Releases 独自で開発したアプリケーションのリリースバージョンの成果物を格納するリポジトリ
Snapshots 独自で開発したアプリケーションのSNAPSHOTバージョンの成果物を格納するリポジトリ

新規で他の外部リポジトリを登録する場合、Typeをproxy、Providerをmaven2で登録するとよい。
※Maven3を使うときもProviderはmaven2でいいっぽい。
以下あたりを登録といたほうがよいかな?

セントラル以外に上記が必要になる場面があるかはわからん。。。

NEXUSサーバの設定

プロキシ設定

NEXUSサーバがプロキシ配下にある場合、Mavenセントラルリポジトリ等に接続するためにプロキシの設定を行う必要がある。

  • Web Consoleから管理者権限でログイン
  • サイドバーの「Administration」→「Server」を選択
  • Default HTTP Proxy Settings(optional)」と「Default HTTPS Proxy Settings(optional,defaults to HTTP Proxy Settings)」を設定

クライアントの設定

独自で構築したNEXUSをクライアントマシン(Maven)から利用するための設定。

クライアントから独自NEXUSへアクセスする設定

■settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings>

  <!-- ミラーとしてアクセスするための設定 -->
  <mirrors>
    <mirror>
      <id>my-nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://[IPorFQDN]/nexus/content/groups/public/</url>
    </mirror>
  </mirrors>
  
  <activeProfiles>
    <activeProfile>my-nexus</activeProfile>
  </activeProfiles>

  <profiles>
    <profile>
      <id>my-nexus</id>
      <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>
  
  <!-- mvn deployする際の認証の設定 -->
  <servers>
    <server>
      <id>releases</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>
    <server>
      <id>snapshots</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>
  </servers>

</settings>

mvn deployを実行する際の認証の設定はsettings.xmlへ行うが、デプロイ先の設定はpom.xmlへ行う。
■pom.xml

<distributionManagement>
  <repository>
    <id>releases</id>
    <url>http://[IPorFQDN]:8081/nexus/content/repositories/releases/</url>
  </repository>
  <snapshotRepository>
    <id>snapshots</id>
    <url>http://[IPorFQDN]:8081/nexus/content/repositories/snapshots/</url>
  </snapshotRepository>
</distributionManagement>

idsettings.xmlserversへ記載したものとそろえること。

参考:
http://books.sonatype.com/nexus-book/index.html http://terasolunaorg.github.io/guideline/5.0.0.RELEASE/ja/Appendix/Nexus.html