[root@rhce-ryanrudolf]# rm -rf / 2> /dev/null

things I break/fix for fun and learning

Jan 12, 2019 - 4 minute read - Comments

Network Monitoring with Zabbix

I want to implement network monitoring in my homelab environment. There are lots of enterprise-grade products that are capable of this, and I have narrowed it down between Nagios and Zabbix. I’ve already had experience configuring Nagios from my previous employer, and for something different this time I will go for Zabbix. Or I might end up doing both, as it has been a while since I’ve done Nagios (around 2007-2008).

Preliminary Steps:

  • Create a CentOS7 virtual machine using minimal ISO. I have a spacewalk server that also doubles as my PXE server. Spacewalk automates the install process and automatically registers to my spacewalk server. Screenshots of the automated deployment here, here, here and here.

  • Once the VM is created, login as root and change the hostname. For this host, I will use the hostname zabbix01. I would like to stick with Toy Story characters, but I realized that it is not scalable and will introduce problems along the way. (Ex - I need to login to the zabbix server, is it sid, or buzz or woody?)

    hostnamectl set-hostname zabbix01
  • Change IP address from dynamic to static. For this server, I will use, gateway will be my router and DNS will be my custom DNS server

    nmcli con show
    nmcli con mod ens32 ipv4.method manual ipv4.address ipv4.gateway ipv4.dns ipv4.dns-search ryanrudolf.com
    systemctl restart network
  • Login to DNS server (sid) and add the A record of zabbix01 to the forward zone and reverse zone.

    ssh root@sid
    echo "zabbix01 IN A" >> /var/named/ryanrudolf.com.zone
    echo "102 IN PTR zabbix01.ryanrudolf.com." >> /var/named/ryanrudolf.com.revzone
    systemctl restart named
  • Copy ssh keys for password-less logins. We can now use hostname instead of static IP.

    ssh-copy-id root@zabbix01
  • Since this is managed by spacewalk, we need to import the spacewalk certificates so that we can install packages from the spacewalk repo. This saves bandwidth when installing packages. Instead of downloading packages from the internet, it will instead download packages from my spacewalk server.

    rpm --import -k https://spacewalk.ryanrudolf.com/pub/RPM-GPG-KEY-CentOS-7
    rpm --import http://spacewalk.ryanrudolf.com/pub/RPM-GPG-KEY-EPEL-7
  • And finally do a yum update to install any updates.

  • Login to the spacewalk server, and it will show that zabbix01 is up-to-date. Screenshot here. It also shows that my server sid has pending updates, and my server ansible is not communicating (as it is powered off).

Installing Zabbix:

It’s time to install and configure Zabbix! I am following the official documentation from the Zabbix website located here, with a few minor adjustments.

  • Install Zabbix repository -

    rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
  • Install mariadb (mysql) -

    yum install mariadb-server
  • Install Zabbix server, front-end and agent. Since I am using mariadb (mysql), I will install the appropriate mysql package -

    yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent
  • Enable and start mariadb-server -

    systemctl enable mariadb
    systemctl start mariadb
  • Login to the database. Initial password is blank -

    mysql -u root -p
  • Once logged in, it will display the MariaDB prompt.

  • Create initial database -

    MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
    Query OK, 1 row affected (0.00 sec)
  • Setup database password and once done, logout of the database -

    MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
    Query OK, 0 rows affected (0.00 sec)
    MariaDB [(none)]> quit
  • Import database schema and data. It will prompt to enter the new database password created earlier -

    zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
  • Configure the database for Zabbix server -

    vi /etc/zabbix/zabbix_server.conf
  • Configure PHP for Zabbix frontend, uncomment and set the correct time zone -

    vi /etc/httpd/conf.d/zabbix.conf
    php_value date.timezone America/Toronto
  • Configure webserver to use /usr/share/zabbix as the document root. Comment Alias and replace with DocumentRoot -

    vi /etc/httpd/conf.d/zabbix.conf
    #Alias /zabbix /usr/share/zabbix
    DocumentRoot /usr/share/zabbix
  • Enable and start the Zabbix agent / server -

    systemctl enable zabbix-server zabbix-agent httpd
    systemctl start zabbix-server zabbix-agent httpd
  • Configure firewall to allow Zabbix web frontend and agent traffic -

    firewall-cmd --add-service=http --permanent
    firewall-cmd --add-port=10051/tcp --permanent
    firewall-cmd --reload

Zabbix is now installed! It can be accessed via http://zabbix01/ , default username:password is Admin:zabbix.

Installing Zabbix Agent

Now that the Zabbix server is installed, it can start monitoring servers. To monitor servers, we can use the Zabbix agent, SNMP (Simple Network Management Protocol), IPMI (Intelligent Platform Management Interface) and JMX (for Java applications). For my CentOS servers I will use the Zabbix agents.

  • Install Zabbix repository -

    rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
  • Install Zabbix agent -

    yum install zabbix-agent
  • Configure Zabbix agent configuration file to use the Zabbix server IP / hostname. Under Server and ServerActive, enter the IP / hostname of the Zabbix server -

    vi /etc/zabbix/zabbix_agentd.conf
  • Enable and start the Zabbix agent service -

    systemctl enable zabbix-agent
    systemctl start zabbix-agent
  • Allow firewall rules for the Zabbix agent traffic -

    firewall-cmd --add-port=10050/tcp --permanent
    firewall-cmd --reload

And that’s it! Zabbix agent is installed. Next step will be to create / add hosts in the Zabbix frontend.

Screenshot of Zabbix web frontend

zabbix frontend

Update 1 - Hosts added to Zabbix

zabbix hosts added

Update 2 - Zabbix dashboard in action! Two hosts have errors and needs to be remediated

zabbix dashboard

Update 3 - Zabbix and Grafana in action!

zabbix and grafana

Like this page? Share it!

Compiling Linux Kernel 5 SSL Certificate Expired

comments powered by Disqus