Google cloud platform 将启动脚本日志推送到gcp中的单独文件
在GCP中,对于自动推送到Google cloud platform 将启动脚本日志推送到gcp中的单独文件,google-cloud-platform,cloud,startup,logfile,Google Cloud Platform,Cloud,Startup,Logfile,在GCP中,对于自动推送到/var/log/Syslog的ubuntu-startup脚本日志,如果在长时间后需要,我们可能会由于日志轮换而错过这些日志。有没有办法将这些日志重定向到另一个日志文件? 我的启动脚本是一个简单的BASH脚本,具有多个命令,不能将单个命令的输出重定向到文件。 < P>可以考虑这个解决方案: 将启动脚本中的输出重定向到专用 /tmp目录中的启动脚本.log文件 安装stackdriver日志记录agent 为启动脚本.log添加特定配置 然后,您可以通过GCP St
/var/log/Syslog
的ubuntu-startup脚本日志,如果在长时间后需要,我们可能会由于日志轮换而错过这些日志。有没有办法将这些日志重定向到另一个日志文件?
我的启动脚本是一个简单的BASH脚本,具有多个命令,不能将单个命令的输出重定向到文件。 < P>可以考虑这个解决方案:
- 将
启动脚本中的输出重定向到专用
目录中的/tmp
文件启动脚本.log
- 安装
agentstackdriver日志记录
- 为
启动脚本.log添加特定配置
gcloud
命令)浏览日志
GCP日志控制台屏幕截图:
Stackdriver日志记录将只保留日志30天。
对于较长的保留期,您可以轻松创建接收器
,将日志导出到BigQuery表或云存储桶。
查看有关导出日志的官方文档:
启动脚本.sh
:
#! /bin/bash
# install gcp logging agent
curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
sudo bash install-logging-agent.sh
# setup a configuration for startup-script logs only
cat > /etc/google-fluentd/config.d/startup-script-log.conf <<- EOM
<source>
@type tail
# Format 'none' indicates the log is unstructured (text).
format none
# The path of the log file.
path /tmp/startup-script-log.log
# The path of the position file that records where in the log file
# we have processed already. This is useful when the agent
# restarts.
pos_file /var/lib/google-fluentd/pos/startup-script-log.pos
read_from_head true
# The log tag for this log input.
tag startup-script-log
</source>
EOM
# restart logging agent
sudo service google-fluentd restart
# redirect outputs to dedicated startup-script log
exec &>> /tmp/startup-script-log.log
# your startup-script content
# ...
echo "hello the world"
#/bin/bash
#安装gcp日志代理
curl-sSOhttps://dl.google.com/cloudagents/install-logging-agent.sh
sudobash安装-logging-agent.sh
#仅为启动脚本日志设置配置
cat>/etc/google fluentd/config.d/startup-script-log.conf/tmp/startup-script-log.log
#您的启动脚本内容
# ...
回声“世界你好”