はじめに
コマンドjqを利用
$ cat in.json | jq
Ubuntuでjqをインストールする場合は以下。
$ sudo apt-get install jq
CentOSでjqをインストールする場合は以下。
$ sudo yum install jq
Pythonのモジュールを利用
$ cat in.json | python -m json.tool
以下のようにループを利用して必要な台数分の定義を生成するVagrantfileを準備すればよい。
# -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure(2) do |config| MAX_VM_COUNT = 3 (0 ... MAX_VM_COUNT).each do |counter| config.vm.define "node#{counter}" do |server| server.vm.box = "willyhu/ubuntu-16.04-server-amd64" server.vm.network "private_network", ip: "192.168.10.#{counter+100}", netmask: "255.255.255.0" end end end
ここでは、node0 〜 node2の3台のVMを作成し、それぞれにIPアドレス192.168.10.100 〜 192.168.10.102を割り当てている。
Ubuntu 16.04でのVagrant + libvirtの環境構築に苦労したので、手順を残しておく。 VagrantでKVMを扱えるようにするには、vagrant-libvirtというサードパーティ製のプラグインが必要になる。
以下の手順は、KVMの環境は構築済みであることが前提。
$ sudo apt-get install vagrant
apt-getでインストールされるVagrantは1.8.1と若干古い(現時点での最新は1.9.1)が、後述のvagrant-libvirtのインストールに影響があるかもしれないので、これを利用する。
/etc/apt/sources.listのdeb-srcのコメントアウトを外しておく。 コメントアウトを外しておかないと、後述のapt-get build-depの実行に失敗する。
$ sudo sed -i 's/^# deb-src/deb-src/g' /etc/apt/sources.list
$ sudo apt-get update
また、Vagrant 1.8.1にはプラグインのインストールに失敗するバグがあるため、(正式な対処ではないが)以下のように修正する。
$ sudo sed -i'' "s/Specification.all = nil/Specification.reset/" /usr/lib/ruby/vendor_ruby/vagrant/bundler.rb
まず、必要な依存物のインストールなどを行う。
$ sudo apt-get build-dep vagrant ruby-libvirt
$ sudo apt-get install qemu libvirt-bin ebtables dnsmasq
$ sudo apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev
そして、vagrant-libvirtのインストールを行う。
$ vagrant plugin install vagrant-libvirt
boxのホスティングサイトのAtlasから適当なboxを選ぶ。 数は少ないが、キーワード「libvirt」で検索すると、いくつかヒットする。 ここでは、willyhu/ubuntu-16.04-server-amd64を利用することにする。
適当にvagrant-testという作業ディレクトリを作成し、そのディレクトリの中で以下のようにboxを起動する。
$ mkdir vagrant-test
$ cd vagrant-test
$ vagrant init willyhu/ubuntu-16.04-server-amd64
$ vagrant up --provider libvirt
$ vagrant ssh
https://github.com/vagrant-libvirt/vagrant-libvirt
$ vagrant plugin install vagrant-libvirt
Installing the 'vagrant-libvirt' plugin. This can take a few minutes...
/usr/lib/ruby/2.3.0/rubygems/specification.rb:946:in `all=': undefined method `group_by' for nil:NilClass (NoMethodError)
from /usr/lib/ruby/vendor_ruby/vagrant/bundler.rb:275:in `with_isolated_gem'
from /usr/lib/ruby/vendor_ruby/vagrant/bundler.rb:231:in `internal_install'
from /usr/lib/ruby/vendor_ruby/vagrant/bundler.rb:102:in `install'
from /usr/lib/ruby/vendor_ruby/vagrant/plugin/manager.rb:62:in `block in install_plugin'
from /usr/lib/ruby/vendor_ruby/vagrant/plugin/manager.rb:72:in `install_plugin'
from /usr/share/vagrant/plugins/commands/plugin/action/install_gem.rb:37:in `call'
from /usr/lib/ruby/vendor_ruby/vagrant/action/warden.rb:34:in `call'
from /usr/lib/ruby/vendor_ruby/vagrant/action/builder.rb:116:in `call'
from /usr/lib/ruby/vendor_ruby/vagrant/action/runner.rb:66:in `block in run'
from /usr/lib/ruby/vendor_ruby/vagrant/util/busy.rb:19:in `busy'
from /usr/lib/ruby/vendor_ruby/vagrant/action/runner.rb:66:in `run'
from /usr/share/vagrant/plugins/commands/plugin/command/base.rb:14:in `action'
from /usr/share/vagrant/plugins/commands/plugin/command/install.rb:32:in `block in execute'
from /usr/share/vagrant/plugins/commands/plugin/command/install.rb:31:in `each'
from /usr/share/vagrant/plugins/commands/plugin/command/install.rb:31:in `execute'
from /usr/share/vagrant/plugins/commands/plugin/command/root.rb:56:in `execute'
from /usr/lib/ruby/vendor_ruby/vagrant/cli.rb:42:in `execute'
from /usr/lib/ruby/vendor_ruby/vagrant/environment.rb:268:in `cli'
from /usr/bin/vagrant:173:in `<main>'
https://github.com/mitchellh/vagrant/issues/6911
http://stackoverflow.com/questions/36811863/cant-install-vagrant-plugins-in-ubuntu-16-04
CPUがハードウェア仮想化をサポートしているか検査。 以下のコマンドを実行した結果、1以上が表示されればOK。
$ egrep -c '(vmx|svm)' /proc/cpuinfo
$ sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
$ sudo apt-get install virt-manager
ほとんどのJava EEのアプリケーションサーバは、Javaで実装した独自のWebサーバを持っている。 通常はそのWebサーバを利用すればよいのだが、運用の都合などにより、時々前段にApacheを配置することがある。 その時のために、mod_jkを利用してAJPでApacheと各種アプリケーションサーバを連携させる設定方法をメモしておく。
ただ、前段にApacheを配置する場合でも、通常はmod_proxy_httpを利用してHTTPで繋げればよいのだが。。。
OSはUbuntu 16.04 LTSを利用。
$ uname -srvm
Linux 4.4.0-47-generic #68-Ubuntu SMP Wed Oct 26 19:39:52 UTC 2016 x86_64
Javaは導入済みであることを前提とする。
ここでは、お手軽なのでapt-getでインストール。
$ sudo apt-get install apache2 libapache2-mod-jk
次にmod_jkの設定を行うために、jk.confを編集。 念のためバックアップをとった後に編集する。
$ cd /etc/apache2/mods-available
$ sudo cp jk.conf jk.conf.org
$ sudo vi jk.conf
デフォルトのjk.confではまともに動作しないので、余分な項目を削って、以下の内容にしておく。
<IfModule jk_module>
JkWorkersFile /etc/libapache2-mod-jk/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel info
</IfModule>
/etc/apache2/mods-enabledにシンボリックリンクを作成してmod_jkを有効化。
$ cd /etc/apache2/mods-enabled
$ sudo ln -s ../mods-available/jk.load jk.load
$ sudo ln -s ../mods-available/jk.conf jk.conf
現在有効なサイト(デフォルトでは/etc/apache2/sites-enabled/000-default.conf)に、AJPの転送元と転送先のマッピング(JkMount)を追加。
<VirtualHost *:80>
# (略)
JkMount /* ajp13_worker
</VirtualHost>
最後に、Apacheを再起動。
$ sudo systemctl restart apache2
デフォルトでAJPのポート(8009)がオープンされているので、特段の設定は不要でTomcatを起動するだけ。
$ cd /path/to/tomcat
$ bin/catalina.sh start
参考: Apache Tomcat 8 Configuration Reference - The AJP Connector
GlassFish 4のディレクトリに移動後、管理コマンドを利用してドメインの起動とAJPリスナを作成。
$ cd /path/to/glassfish4
$ bin/asadmin start-domain domain1
$ bin/asadmin create-network-listener --protocol http-listener-1 --listenerport 8009 --jkenabled true jk-connector
参考: GlassFish 4.0 Administration Guide
WildFly 10のディレクトリに移動後、WildFlyをバックグラウンドで起動し、そして管理コマンドを利用してAJPリスナを作成。
$ cd /path/to/wildfly10
$ bin/standalone.sh &
$ bin/jboss-cli.sh --connect
[standalone@localhost:9990 /] /subsystem=undertow/server=default-server/ajp-listener=myListener:add(socket-binding=ajp, scheme=http, enabled=true)
参考: WildFly Admin Guide - AJP listeners
Jetty 9はAJPには未対応。 Jetty 8まではAJPに対応していたらしい。
参考: Jetty - Howto - Configure AJP13
http://localhostとhttp://localhost:8080にアクセスして、それぞれ同じ画面(各アプリケーションサーバのトップ画面)が表示されればOK。 ブラウザのキャッシュに引っかからないように、強制リフレッシュ(Google ChromeだとCTRL + F5)したほうがよい。