Visualiser une révision

[Tuto/HowTo] Nextcloud - Health Check avec HaProxy

voxdemonix : révision n°5 (13 octobre 2018 00:02:29)

Introduction
============
Pour des raisons d'efficacité et d'optimisation, il est déconseillé d'utiliser l'_index.php_ ou _status.php_ afin de faire les Health Check de HaProxy ou tout autre frontend.
Ici nous allons utiliser un script dédié dont le but est de tester "l'état de santé" des machines tout en consommant le moins de ressources possible.
Rappel : En cas de mise à jours Nextcloud râlent s'il détecte des fichiers qui ne sont pas d'origine. Lors d'une update pensez donc a déplacer le fichiers ailleurs puis a le ré-insérer une fois la mise à jours terminée.

Mise en place
=============

Ajoutez [le script suivant](https://gitlab.com/voxdemonix/divers-script/blob/master/nextcloud/HealthCheck.php) à la racine de votre installation de Nextcloud.

```
cd /var/www/html/nextcloud/
wget https://gitlab.com/voxdemonix/divers-script/raw/master/nextcloud/HealthCheck.php
```

Accordez dessus les bonnes permissions.

```
chown www-data:www-data ./HealthCheck.php
```

Adaptez puis ajoutez dans votre fichier de configuration HaProxy ( _/etc/haproxy/haproxy.cfg_ ), les lignes suivantes à votre backend qui gère votre cloud.

```
        http-check expect status 204
        option httpchk GET http://www.my_cloud.com/HealthCheck.php HTTP/1.0
```


Exemple :

```
backend nextcloud_cluster
        mode http
        balance leastconn
        http-request add-header X-Forwarded-Proto https if { ssl_fc }
        option forwardfor
        http-check expect status 204
        option httpchk GET http://www.my_cloud.com/HealthCheck.php HTTP/1.0
        cookie SERVERID insert indirect nocache
        default-server inter 10s fastinter 500 fall 2 rise 2
                # force https
       acl http      ssl_fc,not
       http-request redirect scheme https if http

	server Machine1 Machine1:80 weight 1 check cookie Machine1                # deny access to  status.php
        acl restricted_page path_beg,url_dec -i /status.php
        http-request deny if restricted_page
	server Machine2 Machine2:80 weight 1 check cookie Machine2
```


Maintenant éditez vos fichiers de configuration vhost pour apache2

```
nano /etc/apache2/sites-enabled/vhost-www.my-cloud.com.conf
```

Ajoutez les lignes suivante en adaptant éventuellement le path vers votre fichier log.

```
SetEnvIf Request_URI HealthCheck.php dontlog
CustomLog ${APACHE_LOG_DIR}/access.log combined env=!dontlog
```


Farm Link
=========

* [[Tuto/HowTo] Nextcloud - add Health Check script for Load Balancer](https://www.0rion.netlib.re/forum4/viewtopic.php?f=107&t=821) (article d'origine)