Difference between revisions of "Icinga2: Haproxy- master/slave setup"
Line 25: | Line 25: | ||
Open the configuration file and copy and paste the configuration below. | Open the configuration file and copy and paste the configuration below. | ||
− | + | cd /etc/haproxy | |
+ | sudo vi haproxy.cfg | ||
+ | |||
+ | # HAProxy's stats | ||
+ | listen stats | ||
+ | bind 10.192.32.8:80 | ||
+ | stats enable | ||
+ | stats hide-version | ||
+ | stats uri / | ||
+ | stats realm HAProxy Statistics | ||
+ | stats auth user_name:user_password | ||
+ | |||
+ | listen mysql-cluster | ||
+ | bind 0.0.0.0:3306 | ||
+ | mode tcp | ||
+ | option tcplog | ||
+ | balance roundrobin | ||
+ | option log-health-checks | ||
+ | log /dev/log local0 crit | ||
+ | option tcpka | ||
+ | option mysql-check user haproxy_user | ||
+ | server db1001 10.192.16.9:3306 check inter 3s fall 3 rise 6 | ||
+ | server db1002 10.192.32.2:3306 check backup | ||
+ | server db1005 10.192.32.2:3306 check backup | ||
=Database configuration= | =Database configuration= | ||
=Icinga2 configuration= | =Icinga2 configuration= |
Revision as of 20:29, 28 August 2019
In This tutorial I will be setting up Icinga2 to use a database proxy (dbproxy) to connect to it's master database and fail-over to the slave database if master database is not available for some reasons.
Note: We will not cover the Icinga2, Icingaweb2 and master/slave setup in this tutorial
Prerequisites
1 icinga2 server: icinga1001 1 master database master server: db1001 1 dbproxy server: dbproxy1001 2 slaves database severs: db1002 and db1005
Setup
Existing configuration
In my existing configuration, I have Icinga2 connecting directly to the database master (db1001). See image below
New configuration
In the new configuration we will need to put a dbproxy between Icinga2 and the database master server. See image below
Haproxy setup and configuration
On the dbpoxy1001, install haproxy:
sudo apt-get install haproxy
Open the configuration file and copy and paste the configuration below.
cd /etc/haproxy sudo vi haproxy.cfg
# HAProxy's stats listen stats bind 10.192.32.8:80 stats enable stats hide-version stats uri / stats realm HAProxy Statistics stats auth user_name:user_password
listen mysql-cluster bind 0.0.0.0:3306 mode tcp option tcplog balance roundrobin option log-health-checks log /dev/log local0 crit option tcpka option mysql-check user haproxy_user server db1001 10.192.16.9:3306 check inter 3s fall 3 rise 6 server db1002 10.192.32.2:3306 check backup server db1005 10.192.32.2:3306 check backup