Cette page explique comment sauvegarder et restaurer un schéma Ranger sur Dataproc avec des clusters Ranger.
Avant de commencer
Créez un bucket si nécessaire. Vous devez avoir accès à un bucket Cloud Storage, que vous utiliserez pour stocker et restaurer un schéma Ranger.
Pour créer un 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.
Sauvegarder un schéma Ranger
Utilisez SSH pour vous connecter au nœud maître Dataproc du cluster avec le schéma Ranger. Exécutez les commandes de cette section dans la session de terminal SSH exécutée sur le nœud maître.
Définir des variables d'environnement.
BUCKET_NAME=bucket name \ MYSQL_PASSWORD=MySQL password SCHEMA_FILE=schema filename
Remplacez les éléments suivants :
MySQL password: vous pouvez ouvrir
/etc/mysql/my.cnf
sur le nœud maître du cluster pour copier le mot de passe MySQL.bucket name: nom du bucket Cloud Storage à utiliser pour stocker le schéma Ranger.
schema filename: spécifiez un nom de fichier, sans l'extension de nom de fichier
.sql
. Le schéma Ranger est enregistré dans ce fichier sur le nœud maître, puis dans bucket name dans Cloud Storage .
Arrêtez les services Hive.
sudo systemctl stop hive-metastore.service sudo systemctl stop hive-server2.service
Empêcher les modifications apportées aux tables de schéma 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;
Enregistrez le schéma Ranger dans un fichier
.sql
.mysqldump -u root -p${MYSQL_PASSWORD} ranger > ${SCHEMA_FILE}.sql
Réinitialisez les droits 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;
Redémarrez les services Hive et 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
Copiez le schéma Ranger dans Cloud Storage.
gcloud storage cp ${SCHEMA_FILE}.sql gs://${BUCKET_NAME}
Restaurer un schéma Ranger
Utilisez SSH pour vous connecter au nœud maître Dataproc du cluster dans lequel vous allez restaurer le schéma du cluster. Exécutez les commandes de cette section dans la session de terminal SSH exécutée sur le nœud maître.
Définir des variables d'environnement.
BUCKET_NAME=bucket name \ MYSQL_PASSWORD=MySQL password SCHEMA_FILE=schema filename
Remplacez les éléments suivants :
MySQL password: vous pouvez ouvrir
/etc/mysql/my.cnf
sur le nœud maître du cluster pour copier le mot de passe MySQL.bucket name: nom du bucket Cloud Storage contenant le schéma Ranger enregistré.
schema filename: nom du nom de fichier du schéma Ranger, sans l'extension de nom de fichier
.sql
, enregistré dans bucket name dans Cloud Storage.
Arrêtez les services Hive.
sudo systemctl stop hive-metastore.service sudo systemctl stop hive-server2.service
Empêcher les modifications apportées aux tables de schéma 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;
Copiez le fichier
.sql
du schéma Ranger dans Cloud Storage vers le nœud maître du cluster.gcloud storage cp ${BUCKET_NAME}/${SCHEMA_FILE}.sql .
Restaurez le schéma Ranger. Cette étape écrase le contenu du schéma Ranger existant.
mysqldump -u root -p${MYSQL_PASSWORD} ranger < ${SCHEMA_FILE}.sql
Réinitialisez les droits 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;
Mettez à jour les fichiers de configuration de Ranger. Remplacez l'hôte de la base de données Ranger par un nouveau nom d'hôte de base de données dans les fichiers suivants avec les propriétés suivantes:
Fichier Propriété ranger-hdfs-security.xml
ranger.plugin.hdfs.policy.rest.url
ranger-yarn-security.xml
ranger.plugin.yarn.policy.rest.url
Redémarrez les services Hive et 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