仮想マシン構築後、ブラウザからhttp://192.168.55.103:8082/でH2コンソールにアクセスできます。
Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/debian-9.2"
config.vm.hostname = "db92h2db"
config.vm.provider :virtualbox do |vbox|
vbox.name = "db92h2db"
vbox.cpus = 2
vbox.memory = 2048
vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
end
config.vm.network "private_network", ip: "192.168.55.103", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.103", :netmask => "255.255.255.0"
config.vm.provision "shell", inline: <<-SHELL
# update packages
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
locale-gen ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8
# install java
apt-get -y install openjdk-8-jdk
# download h2 database
apt-get -y install unzip
export h2db=h2-2017-06-10.zip
wget http://www.h2database.com/$h2db
# install h2 database
unzip $h2db
echo 'webAllowOthers = true' > /root/.h2.server.properties
mv h2 /opt
# setup console as service
cat << EOF > /opt/h2/bin/h2env
H2CUSTOMJARS=
EOF
cat << EOF > /etc/systemd/system/h2.service
[Unit]
Description=H2 database
After=syslog.target network.target
[Service]
Type=simple
EnvironmentFile=/opt/h2/bin/h2env
WorkingDirectory=/opt/h2
ExecStart=/usr/bin/java -cp "/opt/h2/bin/h2-1.4.196.jar:\\$H2CUSTOMJARS" org.h2.tools.Console -tcpAllowOthers
ExecStop=/usr/bin/kill -3 \\${MAINPID}
[Install]
WantedBy=multi-user.target
EOF
systemctl enable h2.service
systemctl start h2.service
echo 'access URL: http://192.168.55.103:8082/'
echo 'username: sa default password: sa'
echo 'Driver class: org.h2.Driver'
echo 'JDBC URL: jdbc:h2:tcp://192.168.55.103/~/test'
SHELL
end
〇H2コンソールのスクリーンショット
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。
0 件のコメント:
コメントを投稿