CENTREON – Installation MariaDB 10 en cluster + HAProxy sur Centos 7

Suite à une monté en charge de ma supervision, et à des fin d’optimisé la partie base de donnée pour Centreon qui effectuée de plus en plus de requette, que la quantité sauvegardé devient importante.
Je modifie l’infrastructure que j’ai monté oui y rajouter un base de données en HA

AVANT

APRES

A cette étape, 2 possibilités s’offre à moi :

Soit une configuration avec 4 serveurs Soit une configuration avec 3 serveurs.
Celle-ci peut provoquer un problème avec le HAProxy au niveau des ports réseaus
Load Balancer
Hostname: haproxy
OS: Centos 7 Private IP: 192.168.1.50
Node 1
Hostname: serveur1
OS: Centos 7 Private IP: 192.168.1.51
Node 2
Hostname: serveur2
OS: Centos 7 Private IP: 192.168.1.52
Node 3
Hostname: serveur3
OS: Centos 7 Private IP: 192.168.1.52
Node 1 + Load Balancer
Hostname: serveur1
OS: Centos 7 Private IP: 192.168.1.51
Node 2
Hostname: serveur2
OS: Centos 7 Private IP: 192.168.1.52
Node 3
Hostname: serveur3
OS: Centos 7 Private IP: 192.168.1.52

Ceci est à faire une chacun des 3 serveurs (ou X serveurs) qui hébergeront les base de données

Nous exécution une mise à jour

yum -y update && yum -y upgrade

Nous ajoutons un nouveau repository

tee /etc/yum.repos.d/MariaDB.repo <<-‘EOF’
# MariaDB 10.1 CentOS repository list – created 2016-04-04 21:28 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF

Nous exécution une mise à jour avec le nouveau repository

yum -y update

Nous lancons l’installation de l’application

yum -y install mariadb-server mariadb-client

Nous pouvons démarrer le service MySQL

systemctl start mysql

Nous réinitiation le mot de passe ROOT de MySQL

‘/usr/bin/mysqladmin’ -u root password ‘Passw0rdTemp’

Nous lancons le script de sécurité de la base de données

mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we’ll need the current
password for the root user. If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer ‘n’.

Change the root password? [Y/n] Y
New password:NEW_PASSWORD
Re-enter new password:NEW_PASSWORD
Password updated successfully!
Reloading privilege tables..
… Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]Y
… Success!

Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] N
… skipping.

By default, MariaDB comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] N
… skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.

Nous arrétons le service MySQL

systemctl stop mysql

Création du répertoire de log

mkdir /var/log/mysql
chown mysql:mysql /var/log/mysql/
chmod 755 /var/log/mysql/

Nous allons modifier le fichier de configuration MySQL sur chaque serveur

nano /etc/my.cnf.d/server.cnf

Ceux-ci est commun au 3 serveurs

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
innodb_force_recovery=0
ignore-db-dir=lost+found
open-files-limit=32000
innodb_file_per_table=1
key_buffer_size=4000M
sort_buffer_size=64M
join_buffer_size=8M
thread_cache_size=64M
read_buffer_size=1024K
read_rnd_buffer_size=512K
max_allowed_packet=1024M
#LOGS
general_log_file=/var/log/mysql/mysql.log
general_log=0
slow_query_log_file=var/log/mysql/mysql-slow.log
slow_query_log=1
long_query_time=10
log_error=/var/log/mysql/mysql_error.log

Serveur1 Serveur2 Serveur3

