Install Zabbix on an AWS Instance with Amazon Linux

Amazon Linux is cheaper than the other Linux flavors available in AWS, but the package manager is missing a few things – namely Zabbix. Let’s install Zabbix!

UPDATE:
Oh, but hold the phone! I went about this entirely the wrong way! As Tag mentions in the comments below, there is a much better way to do this, and it is to use another repo! Naive me thought that AWS’s version of Linux had its own special repos. That’s not the case. They are still pretty much CentOS! Please use the method he outlined in the comments!!!

Step 1) Live dangerously

sudo -sH

Optional) Don’t live dangerously, and use sudo for some of the following commands.

Step 2) Save the pre-compiled package and source to your /tmp directory.

cd /tmp

wget http://www.zabbix.com/downloads/2.0.0/zabbix_agents_2.0.0.linux2_6_23.amd64.tar.gz

wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.0.0/zabbix-2.0.0.tar.gz

Step 3) Put things in their places

mkdir /tmp/zabbix

cd /tmp/zabbix

tar -xzvf /tmp/zabbix_agents_2.0.0.linux2_6_23.amd64.tar.gz

tar -xzvf /tmp/zabbix-2.0.0.tar.gz

cp /tmp/zabbix/bin/* /usr/bin

cp /tmp/zabbix/sbin/* /usr/sbin

mv /tmp/zabbix/zabbix-2.0.0/conf/zabbix_agentd /tmp/zabbix/zabbix-2.0.0/conf/zabbix_agentd.d

If you do not already have a /usr/local/etc folder, create it here.

mkdir /usr/local/etc

cp -r /tmp/zabbix/zabbix-2.0.0/conf/* /usr/local/etc

Step 4) Create the Zabbix user and group, set up permissions

groupadd zabbix

useradd -g zabbix zabbix

mkdir /var/log/zabbix-agent

chown zabbix:zabbix /var/log/zabbix-agent

Step 5) Edit the config files with nano (or vi, or emacs….)

nano /usr/local/etc/zabbix_agentd.conf

Change “Server=127.0.0.1” to the IP address of your Zabbix server:
e.g. Server=10.11.22.33

Change “LogFile=/tmp/zabbix_agentd.log” to the better location you set up earlier:
LogFile=/var/log/zabbix-agent/zabbix_agentd.log

Change “ServerActive=127.0.0.1” option to the IP address of your Zabbix server:
e.g. ServerActive=10.11.22.33

Change “Hostname=Zabbix server” to your hostname, or just comment it out
e.g. Hostname=myserver or #Hostname=Zabbix server

Set the “Include” path:
“Include=/usr/local/etc/zabbix_agentd.d/”

Change anything else as necessary. (Maybe set ListenIP the same as ServerActive?)

Save and exit

Step 6) Set up the service


nano /etc/init.d/zabbix-agent

Paste the following wall of text into that file;

#! /bin/sh
counter=0
zabbix_counter=$(ps -ef | grep zabbix_agentd | grep -v grep | wc -l)

start(){
echo "-------------------------------------------------------------------"
echo " LAUNCHING ZABBIX AGENT"

if [ $zabbix_counter -gt 0 ]; then
echo " * Zabbix agent was previously running"
echo " * Number of Zabbix agentd instances= $zabbix_counter"
echo "-----------------------------------------------------------------"
fi

# Checking if the user is able to start the agent.... if the user is not able to, script performs su to
# the user zabbix and starts the agent

if [ $(whoami) != "zabbix" ];then
sudo -u zabbix zabbix_agentd
else
# Script is acting as the zabbix user, so it can start the agent.
zabbix_agentd
fi
sleep 10

zabbix_counter=$(ps -ef | grep zabbix_agentd | grep -v grep | wc -l)
if [ $zabbix_counter -gt 0 ]; then
echo " * Zabbix agent succesfully started"
echo " * Number of zabbix agentd instances= $zabbix_counter"
echo "-------------------------------------------------------------------"
else
echo " * Zabbix agent couldn't be started, check Zabbix logs"
echo "-------------------------------------------------------------------"
fi

}

stop(){
# Checking if the user is able to stop the agent.... if the user is not able to, script performs su to
# the user zabbix and kills the agent. Also script tries to kill zabbix-agent processes 5 times using a counter, if at
# the fith try the agent is still there, script outputs a message to the console.

echo "-------------------------------------------------------------------"
echo " STOPPING ZABBIX AGENT"

if [ $zabbix_counter -eq 0 ]; then
echo " * Zabbix agent was not running on this machine"
echo "-------------------------------------------------------------------"
fi

while [ $zabbix_counter -gt 0 ] && [ $counter -lt 5 ] ; do

let counter=counter+1

echo " * Number of Attempts (Max 5)=$counter"
echo " * Stopping zabbix.."
echo " * Number of zabbix agentd instances= $zabbix_counter"

if [ $(whoami) != "zabbix" ];then
sudo -u zabbix killall zabbix_agentd > /dev/null &
else
killall zabbix_agentd > /dev/null &
fi

sleep 10
# Script has a 10 second delay to avoid attempting to kill a process that is still shutting down. If the script
# can't kill the processes, an error will appear.
# After 10 seconds script checks again the number of zabbix_agentd processes running,
# if it's 0, script will exit the loop and continue on

zabbix_counter=$(ps -ef | grep zabbix_agentd | grep -v grep | wc -l)

done

if [ $zabbix_counter -gt 0 ]; then
echo " * Zabbix agent couldn't be stopped, check Zabbix logs"
echo "-------------------------------------------------------------------"
fi

if [ $zabbix_counter -eq 0 ]; then
echo " * Zabbix agent successfully stopped"
echo "-------------------------------------------------------------------"
fi

}

restart(){
stop
# Gives system some time to stop processes before script restarts service
sleep 10
# Now script can start the agent again
start
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: zabbix {start|stop|restart}"
exit 1
esac

exit 0

Handle some permissions

chmod 744 /etc/init.d/zabbix-agent

ln -s /etc/init.d/zabbix-agent /sbin/zabbix-agent

Step 8) Run Zabbix

service zabbix-agent start

Step 9) Post a comment on the site if anything here could be done better, or if anything didn’t work. I will politely ignore you  :3

9 thoughts on “Install Zabbix on an AWS Instance with Amazon Linux

  1. This way is not optimal. Manually installing outside of your package manager is asking for problems. Especially where maintainability, patching, upgrades, and overhead are concerned.

    Here’s an easier and more manageable way.

    # sudo yum-config-manager –enable epel

    # sudo yum update -y

    # yum search “zabbix”

    For agent only:
    # sudo yum install zabbix-agent

    For server, agent, and web interface:
    # sudo yum install zabbix-agent zabbix-server-mysql zabbix-web-mysql

      • MEEP! I also see the comment box merged the TWO DASHES sudo yum-config-manager –enable epel!!!

        That’s:

        –enable epel ([DASH-DASH]enable)

        Sorry about that!

    • Thank you very much for contributing this. This is going to save people time and headaches.

      I learned that I made a mistake in falsely assuming that Zabbix was unavailable through package managers for Amazon Linux. Although Amazon Linux is quite similar to CentOS, I saw that it used different repos than CentOS does, and believed that I wouldn’t be able to use Yum to install Zabbix-agent.
      However, the EPEL repo is meant to provide packages to all of the Redhatty flavors, and this is a much better solution.
      I will edit the post with your improved instructions (and leave the manual way because it took so long to type out)

    • Hey Paul,
      Isolate that problem, determine what it is, then go to Google for more information.

      So, you’re going to want to confirm simple things first: is the IP address correct? Is the web server running?

      Next, find out the error message. What is displayed in the browser? What is displayed in the webserver’s error logs?

      Finally, go onto Google for resolution of the issues, and learn what caused it!

      Good luck!

Leave a Reply to eli Cancel reply

Your email address will not be published. Required fields are marked *