當系統越來越龐大複雜,這時候不管是 access log 或是 audit log 就變得相對重要。在雲端分散式系統中,如何整合 log 也變得有更大的需求。以下就來介紹說明如何透過 Stackdriver 把資料收入 GCP 的 Cloud Logging service 中
先安裝相關的 agent
CentOS
curl -sSO https://dl.google.com/cloudagents/add-logging-agent-repo.sh sudo bash add-logging-agent-repo.sh sudo yum install google-fluentd
啟用 Stackdriver agent
sudo systemctl start google-fluentd sudo systemctl enable google-fluentd
編輯相關設定
/etc/google-fluentd/config.d/td-agent.conf
vi /etc/google-fluentd/config.d/td-agent.conf
可以在裡面加上你要監控的 log 目錄
<source> @type tail format apache path /var/log/apache2/access.log tag apache-access </source> <source> @type tail format apache path /var/log/apache2/error.log tag apache-error </source>