« Documentation » : différence entre les versions

De wikisio
Aucun résumé des modifications
Aucun résumé des modifications
 
(6 versions intermédiaires par 2 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
<strong>0 - Mise en place </strong>
0 - Mise en place initiale =


- VPS:
==  VPS ==
* Aller sur [https://pulseheberg.com PulseHeberg]
* Acheter le '''VPS EDU-2''' dans la section ''Education Cloud''


Aller sur pulseheberg.com et acheter le VPS EDU-2 dans Education Cloud.
==  Nom de domaine ==
* Acheter un nom de domaine sur [https://www.ovhcloud.com OVHcloud]
* Associer le domaine à l'IP publique du VPS dans la section '''Zone DNS'''


- Nom de domaine
----


Aller sur ovhcloud.com et acheter un domaine, puis l'associer a son IP dans la section
=  1 - Sécurité =


==  Bonnes pratiques SSH ==
* Éditer le fichier de configuration SSH :
<syntaxhighlight lang="bash">
sudo nano /etc/ssh/sshd_config
</syntaxhighlight>


* Modifier ou ajouter :
<pre>
Port 2222
PermitRootLogin no
</pre>


* Redémarrer le service :
<syntaxhighlight lang="bash">
sudo systemctl restart ssh
</syntaxhighlight>


<strong>1 - Sécurité</strong>
==  Fail2Ban ==
* Modifier ou créer <code>/etc/fail2ban/jail.local</code> :
<syntaxhighlight lang="ini">
[sshd]
enabled = true
port = 2222
filter = sshd
logpath = /var/log/auth.log
maxretry = 5
bantime = 3600
</syntaxhighlight>


- bonnes pratiques SSH (Root, port, ...)
* Redémarrer Fail2Ban :
<syntaxhighlight lang="bash">
sudo systemctl restart fail2ban
</syntaxhighlight>


Désactiver dans /etc/ssh/sshd_config l'acces root et changer le port par défaut.
==  IPSet ==
* Créer une liste d'IP à bloquer :
<syntaxhighlight lang="bash">
sudo ipset create blacklist hash:ip
</syntaxhighlight>


- Fail2Ban
* Ajouter une règle dans iptables :
<syntaxhighlight lang="bash">
sudo iptables -I INPUT -m set --match-set blacklist src -j DROP
</syntaxhighlight>


- IPSet
* Sauvegarder :
<syntaxhighlight lang="bash">
sudo netfilter-persistent save
</syntaxhighlight>


----


=  2 - Containerisation (LXC) =


==  Installation ==
<syntaxhighlight lang="bash">
sudo apt-get update
sudo apt-get install lxc lxc-templates
</syntaxhighlight>


==  Création des containers ==
<syntaxhighlight lang="bash">
sudo lxc-create -n nginx -t debian
sudo lxc-create -n monsite -t debian
</syntaxhighlight>


==  Configuration IP ==
* Container '''nginx''' : <code>10.0.3.10</code>
* Container '''monsite''' : <code>10.0.3.101</code>


(Fichiers : <code>/var/lib/lxc/&lt;nom&gt;/rootfs/etc/network/interfaces</code>)


==  Installation des services ==
* Dans '''monsite''' :
<syntaxhighlight lang="bash">
sudo apt install apache2
</syntaxhighlight>


<strong>2 - Containerisation</strong>
* Dans '''nginx''' :
<syntaxhighlight lang="bash">
sudo apt install nginx
</syntaxhighlight>


- Mise en place de LXC
==  Redirections NAT ==
<syntaxhighlight lang="bash">
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 10.0.3.10:80
sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 10.0.3.10:443
sudo iptables -t nat -A POSTROUTING -j MASQUERADE
</syntaxhighlight>


- Reverse proxy configurer
==  Reverse Proxy ==
* Exemple de configuration Nginx :
<syntaxhighlight lang="nginx">
server {
    listen 80;
    server_name monsite.exemple.com;


    access_log off;


    if ($request_method !~ ^(GET|HEAD|POST)$) {
        return 444;
    }


    location / {
        proxy_pass http://10.0.3.101:80/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
</syntaxhighlight>


----


=  3 - Documentation (MediaWiki) =


==  Installation ==
<syntaxhighlight lang="bash">
cd /tmp
wget https://releases.wikimedia.org/mediawiki/1.41/mediawiki-1.41.0.tar.gz
tar -xzf mediawiki-1.41.0.tar.gz
sudo rm -rf /var/www/html/*
sudo mv mediawiki-1.41.0/* /var/www/html/
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/
</syntaxhighlight>


==  Sécurisation ==


<strong>3 - Documentation</strong>
=== Certificat SSL ===
<syntaxhighlight lang="bash">
sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d monsite.exemple.com
</syntaxhighlight>


- mise en place du sous-domaine doc.votredomaine.ovh
=== Authentification Apache ===
<syntaxhighlight lang="bash">
sudo apt install apache2-utils
sudo htpasswd -c /etc/apache2/.htpasswd admin
</syntaxhighlight>


- Mise a disposition d'une base de connaissance (Mediawiki ou autre) sécurisé ("apache-auth")
* Ajouter dans la configuration Apache :
<syntaxhighlight lang="apache">
<Directory "/var/www/html">
    AuthType Basic
    AuthName "Restricted Access"
    AuthUserFile /etc/apache2/.htpasswd
    Require valid-user
</Directory>
</syntaxhighlight>


- mise en place d'une solution de backups (locale pour commencer)
* Redémarrer :
<syntaxhighlight lang="bash">
sudo systemctl restart apache2
</syntaxhighlight>
 
----
 
=  4 - Backups locaux =
 
== Script de sauvegarde ==
Créer <code>/usr/local/bin/backup_mediawiki.sh</code> :
<syntaxhighlight lang="bash">
#!/bin/bash
 
BACKUP_DIR="/var/backups/mediawiki"
DATE=$(date +%F)
DB_NAME="nom_de_la_bdd"
DB_USER="user"
DB_PASS="motdepasse"
 
mkdir -p $BACKUP_DIR
 
mysqldump -u $DB_USER -p$DB_PASS $DB_NAME > $BACKUP_DIR/wiki-db-$DATE.sql
 
tar -czf $BACKUP_DIR/wiki-files-$DATE.tar.gz /var/www/html
 
find $BACKUP_DIR -type f -mtime +7 -delete
</syntaxhighlight>
 
== Crontab ==
Ajouter dans <code>crontab -e</code> :
<syntaxhighlight lang="bash">
0 3 * * * /usr/local/bin/backup_mediawiki.sh
</syntaxhighlight>

Dernière version du 15 octobre 2025 à 12:27

0 - Mise en place initiale

VPS

  • Aller sur PulseHeberg
  • Acheter le VPS EDU-2 dans la section Education Cloud

Nom de domaine

  • Acheter un nom de domaine sur OVHcloud
  • Associer le domaine à l'IP publique du VPS dans la section Zone DNS

1 - Sécurité

Bonnes pratiques SSH

  • Éditer le fichier de configuration SSH :

<syntaxhighlight lang="bash"> sudo nano /etc/ssh/sshd_config </syntaxhighlight>

  • Modifier ou ajouter :
Port 2222
PermitRootLogin no
  • Redémarrer le service :

<syntaxhighlight lang="bash"> sudo systemctl restart ssh </syntaxhighlight>

Fail2Ban

  • Modifier ou créer /etc/fail2ban/jail.local :

<syntaxhighlight lang="ini"> [sshd] enabled = true port = 2222 filter = sshd logpath = /var/log/auth.log maxretry = 5 bantime = 3600 </syntaxhighlight>

  • Redémarrer Fail2Ban :

<syntaxhighlight lang="bash"> sudo systemctl restart fail2ban </syntaxhighlight>

IPSet

  • Créer une liste d'IP à bloquer :

<syntaxhighlight lang="bash"> sudo ipset create blacklist hash:ip </syntaxhighlight>

  • Ajouter une règle dans iptables :

<syntaxhighlight lang="bash"> sudo iptables -I INPUT -m set --match-set blacklist src -j DROP </syntaxhighlight>

  • Sauvegarder :

<syntaxhighlight lang="bash"> sudo netfilter-persistent save </syntaxhighlight>


2 - Containerisation (LXC)

Installation

<syntaxhighlight lang="bash"> sudo apt-get update sudo apt-get install lxc lxc-templates </syntaxhighlight>

Création des containers

<syntaxhighlight lang="bash"> sudo lxc-create -n nginx -t debian sudo lxc-create -n monsite -t debian </syntaxhighlight>

Configuration IP

  • Container nginx : 10.0.3.10
  • Container monsite : 10.0.3.101

(Fichiers : /var/lib/lxc/<nom>/rootfs/etc/network/interfaces)

Installation des services

  • Dans monsite :

<syntaxhighlight lang="bash"> sudo apt install apache2 </syntaxhighlight>

  • Dans nginx :

<syntaxhighlight lang="bash"> sudo apt install nginx </syntaxhighlight>

Redirections NAT

<syntaxhighlight lang="bash"> sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 10.0.3.10:80 sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 10.0.3.10:443 sudo iptables -t nat -A POSTROUTING -j MASQUERADE </syntaxhighlight>

Reverse Proxy

  • Exemple de configuration Nginx :

<syntaxhighlight lang="nginx"> server {

   listen 80;
   server_name monsite.exemple.com;
   access_log off;
   if ($request_method !~ ^(GET|HEAD|POST)$) {
       return 444;
   }
   location / {
       proxy_pass http://10.0.3.101:80/;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   }

} </syntaxhighlight>


3 - Documentation (MediaWiki)

Installation

<syntaxhighlight lang="bash"> cd /tmp wget https://releases.wikimedia.org/mediawiki/1.41/mediawiki-1.41.0.tar.gz tar -xzf mediawiki-1.41.0.tar.gz sudo rm -rf /var/www/html/* sudo mv mediawiki-1.41.0/* /var/www/html/ sudo chown -R www-data:www-data /var/www/html/ sudo chmod -R 755 /var/www/html/ </syntaxhighlight>

Sécurisation

Certificat SSL

<syntaxhighlight lang="bash"> sudo apt install certbot python3-certbot-apache sudo certbot --apache -d monsite.exemple.com </syntaxhighlight>

Authentification Apache

<syntaxhighlight lang="bash"> sudo apt install apache2-utils sudo htpasswd -c /etc/apache2/.htpasswd admin </syntaxhighlight>

  • Ajouter dans la configuration Apache :

<syntaxhighlight lang="apache"> <Directory "/var/www/html">

   AuthType Basic
   AuthName "Restricted Access"
   AuthUserFile /etc/apache2/.htpasswd
   Require valid-user

</Directory> </syntaxhighlight>

  • Redémarrer :

<syntaxhighlight lang="bash"> sudo systemctl restart apache2 </syntaxhighlight>


4 - Backups locaux

Script de sauvegarde

Créer /usr/local/bin/backup_mediawiki.sh : <syntaxhighlight lang="bash">

  1. !/bin/bash

BACKUP_DIR="/var/backups/mediawiki" DATE=$(date +%F) DB_NAME="nom_de_la_bdd" DB_USER="user" DB_PASS="motdepasse"

mkdir -p $BACKUP_DIR

mysqldump -u $DB_USER -p$DB_PASS $DB_NAME > $BACKUP_DIR/wiki-db-$DATE.sql

tar -czf $BACKUP_DIR/wiki-files-$DATE.tar.gz /var/www/html

find $BACKUP_DIR -type f -mtime +7 -delete </syntaxhighlight>

Crontab

Ajouter dans crontab -e : <syntaxhighlight lang="bash"> 0 3 * * * /usr/local/bin/backup_mediawiki.sh </syntaxhighlight>