GCP ops agent安装

Ops Agent 是用于从 Compute Engine 实例收集遥测数据的主要代理。通过将日志记录和指标组合到单个代理中,Ops Agent 对日志使用 Fluent Bit(支持高吞吐量日志记录),对指标使用 OpenTelemetry 收集器

参考文档:https://cloud.google.com/stackdriver/docs/solutions/agents/ops-agent/installation

1. 命令安装最新版本:

curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh
sudo bash add-google-cloud-ops-agent-repo.sh --also-install

返回消息:

  google-cloud-ops-agent
0 upgraded, 1 newly installed, 0 to remove and 16 not upgraded.
Need to get 45.2 MB of archives.
After this operation, 143 MB of additional disk space will be used.
Get:1 https://packages.cloud.google.com/apt google-cloud-ops-agent-bullseye-all/main amd64 google-cloud-ops-agent amd64 2.22.0~debian11 [45.2 MB]
Fetched 45.2 MB in 8s (5763 kB/s)                                                                                                                
Selecting previously unselected package google-cloud-ops-agent.
(Reading database ... 53759 files and directories currently installed.)
Preparing to unpack .../google-cloud-ops-agent_2.22.0~debian11_amd64.deb ...
Unpacking google-cloud-ops-agent (2.22.0~debian11) ...
Setting up google-cloud-ops-agent (2.22.0~debian11) ...
Created symlink /etc/systemd/system/multi-user.target.wants/google-cloud-ops-agent.service → /lib/systemd/system/google-cloud-ops-agent.service.
google-cloud-ops-agent  installation succeeded.

2. 控制台安装:

复制安装命令,在机器内部或cloud shell执行。

image

3. 安装后效果:

image

4. 踩坑:

若在控制台安装报错,可根据引导进行排查。

root@wanggaoli-dasan:~# :> agents_to_install.csv && \
echo '"projects/mec-test-344202/zones/asia-northeast1-b/instances/wanggaoli-dasan","[{""type"":""ops-agent""}]"' >> agents_to_install.csv && \
curl -sSO https://dl.google.com/cloudagents/mass-provision-google-cloud-ops-agents.py && \
python3 mass-provision-google-cloud-ops-agents.py --file agents_to_install.csv
See log files in folder: ./google_cloud_ops_agent_provisioning/20221021-081619_347828
2022-10-21T08:16:19.348823Z Processing instance: projects/mec-test-344202/zones/asia-northeast1-b/instances/wanggaoli-dasan.
---------------------Getting output-------------------------
Progress: |==================================================| 100.0% [1/1] (100.0%) completed; [0/1] (0.0%) succeeded; [1/1] (100.0%) failed;
Instance: projects/mec-test-344202/zones/asia-northeast1-b/instances/wanggaoli-dasan fails to run ops-agent. See log file in: ./google_cloud_ops_agent_provisioning/20221021-081619_347828/mec-test-344202_asia-northeast1-b_wanggaoli-dasan.log

SUCCEEDED: [0/1] (0.0%)
FAILED: [1/1] (100.0%)
COMPLETED: [1/1] (100.0%)

root@wanggaoli-dasan:~# cat ./google_cloud_ops_agent_provisioning/20221021-081619_347828/mec-test-344202_asia-northeast1-b_wanggaoli-dasan.log
Installing ops-agent
WARNING: The private SSH key file for gcloud does not exist.
WARNING: The public SSH key file for gcloud does not exist.
WARNING: You do not have an SSH key for gcloud.
WARNING: SSH keygen will be executed to generate a key.
Generating public/private rsa key pair.
Your identification has been saved in /root/.ssh/google_compute_engine
Your public key has been saved in /root/.ssh/google_compute_engine.pub
The key fingerprint is:
SHA256:wBfr/SytA05DrAEfS8ssPwktzxSY+40cfKvu556r3fw root@wanggaoli-dasan
The key's randomart image is:
+---[RSA 3072]----+
|     o  .        |
|    +.+  o       |
|     Xo*o        |
|    = %++.       |
|     @ XS..      |
|      @ *  +     |
|       = o. +    |
|      ..o+.o     |
|     o+=*.+oE    |
+----[SHA256]-----+
ERROR: (gcloud.compute.ssh) Could not fetch resource:
 - Request had insufficient authentication scopes.

解决方案:

需要gcloud授权通过gcloud auth login后,再次执行安装命令即可。

wanggaoli@cloudshell:~ (mec-test-344202)$ :> agents_to_install.csv && echo '"projects/mec-test-344202/zones/asia-northeast1-b/instances/wanggaoli-dasan","[{""type"":""ops-agent""}]"' >> agents_to_install.csv && curl -sSO https://dl.google.com/cloudagents/mass-provision-google-cloud-ops-agents.py && python3 mass-provision-google-cloud-ops-agents.py --file agents_to_install.csv
See log files in folder: ./google_cloud_ops_agent_provisioning/20221021-082008_345601
2022-10-21T08:20:08.347387Z Processing instance: projects/mec-test-344202/zones/asia-northeast1-b/instances/wanggaoli-dasan.
---------------------Getting output-------------------------
Progress: |==================================================| 100.0% [1/1] (100.0%) completed; [1/1] (100.0%) succeeded; [0/1] (0.0%) failed;
Instance: projects/mec-test-344202/zones/asia-northeast1-b/instances/wanggaoli-dasan successfully runs ops-agent. See log file in: ./google_cloud_ops_agent_provisioning/20221021-082008_345601/mec-test-344202_asia-northeast1-b_wanggaoli-dasan.log

SUCCEEDED: [1/1] (100.0%)
FAILED: [0/1] (0.0%)
COMPLETED: [1/1] (100.0%)

版权声明:
作者:WangGaoli
链接:https://wanggaoli.com/3576.html
来源:王高利的个人博客
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>