[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-19。"],[[["\u003cp\u003eThe Ops Agent is used to collect logs and metrics from your Bare Metal Solution server and send them to Cloud Logging and Cloud Monitoring.\u003c/p\u003e\n"],["\u003cp\u003eBefore installing, ensure your server runs a supported OS (RHEL 7.x/8.x, SLES 12.x/15.x) and has Service Account Credentials for Cloud Logging and Cloud Monitoring.\u003c/p\u003e\n"],["\u003cp\u003eAuthorizing the Ops Agent involves creating a service account, assigning it the Monitoring Metric Writer and Logs Writer roles, and obtaining a JSON key for authentication.\u003c/p\u003e\n"],["\u003cp\u003eTo authorize a service account, you must copy the private key file to \u003ccode\u003e/etc/google/auth/application_default_credentials.json\u003c/code\u003e on the Bare Metal Solution server.\u003c/p\u003e\n"],["\u003cp\u003eThe installation of the Ops Agent is done via a script downloaded from google, and it is started automatically after the installation is complete.\u003c/p\u003e\n"]]],[],null,["# Set up Ops Agent for Bare Metal Solution\n========================================\n\nThe Ops Agent collects logs and metrics on your Bare Metal Solution server. It\nsends your logs to Cloud Logging and your metrics to Cloud Monitoring. To\nlearn more about Ops Agent, see\n[Ops Agent overview](/stackdriver/docs/solutions/agents/ops-agent).\n\nIf you already have an existing OS-level monitoring solution, ensure that you\ncan share data with us in event of an incident where you need our support. If\nyou don't have any such solution or anything else, we recommend that you use\nOps Agent.\n\nBefore you begin\n----------------\n\n- Ensure that your Bare Metal Solution server is running a supported OS. The\n following OSes are supported for Ops Agent:\n\n - RHEL 7.x\n - RHEL 8.x\n - SLES 12.x\n - SLES 15.x\n- Ensure that you have the Service Account Credentials on your\n Bare Metal Solution server that authorize communication with Cloud Logging\n and Cloud Monitoring. If you don't have the required credentials, you must\n [authorize the Ops Agent](#bms-authorize-opsagent-process) before installing it.\n\n- [Enable the services](/service-usage/docs/enable-disable) for both the\n Cloud Logging API and Cloud Monitoring API.\n\nAuthorize the Ops Agent\n-----------------------\n\nBefore installing the Ops Agent, you must ensure that it has the\npermission to send information to Google Cloud. This\npermission is given by using Service Account Credentials that must be\nstored on your Bare Metal Solution server. These credentials serve as\n[Application Default Credentials (ADC)](/docs/authentication/application-default-credentials)\nfor the Ops Agent.\n\nAuthorization refers to the process of determining what permissions an\nauthenticated client has for a set of resources. Google Cloud authorizes\nthe Ops Agent on a Bare Metal Solution server by using ADC.\n\nThe Ops Agent supports ADC that authenticate using a private key from a service\naccount. The key authorizes the key pair on a service account in a project,\nwhich lets you create an access token. The token is then used to provide an\nidentity so that you can interact with Google Cloud APIs on behalf of the\nservice account.\n\nAuthorizing the agent involves the following steps:\n\n1. [Create a service account](#bms-create-service-account).\n2. [Authorize the service account with a private key](#bms-authorize-service-account).\n3. [Authorize the Ops Agent](#bms-authorize-opsagent).\n\nIf you already have the required credentials, you can skip this process and\n[install the Ops Agent](#bms-install-opsagent).\n\n### Create a service account and key\n\nThis section describes how to create a new service account and grant it the\nnecessary roles, and how to update an existing service account if it doesn't\nhave the necessary roles.\n\nTo create a service account, complete the\n[creating a service account](/iam/docs/service-accounts-create) procedures with\nthe following information:\n\n1. Select the same Google Cloud project that contains your Bare Metal Solution server to create the service account.\n2. In the **Role** drop-down menu, select the following roles:\n - **Monitoring** \\\u003e **Monitoring Metric Writer**.\n - **Logging** \\\u003e **Logs Writer**.\n3. Select **JSON** as the **Key type**.\n4. Click **Create**.\n\n When you click **Create** , a file that contains a service account key is\n downloaded to your local system. For more information, see\n [Create and delete service account keys](/iam/docs/keys-create-delete).\n\n| **Note:** Service account keys are a security risk if not managed correctly. You are responsible for the security of the private key and for other operations described by [Best practices for managing service account keys](/iam/docs/best-practices-for-managing-service-account-keys). If you are prevented from creating a service account key, service account key creation might be disabled for your organization. For more information, see [Managing secure-by-default organization resources](/resource-manager/docs/secure-by-default-organizations).\n|\n|\n| If you acquired the service account key from an external source, you must validate it before use.\n| For more information, see [Security requirements for externally sourced credentials\"](/docs/authentication/external/externally-sourced-credentials).\n\nNext, authorize the Ops Agent by using a service account private key.\n\n### Authorize a service account with a private key\n\nTo authorize the Ops Agent by using a service account private key, do\nthe following:\n\n1. Copy the private key file to the following location on your\n Bare Metal Solution server so that the Ops Agent can recognize the\n credentials.\n\n **Warning:** If you already have a credential file, ensure that your new credentials don't overwrite the credentials for your current applications. \n\n /etc/google/auth/application_default_credentials.json\n\n2. Create an environment variable to point to the credentials file on your\n workstation. The following example creates a variable called `CREDS`:\n\n CREDS=\"~/Downloads/\u003cvar translate=\"no\"\u003ePROJECT-NAME\u003c/var\u003e-\u003cvar translate=\"no\"\u003eKEY-ID\u003c/var\u003e.json\"\n\n3. Transfer the service account key to your Bare Metal Solution server.\n\n | **Note:** The following instructions assume that you have a Linux environment on both your local system and your server. If you're using a different environment, consult the documentation from your cloud provider for how to copy the private key file. Ensure that the private key file is in the same location as the `CREDS` variable.\n\n On your local system, use the scp command-line tool.\n 1. Go to the **Servers** page.\n\n [Go to Servers](https://console.cloud.google.com/compute/bareMetalSolution/servers)\n 2. Identify the following information for your server:\n\n - Project ID\n - Server name\n - Location of the server\n 3. On your Bare Metal Solution server, run the following commands:\n\n GOOGLE_APPLICATION_CREDENTIALS=\"/etc/google/auth/application_default_credentials.json\"\n sudo mkdir -p /etc/google/auth\n sudo mv \"$HOME/temp.json\" \"$GOOGLE_APPLICATION_CREDENTIALS\"\n sudo chown root:root \"$GOOGLE_APPLICATION_CREDENTIALS\"\n sudo chmod 0400 \"$GOOGLE_APPLICATION_CREDENTIALS\"\n\n The variable `GOOGLE_APPLICATION_CREDENTIALS` must be visible to the\n Ops Agent process. If your credential file is not in the previously\n listed default location, then in addition to the commands in the preceding\n examples, ensure that\n [`GOOGLE_APPLICATION_CREDENTIALS` is defined](/docs/authentication/set-up-adc-on-premises#wlif-key)\n and visible to the Ops Agent process.\n\n### Authorize the Ops Agent\n\n1. Edit the `/etc/systemd/system.conf` file to add the following information.\n Create the file if it doesn't exist.\n\n DefaultEnvironment=GOOGLE_APPLICATION_CREDENTIALS=\u003cvar translate=\"no\"\u003epath_to_credentials_file\u003c/var\u003e BMS_PROJECT_ID=\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e BMS_LOCATION=\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e BMS_INSTANCE_ID=\u003cvar translate=\"no\"\u003eSERVER_ID\u003c/var\u003e\n\n2. Reload the environment variables.\n\n sudo systemctl daemon-reload\n\n Your Bare Metal Solution server now has the credentials that the Ops Agent\n needs.\n3. On your Bare Metal Solution server, restart the Ops Agent to use the new\n credentials by running the following command:\n\n sudo service google-cloud-ops-agent restart\n\nInstall the Ops Agent\n---------------------\n\nTo install the agent using the command line, do the following:\n\n1. Open a terminal connection to your Bare Metal Solution server using SSH or a\n similar tool and ensure that you have sudo access.\n\n2. Change to a directory for which you have write access. For example, your home\n directory.\n\n3. Download and run the Ops Agent installation script by running the following\n commands:\n\n curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh\n\n sudo REPO_SUFFIX=bms bash add-google-cloud-ops-agent-repo.sh --also-install\n\nAfter the installation is complete, the Ops Agent is started automatically.\n\nWhat's next\n-----------\n\n- Learn about Ops Agent's default and custom configurations. See [Configure the Ops Agent](/stackdriver/docs/solutions/agents/ops-agent/configuration)."]]