[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address= »gcomm://192.168.1.51,192.168.1.52,192.168.1.53″
#wsrep_provider_options= »gcache.size=300M; gcache.page_size=300M »
binlog_format=row
default_storage_engine=InnoDB
query_cache_size=0
innodb_autoinc_lock_mode=2
# Allow server to accept connections on all interfaces.
bind-address=0.0.0.0
# Optional setting
wsrep_cluster_name= »clusterMySQL »
wsrep_node_name= »serveur1″
wsrep_node_address= »192.168.1.51″
wsrep_sst_method=rsync
wsrep_slave_threads=1

[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address= »gcomm://192.168.1.51,192.168.1.52,192.168.1.53″
#wsrep_provider_options= »gcache.size=300M; gcache.page_size=300M »
binlog_format=row
default_storage_engine=InnoDB
query_cache_size=0
innodb_autoinc_lock_mode=2
# Allow server to accept connections on all interfaces.
bind-address=0.0.0.0
# Optional setting
wsrep_cluster_name= »clusterMySQL »
wsrep_node_name= »serveur2″
wsrep_node_address= »192.168.1.52″
wsrep_sst_method=rsync
wsrep_slave_threads=1

etc …

Rajoutons une contrainte pour Centreon

nano /etc/systemd/system/mariadb.service.d/LimitNOFILE.conf

Contenu du fichier

[Service]
LimitNOFILE=32000

Nous rechargons la configuration des service

systemctl daemon-reload

Nous désactivons les politiques d’accès

setenforce 0

Pour ne pas avoir de blocage avec le firewall, nous ouvrons un certains nombre de port réseau

Configuration avec 4 serveurs Configuration avec 3 serveurs.

firewall-cmd –permanent –add-port=3306/tcp #base de données
firewall-cmd –permanent –add-port=4444/tcp #base de données
firewall-cmd –permanent –add-port=8282/tcp #Statisques de HAProxy
(ce port doit être modifier)
firewall-cmd –permanent –add-port=9200/tcp #base de données
firewall-cmd –permanent –add-port=4567/tcp #base de données
firewall-cmd –permanent –add-port=4568/tcp #base de données
firewall-cmd –reload

firewall-cmd –permanent –add-port=3306/tcp #base de données
firewall-cmd –permanent –add-port=4444/tcp #base de données
firewall-cmd –permanent –add-port=8282/tcp #Statisques de HAProxy
(ce port doit être modifier)
firewall-cmd –permanent –add-port=9200/tcp #base de données
firewall-cmd –permanent –add-port=3030/tcp #base de données
(ce port doit être modifier)
firewall-cmd –permanent –add-port=4567/tcp #base de données
firewall-cmd –permanent –add-port=4568/tcp #base de données
firewall-cmd –reload

Nous pouvons aussi desactivé complétement le firewall

systemctl disable firewalld
systemctl stop firewalld
systemctl status firewalld

La commande suivant est à lancer seulement sur le premier serveur

galera_new_cluster
systemctl start mysql

Nous controlons que le service à bien démarrer

systemctl status mysql

Nous devons obtenir ceci nous indiquant que le service fonctionne correctement

● mariadb.service – MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since mar. 2017-08-08 16:47:08 CEST; 20h ago
Main PID: 2969 (mysqld)
Status: « Taking your SQL requests now… »
CGroup: /system.slice/mariadb.service
└─2969 /usr/sbin/mysqld –wsrep-new-cluster –wsrep_start_position=9d28cc81-7c45-11e7-9d6b-53f678c75d63:0

août 08 16:47:04 serveur1.tips-of-mine.local systemd[1]: Starting MariaDB database server…
août 08 16:47:05 serveur1.tips-of-mine.local sh[2859]: 2017-08-08 16:47:05 140169514576128 [Note] /usr/sbin/mysqld (mysqld 10.1.25-MariaDB) starting as process 2937 …
août 08 16:47:08 serveur1.tips-of-mine.local sh[2859]: WSREP: Recovered position 9d28cc81-7c45-11e7-9d6b-53f678c75d63:0
août 08 16:47:08 serveur1.tips-of-mine.local mysqld[2969]: 2017-08-08 16:47:08 140484526786816 [Note] /usr/sbin/mysqld (mysqld 10.1.25-MariaDB) starting as process 2969 …
août 08 16:47:08 serveur1.tips-of-mine.local systemd[1]: Started MariaDB database server.

Nous pouvons contoler la configuration du cluster avec la commande suivant

mysql -uroot -p -e « show status like ‘wsrep%' »

Nous obtenons ceci :

Enter password:
+——————————+—————————————+
| Variable_name | Value |
+——————————+—————————————+
| wsrep_apply_oooe | 0.000000 |
| wsrep_apply_oool | 0.000000 |
| wsrep_apply_window | 1.000000 |
| wsrep_causal_reads | 0 |
| wsrep_cert_deps_distance | 1.000000 |
| wsrep_cert_index_size | 1 |
| wsrep_cert_interval | 0.000000 |
| wsrep_cluster_conf_id | 54 |
| wsrep_cluster_size | 2 |
| wsrep_cluster_state_uuid | 9d28cc81-7c45-11e7-9d6b-53f678c75d63 |
| wsrep_cluster_status | Primary |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 1.000000 |
| wsrep_connected | ON |
| wsrep_desync_count | 0 |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | 0/0/0/0/0 |
| wsrep_evs_state | OPERATIONAL |
| wsrep_flow_control_paused | 0.000000 |
| wsrep_flow_control_paused_ns | 0 |
| wsrep_flow_control_recv | 0 |
| wsrep_flow_control_sent | 0 |
| wsrep_gcomm_uuid | 73fa0e2b-7c48-11e7-8176-c28962b7e539 |
| wsrep_incoming_addresses | 192.168.1.51:3306,192.168.1.52:3306 |
| wsrep_last_committed | 2 |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_cached_downto | 1 |
| wsrep_local_cert_failures | 0 |
| wsrep_local_commits | 0 |
| wsrep_local_index | 0 |
| wsrep_local_recv_queue | 0 |
| wsrep_local_recv_queue_avg | 0.007299 |
| wsrep_local_recv_queue_max | 2 |
| wsrep_local_recv_queue_min | 0 |
| wsrep_local_replays | 0 |
| wsrep_local_send_queue | 0 |
| wsrep_local_send_queue_avg | 0.000000 |
| wsrep_local_send_queue_max | 1 |
| wsrep_local_send_queue_min | 0 |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| wsrep_local_state_uuid | 9d28cc81-7c45-11e7-9d6b-53f678c75d63 |
| wsrep_protocol_version | 7 |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 25.3.20(r3703) |
| wsrep_ready | ON |
| wsrep_received | 137 |
| wsrep_received_bytes | 11582 |
| wsrep_repl_data_bytes | 436 |
| wsrep_repl_keys | 1 |
| wsrep_repl_keys_bytes | 31 |
| wsrep_repl_other_bytes | 0 |
| wsrep_replicated | 1 |
| wsrep_replicated_bytes | 531 |
| wsrep_thread_count | 2 |
+——————————+—————————————+

Pour ne voir que ce qui nous intérésse, voici la commande qui affiche que le nombre de noeud du cluster

mysql -u root -p -e « SHOW STATUS LIKE ‘wsrep_cluster_size' »

Enter password:
+——————–+——-+
| Variable_name | Value |
+——————–+——-+
| wsrep_cluster_size | 1 |
+——————–+——-+

Depuis les autres serveurs, nous pouvons lancer la commande pour lancer le service MySQL

systemctl start mysql

Et au fure et à mesure que lancons le service MySQL sur les autres serveur, depuis la premeir nous pouvons relancer la commande suivante pour voir le nombre de serveur gripper qui indique le nombre de serveur dans le cluster

mysql -u root -p -e « SHOW STATUS LIKE ‘wsrep_cluster_size' »

Enter password:
+——————–+——-+
| Variable_name | Value |
+——————–+——-+
| wsrep_cluster_size | 3 |
+——————–+——-+

netstat -ntpl | grep sql

A partie d’ici, il faut faire les commandes sur le serveur HAProxy (ou le serveur 1 en fonctionne des configuration)

groupadd -g 1492 mysqlchk
useradd -u 1492 -g mysqlchk -m -r -d /usr/share/mysqlcheck -c « MySQL check » -s /bin/bash mysqlchk
usermod -aG mysqlchk mysqlchk

A faire seulement sur l’un des noeuds

mysql -u root -p
> GRANT PROCESS ON *.* TO ‘clustercheckuser’@’localhost’ IDENTIFIED BY ‘clustercheckpassword!’;

Installation du composant

yum install xinetd

Téléchargmenet du composant

cd /usr/local/src
curl -o clustercheck https://raw.githubusercontent.com/olafz/percona-clustercheck/master/clustercheck
chmod +x clustercheck
mv clustercheck /usr/bin/

Création du fichier de configuration

tee /etc/xinetd.d/mysqlchk <<-‘EOF’
# default: on
# description: mysqlcheck
service mysqlcheck
{
disable = no
flags = REUSE
socket_type = stream
port = 9200 # This port used by xinetd for clustercheck
wait = no
user = nobody
server = /usr/bin/clustercheck
log_on_failure += USERID
only_from = 0.0.0.0/0
per_source = UNLIMITED
}
EOF

Nous rémarrons le service

systemctl start xinetd

Nous pouvons controler que tout fonctionne

/usr/bin/clustercheck

Si nous obtenons le message si-dessous tout est OK

HTTP/1.1 200 OK
Content-Type: text/plain
Connection: close
Content-Length: 40

Percona XtraDB Cluster Node is synced.

Installation du la couche proxy

yum install haproxy

Nous éditons le fichier de configuration du service

nano /etc/rsyslog.conf

Nous devons décommentaié les lignes (15 et 16)

# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

Ajouter la ligne (17)

$AllowedSender UDP, 127.0.0.1

Nous devons modifier les lignes (56 et 57)

*.info;mail.none;authpriv.none;cron.none,local2.none /var/log/messages
local2.* /var/log/haproxy.log

Nous sauvegardons le fichier de configuration par defaut en cas de problème ou d’ajustement de variable

cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
rm /etc/haproxy/haproxy.cfg

Nous allons créer le fichier avec le modéle suivant

tee /etc/haproxy/haproxy.cfg <<-‘EOF’
#
# /etc/haproxy/haproxy.cfg
#

#———————————————————————
# Global settings
#———————————————————————
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the ‘-r’ option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2
log /dev/log local0
log /dev/log local1 notice

chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 1020
user haproxy
group haproxy
daemon

# turn on stats unix socket
stats socket /var/lib/haproxy/stats.sock mode 660 level admin
stats timeout 30s

#———————————————————————
# common defaults that all the ‘frontend’ and ‘backend’ sections will
# use if not designated in their block
#———————————————————————
defaults
mode http
log global
option tcplog
option dontlognull
option redispatch
retries 3
timeout queue 45s
timeout connect 5s
timeout client 1m
timeout server 1m
timeout check 10s
maxconn 1020

#———————————————————————
# HAProxy statistics backend
#———————————————————————
#Nous devons modifier le port réseau
#ainsique le login et mot de passe des statistique
listen stats 0.0.0.0:8282
mode http
stats enable
stats show-legends
stats show-node
stats refresh 5s
stats uri /haproxy
stats realm HAProxy\ Statistics
stats auth Admin:Passw0rd
stats admin if TRUE

#Nous devons modifier le port laisser 3306 si vous avez un serveur HAproxy à par
# mettre le port réseau choisi plus haut
listen ClusterMySQL
bind *:3306
mode tcp
maxconn 200
balance roundrobin
option forwardfor
option tcpka
option mysql-check user haproxy_check
option httpchk
option tcp-check
option allbackups
server quasrv054002v10 192.168.1.51:3306 maxconn 60 check port 3306 inter 12000 downinter 5s rise 3 fall 3 slowstart 60s weight 1
server quasrv054002v08 192.168.1.52:3306 maxconn 60 check port 3306 inter 12000 downinter 5s rise 3 fall 3 slowstart 60s weight 2
server quasrv054002v11 192.168.1.53:3306 maxconn 60 check port 3306 inter 12000 downinter 5s rise 3 fall 3 slowstart 60s weight 3
EOF

Nous lancons le service

systemctl start haproxy

Nous controlons que le service à bien démarrer

systemctl status haproxy

Nous devons obtenir ceci nous indiquant que le service fonctionne correctement

● haproxy.service – HAProxy Load Balancer
Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled)
Active: active (running) since mer. 2017-08-09 10:50:58 CEST; 1h 59min ago
Main PID: 12223 (haproxy-systemd)
CGroup: /system.slice/haproxy.service
├─12223 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
├─12224 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
└─12225 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

août 09 10:50:58 HAPROXY.tips-of-mine.local systemd[1]: Starting HAProxy Load Balancer…
août 09 10:50:58 HAPROXY.tips-of-mine.local haproxy-systemd-wrapper[12223]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
août 09 10:50:58 HAPROXY.tips-of-mine.local haproxy-systemd-wrapper[12223]: [WARNING] 220/105058 (12224) : parsing [/etc/haproxy/haproxy.cfg:77] : ‘maxconn’ ignored because backend ‘ClusterMySQL-Back’ …’ instead ?
août 09 10:50:58 HAPROXY.tips-of-mine.local haproxy-systemd-wrapper[12223]: [WARNING] 220/105058 (12224) : config : ‘option forwardfor’ ignored for backend ‘ClusterMySQL-Back’ as it requires HTTP mode.
août 09 10:50:58 HAPROXY.tips-of-mine.local haproxy[12224]: Proxy stats started.
août 09 10:50:58 HAPROXY.tips-of-mine.local haproxy[12224]: Proxy stats started.
août 09 10:50:58 HAPROXY.tips-of-mine.local haproxy[12224]: Proxy ClusterMySQL-Front started.
août 09 10:50:58 HAPROXY.tips-of-mine.local haproxy[12224]: Proxy ClusterMySQL-Front started.
août 09 10:50:58 HAPROXY.tips-of-mine.local haproxy[12224]: Proxy ClusterMySQL-Back started.
août 09 10:50:58 HAPROXY.tips-of-mine.local haproxy[12224]: Proxy ClusterMySQL-Back started.
Hint: Some lines were ellipsized, use -l to show in full.

Pour commencer à générer du traffic, nous lancons la commande suivante

mysql -u root -p -h 192.168.1.50 -P 3306 -e « select @@hostname »

Nouys pouvons donc aller voir les statistiques du serveur HAProxy sur son interface Web:
http://192.168.1.50:8282/haproxy
user: Admin
password: Passw0rd

Nous pouvons donc utiliser ce cluster avec l’adresse IP du HAProxy 192.168.1.50:3306 ou le nom du serveur1 avec le port réseau définie 192.168.1.51:3030

Nous pouvons aussi controler la réplication entre les serveurs
Depuis l’un des serveurs saisir :

mysql -u root -p -e « create database TestDeReplication »

Et depuis les autres serveurs nous pouvons controler que la table est bien créé

mysql -u root -p -e « show databases »;

Taggé , , , , , , , , .Mettre en favori le Permaliens.

Les commentaires sont fermés.