如何通过Cloudera Manager API永久禁用服务
Absolutely, you can pull this off with the Cloudera Manager (CM) API! The trick is adjusting a persistent service configuration that stops the service from automatically firing up after a CM or server restart. Here's a straightforward, step-by-step guide:
1. Find Your Target Service's ID
First, you need the unique identifier (name) of the service you want to disable. Run this API call to list all services in your cluster:
curl -u "your-cm-username:your-cm-password" "http://<cm-server-host>:7183/api/v40/clusters/<your-cluster-name>/services"
Scan the response for the name field of your target service (e.g., hbase, kafka, solr) — this is the ID you'll use in later commands.
2. Stop the Service (If It’s Running)
Before locking down auto-start, make sure the service is stopped:
curl -u "your-cm-username:your-cm-password" -X POST \ "http://<cm-server-host>:7183/api/v40/clusters/<your-cluster-name>/services/<service-id>/commands/stop"
Wait for the command to finish (you can check the service status via the API if you want to be thorough).
3. Disable Auto-Start Permanently
The key configuration here is service_auto_start — setting this to false guarantees the service won’t launch automatically when CM or the server restarts. Use this PUT request to update the service’s settings:
curl -u "your-cm-username:your-cm-password" -X PUT -H "Content-Type: application/json" \ "http://<cm-server-host>:7183/api/v40/clusters/<your-cluster-name>/services/<service-id>/config" \ -d '{ "items": [ { "name": "service_auto_start", "value": "false" } ] }'
This change gets saved in CM’s database, so it’ll stick even through CM restarts, cluster reboots, or server power cycles.
4. Verify the Configuration (Optional)
To double-check the setting took effect, fetch the service’s current configuration:
curl -u "your-cm-username:your-cm-password" \ "http://<cm-server-host>:7183/api/v40/clusters/<your-cluster-name>/services/<service-id>/config?view=full"
Look for the service_auto_start entry to confirm it’s set to false.
Re-Enabling the Service Later
If you ever want to bring back auto-start functionality, just repeat step 3 but set "value": "true", then start the service with the start command.
内容的提问来源于stack exchange,提问作者user697110

