Auf dieser Seite wird beschrieben, wie Sie ein Ranger-Schema in Dataproc mit Ranger-Clustern sichern und wiederherstellen.
Hinweise
Erstellen Sie bei Bedarf einen Bucket. Sie benötigen Zugriff auf einen Cloud Storage-Bucket, in dem Sie ein Ranger-Schema speichern und aus dem Sie es wiederherstellen können.
So erstellen Sie einen Bucket:
- In the Google Cloud console, go to the Cloud Storage Buckets page.
- Click Create.
- On the Create a bucket page, enter your bucket information. To go to the next
step, click Continue.
-
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_box
Add label, and specify a
key
and avalue
for your label.
-
In the Choose where to store your data section, do the following:
- Select a Location type.
- Choose a location where your bucket's data is permanently stored from the Location type drop-down menu.
- If you select the dual-region location type, you can also choose to enable turbo replication by using the relevant checkbox.
- To set up cross-bucket replication, select
Add cross-bucket replication via Storage Transfer Service and
follow these steps:
Set up cross-bucket replication
- In the Bucket menu, select a bucket.
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.
-
In the Choose how to store your data section, do the following:
- Select a default storage class for the bucket or Autoclass for automatic storage class management of your bucket's data.
- To enable hierarchical namespace, in the Optimize storage for data-intensive workloads section, select Enable hierarchical namespace on this bucket.
- 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.
-
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 (Data encryption method. ), and select a
- Select any of the options under Data protection that you
want to set for your bucket.
-
In the Get started section, do the following:
- Click Create.
Ranger-Schema sichern
Stellen Sie mit SSH eine Verbindung zum Dataproc-Masterknoten des Clusters mit dem Ranger-Schema her. Führen Sie die Befehle in diesem Abschnitt in der SSH-Terminalsitzung aus, die auf dem Masterknoten ausgeführt wird.
Umgebungsvariablen festlegen
BUCKET_NAME=bucket name \ MYSQL_PASSWORD=MySQL password SCHEMA_FILE=schema filename
Ersetzen Sie Folgendes:
MySQL password: Sie können
/etc/mysql/my.cnf
auf dem Masterknoten des Clusters öffnen, um das MySQL-Passwort zu kopieren.bucket name: Der Name des Cloud Storage-Bucket, in dem das Ranger-Schema gespeichert werden soll.
schema filename: Geben Sie einen Dateinamen ohne die Dateinamenerweiterung
.sql
an. Das Ranger-Schema wird in dieser Datei auf dem Masterknoten gespeichert und dann in bucket name in Cloud Storage gespeichert .
Beenden Sie die Hive-Dienste.
sudo systemctl stop hive-metastore.service sudo systemctl stop hive-server2.service
Änderungen an den Ranger-Schematabellen verhindern
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;
Speichern Sie das Ranger-Schema in einer
.sql
-Datei.mysqldump -u root -p${MYSQL_PASSWORD} ranger > ${SCHEMA_FILE}.sql
Ranger-Berechtigungen zurücksetzen
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;
Starten Sie die Hive- und Ranger-Dienste neu.
sudo systemctl start hive-metastore.service sudo systemctl start hive-server2.service sudo systemctl restart ranger-admin.service sudo systemctl restart ranger-usersync.service
Kopieren Sie das Ranger-Schema nach Cloud Storage.
gcloud storage cp ${SCHEMA_FILE}.sql gs://${BUCKET_NAME}
Ranger-Schema wiederherstellen
Stellen Sie mit SSH eine Verbindung zum Dataproc-Masterknoten des Clusters her, in dem Sie das Clusterschema wiederherstellen. Führen Sie die Befehle in diesem Abschnitt in der SSH-Terminalsitzung aus, die auf dem Masterknoten ausgeführt wird.
Umgebungsvariablen festlegen
BUCKET_NAME=bucket name \ MYSQL_PASSWORD=MySQL password SCHEMA_FILE=schema filename
Ersetzen Sie Folgendes:
MySQL password: Sie können
/etc/mysql/my.cnf
auf dem Masterknoten des Clusters öffnen, um das MySQL-Passwort zu kopieren.bucket name: Der Name des Cloud Storage-Bucket, der das gespeicherte Ranger-Schema enthält.
schema filename: Der Name des Ranger-Schemadateinamens ohne die Dateiendung
.sql
, der in bucket name in Cloud Storage gespeichert ist.
Beenden Sie die Hive-Dienste.
sudo systemctl stop hive-metastore.service sudo systemctl stop hive-server2.service
Änderungen an den Ranger-Schematabellen verhindern
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;
Kopieren Sie die Ranger-Schemadatei
.sql
in Cloud Storage auf den Masterknoten des Clusters.gcloud storage cp ${BUCKET_NAME}/${SCHEMA_FILE}.sql .
Stellen Sie das Ranger-Schema wieder her. Bei diesem Schritt werden die Inhalte des vorhandenen Ranger-Schemas überschrieben.
mysqldump -u root -p${MYSQL_PASSWORD} ranger < ${SCHEMA_FILE}.sql
Ranger-Berechtigungen zurücksetzen
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;
Aktualisieren Sie die Ranger-Konfigurationsdateien. Ändern Sie den Ranger DB-Host in den folgenden Dateien mit den folgenden Attributen in einen neuen Datenbank-Hostnamen:
Datei Attribut ranger-hdfs-security.xml
ranger.plugin.hdfs.policy.rest.url
ranger-yarn-security.xml
ranger.plugin.yarn.policy.rest.url
Starten Sie die Hive- und Ranger-Dienste neu.
sudo systemctl start hive-metastore.service sudo systemctl start hive-server2.service sudo systemctl restart ranger-admin.service sudo systemctl restart ranger-usersync.service