Ranger スキーマをバックアップおよび復元する

このページでは、Ranger クラスタを使用した Dataproc で Ranger スキーマをバックアップして復元する方法について説明します。

始める前に

  1. 必要に応じてバケットを作成します。Ranger スキーマの保存と復元に使用する Cloud Storage バケットにアクセスできる必要があります。

    バケットを作成するには:

    1. In the Google Cloud console, go to the Cloud Storage Buckets page.

      Go to Buckets

    2. Click Create.
    3. On the Create a bucket page, enter your bucket information. To go to the next step, click Continue.
      1. In the Get started section, do the following:
        • Enter a globally unique name that meets the bucket naming requirements.
        • To add a bucket label, expand the Labels section (), click Add label, and specify a key and a value for your label.
      2. In the Choose where to store your data section, do the following:
        1. Select a Location type.
        2. Choose a location where your bucket's data is permanently stored from the Location type drop-down menu.
        3. To set up cross-bucket replication, select Add cross-bucket replication via Storage Transfer Service and follow these steps:

          Set up cross-bucket replication

          1. In the Bucket menu, select a bucket.
          2. In the Replication settings section, click Configure to configure settings for the replication job.

            The Configure cross-bucket replication pane appears.

            • To filter objects to replicate by object name prefix, enter a prefix that you want to include or exclude objects from, then click Add a prefix.
            • To set a storage class for the replicated objects, select a storage class from the Storage class menu. If you skip this step, the replicated objects will use the destination bucket's storage class by default.
            • Click Done.
      3. In the Choose how to store your data section, do the following:
        1. Select a default storage class for the bucket or Autoclass for automatic storage class management of your bucket's data.
        2. To enable hierarchical namespace, in the Optimize storage for data-intensive workloads section, select Enable hierarchical namespace on this bucket.
      4. In the Choose how to control access to objects section, select whether or not your bucket enforces public access prevention, and select an access control method for your bucket's objects.
      5. In the Choose how to protect object data section, do the following:
        • Select any of the options under Data protection that you want to set for your bucket.
          • To enable soft delete, click the Soft delete policy (For data recovery) checkbox, and specify the number of days you want to retain objects after deletion.
          • To set Object Versioning, click the Object versioning (For version control) checkbox, and specify the maximum number of versions per object and the number of days after which the noncurrent versions expire.
          • To enable the retention policy on objects and buckets, click the Retention (For compliance) checkbox, and then do the following:
            • To enable Object Retention Lock, click the Enable object retention checkbox.
            • To enable Bucket Lock, click the Set bucket retention policy checkbox, and choose a unit of time and a length of time for your retention period.
        • To choose how your object data will be encrypted, expand the Data encryption section (), and select a Data encryption method.
    4. Click Create.

Ranger スキーマをバックアップする

  1. SSH を使用して、Ranger スキーマを持つクラスタの Dataproc マスターノードに接続します。このセクションのコマンドは、マスターノードで実行されている SSH ターミナル セッションで実行します。

  2. 環境変数を設定します。

    BUCKET_NAME=bucket name \
      MYSQL_PASSWORD=MySQL password
      SCHEMA_FILE=schema filename
    

    次のように置き換えます。

    • MySQL password: クラスタ マスターノードで /etc/mysql/my.cnf を開いて、MySQL パスワードをコピーできます。

    • bucket name: Ranger スキーマの保存に使用する Cloud Storage バケットの名前。

    • schema filename: ファイル拡張子(.sql)なしでファイル名を指定します。Ranger スキーマは、マスターノードのこのファイルに保存してから、Cloud Storage の bucket name に保存します。

  3. Hive サービスを停止します。

    sudo systemctl stop hive-metastore.service
    sudo systemctl stop hive-server2.service
    

  4. Ranger スキーマ テーブルへの変更を防止します。

    mysql -u root -p${MYSQL_PASSWORD}
    REVOKE ALL PRIVILEGES ON ranger.* from 'rangeradmin'@'localhost';
    GRANT SELECT ON ranger.* TO 'rangeradmin'@'localhost';
    FLUSH PRIVILEGES;
    SHOW GRANTS FOR 'rangeradmin'@'localhost';
    exit;
    
  5. Ranger スキーマを .sql ファイルに保存します。

    mysqldump -u root -p${MYSQL_PASSWORD} ranger > ${SCHEMA_FILE}.sql
    
  6. Ranger 権限をリセットします。

    mysql -u root -p${MYSQL_PASSWORD}
    REVOKE SELECT ON ranger.* from 'rangeradmin'@'localhost';
    GRANT ALL PRIVILEGES ON ranger.* to 'rangeradmin'@'localhost';
    FLUSH PRIVILEGES;
    SHOW GRANTS FOR 'rangeradmin'@'localhost';
    exit;
    
  7. Hive サービスと Ranger サービスを再起動します。

    sudo systemctl start hive-metastore.service
      sudo systemctl start hive-server2.service
      sudo systemctl restart ranger-admin.service
      sudo systemctl restart ranger-usersync.service
    
  8. Ranger スキーマを Cloud Storage にコピーします。

    gcloud storage cp ${SCHEMA_FILE}.sql gs://${BUCKET_NAME}
    

