かんがるーさんの日記

最近自分が興味をもったものを調べた時の手順等を書いています。今は Spring Boot をいじっています。

共有ライブラリを管理するために Sonatype の Nexus Repository Manager OSS を使用する ( その26 )( Linux のサーバに Nexus Repository Manager OSS をインストールする )

概要

共有ライブラリを管理するために Sonatype の Nexus Repository Manager OSS を使用する ( その25 )( Windows 版 Nexus 3 インストール手順 ) の続きです。

参照したサイト・書籍

目次

  1. Oracle VM VirtualBox のインストール
  2. Vagrant のインストール
  3. CentOS の仮想サーバを構築する
  4. Unix 版 Nexus Repository Manager OSS をインストールする
  5. JDK をインストールする
  6. 動作確認
  7. サービスとして登録・起動する
  8. ksbysample-library-depend-spring ライブラリをアップロードしてみる
  9. 次回は。。。

手順

Oracle VM VirtualBox のインストール

  1. Download VirtualBox のページの「Windows hosts」リンクをクリックし、VirtualBox-5.1.12-112440-Win.exe をダウンロードします。

    f:id:ksby:20170103193035p:plain

  2. VirtualBox-5.1.12-112440-Win.exe を実行します。

  3. Oracle VM VirtualBox 5.1.12 Setup」ダイアログが表示されます。「Next >」ボタンをクリックします。

  4. 「Custom Setup」画面が表示されます。「Location」を C:\virtualbox\ に変更した後、「Next >」ボタンをクリックします。

    f:id:ksby:20170103194330p:plain

  5. 次の画面が表示されます。チェックの状態を以下の画像の通り変更した後、「Next >」ボタンをクリックします。

    f:id:ksby:20170103194512p:plain

    ※「Create start menu entries」だけチェックを残したのは、仮想サーバの情報を確認するために VirtualBox の管理画面を見たい場合があるためです。

  6. 「Warning: Network Interfaces」画面が表示されます。「Yes」ボタンをクリックします。

  7. 「Ready to Install」画面が表示されます。「Install」ボタンをクリックします。

    インストールの途中で以下のようなダイアログが3回表示されますので都度「インストール」ボタンをクリックします。

    f:id:ksby:20170103194918p:plain

  8. インストールが完了すると「Oracle VM VirtualBox 5.1.12 installation is complete」画面が表示されます。「Start Oracle VM VirtualBox 5.1.12 after installation」のチェックボックスを外した後、「Finish」ボタンをクリックします。

Vagrant のインストール

  1. DOWNLOAD VAGRANT のページの Windows の「Universal (32 and 64-bit)」のリンクをクリックし、vagrant_1.9.1.msi をダウンロードします。

  2. vagrant_1.9.1.msi を実行します。

  3. Vagrant Setup」ダイアログが表示されます。「Next」ボタンをクリックします。

  4. 「End-User License Agreement」画面が表示されます。「I accept the terms in the License Agreement」をチェックした後、「Next」ボタンをクリックします。

  5. Destination Folder」画面が表示されます。C:\vagrant\ に変更した後、「Next」ボタンをクリックします。

  6. 「Ready to install Vagrant」画面が表示されます。「Install」ボタンをクリックします。

  7. インストールが完了すると「Completed the Vagrant Setup Wizard」画面が表示されます。「Finish」ボタンをクリックします。

  8. PC の再起動を求めるダイアログが表示されるので、「YES」ボタンをクリックして再起動します。

CentOS の仮想サーバを構築する

  1. C:\work\vagrant フォルダを作成します。

  2. C:\work\vagrant の下に boxes フォルダを作成します。

  3. Vagrantbox.es のページの以下の画像の赤枠の box ファイルの URL をコピーします。

    f:id:ksby:20170103232741p:plain

  4. コピーした URL をブラウザのアドレスバーにペーストして box ファイル centos-7-x86_64.box をダウンロードし、C:\work\vagrant\boxes の下に保存します。

  5. vagrant box add コマンドでダウンロードした box ファイルを追加します。

    f:id:ksby:20170104112823p:plain

  6. C:\work\vagrant の下に nexus-server フォルダを作成します。

  7. vagrant init コマンドで Vagrantfile を作成します。作成された時点の Vagrantfile は リンク先のその1の内容 です。

    f:id:ksby:20170104114633p:plain

  8. Vagrantfile をエディタで開き リンク先のその2の内容 に変更します。今はメモリを 2GB に増やすだけです。

  9. vagrant up コマンドを実行して仮想サーバを起動します。

    f:id:ksby:20170104120332p:plain f:id:ksby:20170104120502p:plain

  10. 起動した仮想サーバに ssh でアクセスしたいので、ssh.exe が入っている C:\Git\usr\bin を環境変数 PATH に追加します。

  11. vagrant ssh コマンドで仮想サーバに接続できることを確認します。

    f:id:ksby:20170104121041p:plain

