1.1.3.1. 環境構築・データ匿名化⾃動実⾏を設定する

Terraform側の実行操作

  1. リソース作成サーバーにアクセスします。
    「cd ”作業ディレクトリ”」を実行し、設定ファイルがあるディレクトリまで移動します。
  2. 初回実行の場合は「terraform init」を実行し、作業ディレクトリを一度初期化します。
    以降は設定ファイルに変更を行った場合などに実行します。
    #  terraform init
    Initializing the backend...
    
    Initializing provider plugins...
    - Reusing previous version of nttcom/ecl from the dependency lock file
    - Using previously-installed nttcom/ecl v1.11.2
    
    Terraform has been successfully initialized!
    
    You may now begin working with Terraform. Try running "terraform plan" to see
    any changes that are required for your infrastructure. All Terraform commands
    should now work.
    
    If you ever set or change modules or backend configuration for Terraform,
    rerun this command to reinitialize your working directory. If you forget, other
    commands will detect it and remind you to do so if necessary.
    
  3. 「terraform apply」を実行します。
    設定内容の確認が表示されるので、問題なければ「yes」と入力しリソースの作成を開始します。
    #  terraform apply
    
    Terraform used the selected providers to generate the following execution plan.
    Resource actions are indicated with the following symbols:
      + create
    
    Terraform will perform the following actions:
    
      # ecl_compute_instance_v2.boot-from-volume will be created
      + resource "ecl_compute_instance_v2" "boot-from-volume" {
          + access_ip_v4        = (known after apply)
          + all_metadata        = (known after apply)
          + availability_zone   = "zone1-groupb"
          + config_drive        = false
          + flavor_id           = "2CPU-8GB"
          + flavor_name         = (known after apply)
          + id                  = (known after apply)
          + image_id            = (known after apply)
          + image_name          = (known after apply)
          + name                = "linuxdvsv02"
          + power_state         = "active"
          + region              = (known after apply)
          + stop_before_destroy = false
    
          + block_device {
              + boot_index            = 0
              + delete_on_termination = true
              + destination_type      = "volume"
              + source_type           = "volume"
              + uuid                  = (known after apply)
          }
    
          + network {
              + access_network = false
              + fixed_ip_v4    = "172.16.20.25"
              + mac            = (known after apply)
              + name           = (known after apply)
              + port           = (known after apply)
              + uuid           = "※使用するロジカルネットワークのID"
            }
        }
    
      # ecl_compute_volume_v2.volume_1 will be created
      + resource "ecl_compute_volume_v2" "volume_1" {
          + attachment        = (known after apply)
          + availability_zone = "zone1-groupb"
          + id                = (known after apply)
          + image_id          = "※使用するOSのID"
          + metadata          = (known after apply)
          + name              = "linuxdvsv02_root_vol"
          + region            = (known after apply)
          + size              = 500
          + volume_type       = (known after apply)
        }
    
    Plan: 2 to add, 0 to change, 0 to destroy.
    
    Do you want to perform these actions?
      Terraform will perform the actions described above.
      Only 'yes' will be accepted to approve.
    
      Enter a value: yes
    
    ecl_compute_volume_v2.volume_1: Creating...
    ecl_compute_volume_v2.volume_1: Still creating... [10s elapsed]
    ecl_compute_volume_v2.volume_1: Still creating... [20s elapsed]
    ecl_compute_volume_v2.volume_1: Still creating... [30s elapsed]
    ecl_compute_volume_v2.volume_1: Still creating... [40s elapsed]
    ecl_compute_volume_v2.volume_1: Still creating... [50s elapsed]
    ecl_compute_volume_v2.volume_1: Still creating... [1m0s elapsed]
    ecl_compute_volume_v2.volume_1: Still creating... [1m10s elapsed]
    ecl_compute_volume_v2.volume_1: Still creating... [1m20s elapsed]
    ecl_compute_volume_v2.volume_1: Still creating... [1m30s elapsed]
    ecl_compute_volume_v2.volume_1: Still creating... [1m40s elapsed]
    ecl_compute_volume_v2.volume_1: Still creating... [1m50s elapsed]
    ecl_compute_volume_v2.volume_1: Still creating... [2m0s elapsed]
    ecl_compute_volume_v2.volume_1: Still creating... [2m10s elapsed]
    ecl_compute_volume_v2.volume_1: Still creating... [2m20s elapsed]
    ecl_compute_volume_v2.volume_1: Creation complete after 2m21s [id=※作成されたルートボリュームのID]
    ecl_compute_instance_v2.boot-from-volume: Creating...
    ecl_compute_instance_v2.boot-from-volume: Still creating... [10s elapsed]
    ecl_compute_instance_v2.boot-from-volume: Creation complete after 14s [id=※作成された仮想サーバーのID]
    
    Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
    

