Book Image

Zabbix Cookbook

By : Patrik Uytterhoeven, patrik uytterhoeven
Book Image

Zabbix Cookbook

By: Patrik Uytterhoeven, patrik uytterhoeven

Overview of this book

Table of Contents (18 chapters)
Zabbix Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Agent installation and configuration


In this section, we will explain you the installation and configuration of the Zabbix agent. The Zabbix agent is a small piece of software about 700 KB in size. You will need to install this agent on all your servers to be able to monitor the local resources with Zabbix.

Getting ready

In this recipe, to get our Zabbix agent installed, we need to have our server with the Zabbix server up and running as explained in Server installation and configuration. In this setup, we will install our agent first on the Zabbix server. We just make use of the Zabbix server in this setup to install a server that can monitor itself. If you monitor another server then there is no need to install a Zabbix server, only the agent is enough.

How to do it...

Installing the Zabbix agent is quite easy once our server has been set up. The first thing we need to do is install the agent package.

Installing the agent packages can be done by running yum as we have already added the repository to our package manager in the previous recipe Server installation and configuration. In case you have skipped it, then go back and add the Zabbix repository to your package manager.

  1. Install the Zabbix agent from the package manager:

    # yum install zabbix-agent
    
  2. Open the correct port in your firewall. The Zabbix server communicates to the agent if the agent is passive. So, if your agent is on a server other than Zabbix, then we need to open the firewall on port 10050. (We shall further explain active and passive agents in Chapter 4).

  3. Edit the firewall, open the file /etc/sysconfig/iptables and add the following after the line with dport 22 in the next line:

    # -A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT
    
  4. Users of RHEL 7 can run:

    # firewall-cmd --permanent --add-port=10050/tcp
    
  5. Now that the firewall is adjusted, you can restart the same:

    # service iptables restart
    # firewall-cmd --reload (if you use RHEL 7)
    

    The only thing left to do is edit the zabbix_agentd.conf file, start the agent, and make sure it starts after a reboot.

  6. Edit the Zabbix agent configuration file and add or change the following settings. We will see later in Chapter 4 the difference between active and passive; for now just fill in both variables.

    # vi /etc/zabbix/zabbix_agentd.conf
    Server=<ip of the zabbix server>
    ServerActive=<ip of the zabbix server>
    

    That's all for now in order to edit in the zabbix_agentd.conf file.

  7. Now, let's start the Zabbix agent:

    # service zabbix-agent start
    # systemctl start zabbix-agent (if you use RHEL 7)
    
  8. And finally make sure that our agent will come online after a reboot:

    # chkconfig zabbix-agent on
    # systemctl enable zabbix-agent (for RHEL 7 users)
    
  9. Check again that there are no errors in the log file from the agent:

    # tail /var/log/zabbix/zabbix_agentd.log
    

How it works...

The agent we have installed is installed from the Zabbix repository on the Zabbix server, and communicates to the server on port 10051 if we make use of an active agent. If we make use of a passive agent, then our Zabbix server will talk to the Zabbix agent on port 10050. Remember that our agent is installed locally on our host; so all communication stays on our server. This is not the case if our agent is installed on another server instead of our Zabbix server. We have edited the configuration file from the agent and changed the Server and ServerActive options. Our Zabbix agent is now ready to communicate with our Zabbix server. Based on the two parameters we have changed, the agent knows what the IP is from the Zabbix server.

The difference between passive and active modes is that the client in passive mode will wait for the Zabbix server to ask for data from the Zabbix agent.

The agent in active mode will ask the server first what it needs to monitor and pull this data from the Zabbix server. From that moment on, the Zabbix agent will send the values by itself to the server at regular intervals.

So when we use a passive agent the Zabbix server pulls the data from the agent where a active agent pushes the data to the server.

We did not change the hostname item in the zabbix_agentd.conf file, a parameter we normally need to change and give the host a unique name. In our case the name in the agent will already be in the Zabbix server that we have installed, so there is no need to change it this time.

There's more...

Just like our server, the agent has a plenty more options to set in its configuration file. So open the file again and have a look at what else we can adjust. In the following URLs you will find all options that can be changed in the Zabbix agent configuration file for Unix and Windows:

https://www.zabbix.com/documentation/2.4/manual/appendix/config/zabbix_agentd.

https://www.zabbix.com/documentation/2.4/manual/appendix/config/zabbix_agentd_win.