Install Zabbix Agent from Source on Linux

1
2
groupadd zabbix
useradd -g zabbix zabbix

Download and install latest version of zabbix from source.

1. cd /usr/local/src
2. wget http://freefr.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz
3. tar -zxvf zabbix-3.0.3.tar.gz
4. cd zabbix-3.0.3
5. ./configure --enable-agent
6. make install

Edit Zabbix agent configuration file at

1
vi /usr/local/etc/zabbix_agentd.conf

Add Zabbix server IP address to the file.

1
Server = 127.0.0.1, ZABBIX_SERVER_IP

Start zabbix_agentd

1
[root@server ~]# zabbix_agentd

Verify Zabbix agent log for errors.

1
tail /tmp/zabbix_agentd.log

Then login to Zabbix Dashboard on zabbix server and add a new host by entering the following details.

1
2
3
Host name: client host name
Groups: Linux Servers
IP address: client host IP

Enable Zabbix Agent to start on Boot CentOS

1
2
3
4
[root@server ~]# cd /usr/local/src/zabbix-*/
[root@server zabbix-3.0.3]# cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/zabbix_agentd
[root@server zabbix-3.0.3]# chkconfig --add zabbix_agentd
[root@server zabbix-3.0.3]# chkconfig zabbix_agentd on

If everything is alright, you should see 3:on like below when running the following command.

1
2
3
[root@server ~]# chkconfig | grep zabbix
zabbix_agentd   0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@server ~]#

Enable Zabbix Agent to start on Boot (Ubuntu/Debian)

1
2
3
4
cd ~/zabbix-source/zabbix-*/
cp misc/init.d/debian/zabbix-agent /etc/init.d
chmod 755 /etc/init.d/zabbix-agent
update-rc.d zabbix-agent defaults

Reference: https://blog.hostonnet.com/install-zabbix-agent-from-source-linux

How to set up Zabbix Server

docker network create --subnet 172.20.0.0/16 --ip-range 172.20.240.0/20 zabbix-net

docker run --name postgres-server -t -e POSTGRES_USER="zabbix" -e POSTGRES_PASSWORD="zabbix_pwd" -e POSTGRES_DB="zabbix" --network=zabbix-net --restart unless-stopped -d postgres:latest

docker run --name zabbix-snmptraps -t -v /zbx_instance/snmptraps:/var/lib/zabbix/snmptraps:rw -v /var/lib/zabbix/mibs:/usr/share/snmp/mibs:ro --network=zabbix-net -p 162:1162/udp --restart unless-stopped -d zabbix/zabbix-snmptraps:alpine-5.4-latest

docker run --name zabbix-server-pgsql -t -e DB_SERVER_HOST="postgres-server" -e POSTGRES_USER="zabbix" -e POSTGRES_PASSWORD="zabbix_pwd" -e POSTGRES_DB="zabbix" -e ZBX_ENABLE_SNMP_TRAPS="true" --network=zabbix-net -p 10051:10051 --volumes-from zabbix-snmptraps --restart unless-stopped -d zabbix/zabbix-server-pgsql:alpine-5.4-latest

docker run --name zabbix-web-nginx-pgsql -t -e ZBX_SERVER_HOST="zabbix-server-pgsql" -e DB_SERVER_HOST="postgres-server" -e POSTGRES_USER="zabbix" -e POSTGRES_PASSWORD="zabbix_pwd" -e POSTGRES_DB="zabbix" --network=zabbix-net -p 443:8443 -p 8080:8080 -v /etc/ssl/nginx:/etc/ssl/nginx:ro --restart unless-stopped -d zabbix/zabbix-web-nginx-pgsql:alpine-5.4-latest

Reference: https://www.zabbix.com/documentation/current/en/manual/installation/containers

How to install Zabbix agent on CentOS 8

Step 1: Go to the /etc/yum.repos.d/ directory.

cd /etc/yum.repos.d/

Step 2: Run the below commands

sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

Step 3: Now run the yum update

yum update -y

Step 4:

dnf install https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-agent-6.0.3-1.el8.x86_64.rpm

Edit /etc/zabbix/zabbix_agentd.conf

#Server=[zabbix server ip]
#Hostname=[ Hostname of client system ]

Server=192.168.1.100
ServerAlive=192.168.1.100
Hostname=Server1

systemctl enable zabbix-agent
systemctl start zabbix-agent

References:

https://techglimpse.com/failed-metadata-repo-appstream-centos-8/

https://tecadmin.net/install-zabbix-agent-centos-8/

How to set up SSMTP

  1. Install ssmtp Install ssmtp:
    sudo apt-get install ssmtp
    
  2. Edit the ssmtp config file:
    gksu gedit /etc/ssmtp/ssmtp.conf
    
  3. Append the following text:
    root=username@gmail.com
    mailhub=smtp.gmail.com:465
    rewriteDomain=gmail.com
    AuthUser=username
    AuthPass=password
    FromLineOverride=YES
    UseTLS=YES
    
  4. Run ssmtp and provide the recipient email address:
    ssmtp recepient_name@gmail.com
    
  5. Provide the message details as follows:
    To: recipient_name@gmail.com
    From: username@gmail.com
    Subject: Sent from a terminal!
    
    Your content goes here. Lorem ipsum dolor sit amet, consectetur adipisicing.
    (Notice the blank space between the subject and the body.)
    
    
    ssmtp recipient_name@gmail.com < filename.txt
    

UC-GZ1 crontab

@reboot sleep 61; /sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 1852 -j DNAT --to-destination 192.168.0.61:1852
@reboot sleep 61; /sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j DNAT --to-destination 192.168.0.61:443
@reboot sleep 61; /sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 992 -j DNAT --to-destination 192.168.0.61:992
@reboot sleep 61; /sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 1194 -j DNAT --to-destination 192.168.0.61:1194
@reboot sleep 61; /sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 1852 -j DNAT --to-destination 192.168.0.61:1852
@reboot sleep 61; /sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 5555 -j DNAT --to-destination 192.168.0.61:5555
@reboot sleep 61; /sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8888 -j DNAT --to-destination 192.168.0.61:8888
@reboot sleep 61; /sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 18106 -j DNAT --to-destination 192.168.0.61:18106
@reboot sleep 61; /sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 18158 -j DNAT --to-destination 192.168.0.61:18158
@reboot sleep 61; /sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 18208 -j DNAT --to-destination 192.168.0.61:18208

@reboot sleep 61; /sbin/iptables -t nat -A PREROUTING -i eth0 -p udp --dport 1852 -j DNAT --to-destination 192.168.0.61:1852
@reboot sleep 65; /usr/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE