Installing Zabbix on CentOS/RedHat


     Installing Zabbix on CentOS/RedHat using source code

Setting up the user accounts

The Zabbix server and client both need a user account that they can run on, so may as well set this up first. This also needs to be done on every monitored machine that is running the Zabbix agent:

[root@server]#  groupadd -g 130 zabbix

[root@server]#  useradd -u 130 -g zabbix -c ‘Zabbix monitoring’ zabbix

I have added the ”-u 130” parameter – this ensures that the zabbix user gets created with the same user ID on every server that we created it on, as well as with the zabbix group.

Zabbix Installation

We will be installing following components:

  • Zabbix Server (for gathering data)
  • Zabbix Agent (for monitoring)
  • Net-SNMP (for SNMP Support)
  • Jabber (for notifications)
  • OpenIPMI (for monitoring)
  • cURL (for web monitoring)

All these commands are done with the user root, starting of from the root home folder /root

Dependencies

First install all the dependencies with yum using the command

[root@server]#  yum install zlib-devel mysql-devel glibc-devel curl-devel gcc automake mysql libidn-devel openssl-devel net-snmp-devel rpm-devel OpenIPMI-devel

For Jabber we will need the packages iksemel-devel wich depends on iksemel, however these RPM‘s aren’t in the CentOS Repo’s so we will be use them from EPEL instead.

Configure the EPEL repository

[root@server]# rpm -Uvh http://epel.mirror.net.in/epel/6/i386/epel-release-6-8.noarch.rpm

Then we can install the following packages with yum

[root@server]# yum –enablerepo=epel install iksemel iksemel-devel

Compile and Install Source

Now that we have our dependencies set up we need to download the actual source, this can also be done with the wget command.

[root@server]# wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/1.8.16/zabbix-1.8.16.tar.gz/download

After it has downloaded the file we can unzip and untar with following command.

[root@server]#  tar –zxvf  zabbix-1.8.1.tar.gz

This should have created a folder called zabbix-1.8.1 in your home directory. Next we need to browse to the directory and configure our setup.

[root@server]#  cd zabbix-1.8.1

[root@server]#  ./configure –enable-server –with-mysql –with-net-snmp –with-jabber –with-libcurl –with-openipmi –enable-agent

If you encounter any problems you should read the error messages carefully and check the config.log located in the same directory. If all goes well it will print out your configuration, please make sure following is set:

Enable server:                       yes

With database:                      MySQL

WEB Monitoring via:           cURL

Native Jabber:                       yes

SNMP:                                  net-snmp

IPMI:                                    openipmi

Enable agent:                        yes

If everything matches the above we can carry on with the command make and make install

[root@server]# make

[root@server]# make install

**********************************Note*********************************************

checkinstall

After make has compiled we won’t be using make install, but checkinstall which gives us the option to first make a RPM out of the installation and than install it. This gives us the advantage to be able to deinstall Zabbix again with rpm. Because checkinstall also isn’t on the CentOS Repo we will download it using wget to our home directory.

[root@server]# cd ..

[root@server]#  wget http://dag.wieers.com/rpm/packages/checkinstall/checkinstall-1.6.0-3.el5.rf.i386.rpm

and than install checkinstall with rpm and rpmbuild with yum

[root@server~]# rpm -ivh checkinstall-1.6.0-3.el5.rf.i386.rpm

[root@server~]# yum install rpm-build

Now we can use checkinstall to make a RPM and install it.

[root@server~]# cd zabbix-1.8.1

[root@server~]#checkinstall –nodoc –install=yes -y

You Should be able to choose what kind of package that you wish you create, because CentOS is based on RedHat we are going for [R], type R and press Enter.

If you don’t encounter any errors you should get following output:

**********************************************************************

Done. The new package has been installed and saved to /usr/src/redhat/RPMS/i386/zabbix-1.8.1-1.i386.rpm

You can remove it from your system anytime using:

rpm -e zabbix-1.8.1-1

**********************************************************************

Now Zabbix is installed.

Creating the MySQL DB

We will have to create a database for Zabbix and than import scripts which will do the rest for us.

First of make sure the MySQL daemon is running using

[root@server]# service mysqld status

If not you can start it with

[root@server]#  service mysqld start

Now  create a new db for Zabbix.

[root@server]#  mysql -u root -p

and enter the password you set before.

mysql> create database zabbix character set utf8;

Next we want to tell MySQL that our zabbix user hast he rights to mess with the db so lets give him all rights

mysql> grant all privileges on zabbix.* to ‘zabbix’@’localhost’ identified by ‘set-password-here’;

mysql> quit;

