2018年7月13日金曜日

VagrantでpgwebとPostgreSQL10がインストールされた仮想マシン(Ubuntu18.04)を構築する

pgwebはPostgreSQLのwebインターフェイスです。

〇pgwebの画面


〇構築方法
以下のVagrantfileを使用して、pgwebとPostgreSQL10をインストールした仮想マシン(Ubuntu18.04)を構築する事ができます。
仮想マシン構築後、ブラウザからhttp://192.168.55.109:8080/にアクセスします。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/ubuntu-18.04"
  config.vm.hostname = "ub1804pg10pgweb"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "ub1804pg10pgweb"
     vbox.cpus = 2
     vbox.memory = 2048
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.109", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.109", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

# install postgresql
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
apt-get -y install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt-get update
apt-get upgrade
apt-get -y install postgresql-10

echo "listen_addresses='*'" >> /etc/postgresql/10/main/postgresql.conf

#sed -i 's/host.*all.*all.*127.0.0.1/#host    all             all             127.0.0.1/g' /etc/postgresql/10/main/pg_hba.conf

echo "host    all         all         127.0.0.1/32          password" >> /etc/postgresql/10/main/pg_hba.conf
echo "host    all         all         192.168.1.0/24          password" >> /etc/postgresql/10/main/pg_hba.conf
echo "host    all         all         192.168.55.0/24          password" >> /etc/postgresql/10/main/pg_hba.conf

su - postgres << EOF
createdb -T template0 --locale=ja_JP.UTF-8 --encoding=UTF8 dwh
psql -c "
alter user postgres with password 'postgres';
create user dwh with password 'dwh';
grant all privileges on database dwh to dwh;
"
EOF
echo "postgres:postgres" | chpasswd
systemctl restart postgresql.service

# install pgweb
apt-get -y install unzip
wget https://github.com/sosedoff/pgweb/releases/download/v0.9.12/pgweb_linux_amd64.zip
unzip pgweb_linux_amd64.zip
mkdir -p /opt/pgweb
mv pgweb_linux_amd64 /opt/pgweb

cat << EOF > /etc/systemd/system/pgweb.service
[Unit]
Description=pgweb

[Service]
Type=simple
ExecStart=/opt/pgweb/pgweb_linux_amd64 --sessions --bind=0.0.0.0 --listen=8080
WorkingDirectory=/opt/pgweb
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
EOF
systemctl enable pgweb
systemctl start pgweb

echo 'access http://192.168.55.109:8080/'
echo 'user: postgres, password: postgres'
SHELL
end


○関連情報
・pgwebに関する他の記事はこちらを参照してください。

0 件のコメント:

コメントを投稿