En esta página se explica cómo crear una copia de seguridad y restaurar un esquema de Ranger en clústeres de Dataproc con Ranger.
Antes de empezar
Crea un segmento si es necesario. Debes tener acceso a un segmento de Cloud Storage, que usarás para almacenar y restaurar un esquema de Ranger.
Para crear un segmento, sigue estas instrucciones:
- 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.
Crear una copia de seguridad de un esquema de Ranger
Usa SSH para conectarte al nodo maestro de Dataproc del clúster con el esquema de Ranger. Ejecuta los comandos de esta sección en la sesión de terminal SSH que se esté ejecutando en el nodo maestro.
Define las variables de entorno.
BUCKET_NAME=bucket name \ MYSQL_PASSWORD=MySQL password SCHEMA_FILE=schema filename
Haz los cambios siguientes:
MySQL password: puedes abrir
/etc/mysql/my.cnf
en el nodo maestro del clúster para copiar la contraseña de MySQL.bucket name: nombre del segmento de Cloud Storage que se usará para almacenar el esquema de Ranger.
schema filename: especifica un nombre de archivo sin la extensión de nombre de archivo
.sql
. El esquema de Ranger se guarda en este archivo del nodo maestro y, a continuación, en bucket name en Cloud Storage .
Detener los servicios de Hive.
sudo systemctl stop hive-metastore.service sudo systemctl stop hive-server2.service
Evita que se hagan cambios en las tablas de esquema de 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;
Guarda el esquema de Ranger en un archivo
.sql
.mysqldump -u root -p${MYSQL_PASSWORD} ranger > ${SCHEMA_FILE}.sql
Restablecer los privilegios de 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;
Reinicia los servicios de Hive y 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
Copia el esquema de Ranger en Cloud Storage.
gcloud storage cp ${SCHEMA_FILE}.sql gs://${BUCKET_NAME}
Restaurar un esquema de Ranger
Usa SSH para conectarte al nodo maestro de Dataproc del clúster en el que vas a restaurar el esquema del clúster. Ejecuta los comandos de esta sección en la sesión de terminal SSH que se esté ejecutando en el nodo maestro.
Define las variables de entorno.
BUCKET_NAME=bucket name \ MYSQL_PASSWORD=MySQL password SCHEMA_FILE=schema filename
Haz los cambios siguientes:
MySQL password: puedes abrir
/etc/mysql/my.cnf
en el nodo maestro del clúster para copiar la contraseña de MySQL.bucket name: nombre del segmento de Cloud Storage que contiene el esquema de Ranger guardado.
schema filename: nombre del archivo de esquema de Ranger, sin la extensión
.sql
, guardado en bucket name en Cloud Storage.
Detener los servicios de Hive.
sudo systemctl stop hive-metastore.service sudo systemctl stop hive-server2.service
Evita que se hagan cambios en las tablas de esquema de 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;
Copia el archivo de esquema de Ranger
.sql
de Cloud Storage en el nodo maestro del clúster.gcloud storage cp ${BUCKET_NAME}/${SCHEMA_FILE}.sql .
Restaura el esquema de Ranger. En este paso se sobrescribe el contenido del esquema de Ranger.
mysqldump -u root -p${MYSQL_PASSWORD} ranger < ${SCHEMA_FILE}.sql
Restablecer los privilegios de 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;
Actualiza los archivos de configuración de Ranger. Cambia el host de la base de datos de Ranger por el nombre de host de una nueva base de datos en los siguientes archivos con las siguientes propiedades:
Archivo Propiedad ranger-hdfs-security.xml
ranger.plugin.hdfs.policy.rest.url
ranger-yarn-security.xml
ranger.plugin.yarn.policy.rest.url
Reinicia los servicios de Hive y 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