Ranger スキーマを復元する

  1. SSH を使用して、クラスタ スキーマを復元するクラスタの Dataproc マスターノードに接続します。このセクションのコマンドは、マスターノードで実行されている SSH ターミナル セッションで実行します。

  2. 環境変数を設定します。

    BUCKET_NAME=bucket name \
      MYSQL_PASSWORD=MySQL password
      SCHEMA_FILE=schema filename
    

    次のように置き換えます。

    • MySQL password: クラスタ マスターノードで /etc/mysql/my.cnf を開いて、MySQL パスワードをコピーできます。

    • bucket name: 保存された Ranger スキーマを含む Cloud Storage バケットの名前。

    • schema filename: Cloud Storage の bucket name に保存されている Ranger スキーマ ファイルの名前(.sql ファイル拡張子なし)。

  3. Hive サービスを停止します。

    sudo systemctl stop hive-metastore.service
    sudo systemctl stop hive-server2.service
    

  4. Ranger スキーマ テーブルへの変更を防止します。

    mysql -u root -p${MYSQL_PASSWORD}
    REVOKE ALL PRIVILEGES ON ranger.* from 'rangeradmin'@'localhost';
    GRANT SELECT ON ranger.* TO 'rangeradmin'@'localhost';
    FLUSH PRIVILEGES;
    SHOW GRANTS FOR 'rangeradmin'@'localhost';
    exit;
    
  5. Cloud Storage の Ranger スキーマ .sql ファイルをクラスタのマスターノードにコピーします。

    gcloud storage cp ${BUCKET_NAME}/${SCHEMA_FILE}.sql .
    
  6. Ranger スキーマを復元します。このステップでは、既存の Ranger スキーマの内容が上書きされます。

    mysqldump -u root -p${MYSQL_PASSWORD} ranger < ${SCHEMA_FILE}.sql
    
  7. Ranger 権限をリセットします。

    mysql -u root -p${MYSQL_PASSWORD}
    REVOKE SELECT ON ranger.* from 'rangeradmin'@'localhost';
    GRANT ALL PRIVILEGES ON ranger.* to 'rangeradmin'@'localhost';
    FLUSH PRIVILEGES;
    SHOW GRANTS FOR 'rangeradmin'@'localhost';
    exit;
    
  8. Ranger 構成ファイルを更新します。次のプロパティを使用して、次のファイルで Ranger DB ホストを新しいデータベースのホスト名に変更します。

    ファイル プロパティ
    ranger-hdfs-security.xml ranger.plugin.hdfs.policy.rest.url
    ranger-yarn-security.xml ranger.plugin.yarn.policy.rest.url
  9. Hive サービスと Ranger サービスを再起動します。

    sudo systemctl start hive-metastore.service
      sudo systemctl start hive-server2.service
      sudo systemctl restart ranger-admin.service
      sudo systemctl restart ranger-usersync.service