Monday, July 15, 2013

Zabbix-Agent for Debian & RHL Linux distributions

#Replace the values inside "{}" with your own settings
#First we add the Monitoring server to our server host file:
echo "{xxx.xxx.xxx.xxx} {your.server.tld}" >> /etc/hosts



#Next we add the zabbix user and group
groupadd zabbix
useradd -g zabbix zabbix

#Now we need to set the firewall rules to allow zabbix access to our server:
iptables -I INPUT 1 -p tcp -s {xxx.xxx.xxx.xxx} --dport 10050 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -I INPUT 1 -p tcp -s {xxx.xxx.xxx.xxx} --dport 10051 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -I INPUT 1 -p udp -s {xxx.xxx.xxx.xxx} --dport 10050 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -I INPUT 1 -p udp -s {xxx.xxx.xxx.xxx} --dport 10051 -m state --state NEW,ESTABLISHED -j ACCEPT

#We must set zabbix as a listed service in our system services:
cat <<EOF>> /etc/services
### Zabbix Services ###
zabbix-agent    10050/tcp                       #Zabbix Agent
zabbix-agent    10050/udp                       #Zabbix Agent
zabbix-trapper  10051/tcp                       #Zabbix Trapper
zabbix-trapper  10051/udp                       #Zabbix Trapper
EOF


#Create the download directory and grab the files of the net so we can install our monitoring:
mkdir -p /downloads/zabbix
cd /downloads/zabbix
wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.0.6/zabbix-2.0.6.tar.gz
tar zxvf zabbix-2.0.6.tar.gz
cd zabbix-2.0.6


#Time to configure and install our monitoring agent from source:
./configure --enable-agent --enable-static
make install


#Copy the startup script to the server location:
#For Debian
cp /downloads/zabbix/zabbix-2.0.6/misc/init.d/debian/zabbix_agentd /etc/init.d/
#For RHL
cp /downloads/zabbix/zabbix-2.0.6/misc/init.d/fedora/zabbix_agentd /etc/init.d/

#Add the execute permisions:
chmod +x /etc/init.d/zabbix-agentd

#Then add it to our startup for the server:
1
2
3
4
iptables -I INPUT 1 -p tcp -s {xxx.xxx.xxx.xxx} --dport 10050 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -I INPUT 1 -p tcp -s {xxx.xxx.xxx.xxx} --dport 10051 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -I INPUT 1 -p udp -s {xxx.xxx.xxx.xxx} --dport 10050 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -I INPUT 1 -p udp -s {xxx.xxx.xxx.xxx} --dport 10051 -m state --state NEW,ESTABLISHED -j ACCEPT

#For Debian
update-rc.d zabbix-agentd defaults
#For RHL
chkconfig --level 345 scriptname on

#If you find that the startup script is not working for you, feel free to add the agent daemon to your rc.local, it can be done so:
nano /etc/rc.local

Alter the section that reads from
[...]
zabbix_agentd
exit 0
[...]


#Edit the following 2 files and  be sure to add the monitoring server you listed in step one under the active monitoring server:
nano /usr/local/etc/zabbix_agent.conf
nano /usr/local/etc/zabbix_agentd.conf

#And we are ready to start our zabbix-agent:
zabbix_agentd


Thats all folks!

No comments:

Post a Comment