LoginSignup
1
3

More than 5 years have passed since last update.

Nexus Repository OSSをUbuntu 18.04 LTSにインストールする

Posted at

はじめに

この記事は、インストール直後のUbuntu Server 18.04 LTS(以降、Ubuntu)へNexus Repository OSS(以降、Nexus)をインストールした、記録です。
なお、この記事では、VirtualBoxで作ったUbuntuのVM(1コア、メモリ2GB、可変ストレージ50GB)を利用します。

この記事を書くのに使った環境

注意

  • HTTPSじゃない
  • パスワードは初期状態のまま

ここら辺を変えたいという場合は、資料を参考にして、変更が必要です。

手順

0. 準備

0-1. Ubuntuをインストールする

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04 LTS"

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04 LTS
Release:        18.04
Codename:       bionic

0-1. パッケージを最新化する

$ sudo apt -y update && sudo apt -y upgrade

0-2. JREをインストールする

$ sudo apt -y install openjdk-8-jre

ここでは、OpenJRE8を利用する

0-2-1. バージョン

$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.18.04.1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)

1. Nexusを起動するユーザー( nexus )を作成する

$ sudo useradd nexus

2. Nexusをダウンロードし、 /opt に置く

$ export NEXUS_VERSION=3.13.0-01
$ curl -O https://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-${NEXUS_VERSION}-unix.tar.gz
$ tar -zxvf nexus-${NEXUS_VERSION}-unix.tar.gz
$ sudo cp -rf nexus-${NEXUS_VERSION} /opt/
$ sudo cp -rf sonatype-work/ /opt/
$ unset NEXUS_VERSION

コピーしている2つのディレクトリは、以下の意味があります

  • nexus-${NEXUS_VERSION} は、プログラムが格納されているディレクトリ
  • sonatype-work は、データを格納するディレクトリ

3. Nexusの所有者を起動するユーザーに変更する

$ export NEXUS_VERSION=3.13.0-01
$ cd /opt/
$ sudo ln -nfs /opt/nexus-${NEXUS_VERSION}/ /opt/nexus
$ sudo chown -R nexus:nexus nexus-${NEXUS_VERSION}/
$ sudo chown -R nexus:nexus sonatype-work/
$ sudo chown -R nexus:nexus nexus
$ unset NEXUS_VERSION

「バージョン(ここでは、 3.13.0-01)が変わった時の影響範囲がバージョンだけ」になるように、シンボリックリンクを作成しています

3-1. 実行結果

これで、実行するのは /opt/nexus 以下のファイルを指定すれば良くなりました。
バージョンに依存する部分を隠蔽したので、バージョン更新時に楽になります。

$ ls -lh /opt
total 8.0K
lrwxrwxrwx 1 nexus nexus   21 Aug  7 05:53 nexus -> /opt/nexus-3.13.0-01/
drwxr-xr-x 9 nexus nexus 4.0K Aug  7 05:50 nexus-3.13.0-01
drwxr-xr-x 3 nexus nexus 4.0K Aug  7 05:51 sonatype-work

4. Nexusを nexus アカウントで起動する

$ sudo mkdir -p /home/nexus
$ sudo touch /home/nexus/.bashrc
$ sudo echo "NEXUS_HOME=\"/opt/nexus\"" | sudo tee -a /home/nexus/.bashrc > /dev/null
$ sudo chown -R nexus:nexus /home/nexus
$ sudo echo "run_as_user=\"nexus\"" | sudo tee -a /opt/nexus/bin/nexus.rc > /dev/null

5. Nexusを自動起動する設定をおこなう

systemd でNexusを自動起動できるように設定をおこなう

$ sudo mkdir -p /etc/systemd/system/nexus.service.d/
$ sudo touch /etc/systemd/system/nexus.service.d/override.conf
$ sudo echo "[Service]
LimitNOFILE=65536" | sudo tee -a /etc/systemd/system/nexus.service.d/override.conf
$ echo "[Unit]
Description=nexus service
After=network.target

[Service]
Type=forking
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
User=nexus
Restart=on-abort

[Install]
WantedBy=multi-user.target" | sudo tee -a /etc/systemd/system/nexus.service
$ sudo systemctl daemon-reload
$ sudo systemctl enable nexus.service
$ sudo systemctl start nexus.service

6. Nexus実行状況の確認

systemctl status nexus を実行した結果、 Active: active (running) が出力されれば、インストールしたNexusが動作している

$ systemctl status nexus
● nexus.service - nexus service
   Loaded: loaded (/etc/systemd/system/nexus.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/nexus.service.d
           └─override.conf
   Active: active (running) since Tue 2018-08-07 11:25:10 UTC; 8s ago
  Process: 11252 ExecStart=/opt/nexus/bin/nexus start (code=exited, status=0/SUCCESS)
 Main PID: 11420 (java)
    Tasks: 35 (limit: 2321)
   CGroup: /system.slice/nexus.service
           └─11420 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -server -Dinstall4j.jvmDir=/usr/lib/jvm/java-8-open

Aug 07 11:25:10 nexus systemd[1]: Starting nexus service...
Aug 07 11:25:10 nexus nexus[11252]: Starting nexus
Aug 07 11:25:10 nexus systemd[1]: Started nexus service.

7. サービスを利用する

再起動し、 http://localhost:8081/ にアクセスして、Nexusの画面に切り替われば、無事終了

個人的な感想

オンプレミスでデータを保持し続けるWebサービスを立ち上げる場合、DockerよりもVMで作る方が、バージョンアップなどが楽...。

資料

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3