Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  10] [ 0]  / answers: 1 / hits: 19753  / 3 Years ago, sun, june 27, 2021, 6:40:22

I would like to rotate my openvpn logs. How can I accomplish this?


More From » openvpn

 Answers
2

Add the contents of the following to new file /etc/rsyslog.d/20-ovpn.conf. This makes sure that log events sent to rsyslog are handled nicely.



# Create a template for the vpn log location
$template OpenVPN,"/var/log/openvpn/ovpn.log"

# Save log events where the programname starts with ovpn like ovpn-server to the
# location mentioned in the template
:programname, startswith, "ovpn-" -?OpenVPN

# Stop processing ovpn-* log events
:programname, startswith, "ovpn-" ~


Run this command and make sure that there is no output.



grep ^log /etc/openvpn/server.conf


If this command outputs any lines, then your need to go into the config and comment out the log or log-append line. This will trigger the default logging that sends it to syslog.



Finally, create a new file /etc/logrotate.d/ovpn and add the contents below to that file. This will do a weekly rotation or rotate once a log file becomes 100M in size. It will keep 4 weeks and compress everything but that last two.



/var/log/openvpn/*.log {
weekly
size 100M
rotate 4
compress
delaycompress
missingok
notifempty
create 640 syslog adm
}


Restart the rsyslog and then openvpn services to make sure these new configs take. You should see /var/log/openvpn and /var/log/openvpn/ovpn.log get created immediately by rsyslog after openvpn restarts.


[#26134] Tuesday, June 29, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
amelican

Total Points: 162
Total Questions: 116
Total Answers: 108

Location: Guam
Member since Mon, May 29, 2023
12 Months ago
;