2018年6月15日金曜日

VagrantでApache Nifi 1.6.0とPostgreSQLがインストールされた仮想マシン(Debian Stretch/9.4)を構築する。

Apache Nifiは様々なデータを処理・分配するためのソフトウェアです。

〇Apache Nifiの画面


〇構築方法
1.以下のVagrantfileを使用して、Apache Nifi 1.6.0とPercona Serverがインストールされた仮想マシン(Debian Stretch/9.4)を構築します。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-9.4"
  config.vm.hostname = "db94nifi160pg"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db94nifi160pg"
     vbox.cpus = 2
     vbox.memory = 2048
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.104", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.104", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
apt-get -y install task-japanese
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
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

# install postgresql
apt-get -y install postgresql-9.6
echo "listen_addresses='*'" >> /etc/postgresql/9.6/main/postgresql.conf

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

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

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
echo "postgres:postgres" | chpasswd
systemctl restart postgresql.service


# install jdbc driver for postgresql
wget https://jdbc.postgresql.org/download/postgresql-42.2.2.jar
mkdir -p /opt/jdbc
cp postgresql-42.2.2.jar /opt/jdbc

# maximum file handles & maximum forked processes
echo '*  hard  nofile  50000' >> /etc/security/limits.conf
echo '*  soft  nofile  50000' >> /etc/security/limits.conf
echo '*  hard  nproc  10000' >> /etc/security/limits.conf
echo '*  soft  nproc  10000' >> /etc/security/limits.conf

echo '*  soft  nproc  10000' >> /etc/security/limits.d/90-nproc

# install java
apt-get -y install openjdk-8-jdk

# download and install Apache Nifi
wget http://ftp.riken.jp/net/apache/nifi/1.6.0/nifi-1.6.0-bin.tar.gz
tar xvfz nifi-1.6.0-bin.tar.gz
mv nifi-1.6.0 /opt

cat << EOF > /etc/systemd/system/nifi.service
[Unit]
Description=Apache Nifi
After=syslog.target network.target

[Service]
Type=forking
ExecStart=/opt/nifi-1.6.0/bin/nifi.sh start
ExecStop=/opt/nifi-1.6.0/bin/nifi.sh stop
KillMode=none

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

echo 'access url -> http://192.168.1.104:8080/nifi/'
SHELL
end

2.DBCPConnectionPoolで、以下のようにパラメータを設定してローカルのPostgreSQLにアクセスします。
Database Connection URL -> jdbc:postgresql://localhost:5432/test
Database Driver Class Name -> org.postgresql.Driver
Database Driver Location(s) -> /opt/jdbc/postgresql-42.2.2.jar
Database User -> test
Password -> test


0 件のコメント:

コメントを投稿