Setting Up a Syslog-ng Server on Linux
Introduction
Syslog-ng is a powerful and flexible logging daemon that can be used to collect and manage log data from various sources. This guide will walk you through setting up a syslog-ng server on both RPM-based and APT-based Linux systems. We will also cover how to configure a client to send logs to the syslog-ng server.Prerequisites
- Two Linux computers (one as the server and one as the client)
- Root or sudo access on both machines
Setting Up the Syslog-ng Server
On RPM-Based Systems (e.g., CentOS, Fedora)
- Install syslog-ng:
Code:
sudo yum install syslog-ng
- Configure syslog-ng: Edit the syslog-ng configuration file, usually located at /etc/syslog-ng/syslog-ng.conf. Add the following configuration to receive logs from clients:
Code:
source s_network { tcp(ip(0.0.0.0) port(514)); udp(ip(0.0.0.0) port(514)); };
Code:destination d_messages { file("/var/log/messages"); };
Code:destination d_apache_access { file("/var/log/apache/http-access.log"); };
Code:destination d_apache_error { file("/var/log/apache/http-error.log"); };
Code:log { source(s_network); destination(d_messages); };
Code:log { source(s_network); filter(f_apache_access); destination(d_apache_access); };
Code:log { source(s_network); filter(f_apache_error); destination(d_apache_error); };
- Open firewall ports: Ensure that your firewall allows traffic on port 514 for both TCP and UDP:
Code:
sudo firewall-cmd --add-port=514/tcp --permanent
Code:sudo firewall-cmd --add-port=514/udp --permanent
Code:sudo firewall-cmd --reload
- Enable and start syslog-ng:
Code:
sudo systemctl enable syslog-ng
Code:sudo systemctl start syslog-ng
On APT-Based Systems (e.g., Ubuntu, Debian)
- Install syslog-ng:
Code:
sudo apt-get update
Code:sudo apt-get install syslog-ng
- Configure syslog-ng: Edit the syslog-ng configuration file, usually located at /etc/syslog-ng/syslog-ng.conf. Add the following configuration to receive logs from clients:
Code:
source s_network { tcp(ip(0.0.0.0) port(514)); udp(ip(0.0.0.0) port(514)); };
Code:destination d_messages { file("/var/log/messages"); };
Code:destination d_apache_access { file("/var/log/apache/http-access.log"); };
Code:destination d_apache_error { file("/var/log/apache/http-error.log"); };
Code:log { source(s_network); destination(d_messages); };
Code:log { source(s_network); filter(f_apache_access); destination(d_apache_access); };
Code:log { source(s_network); filter(f_apache_error); destination(d_apache_error); };
- Open firewall ports: Ensure that your firewall allows traffic on port 514 for both TCP and UDP:
Code:
sudo ufw allow 514/tcp
Code:sudo ufw allow 514/udp
Code:sudo ufw reload
- Enable and start syslog-ng:
Code:
sudo systemctl enable syslog-ng
Code:sudo systemctl start syslog-ng
Setting Up the Syslog-ng Client
On RPM-Based Systems
- Install syslog-ng:
Code:
sudo yum install syslog-ng
- Configure syslog-ng: Edit the syslog-ng configuration file on the client, usually located at /etc/syslog-ng/syslog-ng.conf. Add the following configuration to send logs to the server:
Code:
destination d_syslog_server { tcp("syslog-server-ip" port(514)); };
Code:log { source(s_src); filter(f_messages); destination(d_syslog_server); };
Code:log { source(s_src); filter(f_apache_access); destination(d_syslog_server); };
Code:log { source(s_src); filter(f_apache_error); destination(d_syslog_server); };
- Enable and start syslog-ng:
Code:
sudo systemctl enable syslog-ng
Code:sudo systemctl start syslog-ng
On APT-Based Systems
- Install syslog-ng:
Code:
sudo apt-get update
Code:sudo apt-get install syslog-ng
- Configure syslog-ng: Edit the syslog-ng configuration file on the client, usually located at /etc/syslog-ng/syslog-ng.conf. Add the following configuration to send logs to the server:
Code:
destination d_syslog_server { tcp("syslog-server-ip" port(514)); };
Code:log { source(s_src); filter(f_messages); destination(d_syslog_server); };
Code:log { source(s_src); filter(f_apache_access); destination(d_syslog_server); };
Code:log { source(s_src); filter(f_apache_error); destination(d_syslog_server); };
- Enable and start syslog-ng:
Code:
sudo systemctl enable syslog-ng
Code:sudo systemctl start syslog-ng
Conclusion
By following these steps, you can set up a syslog-ng server on both RPM-based and APT-based Linux systems and configure clients to send logs to the server. This setup will help you centralize your log management and make it easier to monitor and analyze log data from multiple sources.
Last edited: