To anyone that knows me, it should come as no surprise that I am a huge fan of Puppet. The ease of use is, in my opinion, unparalleled among configuration management systems. In fact, Puppet is my provisioner of choice for Vagrant, as well as for both my personal and professional servers.
While Puppet is insanely useful for configuration management and consistency, it can get a bit tedious figuring out how to set up each individual package. One good example is setting up log aggregation using Loggly.
Setting up Loggly on the syslog level is incredibly easy, thanks to the official Loggly Puppet module. To install the Loggly Puppet module, first log into your Puppet Master server and navigate to your Puppet modules directory:
Then, install the official module using the following command
After you’ve installed the Loggly module, you have to configure your server nodes to utilize the new module. First, open up your nodes module for editing (this can vary based on server configuration):
Within your nodes manifest file, add the following code to one of your server nodes:
Note: Remember to set to your own personal Loggly token. This token can be found under Source Setup > Customer Tokens within your Loggly dashboard
What the previous block of code does is sets up Loggly log aggregation of rsyslog on the designated servers.
Once you’ve completed the basic Loggly syslog setup, the next step will be to set up log aggregation for your various services. In the following examples, we will cover how to set up PHP and Apache log aggregation; however, the same flow can be followed to set up log aggregation for other services as well.
Apache Log Aggregation
Unfortunately, the Loggly Puppet module doesn’t have more advanced configuration options, so we’ll have to manually setup the Apache syslog configuration. Using Puppet’s `file` type, we can setup the proper file to automatically pipe Apache logs to Loggly using syslog. To do this, put the following block of code in the same node that the original Loggly setup was put in above:
What the above block of code does is ensures that `/etc/rsyslog.d/21-apache.conf` is configured as per the recommended Loggly setup. It is worth noting that, while I am using a `content` parameter to configure the file for the purposes of this demonstration, the proper way to manage this file would be to utilize the Puppet File Server.
PHP Log Aggregation
After we’ve set up our Apache log aggregation, setting up our PHP log aggregation is even easier. Much like the Apache setup, the details of the PHP setup can be found within the Loggly documentation. To send our PHP logs to Loggly, all we have to do is save our PHP logs to syslog. To do this, put the following block of code in your Puppet nodes manifest:
While I obviously haven’t gone over how to aggregate all of your application logs in Loggly, the two examples above should give you a good idea on easily it can be done using Puppet. When setting up aggregation for your other applications, the single most useful thing I can recommend for you to do is to follow the great examples provided by Loggly’s own Support Center.