Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 将启动脚本日志推送到gcp中的单独文件_Google Cloud Platform_Cloud_Startup_Logfile - Fatal编程技术网

Google cloud platform 将启动脚本日志推送到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

在GCP中,对于自动推送到
/var/log/Syslog
的ubuntu-startup脚本日志,如果在长时间后需要,我们可能会由于日志轮换而错过这些日志。有没有办法将这些日志重定向到另一个日志文件?
我的启动脚本是一个简单的BASH脚本,具有多个命令,不能将单个命令的输出重定向到文件。

< P>可以考虑这个解决方案:

  • 启动脚本中的输出重定向到专用
    
    /tmp
    目录中的
    启动脚本.log
    文件
  • 安装
    stackdriver日志记录
    agent
  • 启动脚本.log添加特定配置
然后,您可以通过GCP Stackdriver日志控制台(或通过
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
#您的启动脚本内容
# ...
回声“世界你好”