{"id":668,"date":"2018-10-18T07:22:56","date_gmt":"2018-10-18T07:22:56","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=668"},"modified":"2018-10-18T15:35:25","modified_gmt":"2018-10-18T15:35:25","slug":"configure-zabbix-monitoring-server-with-puppet-lisenet-com-linux-security","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/18\/configure-zabbix-monitoring-server-with-puppet-lisenet-com-linux-security\/","title":{"rendered":"Configure Zabbix Monitoring Server with Puppet | Lisenet.com :: Linux | Security"},"content":{"rendered":"<p>We\u2019re going to use Puppet to install and configure a Zabbix server. We will also allow active Zabbix agent auto-registration.<\/p>\n<p>This article is part of the <a href=\"https:\/\/www.lisenet.com\/2018\/homelab-project-with-kvm-katello-and-puppet\/\" target=\"_blank\" rel=\"noopener\">Homelab Project with KVM, Katello and Puppet<\/a> series.<\/p>\n<h2>Homelab<\/h2>\n<p>We have a CentOS 7 VM installed which we want to configure as a Zabbix server:<\/p>\n<p>monitoring.hl.local (10.11.1.13) \u2013 Zabbix server with agent auto-registration<\/p>\n<p>SELinux set to enforcing mode.<\/p>\n<p>See the image below to identify the homelab part this article applies to.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.lisenet.com\/wp-content\/uploads\/2018\/04\/lisenet-homelab-diagram_monitoring.png\" alt=\"\" width=\"1200\" height=\"793\" \/><\/p>\n<h2>Zabbix LTS and PHP<\/h2>\n<p>We want to use a stable Zabbix LTS release, which is Zabbix 3.0 at the time of writing.<\/p>\n<p>Note that Zabbix 3.0 LTS release supports PHP 5.4 or later, however PHP v7 is not supported yet. For more info, see Zabbix <a href=\"https:\/\/www.zabbix.com\/documentation\/3.0\/manual\/installation\/requirements\" target=\"_blank\" rel=\"noopener\">documentation<\/a>.<\/p>\n<p>Also note that PHP 5.6 will receive security support until 31 December 2018. For more info, see PHP <a href=\"https:\/\/secure.php.net\/supported-versions.php\" target=\"_blank\" rel=\"noopener\">supported versions<\/a>. We will therefore use Remi\u2019s PHP 5.6 repository served by Katello (we configured it <a href=\"https:\/\/www.lisenet.com\/2018\/katello-create-products-repositories-content-views-lifecycle-environments-activation-keys\/\" target=\"_blank\" rel=\"noopener\">here<\/a>).<\/p>\n<h2>Configuration with Puppet<\/h2>\n<p>Puppet master runs on the <a href=\"https:\/\/www.lisenet.com\/2016\/install-katello-on-centos-7\/\" target=\"_blank\" rel=\"noopener\">Katello<\/a> server.<\/p>\n<h3>Puppet Modules<\/h3>\n<p>We use <a href=\"https:\/\/forge.puppet.com\/puppet\/zabbix\" target=\"_blank\" rel=\"noopener\">puppet-zabbix<\/a> Puppet module to configure the server. We also use <a href=\"https:\/\/forge.puppet.com\/puppetlabs\/apache\" target=\"_blank\" rel=\"noopener\">puppetlabs-apache<\/a> and <a href=\"https:\/\/forge.puppet.com\/puppetlabs\/mysql\" target=\"_blank\" rel=\"noopener\">puppetlabs-mysql<\/a> to configure frontend and backend services.<\/p>\n<p>Please see each module\u2019s documentation for features supported and configuration options available.<\/p>\n<h3>Manage Firewall<\/h3>\n<p>We start with firewall configuration:<\/p>\n<p>firewall { &#8216;007 allow Zabbix active checks&#8217;:<br \/>\ndport =&gt; [10051],<br \/>\nsource =&gt; &#8216;10.11.1.0\/24&#8217;,<br \/>\nproto =&gt; tcp,<br \/>\naction =&gt; accept,<br \/>\n}-&gt;<br \/>\nfirewall { &#8216;008 allow Zabbix WebUI&#8217;:<br \/>\ndport =&gt; [80, 443],<br \/>\nsource =&gt; &#8216;10.11.1.0\/24&#8217;,<br \/>\nproto =&gt; tcp,<br \/>\naction =&gt; accept,<br \/>\n}<\/p>\n<h3>Install Apache<\/h3>\n<p>We use Apache to run Zabbix frontend, and MySQL as Zabbix backend database.<\/p>\n<p>Do a minimal Apache install only, but make sure that a PHP module is loaded:<\/p>\n<p>class { &#8216;apache&#8217;:<br \/>\ndefault_vhost =&gt; false,<br \/>\ndefault_ssl_vhost =&gt; false,<br \/>\ndefault_mods =&gt; false,<br \/>\nmpm_module =&gt; &#8216;prefork&#8217;,<br \/>\nserver_signature =&gt; &#8216;Off&#8217;,<br \/>\nserver_tokens =&gt; &#8216;Prod&#8217;,<br \/>\ntrace_enable =&gt; &#8216;Off&#8217;,<br \/>\n}<br \/>\ninclude apache::mod::php<\/p>\n<h3>Install MySQL<\/h3>\n<p>MySQL 5.7 repository is served by Katello (we configured it <a href=\"https:\/\/www.lisenet.com\/2018\/katello-create-products-repositories-content-views-lifecycle-environments-activation-keys\/\" target=\"_blank\" rel=\"noopener\">here<\/a>).<\/p>\n<p>class { &#8216;mysql::server&#8217;:<br \/>\npackage_name =&gt; &#8216;mysql-community-server&#8217;,<br \/>\nservice_name =&gt; &#8216;mysqld&#8217;,<br \/>\nroot_password =&gt; &#8216;PleaseChangeMe&#8217;,<br \/>\ncreate_root_my_cnf =&gt; true,<br \/>\nmanage_config_file =&gt; true,<br \/>\nconfig_file =&gt; &#8216;\/etc\/my.cnf&#8217;,<br \/>\npurge_conf_dir =&gt; true,<br \/>\nrestart =&gt; true,<br \/>\noverride_options =&gt; {<br \/>\nmysqld =&gt; {<br \/>\nbind-address =&gt; &#8216;127.0.0.1&#8217;,<br \/>\ndatadir =&gt; &#8216;\/var\/lib\/mysql&#8217;,<br \/>\nlog-error =&gt; &#8216;\/var\/log\/mysqld.log&#8217;,<br \/>\npid-file =&gt; &#8216;\/var\/run\/mysqld\/mysqld.pid&#8217;,<br \/>\nwait_timeout =&gt; &#8216;3600&#8217;,<br \/>\ninteractive_timeout =&gt; &#8216;3600&#8217;,<br \/>\n},<br \/>\nmysqld_safe =&gt; {<br \/>\nlog-error =&gt; &#8216;\/var\/log\/mysqld.log&#8217;,<br \/>\n},<br \/>\n},<br \/>\nremove_default_accounts =&gt; true,<br \/>\n}<\/p>\n<h3>Install Zabbix Server<\/h3>\n<p>Zabbix 3.0 repository is served by Katello. Since this is the case, we set manage_repo to false.<\/p>\n<p>class { &#8216;zabbix&#8217;:<br \/>\nzabbix_version =&gt; &#8216;3.0&#8217;,<br \/>\nzabbix_url =&gt; &#8216;monitoring.hl.local&#8217;,<br \/>\ndatabase_type =&gt; &#8216;mysql&#8217;,<br \/>\nmanage_repo =&gt; false,<br \/>\nmanage_firewall =&gt; true,<br \/>\nmanage_vhost =&gt; true,<br \/>\napache_use_ssl =&gt; true,<br \/>\n}<\/p>\n<p>If all goes well, at this point Zabbix should be up and running.<\/p>\n<h2>Configure Active Agent Auto-Registration<\/h2>\n<p>This part should be configured after the server has been created.<\/p>\n<p>It is possible to allow active Zabbix agent auto-registration, after which the server can start monitoring them. This way new hosts can be added for monitoring without configuring them manually on the server.<\/p>\n<p>When installed succesfully, Zabbix web interface will be accessibe and we can log in with the default credentials:<\/p>\n<ol>\n<li>Username: Admin<\/li>\n<li>Password: zabbix<\/li>\n<\/ol>\n<p>In the Zabbix frontend, go to Configuration &gt; Actions, select Auto registration as the event source and click on Create action. Use something like this:<\/p>\n<ol>\n<li>Name: Linux host autoregistration<\/li>\n<li>Conditions: none<\/li>\n<li>Operations: Link to templates: Template OS Linux<\/li>\n<\/ol>\n<p>See the image below for more info.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.lisenet.com\/wp-content\/uploads\/2018\/04\/lisenet-homelab-zabbix-auto-registration.png\" alt=\"\" width=\"662\" height=\"226\" \/><\/p>\n<p>We don\u2019t use any conditions here as it\u2019s optional and not really necessary for the homelab, however, we could use HostMetadataItem=system.uname if we wanted to separate say Linux servers from Windows.<\/p>\n<h2>Install Zabbix Agents on All Servers<\/h2>\n<p>By now we should have our Zabbix server running with agent auto-registration enabled. One thing that is still left to do is to configure Puppet to install a Zabbix agent on all homelab servers, and allow Zabbix passive checks.<\/p>\n<p>This needs to go in to the main environment manifest file \/etc\/puppetlabs\/code\/environments\/homelab\/manifests\/site.pp so that configuration is applied to all servers.<\/p>\n<p>class { &#8216;zabbix::agent&#8217;:<br \/>\nzabbix_version =&gt; &#8216;3.0&#8217;,<br \/>\n<em>## Do not use DNS, use IP address.<\/em><br \/>\nserver =&gt; &#8216;10.11.1.13&#8217;,<br \/>\n<em>## Do not set logtype to &#8216;system&#8217; unless you want<br \/>\n## to find yourself debugging SELinux problems.<\/em><br \/>\nlogtype =&gt; &#8216;file&#8217;,<br \/>\nlogfile =&gt; &#8216;\/var\/log\/zabbix\/zabbix_agentd.log&#8217;,<br \/>\n<em>## Use Katello repository<\/em><br \/>\nmanage_repo =&gt; false,<br \/>\nmanage_firewall =&gt; false,<br \/>\nmanage_selinux =&gt; true,<br \/>\n<em>## Zabbix Agent does not work well with SELinux<br \/>\n## See: https:\/\/support.zabbix.com\/browse\/ZBX-12592<\/em><br \/>\nselinux_require =&gt; [<br \/>\n&#8216;type kernel_t&#8217;,<br \/>\n&#8216;type devlog_t&#8217;,<br \/>\n&#8216;type zabbix_agent_t&#8217;,<br \/>\n&#8216;class sock_file write&#8217;,<br \/>\n&#8216;class process setrlimit&#8217;,<br \/>\n&#8216;class unix_dgram_socket &#8216;,<br \/>\n],<br \/>\nselinux_rules =&gt; { &#8216;zabbix_agent_t&#8217; =&gt; [<br \/>\n&#8216;allow zabbix_agent_t kernel_t:unix_dgram_socket sendto&#8217;,<br \/>\n&#8216;allow zabbix_agent_t self:process setrlimit&#8217;,<br \/>\n&#8216;allow zabbix_agent_t self:unix_dgram_socket { connect create }&#8217;,<br \/>\n]<br \/>\n},<br \/>\n<em>## Allow active Zabbix agent auto-registration,<br \/>\n## after which the server can start monitoring them.<\/em><br \/>\nserveractive =&gt; &#8216;monitoring.hl.local&#8217;,<br \/>\nhostmetadata =&gt; &#8216;system.uname&#8217;,<br \/>\n}<\/p>\n<p>Configure firewall on all servers to allow Zabbix passive checks:<\/p>\n<p>firewall { &#8216;006 allow Zabbix passive checks&#8217;:<br \/>\nproto =&gt; &#8216;tcp&#8217;,<br \/>\nsource =&gt; &#8216;monitoring.hl.local&#8217;,<br \/>\ndport =&gt; &#8216;10050&#8217;,<br \/>\naction =&gt; &#8216;accept&#8217;,<br \/>\n}<\/p>\n<p>The end result should be similar to this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.lisenet.com\/wp-content\/uploads\/2018\/03\/lisenet-homelab-zabbix.png\" alt=\"\" width=\"1183\" height=\"457\" \/><\/p>\n<p>All agents auto-register with the server.<\/p>\n<p><a href=\"https:\/\/www.lisenet.com\/2018\/configure-zabbix-monitoring-server-with-puppet\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We\u2019re going to use Puppet to install and configure a Zabbix server. We will also allow active Zabbix agent auto-registration. This article is part of the Homelab Project with KVM, Katello and Puppet series. Homelab We have a CentOS 7 VM installed which we want to configure as a Zabbix server: monitoring.hl.local (10.11.1.13) \u2013 Zabbix &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/18\/configure-zabbix-monitoring-server-with-puppet-lisenet-com-linux-security\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Configure Zabbix Monitoring Server with Puppet | Lisenet.com :: Linux | Security&#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":[1],"tags":[],"class_list":["post-668","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=668"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/668\/revisions"}],"predecessor-version":[{"id":797,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/668\/revisions\/797"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}