2020年4月7日火曜日

VagrantでNode-RedとPostgreSQL12をインストールした仮想マシン(Debian Buster/10)を構築する

Node-Redを使用してフロー図による開発を行うことができます。

〇Node-Redの画面
〇構築方法
以下のVagrantfileで、Node-RedとPostgreSQL12をインストールした仮想マシン(Debian Buster/10)を構築する事ができます。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-10"
  config.vm.hostname = "db10node12noderedpg12"
config.vm.network "public_network", ip:"192.168.1.103", :netmask => "255.255.255.0"
config.vm.network "private_network", ip: "192.168.55.103", :netmask => "255.255.255.0"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db10node12noderedpg12"
     vbox.gui = true
     vbox.cpus = 2
     vbox.memory = 2048
  end
  config.vm.provision "shell", inline: <<-SHELL
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
apt-get -y install task-japanese gawk
sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
update-locale LANG=ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
timedatectl set-timezone Asia/Tokyo

# 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 -y install postgresql-12

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

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

systemctl restart postgresql.service
su - postgres << EOF
createdb -T template0 --locale=ja_JP.UTF-8 --encoding=UTF8 test
psql -c "
alter user postgres with password 'postgres';
create user test with password 'test';
grant all privileges on database test to test;
"
EOF
export PGPASSWORD=test
psql -h localhost -d test -U test -c "
create table messages (message_id integer not null, message varchar(100));
insert into messages values (1, 'hello world.');
insert into messages values (2, 'test message.');
"
EOF
echo "postgres:postgres" | chpasswd
systemctl restart postgresql.service

# install nodejs
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

# install Node-Red and Node-Red-Dashboard
sudo apt-get -y install build-essential
npm init --yes
npm install -g --unsafe-perm node-red
npm install -g node-red-dashboard
npm install -g node-red-contrib-postgres-multi

mkdir -p /root/.node-red
cat << EOF > /etc/systemd/system/node-red.service
[Unit]
Description=Node-Red
[Service]
Environment="NODE_OPTIONS=--max-old-space-size=128"
Environment="NODE_RED_OPTIONS=-v"
ExecStart=/usr/bin/node $NODE_OPTIONS /usr/lib/node_modules/node-red/red.js $NODE_RED_OPTIONS
WorkingDirectory=/root/.node-red/
User=root
Group=root
Restart=on-failure
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target
EOF
systemctl enable node-red.service
systemctl start node-red.service

echo 'access to http://192.168.1.103:1880 or http://192.168.1.103:1880/ui'

SHELL
end

0 件のコメント:

コメントを投稿