〇H2 Databaseのコンソール画面
〇構築方法
以下のVagrantfileを使用して、H2 Databaseがインストールされた仮想マシン(Ubuntu18.04)を構築する事ができます。
Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/ubuntu-18.04"
config.vm.hostname = "ub1804h2dbadoptopenjdk11"
config.vm.network :public_network, ip:"192.168.1.103"
config.vm.provider :virtualbox do |vbox|
vbox.name = "ub1804h2dbadoptopenjdk11"
vbox.cpus = 2
vbox.memory = 2048
end
config.vm.provision "shell", inline: <<-SHELL
apt-get update
export DEBIAN_FRONTEND=noninteractive
apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
apt-get -y install language-pack-ja
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
apt-get update
# install AdoptOpenJDK11
cd /opt
wget https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.3%2B7/OpenJDK11U-jdk_x64_linux_hotspot_11.0.3_7.tar.gz
tar xvfz OpenJDK11U-jdk_x64_linux_hotspot_11.0.3_7.tar.gz
cat << EOF > /etc/profile.d/jdk.sh
JAVA_HOME=/opt/jdk-11.0.3+7
PATH=\\$PATH:\\$JAVA_HOME/bin
EOF
# download h2 database
apt-get -y install unzip
export h2db=h2-2019-03-13.zip
wget http://www.h2database.com/$h2db
# install h2 database
unzip $h2db
echo 'webAllowOthers = true' > /root/.h2.server.properties
/opt/jdk-11.0.3+7/bin/java -cp /opt/h2/bin/h2-1.4.199.jar org.h2.tools.Shell -url "jdbc:h2:/opt/test" -user sa -password sa -driver org.h2.Driver -sql "create table test (testid int);"
# setup console as service
cat << EOF > /opt/h2/bin/h2env
JAVA_HOME=/opt/jdk-11.0.3+7
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=/opt/jdk-11.0.3+7/bin/java -cp "/opt/h2/bin/h2-1.4.199.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.1.103:8082/'
echo 'username: sa default password: sa'
echo 'Driver class: org.h2.Driver'
echo 'JDBC URL: jdbc:h2:/opt/test'
init 5
SHELL
end
〇関連情報
・プロジェクトWebサイト
https://www.h2database.com/html/main.html
・H2 Databaseに関する他の記事はこちらを参照してください。
0 件のコメント:
コメントを投稿