2018年9月1日土曜日

AnsibleでApache NiFiとMariaDBをインストールする(Ubuntu18.04用)

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

〇Apache NiFiの画面


〇インストール方法
1.下準備
~/.ansible.cfgに以下の内容を設定します
[ssh_connection]
pipelining=True
[defaults]
host_key_checking = False

2. インストール対象ホストのユーザやパスワードを環境に合わせてinventoryファイルに記入します

inventory例
[nifi-mariadb]
192.168.1.61

[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-mariadb.yml

nifi-mariadb.yml
- hosts: nifi-mariadb
  vars:
    - dbname: test
    - dbuser: test
    - dbpassword: test
    - dbhost: localhost
    - dbport: 3306
  tasks:
    - name: set password for root
      shell: echo "mariadb-server-10.1 mysql-server/root_password password root" | sudo debconf-set-selections
      become: yes
    - name: set password for root
      shell: echo "mariadb-server-10.1 mysql-server/root_password_again password root" | sudo debconf-set-selections
      become: yes
    - name: install mariadb
      apt:
        name: mariadb-server
        state: present
      become: yes
    - name: enable and start mariadb
      systemd:
        name: mysql
        enabled: yes
        state: started
      become: yes
    - name: Install required software
      apt: name={{ item }} state=present
      with_items:
        - libmysqlclient-dev
        - python-pip
      become: true
    - name: install MySQL-python using pip
      pip:
        name: "{{ item }}"
        state: forcereinstall
      with_items:
        - pip
        - MySQL-python
      become: true
    - name: create db
      mysql_db:
        name={{ dbname }}
        state=present
        encoding=utf8
        login_user=root
      become: true
    - name: create and grant a database user
      mysql_user:
        name={{ dbuser }}
        password={{ dbpassword }}
        priv="test.*:ALL"
        state=present
      become: true
    - name: download connectorJ
      get_url:
        url: https://downloads.mariadb.com/Connectors/java/connector-java-2.2.6/mariadb-java-client-2.2.6.jar
        dest: /usr/share/java
      become: true
    - 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
      apt: name={{ item }} state=present
      with_items:
        - openjdk-8-jdk
      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: 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で、以下のようにパラメータを設定してローカルのMariaDBにアクセスします。
Database Connection -> URL jdbc:mariadb://localhost/test
Database Driver Class Name -> org.mariadb.jdbc.Driver
Database Driver Location(s) -> /usr/share/java/maradb-java-client-2.2.6.jar
Database Userr -> test
Password -> test


0 件のコメント:

コメントを投稿