Icinga2: Haproxy- master/slave setup

From ppwiki
Jump to navigation Jump to search

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

Icinga2.png

New configuration

In the new configuration we will need to put a dbproxy between Icinga2 and the database master server. See image below

Icinga21.png

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

Note: change the Bind address in the "listen start" with your dbproxy IP address and the server name and IP addresses in the "listen mysql-cluster" with your master and slaves names and IP addresses. If you are running UFW make sure port 3306 is open on the dbproxy node

As we can see in the haproxy.cfg file, we have a user called " haproxy_user" this user will check the status on all 3 database servers so we need to create this user.The user don't need and privileges on the database but we have to create the user on all 2 database servers.

Database configuration

Create the haproxy_user

The user don't have to be called "haproxy_use" you can call the user anything you want. login on all 3 database servers and issue the command

create user 'haproxy_user'@'dbproxy1001.dfw.labnet';

Create the application user

Icinga2 configuration