It’s important to remember this password as we a going to need it for the Zabbix config files. Now we are going to import the sql scripts into the db so we have tables, and data

[root@server]#  cd create/schema

[root@server]#  cat mysql.sql | mysql -u zabbix -p zabbix

[root@server]#  cd ../data

[root@server]#  cat data.sql | mysql -u zabbix -p zabbix

[root@server]#  cat images_mysql.sql | mysql -u zabbix -p zabbix

To make sure the script worked we can list the tables of the Zabbix database to see if any where created.

mysql> use zabbix;

mysql> show tables;

mysql> quit;

If any problems occur the easiest way is to delete the db with

mysql> drop database zabbix;

and start from the beginning again.

Configuring Zabbix

Now lets create a folder for Zabbix where the config files are stored and then copy the appropriate files.

[root@server]#  mkdir /etc/zabbix

[root@server]#  cd ../..

[root@server]# cp misc/conf/{zabbix_server.conf,zabbix_agentd.conf} /etc/zabbix/

For the beginning the Zabbix agent config file can be left as how it is, but we do need to tell Zabbix where our database is to be found, for that open /etc/zabbix/zabbix_server.conf with your favourite editor

[root@server]#  vim /etc/zabbix/zabbix_server.conf

Look for DBName, with Nano you can do this with Ctrl+W, than type in DBName and press enter. The default value it is set to zabbix, so we can leave that as how it is, but we do need to change the user and password set DBUser to zabbix and DBPassword to the one you set during the MySQL configuration above.

DBName=zabbix

DBUser=zabbix

DBPassword=your-zabbix-mysql-password

Now Zabbix knows where to connect to and with which login information

Permissions and Running Zabbix Server

It is recommended to change the file permissions for the Zabbix config so not every user can just read the password out of our file

[root@server]#   chmod 400 /etc/zabbix/zabbix_server.conf

[root@server]#   chown zabbix /etc/zabbix/zabbix_server.conf

Now we can execute the script zabbix_agentd and zabbix_server which are found in /usr/local/sbin/

[root@server]# /usr/local/sbin/zabbix_agentd

[root@server]#  /usr/local/sbin/zabbix_server

if all went well you shouldn’t get any error messages.

To check if Zabbix is running we can grep the output of all running processes

$ ps -e | grep zabbix

You should see several processes running as zabbix_server and zabbix_agentd, and hopefully they will be running as the zabbix user.

Creating startup scripts

Zabbix comes with startup scripts but it should be mentioned that these scripts are old. All that is needed to be done are minor changes in the scripts.

Login in back to root

$ su –

After a successful login let us copy the scripts from our Zabbix source into our /etc/init.d/ folder. this can be done with the following command:

[root@server]#  cd zabbix-1.8.1

[root@server]#  cp misc/init.d/redhat/8.0/zabbix_* /etc/init.d/

this will copy zabbix_server and zabbix_agentd startup scripts.

Open zabbix_server with your favourite editor.

[root@server]#  vim /etc/init.d/zabbix_server

and than change the progdir to progdir=”/usr/local/sbin/” . Do the exactly the same with zabbix_agentd.

Now let us add it to the services with

[root@server]# chkconfig –add zabbix_server

[root@server]# chkconfig –add zabbix_agentd

[root@server]#  chkconfig  zabbix_server on

[root@server]#  chkconfig  zabbix_agentd on

to verify that the changes have been made, we can use chkconfig to list all configurations with

[root@server]#  chkconfig –list

[root@server]# chkconfig –list | grep zabbix

All that is left to be done, is to make these scripts executable, this is done with the following command

[root@server]#  chmod 755 /etc/init.d/zabbix_server

[root@server]#  chmod 755 /etc/init.d/zabbix_agentd

Now we can control our scripts with

[root@server]#  service zabbix_server {start|stop|restart}

 

About Alex Hunt

Hi All I am Manish Kumar Jha aka Alex Hunt. I am currently working in VMware Software India Pvt Ltd as Operations System Engineer (vCloud Air Operations). I have around 5 Years of IT experience and have exposure on VMware vSphere, vCloud Director, RHEL and modern data center technologies like Cisco UCS and Cisco Nexus 1000v and NSX. If you find any post informational to you please press like and share it across social media and leave your comments if you want to discuss further on any post. Disclaimer: All the information on this website is published in good faith and for general information purpose only. I don’t make any warranties about the completeness, reliability and accuracy of this information. Any action you take upon the information you find on this blog is strictly at your own risk. The Views and opinions published on this blog are my own and not the opinions of my employer or any of the vendors of the product discussed.
This entry was posted in Monitoring. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s