IT Infrastructure Monitoring with Zabbix - Part02

Configure Zabbix Agent: Active vs. Passive ?


Zabbix Agent is installed on servers or client-side devices. Thereby, Zabbix Agent will collect the necessary information from the client computer that needs to be monitored, checked and collected data related to CPU, Memory, Disk and Network interface… or other administrator requirements, then send the results back to Zabbix Server for storage and visualization. It runs on any modern operating system and is very flexible because its functionality can be extended with scripts and modules.
 
First, you need to understand about Active vs Passive Zabbix Agent mode.

See this:

Active vs Passive agent connection

When using a Zabbix agent in active mode, it will connect to the Zabbix server via port 10051 to retrieve configuration and send data. This is a great feature that allows an active Zabbix agent to work behind the firewall and to offload the Zabbix server in large environments.

On the other hand, if you use a Zabbix agent in passive mode, Zabbix server will initiate a connection via port 10050 and retrieve data from the agent. The Zabbix server will do this for every metric (item) every few minutes – which is very inefficient! Because of this, active mode is more recommended.

An additional advantage of the Zabbix agent in active mode is that it can read logs from the device and that is not possible if the Zabbix agent is used in passive mode.

Because, Zabbix-agent is quite easy to install so I won't mention it here.


In this tutorial, I will show you how to configure  Zabbix agent and add host to monitoring system.

1/ Configure Zabbix agent on Linux OS:

Automation configure Zabbix Agent with bash script:

#!/bin/bash

# Function to handle errors
error_exit() {
    echo "Error: $1"
    exit 1
}

# Variables
Server="vnszabbix01.infra.lecuong.info"
ServerActive="vnszabbix01.infra.lecuong.info"
HostMetadata="Linux"
HostnameItem="system.hostname"
ConfigFile="/etc/zabbix/zabbix_agentd.conf"

# Step 1: Create a backup of the original configuration file
cp "$ConfigFile" "${ConfigFile}.bak" || error_exit "Failed to create backup of $ConfigFile"

# Step 2: Use 'sed' to update the configuration with the above vars' values
sudo sed -i -e "s/^Server=.*/Server=${Server}/" \
             -e "s/^ServerActive=.*/ServerActive=${ServerActive}/" \
             -e "s/^HostMetadata=.*/HostMetadata=${HostMetadata}/" \
             -e "s/^HostnameItem=.*/HostnameItem=${HostnameItem}/" "$ConfigFile" || error_exit "Failed to update $ConfigFile"

# Step 3: Configure firewall for the Zabbix-agent using firewalld
sudo firewall-cmd --permanent --add-port=10050/tcp || error_exit "Failed to add port 10050 to the firewall"
# sudo firewall-cmd --permanent --add-port=10051/tcp || error_exit "Failed to add port 10051 to the firewall"
sudo firewall-cmd --reload || error_exit "Failed to reload the firewall"

# Step 4: Start Zabbix agent and set it to boot on startup
sudo systemctl start zabbix-agent || error_exit "Failed to start Zabbix agent"
sudo systemctl enable zabbix-agent || error_exit "Failed to enable Zabbix agent on startup"

echo "Zabbix agent configured to point to server: $Server"


In the "Server" and "ServerActive" parameters put the IP/DNS address of your Zabbix server or proxy!

Save above code with name: zabbix-agent-point-to-server.sh

Set permission:

chmod a+X ./zabbix-agent-point-to-server.sh

Run script to configure Zabbix-agent:

./zabbix-agent-point-to-server.sh


2/ Add host to monitoring system:

**** Create Host groups

Configuration -- Host groups -- Create host group
  • Group name: Linux Server
Click “Add”.

****Configure auto registration for Linux Zabbix Agents

With this step - configure auto registration, your host will be auto add to Zabbix-server.
If you need to add a lot of servers to Zabbix, you need to configure auto registration. or use a programming languages via API.

I'm a lazy guy so I don't like to manually add them one by one!  LOL

Let's go! 

Actions -- Configuration  -- Auto registration  -- Create action:

On the “Action” tab:
  • Name: Auto registration for Linux Servers
  • New condition:  Host metadata contains Linux

On the “Operations” tab: 

add new operation

  • Operation type: Add to host group, then select to which “Host groups” will Linux hosts be added when discovered. In this case, I select "Linux Server"
add new operation:

  • Operation type: Link to the template, , then select to which “templates” will Linux hosts be added when discovered. In this case, I select "Linux by Zabbix agent" (passive checks).

It's done. Wait a few minutes and your Linux server should appear in Zabbix. 

From now on, every time you install a Zabbix agent on a Linux OS, it will automatically be added to the Zabbix-server and linked with the host group and templates  you've select above.


In the next article...
  • IT Infrastructure Monitoring with Zabbix - Part03
Just wait....



Viết nhận xét

Các bạn có thể viết lời nhận xét cho bài viết, nhưng cần tuân thủ một số quy tắc sau:

» Các nhận xét/bình luận phải nghiêm túc, không dung tục, không spam.
» Nội dung phải liên quan tới chủ đề bài viết.
» Viết bằng tiếng việt có dấu hoặc tiếng Anh. Nội dung viết không dấu sẽ bị xóa.
» Hãy để lại tên của bạn khi nhận xét/bình luận, để tôi có thể dễ dàng trả lời bạn khi cần.