啟用 Edge-router.log 的記錄檔輪替功能

您目前查看的是 Apigee Edge 說明文件。
前往 Apigee X 說明文件
info

記錄檔輪替機制旨在簡化系統管理作業,因為這類系統會產生大量記錄檔。可自動輪替、壓縮、移除及郵寄記錄檔。

在 Edge for Private Cloud 中,每個 Apigee 元件的部分主要記錄檔都設定了預設的輪替機制。

舉例來說,在 Router 元件上,下列檔案會使用預設的輪替機制設定:

  • /opt/apigee/var/log/edge-router/logs/system.log
  • /opt/apigee/var/log/edge-router/logs/events.log
  • /opt/apigee/var/log/edge-router/logs/startupruntimeerrors.log
  • /opt/apigee/var/log/edge-router/logs/configurations.log
  • /opt/apigee/var/log/edge-router/logs/transactions.log

不過,Apigee 元件中有某些記錄檔並未設定預設輪替。在 Apigee 元件 Router edge-router.log 檔案中,其中一個檔案預設未設定記錄檔輪替。

您可以使用 logrotatelogbacklog4j 等不同公用程式/架構啟用記錄檔輪替功能。本文說明如何使用 logrotatecrontab,為 /opt/apigee/var/log/edge-router/edge-router.log 檔案設定記錄檔輪替。

事前準備

在路由器上啟用 edge-router.log 的記錄輪替功能

本節說明如何為 Edge 路由器上的/opt/apigee/var/log/edge-router/edge-router.log 記錄啟用記錄輪替。

下列步驟說明如何為 edge-router.log 檔案啟用記錄輪替功能。

  1. 在編輯器中開啟 Router 電腦上的 /opt/apigee/edge-router/logrotate/logrotate.conf 檔案。如果檔案不存在,請建立檔案。例如:

    vi /opt/apigee/edge-router/logrotate/logrotate.conf
    
  2. 在檔案中新增類似下方的程式碼片段:
    /opt/apigee/var/log/edge-router/edge-router.log {
        missingok
        copytruncate
        rotate 5
        size 10M
        compress
        delaycompress
        notifempty
        nocreate
        sharedscripts
        }
  3. 儲存變更。
  4. 使用下列指令開啟 Apigee 使用者的 crontab
    sudo crontab -u apigee -e
    
  5. 在 Apigee 使用者的 crontab 中新增下列 cron 工作:
    0 0 * * * nice -n 19 ionice -c3 /usr/sbin/logrotate -f /opt/apigee/edge-router/logrotate/logrotate.conf
  6. 儲存 crontab,並在下次執行 Cron 工作時監控記錄輪替作業。

在路由器上驗證 edge-router.log 的記錄輪替

  1. 排定的 cron 工作執行完畢後,系統就會輪替記錄檔。在上述範例中,系統已排定 Cron 工作每天凌晨 00:00 執行,以輪替 edge-router.log 檔案。
  2. 前往 /opt/apigee/var/log/edge-router/ 目錄,確認 edge-router.log 檔案已旋轉。

    記錄檔清單範例:

    ls -ltrh | grep 'edge-router'
    
    -rw-r--r--. 1 apigee apigee 6.0K Feb 16 00:00 edge-router.log.1.gz
    -rw-r--r--. 1 apigee apigee 3.0K Feb 16 01:23 edge-router.log

    上述輸出內容表示 edge-router.log 檔案已輪替並儲存為 GZ 檔案。

  3. 如果沒有看到 edge-router.log 檔案正在記錄輪替,請確認您已正確按照「 在路由器上為 edge-router.log 啟用記錄輪替」一文中的所有步驟操作。如果遺漏任何步驟,請再次正確執行所有步驟。
  4. 如果還是無法讓記錄輪替正常運作,請與 Apigee Edge 支援團隊聯絡。