Zabbix in built HA Setup: 2 core, frontend, DB

 On Frontend Server

Step1: Add the Zabbix repo

rpm -Uvh https://repo.zabbix.com/zabbix/7.0/rhel/8/x86_64/zabbix-release-latest-7.0.el8.noarch.rpm

dnf clean all


Step2:  Switch DNF module version for PHP

dnf module switch-to php:8.2


Step3: Install frontend, agent

dnf install zabbix-web-mysql zabbix-apache-conf zabbix-selinux-policy zabbix-agent


Step4: Go to the pat/etc/zabbix/web/zabbix.conf.php, 

if it is not there then copy from where it is

cp /usr/share/zabbix/conf/zabbix.conf.php.example /etc/zabbix/web/zabbix.conf.php

If /etc/zabbix/web/ doesn’t exist, create it first:

mkdir -p /etc/zabbix/web/

cp /usr/share/zabbix/conf/zabbix.conf.php.example /etc/zabbix/web/zabbix.conf.php


Step5: Open it now 

vi /etc/zabbix/web/zabbix.conf.php

Add the following lines

DB['TYPE']                             = 'MYSQL';

$DB['SERVER']                   = 'DB_ip';

$DB['PORT']                             = '3306';

$DB['DATABASE']                 = 'zabbix';

$DB['USER']                             = 'zabbix';

$DB['PASSWORD']                 = 'zabbix';

-------------------------------------------------------------

$ZBX_SERVER                     = 'anycommon_ip';

$ZBX_SERVER_PORT                = '10051';

$ZBX_SERVER_NAME                = 'Zabbix HA';

$IMAGE_FORMAT_DEFAULT   = IMAGE_FORMAT_PNG;


Step6: Install the HA Proxy: automatic way to connect the frontend server to the active Zabbix core server, without having to manually edit /etc/hosts or DNS every time there's a failover.

Why HA Proxy?

  • Automatically check which Zabbix core server is active
  • Forward all connections (port 10051) to the active node
  • No need to change anything manually after failover
  • Works seamlessly with Zabbix built-in HA

yum install haproxy -y  

open the file /etc/haproxy/haproxy.cfg

vi /etc/haproxy/haproxy.cfg

Add the following line at last

frontend zabbix_server

    mode tcp

    bind common_ip:10051

    default_backend zabbix_backends

backend zabbix_backends

    mode tcp

    option tcp-check

    tcp-check connect

    server coreserver core1_ip:10051 check inter 1s fall 1 rise 1

    server coreserver2 core2_ip:10051 check inter 1s fall 1 rise 1


To verify the HAProxy config file

haproxy -c -f /etc/haproxy/haproxy.cfg


Step7: Start the HA Proxy

sudo systemctl restart haproxy

sudo systemctl enable haproxy


Step8: Start the httpd

systemctl restart httpd php-fpm

systemctl enable httpd php-fpm


On Core server1 and Core server2

Step1: Add the Zabbix repo

rpm -Uvh https://repo.zabbix.com/zabbix/7.0/rhel/8/x86_64/zabbix-release-latest-7.0.el8.noarch.rpm

dnf clean all


Step2: Install the Zabbix server, agent
dnf install zabbix-server-mysql zabbix-selinux-policy zabbix-agent

Step3: Open the file /etc/zabbix/zabbix_server.conf

vi  /etc/zabbix/zabbix_server.conf

DBHost=DB_server_ip
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix

For HA
HANodeName=coresserver1   #coreserver2 in case of core2
NodeAddress=coreserver1_ip:10051     #coreserver2 ip icase of core2

Step4: Start thr agent and zabbix server

systemctl restart zabbix-server zabbix-agent 
systemctl enable zabbix-server zabbix-agent

Note: To check the status of HA
zabbix_server -R ha_status


On DB server

Step1: Add the Zabbix repo

rpm -Uvh https://repo.zabbix.com/zabbix/7.0/rhel/8/x86_64/zabbix-release-latest-7.0.el8.noarch.rpm

dnf clean all


Step2: install the sql scripts

dnf install zabbix-sql-scripts zabbix-selinux-policy zabbix-agent


Step3: Install the mysql server

dnf install mysql-server

systemctl restart mysqld


Stpe4: login to DB

mysql -uroot -p

create database zabbix character set utf8mb4 collate utf8mb4_bin;

create user zabbix@localhost identified by 'password';

CREATE USER 'zabbix'@'core1_ip' IDENTIFIED BY 'zabbix';

CREATE USER 'zabbix'@'core2_ip' IDENTIFIED BY 'zabbix';

CREATE USER 'zabbix'@'Frontend_ip' IDENTIFIED BY 'zabbix';

GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'core1_ip';

GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'core2_ip';

GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'frontend_ip';

grant all privileges on zabbix.* to zabbix@localhost;

set global log_bin_trust_function_creators = 1;

quit;


Step5: On Zabbix server host import initial schema and data. You will be prompted to enter your newly created password
zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix

Disable log_bin_trust_function_creators option after importing database schema.

mysql -uroot -p
password

set global log_bin_trust_function_creators = 0;
quit;

Step6: Restart the mysqld service
systemctl restart mysqld


Now you can access the Zabbix ui
http://frontend_ip/zabbix

Note: Necessary zabbix port should be enabled and Selinux should be disabled
10050 TCP, 10051 TCP, 3306 TCP




Comments

Popular posts from this blog

How to enable the syslog monitoring-Zabbix

Zabbix installation: Distribution setup

API & API in Zabbix