{"id":1349,"date":"2019-02-19T17:47:07","date_gmt":"2019-02-19T17:47:07","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw93\/?p=1349"},"modified":"2019-03-07T20:13:15","modified_gmt":"2019-03-07T20:13:15","slug":"running-nagios-as-a-system-service-on-rancheros","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw93\/index.php\/2019\/02\/19\/running-nagios-as-a-system-service-on-rancheros\/","title":{"rendered":"Running Nagios as a System Service on RancherOS"},"content":{"rendered":"<p>Nagios is a fantastic monitoring tool, and I wanted to see if I could<br \/>\nget the agent to run as a system container on RancherOS, in order to<br \/>\nmonitor the host and any Docker containers running on it. It turned out<br \/>\nto be incredibly easy. In this blog post, I\u2019ll walk through how to<br \/>\nlaunch the Nagios agent as system container in RancherOS. Specifically,<br \/>\nI\u2019ll use two vagrant boxes to cover:<\/p>\n<ol>\n<li>Provisioning a server with the Rancher control plane<\/li>\n<li>Adding a second server running Rancher OS<\/li>\n<li>Installing a Nagios agent as system container on the second server<\/li>\n<li>Connecting the Nagios agent to the Nagios management server<\/li>\n<\/ol>\n<h2>System Containers in RancherOS<\/h2>\n<p>First, for anyone who isn\u2019t familiar with RancherOS, it is a minimal<br \/>\ndistribution of Linux designed specifically to run Docker. RancherOS<br \/>\nruns a Docker daemon as PID 1, a role typically occupied by the init<br \/>\nsystem or systemd in most distributions. This daemon runs essential<br \/>\nsystem services like SSH, syslog or NTP as containers, and is called<br \/>\nsystem docker.<\/p>\n<p>A second Docker daemon, called user docker, is launched as a<br \/>\ncontainer. This is where any new containers started by the user are<br \/>\ncreated, as well as containers placed by Rancher or other management<br \/>\nservices.<\/p>\n<p>To give the Nagios agent access to all of the data from the server, as<br \/>\nwell as the system and user containers, it should run in the system<br \/>\ndocker instance. I will run this setup in 2 Vagrant virtual machines.<\/p>\n<p><strong>Set up Rancher<\/strong><\/p>\n<p>Even though we could monitor RancherOS with Nagios directly, I\u2019m going<br \/>\nto set up Rancher in this deployment to manage the containers we create.<br \/>\nThe Rancher team provides a Vagrantfile to run RancherOS in a VM here:<br \/>\n<a href=\"https:\/\/github.com\/rancher\/os-vagrant\">https:\/\/github.com\/rancher\/os-vagrant<\/a> and<br \/>\nanother Vagrantfile for Rancher here:<br \/>\n<a href=\"https:\/\/github.com\/rancher\/rancher]\">https:\/\/github.com\/rancher\/rancher<\/a><br \/>\nBut, since I want to have both in one Vagrant setup, I merged both<br \/>\nVagrantfiles into one and added the option to run multiple RancherOS<br \/>\ninstances in one.<\/p>\n<p>You can find my new Vagrant file here:<br \/>\n[<a href=\"https:\/\/github.com\/buster\/rancher-tutorial\">https:\/\/github.com\/buster\/rancher-tutorial<\/a>]{.c10}<\/p>\n<p>The first step (after installing Vagrant, of course) is to clone this<br \/>\nrepository and edit the Vagrantfile to match your IP addresses in the<br \/>\nlines:<\/p>\n<p># The number of VMs will be added to the following string,<br \/>\n# so Rancher will be on 192.168.0.200, the first RancherOS instance on 192.168.0.201, etc.<br \/>\n$rancher_ip_start = &#8220;192.168.0.20&#8221;<br \/>\n$rancherui_ip = $rancher_ip_start + &#8220;0&#8221;<br \/>\n# the number of rancher instances<br \/>\n$n_rancher = 1<\/p>\n<p>* *<\/p>\n<p>Leave $n_rancher at 1 for now.<\/p>\n<p>After editing this file, run `vagrant up\u2019.<\/p>\n<p>Vagrant will now first setup the Rancher VM, which means Vagrant will<br \/>\ndownload the Virtualbox image, start it and Docker will then download<br \/>\nand run the Rancher Server and the Rancher Agent. Afterwards, the second<br \/>\nVM, which will host our RancherOS instance, will be started and the<br \/>\nRancherOS instance will register itself at the Rancher Server.<\/p>\n<p><a href=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/FD14F41B-EFA1-2421-89A2-A4A63C8F6507.jpg\"><img decoding=\"async\" src=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/t_FD14F41B-EFA1-2421-89A2-A4A63C8F6507.jpg\" alt=\"\" \/><\/a><\/p>\n<p>When finished, browse to the Rancher IP (<a href=\"http:\/\/192.168.0.200:8080\/\">http:\/\/192.168.0.200:8080\/<\/a> in<br \/>\nmy case) and observe your new and shiny VMs:<\/p>\n<p><a href=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/2202D027-4152-E66D-D736-B1B33374F81A.jpg\"><img decoding=\"async\" src=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/t_2202D027-4152-E66D-D736-B1B33374F81A.jpg\" alt=\"\" \/><\/a><\/p>\n<h2><strong>Adding a System Container to Rancher<\/strong><\/h2>\n<p>The next task is to set up the Nagios Agent on the RancherOS instance.<\/p>\n<p>For that you will need to log in to the server, which you do by running<br \/>\n`vagrant ssh rancher1`.<\/p>\n<p>There you will have access to the user docker (by calling `docker`)<br \/>\nand to the system docker by calling `sudo system-docker`.<\/p>\n<p>A system container is not different from your usual docker container,<br \/>\nexcept that it is run by the system docker and that has no networking by<br \/>\ndefault. Thus, it needs to inherit the network of the host (&#8211;net=host<br \/>\nparameter):<\/p>\n<p>sudo system-docker run -d &#8211;net=host &#8211;name nagios-agent buster\/nagios-agent<\/p>\n<p>This nagios agent container comes with a minimal configuration to check<br \/>\nthe load on the second RancherOS<br \/>\ninstance.<a href=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/B644FD77-AB6D-20C4-B5C7-785561B4D1B5.jpg\"><img decoding=\"async\" src=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/t_B644FD77-AB6D-20C4-B5C7-785561B4D1B5.jpg\" alt=\"\" \/><\/a><\/p>\n<h2>[]Deploying the Nagios Server to Rancher<\/h2>\n<p>In order for the Nagios agent to make any sense, we will also need a<br \/>\nNagios Server which polls the Nagios Agent.<\/p>\n<p>This is as easy as any other Rancher deployment, by clicking on \u201cAdd<br \/>\nContainer\u201d in the Rancher UI.<\/p>\n<p>There we will make use of the already existing Nagios Server docker<br \/>\ncontainer from<br \/>\n<a href=\"https:\/\/hub.docker.com\/r\/cpuguy83\/nagios\/\">https:\/\/registry.hub.docker.com\/u\/cpuguy83\/nagios\/<\/a><br \/>\nAlso don\u2019t forget to go to the `Ports` tab and map port 80 to port<br \/>\n8081 so that you can login on nagios.<\/p>\n<p><a href=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/2D3F87C5-1294-AF8A-6E3B-8E8E4584CEC0.jpg\"><img decoding=\"async\" src=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/t_2D3F87C5-1294-AF8A-6E3B-8E8E4584CEC0.jpg\" alt=\"\" \/><\/a><\/p>\n<p>Add this container and after a while, the Nagios Server will be up and<br \/>\nrunning! Browse to<br \/>\n<a href=\"http:\/\/192.168.0.200:8081\/\">http:\/\/192.168.0.200:8081\/<\/a> and<br \/>\nobserve the Nagios UI running. The default username is<br \/>\nnagiosadmin and the password is nagios.<\/p>\n<p><a href=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/354527B2-5C76-D1A8-F672-F35218219983.jpg\"><img decoding=\"async\" src=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/t_354527B2-5C76-D1A8-F672-F35218219983.jpg\" alt=\"\" \/><\/a><\/p>\n<h2>[]Configure Nagios Server<\/h2>\n<p>The Nagios Server only knows itself right now, so we will need to<br \/>\nconfigure it to poll the Nagios Agent.<\/p>\n<p>This can be done in \/opt\/nagios\/etc\/conf.d\/rancher1.cfg, for example.<\/p>\n<p>Rancher offers a very nice terminal into the running containers, which<br \/>\nyou can reach by click on the container and afterwards on the \u201cexecute<br \/>\nshell\u201d url:<\/p>\n<p><a href=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/CE1B5157-4299-1A1A-F7F5-E75C411AFE63.jpg\"><img decoding=\"async\" src=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/t_CE1B5157-4299-1A1A-F7F5-E75C411AFE63.jpg\" alt=\"\" \/><\/a><\/p>\n<p>Now, you can edit the config file by running `nano<br \/>\n\/opt\/nagios\/etc\/conf.d\/rancher1.cfg`.<\/p>\n<p>Add the following lines to the file:<\/p>\n<p>define command{<br \/>\ncommand_name check_nrpe<br \/>\ncommand_line $USER1$\/check_nrpe -H $HOSTADDRESS$ -c $ARG1$<br \/>\n}<br \/>\ndefine host{<br \/>\nuse linux-server<br \/>\nhost_name rancher1<br \/>\naddress 192.168.0.201<br \/>\n}<br \/>\ndefine service{<br \/>\nuse linux-server<br \/>\nhost_name rancher1<br \/>\nservice_description Current Users<br \/>\ncheck_command check_nrpe!check_users<br \/>\n}<br \/>\ndefine service{<br \/>\nuse generic-service<br \/>\nhost_name rancher1<br \/>\nservice_description Current Load<br \/>\ncheck_command check_nrpe!check_load<br \/>\n}<\/p>\n<p><a href=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/C791AD85-CB94-671F-9489-99B68EFB97DD.jpg\"><img decoding=\"async\" src=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/t_C791AD85-CB94-671F-9489-99B68EFB97DD.jpg\" alt=\"\" \/><\/a><\/p>\n<p>Afterwards you can check if the configuration file format is correct by<br \/>\nrunning `nagios -v \/opt\/nagios\/etc\/nagios.cfg`.<\/p>\n<p>To check that the nrpe server on the second host is running you can also<br \/>\nrun a check manually: `\/opt\/nagios\/libexec\/check_nrpe -H<br \/>\n192.168.0.201 -c check_load`<\/p>\n<p>After you have verified the working Nagios setup you simply need to<br \/>\nrestart the Nagios Server container by clicking on the symbol:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/rancher.com\/wp-content\/uploads\/2015\/04\/9E3C674C-5BC3-568D-8374-886410485976.jpg\" alt=\"\" \/><\/p>\n<p>Now, you can login to Nagios again and see the Nagios Plugins doing<br \/>\ntheir work:<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>Using Nagios to monitor multiple RancherOS servers is as easy as running<br \/>\na preconfigured publicly available Docker container from<br \/>\n<a href=\"https:\/\/registry.hub.docker.com\">https:\/\/registry.hub.docker.com<\/a><\/p>\n<p>Starting a system docker container requires a few additional steps<br \/>\ncompared to running a user container, but hopefully we\u2019ve explained<br \/>\nthem clearly here.<\/p>\n<p>In the next few weeks RancherOS will ship 0.3, which includes support<br \/>\nfor predefined system services. That will make configuration of new<br \/>\nagents in the Nagios server as easy as executing a docker run command.<\/p>\n<p>If you\u2019d like to get started with RancherOS, you can download it from<br \/>\nGitHub here. Also, we\u2019re always demoing new features and answering lots<br \/>\nof questions at each months Rancher Meetup, which you can find a link<br \/>\nto for below.<\/p>\n<p>Sebastian Schulze is a Technology Consultant from Germany, with<br \/>\nexperience in Linux, Solaris, Docker, and Vagrant. You can contact him<br \/>\nvia github at:<br \/>\n<a href=\"https:\/\/github.com\/buster\">https:\/\/github.com\/buster<\/a><\/p>\n<p><a href=\"https:\/\/rancher.com\/running-nagios-as-a-system-service-on-rancheros\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nagios is a fantastic monitoring tool, and I wanted to see if I could get the agent to run as a system container on RancherOS, in order to monitor the host and any Docker containers running on it. It turned out to be incredibly easy. In this blog post, I\u2019ll walk through how to launch &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw93\/index.php\/2019\/02\/19\/running-nagios-as-a-system-service-on-rancheros\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Running Nagios as a System Service on RancherOS&#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":[3],"tags":[],"class_list":["post-1349","post","type-post","status-publish","format-standard","hentry","category-kubernetes"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/1349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/comments?post=1349"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/1349\/revisions"}],"predecessor-version":[{"id":1424,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/1349\/revisions\/1424"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/media?parent=1349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/categories?post=1349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/tags?post=1349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}