作成したサーバーの初期設定

  1. 検証DBサーバーにSDPFクラウド/サーバーからアクセスします。
    初回ログインを実行します。
    rootのパスワード変更を求められますので任意のパスワードに変更します。
  2. Ansibleからのリモートアクセス用ユーザーを追加します。
    「useradd ※リモートアクセス用ユーザー名」を実行しユーザー作成後、「passwd ※リモートアクセス用ユーザーのパスワード」を実行しパスワードを設定します。
  3. ソフトウェアインストールを行うためのyum疎通設定を行います。
    「nmtui」を実行し利用するネットワークアダプタのdnsに指定のdnsサーバーを設定します。
    本手順では「8.8.8.8」を設定しています。
  4. 「systemctl restart NetworkManager」を実行し、ネットワーク設定を更新します。
  5. SSH接続設定を行います。
    「vi /etc/ssh/sshd_config」を実行し、設定ファイルを開きます。
    本手順ではパスワード認証でログインできるよう設定し、rootでのログイン制限を行います。
    #  vi /etc/ssh/sshd_config
     PasswordAuthentication no→yes
     PermitRootLogin yes→no
    
  6. 「systemctl restart sshd」を実行しSSH接続設定を更新します。
  7. Ansibleからのリモートアクセス用ユーザーに権限設定を行います。
    「visudo -f /etc/sudoers.d/"リモートアクセスユーザー名"」を実行し設定ファイルを開きます。
    リモートアクセス用の権限設定とPostgreSQL操作時の権限設定を行います。
    ファイルを保存後、適用が完了します。
    #  visudo -f /etc/sudoers.d/※リモートアクセス用ユーザー
     ※リモートアクセス用ユーザー ALL=(root) NOPASSWD:/usr/bin/dnf,/user/bin/yum,/usr/bin/sh
     ※リモートアクセス用ユーザー ALL=(postgres) NOPASSWD:ALL
    

操作対象との接続設定

  1. 検証DBサーバーにアクセスします。
    Ansibleを実行するユーザーにて「ssh-keygen」を実行し、公開鍵を生成します。
  2. 生成した公開鍵を操作対象にコピーします。
     # ssh-copy-id -i .ssh/id_rsa.pub ※検証DBサーバーの接続用ユーザー@172.16.20.25
    
    /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/id_rsa.pub"
     The authenticity of host '172.16.20.25 (172.16.20.25)' can't be established.
     ECDSA key fingerprint is SHA256:*******************************************.
     Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
     /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
     /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
     ※検証DBサーバーの接続用ユーザー@172.16.20.25's password:
    
     Number of key(s) added: 1
    
     Now try logging into the machine, with:   "ssh '※検証DBサーバーの接続用ユーザー@172.16.20.25'"
     and check to make sure that only the key(s) you wanted were added.
    
  3. 「ssh ※検証DBサーバーの接続用ユーザー@172.16.20.25」を実行し、接続できることを確認します。

Ansible側の実行操作

  1. 自動実行化サーバーにアクセスします。
    「cd /etc/ansible/」を実行し設定ファイルがあるパスまで移動します。
  2. 「ansible-playbook -i hosts playbook.yml」を実行し検証DBサーバーにPostgreSQLの導入~テーブル設定とtasokarenaのデータ匿名化処理を行います。
    #PLAY [db_server] ********************************************************************
    
    TASK [Gathering Facts] **************************************************************
    ok: [172.16.20.25]
    
    TASK [PostgreSQL : インストール実行] ********************************************************
    ok: [172.16.20.25]
    
    TASK [PostgreSQL : Postgresqlの初期セットアップ] *********************************************
    ok: [172.16.20.25]
    
    TASK [PostgreSQL : サービスの自動起動設定] *****************************************************
    ok: [172.16.20.25]
    
    TASK [PostgreSQL : サービスの起動] *********************************************************
    ok: [172.16.20.25]
    
    TASK [PostgreSQL : 初期設定] ************************************************************
    ok: [172.16.20.25]
    
    TASK [PostgreSQL : 初期設定] ************************************************************
    ok: [172.16.20.25]
    
    TASK [PostgreSQL : 初期設定後再起動] ********************************************************
    ok: [172.16.20.25]
    
    TASK [PostgreSQL : 接続ユーザー作成] *********************************************************
    ok: [172.16.20.25]
    
    TASK [PostgreSQL : データベースの作成] *******************************************************
    ok: [172.16.20.25]
    
    TASK [PostgreSQL : テーブル作成] **********************************************************
    ok: [172.16.20.25]
    
    PLAY [tasokarena_server] ***************************************************************
    
    TASK [Gathering Facts] **************************************************************
    ok: [172.16.20.23]
    
    TASK [tasokarena : 匿名化実行] ***********************************************************
    ok: [172.16.20.23]
    
    PLAY RECAP **************************************************************************
    172.16.20.23               : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
    172.16.20.25               : ok=11   changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
    
  3. 検証DBサーバーに直接アクセスもしくは外部ツールなどを用いてPostgreSQLの導入と検証DBサーバーに匿名化したデータがインポートされていることを確認します。