Unix 版 Nexus Repository Manager OSS をインストールする

  1. Download Nexus Repository OSS ( http://www.sonatype.com/download-oss-sonatype ) のページにアクセスします。

  2. ページ内の「nexus-3.2.0-01-unix.tar.gz」リンクをクリックしてダウンロードします。

    f:id:ksby:20170104131229p:plain

  3. ダウンロードした nexus-3.2.0-01-unix.tar.gz を C:\work\vagrant\nexus-server に移動します。

  4. vagrant ssh で接続して /opt の下にインストールします。

    f:id:ksby:20170104183419p:plain

JDK をインストールする

  1. nexus run を実行しようとしてみたところエラーメッセージが出ました。/opt/nexus-3.2.0-01/bin の下を見たところ Windows 版にあった jre ディレクトリが存在しませんでしたので、別途インストールします。

    f:id:ksby:20170104212858p:plain

  2. Java SE Development Kit 8 Downloads の「Java SE Development Kit 8u112」の「jdk-8u112-linux-x64.tar.gz」リンクをクリックしてダウンロードします。

  3. ダウンロードした jdk-8u112-linux-x64.tar.gz を C:\work\vagrant\nexus-server に移動します。

  4. 以下のコマンドを実行し、jdk-8u112-linux-x64.tar.gz を展開して /opt/jdk1.8.0_112 を作成した後、/opt/java というシンボリックリンクを作成します。

    f:id:ksby:20170105191147p:plain

  5. /etc/profile.d の下に java.sh を作成し、リンク先の内容 を記述します。記述後は以下のようになります。

    f:id:ksby:20170105191712p:plain

  6. Ctrl+D を押してログアウトした後、再度 vagrant ssh で接続して java -version でバージョン情報が表示されることを確認します。

    f:id:ksby:20170105192526p:plain

動作確認

※動作確認前に Windows 版 nexus のサービスは停止しています。

  1. http://localhost:8081/ でアクセスした時に仮想サーバの nexus の管理画面にアクセスできるよう Vagrantfile を リンク先のその3の内容 に変更します。

  2. vagrant haltvagrant up を実行して仮想サーバを再起動します。

    f:id:ksby:20170105195036p:plain

  3. nexus run を実行します。

    f:id:ksby:20170105195822p:plain

    (.....しばらくログが出力され続けます.....)

    f:id:ksby:20170105195931p:plain

  4. http://localhost:8081/ にアクセスして管理画面が表示されることを確認します。

    f:id:ksby:20170105202616p:plain

  5. Ctrl+C を押して nexus を停止します。

サービスとして登録・起動する

  1. /opt/nexus-3.2.0-01 → /opt/nexus のシンボリックリンクを作成します。

    f:id:ksby:20170105220855p:plain

  2. /etc/systemd/system/ の下に nexus.service を作成し、リンク先の内容 を記述します。

    f:id:ksby:20170105221506p:plain

  3. systemctl コマンドで nexus を起動します。

    f:id:ksby:20170105222140p:plain

  4. http://localhost:8081/ にアクセスして管理画面が表示されることを確認します。

    f:id:ksby:20170105222359p:plain

  5. サーバ起動後に nexus が自動起動されるか確認します。vagrant haltvagrant up を実行して仮想サーバを再起動します。

    f:id:ksby:20170105222713p:plain

  6. vagrant ssh で接続して nexus が起動していることを確認します。また http://localhost:8081/ にアクセスして管理画面が表示されることも確認します。

    f:id:ksby:20170105223018p:plain

ksbysample-library-depend-spring ライブラリをアップロードしてみる

  1. IntelliJ IDEA で ksbysample-library-depend-spring プロジェクトを開きます。

  2. uploadArchives タスクを実行して登録します。BUILD SUCCESSFUL が表示されることが確認できます。

    f:id:ksby:20170105225113p:plain

  3. nexus の管理画面を見ると ksbysample-library-depend-spring ライブラリが登録されていることが確認できます。

    f:id:ksby:20170105225334p:plain

次回は。。。

目次を作成して感想を書いて締める予定です。

ソースコード

Vagrantfile

■その1

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "centos-7-x86_64"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end

■その2

  config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
    # Customize the amount of memory on the VM:
    vb.memory = "2048"
  end

■その3

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "forwarded_port", guest: 8081, host: 8081
  • config.vm.network "forwarded_port", guest: 8081, host: 8081 を追加します。

java.sh

JAVA_HOME=/opt/java
PATH=$PATH:$JAVA_HOME/bin

nexus.service

[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

履歴

2017/01/05
初版発行。