{"id":1576,"date":"2017-03-11T22:36:47","date_gmt":"2017-03-12T02:36:47","guid":{"rendered":"https:\/\/lowtek.ca\/roo\/?p=1576"},"modified":"2017-03-11T22:36:47","modified_gmt":"2017-03-12T02:36:47","slug":"server-upgrade-part-5-rsyslog","status":"publish","type":"post","link":"https:\/\/lowtek.ca\/roo\/2017\/server-upgrade-part-5-rsyslog\/","title":{"rendered":"Server Upgrade Part 5: rsyslog"},"content":{"rendered":"<p>Now that mail is running in a container, logwatch is a lot less interesting because log data is not visible on the host (the container has the logs). One option is to\u00a0map the log files from the container into the host logs, but this might get messy. It seems like a better idea to build out an rsyslog setup to flow logs from the container into the host.<\/p>\n<p>To start with I needed to <a href=\"https:\/\/www.server-world.info\/en\/note?os=Ubuntu_16.04&amp;p=rsyslog\">understand rsyslog<\/a> a <a href=\"https:\/\/vexxhost.com\/resources\/tutorials\/how-to-setup-remote-system-logging-with-rsyslog-on-ubuntu-14-04-lts\/\">bit better<\/a>. Then <a href=\"https:\/\/blog.logentries.com\/2014\/03\/how-to-run-rsyslog-in-a-docker-container-for-logging\/\">I came across a post<\/a> that does pretty much what I&#8217;m trying to accomplish, docker containers sending logs to the host with rsyslog.<\/p>\n<p>Before we configure the container, we need to get our host machine accepting rsyslog input. We&#8217;ll\u00a0need to turn on one of TCP or UDP remote access on the host. I&#8217;ll stick with just TCP for my initial setup.<\/p>\n<p>Edit \/etc\/rsyslog.conf, you&#8217;ll find a comment near the top about TCP reception, uncomment the pair of lines below it<\/p>\n<pre class=\"lang:default decode:true\"># provides TCP syslog reception\r\nmodule(load=\"imtcp\")\r\ninput(type=\"imtcp\" port=\"514\")<\/pre>\n<p>and then restart the service to pick up the new config<\/p>\n<pre class=\"lang:default decode:true \">$ sudo service rsyslog restart<\/pre>\n<p>I&#8217;m using a firewall on the host so I&#8217;ll also\u00a0have to open up the firewall so that things can see this new port. When we do firewall stuff, we should always pause and think about the security implications here.<\/p>\n<p>In my case, the machine that has the port open will be behind my router, which also runs a firewall. So while we&#8217;re punching a hole in the firewall, we actually have another firewall protecting us from the big bad internet.<\/p>\n<pre class=\"lang:default decode:true\">$ sudo ufw allow 514<\/pre>\n<p>At this point our host machine has\u00a0rsyslog running and waiting for traffic. Now let&#8217;s take a look at the mail server container and change it to flow logs to the host rsyslog.<\/p>\n<p>It turns out\u00a0the client is really easy, but you do have to be aware of UDP or TCP. \u00a0Inside the container &#8211; we modify our Dockerfile to create an \/etc\/rsyslog.d\/10-rsyslog.conf file that looks like:<\/p>\n<pre class=\"lang:default decode:true\"># Send all logs to the host\r\n*.* @@myhost:514\r\n<\/pre>\n<p>If you are using TCP, use both @@ &#8211; for UDP just a single @. You also need to use the actual hostname of the host machine (the one we configured with rsyslog just above). We need\u00a0rebuild and\u00a0restart the container to activate the rsyslog configuration.<\/p>\n<p>Back on the host, we see data showing up with the container hostname in the logs. If we look on the host machine in \/var\/log\/syslog we see rsyslogd startup from the mail container:<\/p>\n<pre class=\"lang:default decode:true\">Mar 12 02:17:36 mail rsyslogd: rsyslogd's groupid changed to 104\r\nMar 12 02:17:36 mail rsyslogd: rsyslogd's userid changed to 101\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>There are plenty of other log messages related to the mail container start up as well.<\/p>\n<p>We could\u00a0manually emit some log messages from the client inside the container, by shelling into the container and\u00a0running logger.<\/p>\n<pre class=\"lang:default decode:true\">$ docker exec -it emailcontainer bash\r\nroot@mail:\/# logger testing over tcp<\/pre>\n<p>and in \/var\/log\/syslog on the host we see..<\/p>\n<pre class=\"lang:default decode:true \">Mar 12 02:30:20 mail logger: testing over tcp<\/pre>\n<p>Logwatch should be a lot more interesting<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now that mail is running in a container, logwatch is a lot less interesting because log data is not visible on the host (the container has the logs). One option is to\u00a0map the log files from the container into the host logs, but this might get messy. It seems like a better idea to build &hellip; <a href=\"https:\/\/lowtek.ca\/roo\/2017\/server-upgrade-part-5-rsyslog\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Server Upgrade Part 5: rsyslog&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1576","post","type-post","status-publish","format-standard","hentry","category-computing"],"_links":{"self":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/1576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/comments?post=1576"}],"version-history":[{"count":2,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/1576\/revisions"}],"predecessor-version":[{"id":1578,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/1576\/revisions\/1578"}],"wp:attachment":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/media?parent=1576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/categories?post=1576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/tags?post=1576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}