Configuration de la base

Installation et configuration de la base

apt-get -y install mariadb-server
  • Sécurisation de mariadb
cat << EOF > /srv/lxc/mariadb_secure_installation.sh
#!/bin/bash
# Delete anonymous users
mysql -e "DELETE FROM mysql.user WHERE User='';"
# Ensure the root user can not log in remotely
mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
# Remove the test database
mysql -e "DROP DATABASE IF EXISTS test;
          DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%';"
# Make our changes take effect
mysql -e "FLUSH PRIVILEGES"
EOF
/srv/lxc/mariadb_secure_installation.sh

Remplacez IP_PRIV_db

  • IP_PRIV_db correspond à l’IP privée de la base

Bind de l’adresse privée de la base

sed -i 's/bind-address.*/bind-address = IP_PRIV_db/' /etc/mysql/mariadb.conf.d/50-server.cnf

Création de la base et du user

Remplacez DB_USERNAME DB_PASSWORD IP_PRIV_www

  • IP_PRIV_www correspond à l’IP privée du nextcloud
mysql <<< '
    CREATE DATABASE nextcloud;
    GRANT ALL PRIVILEGES ON nextcloud.* TO "DB_USERNAME"@"IP_PRIV_www" IDENTIFIED BY "'DB_PASSWORD'";
    FLUSH PRIVILEGES;
'

Restart de mariadb

systemctl restart mariadb

Clean du cache

apt-get clean