〇Apache NiFiの画面
〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False
v 2. インストール対象ホストのユーザやパスワードを環境に合わせてinventoryファイルに記入します
inventory例
[nifi-postgresql]
192.168.1.107
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant
3.inventory、kanboard.ymlを準備し、以下のコマンドを実行します。
ansible-playbook -i inventory nifi-postgresql.yml
nifi-postgresql.yml
- hosts: nifi-postgresql
vars:
- dbname: test
- dbuser: test
- dbpassword: test
tasks:
- name: install epel-release
yum:
name: epel-release
state: present
become: yes
- name: download postgresql repos
get_url:
url: https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
dest: /tmp
become: true
- name: install repos
yum: state=present name=/tmp/pgdg-centos10-10-2.noarch.rpm
become: true
- name: install PostgreSQL
yum: name={{ item }} state=latest enablerepo=epel
with_items:
- postgresql10-server
- postgresql10-devel
- postgresql10-contrib
- python-devel
- python36-devel
- python-pip
become: true
- name: install psycopg2 using pip
pip:
name: "{{ item }}"
state: forcereinstall
with_items:
- psycopg2-binary
become: true
- name: initdb
shell: /usr/pgsql-10/bin/postgresql-10-setup initdb
become: yes
- name: configure postgresql.conf
blockinfile:
dest: /var/lib/pgsql/10/data/postgresql.conf
create: yes
block: |
listen_addresses='*'
become: true
- name: edit pg_hba.conf
replace: dest=/var/lib/pgsql/10/data/pg_hba.conf regexp="host.*all.*all.*127.0.0.1" replace="#host all all 127.0.0.1"
become: true
- name: edit pg_hba.conf
replace: dest=/var/lib/pgsql/10/data/pg_hba.conf regexp="^host.*all.*all.*::1/128.*ident" replace="host all all ::1/128 password"
become: true
- name: configure postgresql.conf
blockinfile:
dest: /var/lib/pgsql/10/data/pg_hba.conf
create: yes
block: |
host all all 127.0.0.1/32 password
host all all 192.168.1.0/24 password
host all all 192.168.55.0/24 password
become: true
- name: enable and start postgresql-10.service
systemd:
daemon_reload: yes
enabled: yes
state: started
name: postgresql-10.service
become: true
- name: create PostgreSQL user
postgresql_user:
name: "{{ dbuser }}"
password: "{{ dbpassword }}"
login_user: postgres
encrypted: yes
become: true
become_user: postgres
- name: create a database
postgresql_db:
name: "{{ dbname }}"
owner: "{{ dbuser }}"
encoding: 'UTF-8'
lc_collate: 'ja_JP.UTF-8'
lc_ctype: 'ja_JP.UTF-8'
template: 'template0'
login_user: postgres
become: true
become_user: postgres
- name: configure limits.conf
blockinfile:
dest: /etc/security/limits.conf
create: yes
block: |
* hard nofile 50000
* soft nofile 50000
* hard nproc 10000
* soft nproc 10000
become: true
- name: Install openjdk
yum: name={{ item }} state=present
with_items:
- java-1.8.0-openjdk
become: true
- name: download connectorJ
get_url:
url: https://jdbc.postgresql.org/download/postgresql-42.2.4.jar
dest: /usr/share/java
become: true
- name: download nifi
get_url:
url: http://ftp.riken.jp/net/apache/nifi/1.7.1/nifi-1.7.1-bin.tar.gz
dest: /opt
become: true
- name: extract nifi
unarchive:
remote_src: yes
src: /opt/nifi-1.7.1-bin.tar.gz
dest: /opt/
become: true
- name: setup systemd
blockinfile:
dest: /etc/systemd/system/nifi.service
create: yes
block: |
[Unit]
Description=Apache Nifi
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/opt/nifi-1.7.1/bin/nifi.sh start
ExecStop=/opt/nifi-1.7.1/bin/nifi.sh stop
KillMode=none
[Install]
WantedBy=multi-user.target
become: true
- name: setup systemd
blockinfile:
dest: /opt/nifi-1.7.1/bin/nifi-env.sh
create: yes
block: |
JAVA_HOME=/usr/lib/jvm/jre-1.8.0
become: true
- name: clean up
file:
state: absent
path: /opt/nifi-1.7.1-bin.tar.gz
become: yes
- name: enable and start nifi.service
systemd:
daemon_reload: yes
enabled: yes
state: started
name: nifi.service
become: true
4.DBCPConnectionPoolで、以下のようにパラメータを設定してローカルのPostgreSQLにアクセスします。
Database Connection -> URL jdbc:postgresql://localhost:5432/test
Database Driver Class Name -> org.postgresql.Driver
Database Driver Location(s) -> /usr/share/java/postgresql-42.2.4.jar
Database User -> test
Password -> test
○関連情報
・Apache NiFiに関する他の記事はこちらを参照してください。
・psycopg2に関する他の記事はこちらを参照してください。
・その他のAnsibleの記事
0 件のコメント:
コメントを投稿