openvpn 日誌輪轉

openvpn 日誌輪轉

我嘗試每月輪換 OpenVPN 日誌檔案。問題似乎是簡單地重命名檔案並不能解決問題。資料仍然寫入舊文件(這表示日誌檔案保持開啟狀態並且日誌記錄仍寫入舊文件物件)。

所以現在我編寫了一個腳本,在每個月初更新指向新日誌檔案位置的符號連結後重新啟動 openvpn。

但這個腳本似乎有錯誤,有時無法正確啟動伺服器(tun0 有時會關閉)。

所以我想問一下你們中是否有人知道在 OpenVPN 中實現日誌輪轉的更好方法?

編輯:我正在使用 Debian Squeeze,並且我的重啟腳本在停止和啟動伺服器之間已經休眠了 5ovpn

答案1

有兩種方法可以處理這種情況。理想的方式是讓 logrotate 透過訊號或透過指令重新啟動進程來通知進程postrotate。另一種方法是使用copytruncate.該copytruncate方法應該適合您的情況。這是文檔中的描述:

   copytruncate
          Truncate  the  original log file in place after creating a copy,
          instead of moving the old log file and optionally creating a new
          one,  It  can be used when some program can not be told to close
          its logfile and thus might continue writing (appending)  to  the
          previous log file forever.  Note that there is a very small time
          slice between copying the file and truncating it, so  some  log-
          ging  data  might be lost.  When this option is used, the create
          option will have no effect, as the old log file stays in  place.

答案2

登入系統日誌的解決方法怎麼樣?

請參閱(中的用法--daemon [progname](或--syslog [progname])man openvpnhttp://openvpn.net/index.php/open-source/documentation/manuals/65-openvpn-20x-manpage.html

相關內容