{"id":178,"date":"2022-03-04T21:23:11","date_gmt":"2022-03-04T20:23:11","guid":{"rendered":"https:\/\/tillnet.se\/?p=178"},"modified":"2022-03-04T21:23:11","modified_gmt":"2022-03-04T20:23:11","slug":"zabbix-on-ubuntu-with-ssl","status":"publish","type":"post","link":"https:\/\/www.tillnet.se\/index.php\/2022\/03\/04\/zabbix-on-ubuntu-with-ssl\/","title":{"rendered":"Zabbix on Ubuntu with SSL"},"content":{"rendered":"\n<p>Everyone needs a monitor system, right?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Disclaimer or Scope\/Intention<\/h2>\n\n\n\n<p>This is how I did it. Short guide, more or less for myself so I won\u2019t forget.<br>If Linux\/Ubuntu\/Apache\/SSL-certs is new territory for you this isn\u2019t the guide you were looking for, sorry. Some steps and detailed explanations are omitted.<br>Also never run cmds you don\u2019t trust and know what they do.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What I used<\/h2>\n\n\n\n<p>Machine: VM in Vmware vSphere, 2vCPU, 4GB RAM, 32GB disk.<br>OS: Ubuntu Server 20.04 LTS Free OpenSource (https:\/\/ubuntu.com\/download\/server)<br>WebApp: Zabbix 6.0 Free OpenSource (https:\/\/zabbix.com)<br>SSL cert: I used Let\u2019s Encrypt for my cert and key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preparation<\/h2>\n\n\n\n<p>I downloaded the software from Ubuntu. Spun up a small VM and installed Ubuntu Server on it. Performed some housekeeping on the machine.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"574\" src=\"https:\/\/tillnet.se\/wp-content\/uploads\/2022\/03\/vm-config-1024x574.png\" alt=\"\" class=\"wp-image-179\" srcset=\"https:\/\/www.tillnet.se\/wp-content\/uploads\/2022\/03\/vm-config-1024x574.png 1024w, https:\/\/www.tillnet.se\/wp-content\/uploads\/2022\/03\/vm-config-300x168.png 300w, https:\/\/www.tillnet.se\/wp-content\/uploads\/2022\/03\/vm-config-768x430.png 768w, https:\/\/www.tillnet.se\/wp-content\/uploads\/2022\/03\/vm-config.png 1096w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Spun up a vm in vSphere.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"> Step 1: Install LAMP Stack (Linux, Apache, MySQL, and PHP) <\/h2>\n\n\n\n<p>On the newly setup Ubuntu machine install LAMP Stack and some  extra pieces.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install tasksel\nsudo tasksel install lamp-server\nsudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc\nsudo apt install php-imap\nsudo phpenmod imap<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"> Step 2: Follow instructions on Zabbix homepage. <\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"718\" src=\"https:\/\/tillnet.se\/wp-content\/uploads\/2022\/03\/1-download-1024x718.png\" alt=\"\" class=\"wp-image-180\" srcset=\"https:\/\/www.tillnet.se\/wp-content\/uploads\/2022\/03\/1-download-1024x718.png 1024w, https:\/\/www.tillnet.se\/wp-content\/uploads\/2022\/03\/1-download-300x210.png 300w, https:\/\/www.tillnet.se\/wp-content\/uploads\/2022\/03\/1-download-768x538.png 768w, https:\/\/www.tillnet.se\/wp-content\/uploads\/2022\/03\/1-download.png 1220w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption> https:\/\/www.zabbix.com\/download?zabbix=6.0&amp;os_distribution=ubuntu&amp;os_version=20.04_focal&amp;db=mysql&amp;ws=apache <\/figcaption><\/figure>\n\n\n\n<p>Just a headsup, the step &#8220;<code>zcat \/usr\/share\/doc\/zabbix-sql-scripts\/mysql\/server.sql.gz | mysql -uzabbix -p zabbix<\/code>&#8220;. Will take a long time with low resource utilization, be patient.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Done, ish.<\/h2>\n\n\n\n<p> Now it&#8217;s installed. Enter the FQDN or ip-adress + \/zabbix in a web-browser. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"392\" height=\"422\" src=\"https:\/\/tillnet.se\/wp-content\/uploads\/2022\/03\/done.png\" alt=\"\" class=\"wp-image-181\" srcset=\"https:\/\/www.tillnet.se\/wp-content\/uploads\/2022\/03\/done.png 392w, https:\/\/www.tillnet.se\/wp-content\/uploads\/2022\/03\/done-279x300.png 279w\" sizes=\"auto, (max-width: 392px) 100vw, 392px\" \/><figcaption>This is the Zabbix welcome screen. Enter the user name Admin with password zabbix to log in.<\/figcaption><\/figure>\n\n\n\n<p>More info, https:\/\/www.zabbix.com\/documentation\/6.0\/en\/manual\/quickstart\/login<\/p>\n\n\n\n<p>Optional to continue. Next steps will add SSL\/https and force that.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Remove \/zabbix\/ from URL<\/h2>\n\n\n\n<p>Configure Apache conf for website (this removes &#8220;zabbix&#8221; from the end of the URL), optional.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/apache2\/conf-enabled\/zabbix.conf<\/code><\/pre>\n\n\n\n<p>Comment the three lines at the top regarding alias.<br>Ctr+X, Y, Enter<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo cd \/etc\/apache2\/sites-available\nsudo nano example.com.conf<\/code><\/pre>\n\n\n\n<p>Paste into editor:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80&gt;\n    ServerAdmin webmaster@example.com\n    ServerName example.com\n    ServerAlias www.example.com\n    DocumentRoot \/usr\/share\/zabbix\n    ErrorLog ${APACHE_LOG_DIR}\/error.log\n    CustomLog ${APACHE_LOG_DIR}\/access.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n\n\n\n<p>Then activate the site.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo a2dissite 000-default.conf\nsudo a2ensite example.com.conf\nsudo systemctl reload apache2<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Get SSL cert and key<\/h2>\n\n\n\n<p>All websites should use https now when there\u2019s free and easy services like Let\u2019s Encrypt (https:\/\/letsencrypt.org) or Cloudflare (https:\/\/cloudflare.com). There are good guides on their webpages and also a lot of specific howtos to find elsewhere. This is out of scope for this guide.<\/p>\n\n\n\n<p>Get your cert and key from source of your choosing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6: Copy Cert and Key to Server<\/h2>\n\n\n\n<p>Create a new directory where your Cert and Key will reside.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir -p \/etc\/letsencrypt\/<\/code><\/pre>\n\n\n\n<p>Using nano text editor, create a new file example.com.pem (where example.com is your own domain).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/letsencrypt\/example.com.pem<\/code><\/pre>\n\n\n\n<p>Now paste in your Origin Certificate. Save file and exit. (Press CTRL + X, press Y and then press ENTER).<\/p>\n\n\n\n<p>Create a new file example.com.key (where example.com is your own domain).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/letsencrypt\/example.com.key<\/code><\/pre>\n\n\n\n<p>Paste in your Private Key. Save file and exit. (Press CTRL + X, press Y and then press ENTER).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 7: Configure Apache for https<\/h2>\n\n\n\n<p>Firstly, make sure you have the SSL module enabled for Apache by running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo a2enmod ssl<\/code><\/pre>\n\n\n\n<p>Open the Apache configuration file for your domain.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/apache2\/sites-available\/example.com.conf<\/code><\/pre>\n\n\n\n<p>You need to add a new block underneath for SSL port 443. You can also add a rewrite condition in your port 80 block to redirect all requests to https. Paste example and modify for your domain.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80&gt;\n    ServerAdmin webmaster@example.com\n    ServerName example.com\n    ServerAlias www.example.com\n    DocumentRoot \/usr\/share\/zabbix\n    ErrorLog ${APACHE_LOG_DIR}\/error.log\n    CustomLog ${APACHE_LOG_DIR}\/access.log combined\n\n    ReWriteEngine on\n    ReWriteCond %{SERVER_NAME} =example.com\n    ReWriteRule ^ https:\/\/%{SERVER_NAME}%{REQUEST_URI} &#91;END,NE,R=permanent]\n\n&lt;\/VirtualHost&gt;\n&lt;VirtualHost *:443&gt;\n\n    ServerAdmin webmaster@example.com\n    ServerName example.com\n    ServerAlias www.example.com\n    DocumentRoot \/usr\/share\/zabbix\n    ErrorLog ${APACHE_LOG_DIR}\/error.log\n    CustomLog ${APACHE_LOG_DIR}\/access.log combined\n\n    SSLEngine on\n    SSLCertificateFile \/etc\/letsencrypt\/example.com.pem\n    SSLCertificateKeyFile \/etc\/letsencrypt\/example.com.key\n\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n\n\n\n<p>Save file and exit. (Press CTRL + X, press Y and then press ENTER).<\/p>\n\n\n\n<p>Enable the RewriteEngine.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo a2enmod rewrite<\/code><\/pre>\n\n\n\n<p>Test the configuration syntax for errors.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apachectl configtest<\/code><\/pre>\n\n\n\n<p>You can ignore any errors that say Could not reliably determine the server\u2019s fully qualified domain name.<br>If you see Syntax OK, restart Apache.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart apache2<\/code><\/pre>\n\n\n\n<p>Done. Now you have your own monitoring system.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Everyone needs a monitor system, right? Disclaimer or Scope\/Intention This is how I did it. Short guide, more or less for myself so I won\u2019t &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-178","post","type-post","status-publish","format-standard","hentry","category-it"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tillnet.se\/index.php\/wp-json\/wp\/v2\/posts\/178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tillnet.se\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tillnet.se\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tillnet.se\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tillnet.se\/index.php\/wp-json\/wp\/v2\/comments?post=178"}],"version-history":[{"count":2,"href":"https:\/\/www.tillnet.se\/index.php\/wp-json\/wp\/v2\/posts\/178\/revisions"}],"predecessor-version":[{"id":193,"href":"https:\/\/www.tillnet.se\/index.php\/wp-json\/wp\/v2\/posts\/178\/revisions\/193"}],"wp:attachment":[{"href":"https:\/\/www.tillnet.se\/index.php\/wp-json\/wp\/v2\/media?parent=178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tillnet.se\/index.php\/wp-json\/wp\/v2\/categories?post=178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tillnet.se\/index.php\/wp-json\/wp\/v2\/tags?post=178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}