Installing a Zabbix Agent on CentOS with Custom Variables

in Linux


We’ve found that Zabbix has been reliable for our use case so far. This is a how to guide for installing a Zabbix agent on CentOS 6.

zabbix agent config

This asummes you already have MySQL and other web services installed on the target OS.

Install Zabbix Agent

Get required rpm for CentOS 6.

rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm

Install the zabbix agent.

yum install zabbix-agent

Edit the config file for the zabbix agent.

nano /etc/zabbix/zabbix_agentd.conf

Fill variables with the correct values.

Server=<ip of zabbix server>
ServerActive=<ip of zabbix server>
ListenPort=10050
Hostname=hostname.of.server

Configure Agent to Work with MySQL

To make the zabbix agent get the correct values from MySQL, copy .my.cnf to /etc/zabbix

cp /root/.my.cnf /etc/zabbix
chown zabbix:zabbix /etc/zabbix/.my.cnf
chmod 600 /etc/zabbix/.my.cnf

Create a read only mysql user for the zabbix agent.

CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'r34d0nly';
GRANT SELECT ON *.* TO 'zabbix'@'localhost';

Then in /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf, set HOME to /etc/zabbix

nano /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
HOME=/etc/zabbix

Change mysql.ping in /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf to:

UserParameter=mysql.ping,mysqladmin -uzabbix -pr34d0nly ping | grep -c alive

Add a mysql.running variable to userparameter_mysql.conf.

UserParameter=mysql.running,sudo /etc/init.d/mysql status | grep -c SUCCESS

Configure Sudoers

Run visudo to edit the sudoers file.

visudo

Add the following inside the sudoers file. This will allow the zabbix agent to run mysql status command.

zabbix ALL = NOPASSWD: /etc/init.d/mysql status

Place this right after: Defaults requiretty in visudo.

Defaults:zabbix !requiretty

Start zabbix agent and configure to start on boot.

service zabbix-agent start
chkconfig zabbix-agent on

Test the zabbix agent config and variables.

zabbix_agentd -t "mysql.running" -c /etc/zabbix/zabbix_agentd.conf
zabbix_agentd -t "mysql.ping" -c /etc/zabbix/zabbix_agentd.conf
zabbix_agentd --print

The mysql.running variable is a custom zabbix data. To effectively use the status of this data, a little customization is required on the zabbix server.

Note, make sure that the zabbix server ip is allowed through the firewall. If using CSF firewall, run the following command.

csf -a <ip of zabbix server> zabbix server

 

Leave a Comment

Previous post:

Next post: