Annexes:MariaDB : Différence entre versions

De WikiFr_dbSQWare
Aller à : navigation, rechercher
(Installation par yum)
m
 
(24 révisions intermédiaires par 2 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
 
==Installation par yum==
 
==Installation par yum==
Activation des repo et installation par yum.<br>
+
Activation des repo et installation par dnf.<br>
Exemple pour l’installation d’une MariaDB 10.5 sur CentOS 7.<br>
+
Exemple pour l’installation d’une MariaDB 10.11 sur Rocky Linux 9.<br>
 +
(Version 10.5 sur CentOS 7 : [[Annexes:MariaDBCentOS7|Installation MariaDB CentOS 7]]).<br>
 +
(Version 10.6 sur Rocky 8 : [[Annexes:MariaDBRocky8|Installation MariaDB Rocky 8]]).<br>
 
<br>
 
<br>
Activation du repo officiel MariaDB :
+
Lister les versions de MariaDB dispo :
 
<pre>
 
<pre>
#Activate official repo
+
dnf module list mariadb
yum install -y wget
+
 
 +
Rocky Linux 9 - AppStream
 +
Name                                  Stream                                  Profiles                                                  Summary
 +
mariadb                                10.5 [d]                                client, galera, server [d]                                MariaDB Module
 +
 
 +
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
 +
</pre>
 +
<br>
 +
Forcer la version 10.11 dans la liste du repo :
 +
<pre>
 +
cd /tmp
 
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
 
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
 
chmod +x mariadb_repo_setup
 
chmod +x mariadb_repo_setup
 
./mariadb_repo_setup
 
./mariadb_repo_setup
 +
vi /etc/yum.repos.d/mariadb.repo
 +
</pre>
  
[root@vmsqwarebox ~]# cat /etc/yum.repos.d/mariadb.repo
+
Modifier les lignes pour obtenir ceci :
 +
<pre>
 
[mariadb-main]
 
[mariadb-main]
 
name = MariaDB Server
 
name = MariaDB Server
baseurl = https://downloads.mariadb.com/MariaDB/mariadb-10.5/yum/rhel/$releasever/$basearch
+
baseurl = https://downloads.mariadb.com/MariaDB/mariadb-10.11/yum/rhel/9/x86_64/
 
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY
 
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY
 
gpgcheck = 1
 
gpgcheck = 1
 
enabled = 1
 
enabled = 1
 
...
 
...
...
+
 +
 
 +
</pre>
 +
<br>
 +
 
 +
Lister les versions de MariaDB dispo :
 +
<pre>
 +
dnf list mariadb
 +
 
 +
Available Packages
 +
MariaDB.src                                          10.11.7-1.el9                                                        mariadb-main
 +
mariadb.x86_64                                        3:10.5.22-1.el9_2                                                    appstream
 +
 
 
</pre>
 
</pre>
 
<br>
 
<br>
 
Installation par le repo :
 
Installation par le repo :
 
<pre>
 
<pre>
yum install -y MariaDB-server MariaDB-client MariaDB-common MariaDB-compat MariaDB-shared MariaDB-backup
+
dnf install -y MariaDB-server MariaDB-client MariaDB-common MariaDB-shared MariaDB-backup
 
</pre>
 
</pre>
 
<br>
 
<br>
  
 
==Modifications post-installation==
 
==Modifications post-installation==
Mise en démarrage automatique :
+
Démarrage :
 
<pre>
 
<pre>
[root@vmsqwarebox tmp]# chkconfig mysql on
+
[root@vmsqwarebox tmp]# systemctl start mariadb.service
[root@vmsqwarebox tmp]# service mysql start
 
 
</pre>
 
</pre>
 
<br>
 
<br>
 
Changement du mot de passe du user MySQL ‘root’ :
 
Changement du mot de passe du user MySQL ‘root’ :
 
<pre>
 
<pre>
[root@vmsqwarebox tmp]# /usr/bin/mysql_secure_installation
+
[root@vmsqwarebox tmp]# mariadb-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
 +
haven't set the root password yet, you should just press enter here.
 +
 
 +
...
 
</pre>
 
</pre>
 
<br>
 
<br>
Test de connexion:
+
Remise du user unix ‘mysql’ dans le groupe dba :
 
<pre>
 
<pre>
[root@vmsqwarebox tmp]# mysql -S /var/lib/mysql/mysql.sock -uroot -pSqwareMys
+
[root@vmsqwarebox mysql]# id mysql
Warning: Using a password on the command line interface can be insecure.
+
uid=1004(mysql) gid=989(mysql) groups=989(mysql)
Welcome to the MySQL monitor.  Commands end with ; or \g.
+
[root@vmsqwarebox mysql]# usermod -a -G dba mysql
Your MySQL connection id is 11
+
[root@vmsqwarebox mysql]# id mysql
Server version: 5.6.27 MySQL Community Server (GPL)
+
uid=1004(mysql) gid=989(mysql) groups=989(mysql),1000(dba)
 +
</pre>
 +
<br>
 +
Déplacement de l'instance dans /data :
 +
<pre>
 +
systemctl stop mariadb.service
  
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+
cd /var/lib/
 +
mv mysql /data/mysql/.
 +
mv /data/mysql/mysql /data/mysql/MYS_DBA_PRD
 +
ln -s /data/mysql/MYS_DBA_PRD mysql
  
Oracle is a registered trademark of Oracle Corporation and/or its
+
## Pour les binlog
affiliates. Other names may be trademarks of their respective
+
mkdir -p /data/mysql/MYS_DBA_PRD-binlog
owners.
+
chown mysql:dba /data/mysql/MYS_DBA_PRD-binlog
 
+
## Pour les tables temporaires
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
+
mkdir -p /backups/mysql/MYS_DBA_PRD-tmpdir
 +
chown mysql:dba /backups/mysql/MYS_DBA_PRD-tmpdir
 +
</pre>
 +
<br>
 +
Modif des limites pour mysql (+ dans le service) :
 +
<pre>
 +
vi /etc/security/limits.conf
 +
mysql soft nofile 65535
 +
mysql hard nofile 65535
  
mysql> show databases;
+
vi /usr/lib/systemd/system/mariadb.service
+--------------------+
+
# Number of files limit. previously [mysqld_safe] open-files-limit
| Database          |
+
LimitNOFILE=65535
+--------------------+
 
| information_schema |
 
| mysql              |
 
| performance_schema |
 
+--------------------+
 
3 rows in set (0.00 sec)
 
 
 
mysql> Bye
 
 
 
Remise du user unix ‘mysql’ dans le groupe dba :
 
<pre>
 
[root@vmsqwarebox tmp]# id mysql
 
uid=503(mysql) gid=157(mysql) groupes=157(mysql)
 
[root@vmsqwarebox tmp]# usermod -Gdba,mysql mysql
 
[root@vmsqwarebox tmp]# id mysql
 
uid=503(mysql) gid=157(mysql) groupes=157(mysql),500(dba)
 
 
</pre>
 
</pre>
 
<br>
 
<br>
 
Quelques paramètres conseillés :
 
Quelques paramètres conseillés :
 
<pre>
 
<pre>
[root@vmsqwarebox tmp]# cat /etc/my.cnf
+
[root@vmsqwarebox tmp]# cat /etc/my.cnf.d/server.cnf
[mysqld]
+
[mariadb]
skip-name-resolve
+
datadir=/data/mysql/MYS_DBA_PRD
 +
log_error=MYS_DBA_PRD.err
 +
max_connections = 100
 +
extra_max_connections = 3
 +
skip_name_resolve = 1
 +
innodb_buffer_pool_size = 1024M
 
read_buffer_size = 3M
 
read_buffer_size = 3M
key_buffer_size = 128M
+
key_buffer_size = 32M
max_allowed_packet = 16M
+
max_allowed_packet = 32M
thread_stack = 192K
+
table_definition_cache = 1000
thread_cache_size = 32
 
myisam_recover_options = BACKUP
 
max_connections = 100
 
table_definition_cache = 400
 
 
sort_buffer_size = 32M
 
sort_buffer_size = 32M
myisam_sort_buffer_size = 64M
 
innodb_buffer_pool_size = 1024M
 
 
join_buffer_size = 64M
 
join_buffer_size = 64M
tmp_table_size = 16M
+
#innodb_thread_concurrency = 16 Deprecated: MariaDB 10.5.5 Removed: MariaDB 10.6.0
innodb_thread_concurrency = 16
+
slow_query_log = 1
 +
slow_query_log_file=MYS_DBA_PRD-slow.log
 +
long_query_time = 2.0
 +
server_id                = 10
 +
binlog_cache_size        = 100M
 +
max_binlog_size          = 250M
 +
# log_bin                  = /data/mysql/MYS_DBA_PRD-binlog/MYSQL_BIN_PROD.log
 +
# log_bin_index            = /data/mysql/MYS_DBA_PRD-binlog/MYSQL_BIN_INDEX_PROD.log
 +
# binlog_format            = MIXED
 +
log_slave_updates        = 1
 +
sync_binlog              = 1
 +
expire_logs_days        = 1
 +
tmp_table_size = 64M
 
innodb_file_per_table = 1
 
innodb_file_per_table = 1
 +
tmpdir = /backups/mysql/MYS_DBA_PRD-tmpdir
 +
</pre>
 +
<br>
 +
Rechargement de la conf et redémarrage de MariaDB :
 +
<pre>
 +
systemctl daemon-reload
 +
systemctl start mariadb.service
 +
systemctl enable mariadb.service
 
</pre>
 
</pre>
 
<br>
 
<br>
==Patch de RPM==
+
 
Téléchargez les RPM client, devel, shared, shared-compat et server pour votre OS et mettez-les dans /tmp.<br>
+
Modification du plugin de connexion pour root<br>
Exemple pour patcher d’une 5.6.27 à une 5.6.43 :
+
 
 
<pre>
 
<pre>
[root@vmsqwarebox home]# cd /tmp
+
root@vmsqwarebox:/root # mysql -uroot -p<rootpass>
 +
MariaDB [(none)]> USE mysql;
 +
Reading table information for completion of table and column names
 +
You can turn off this feature to get a quicker startup with -A
 +
 
 +
Database changed
 +
MariaDB [mysql]> select user, plugin, host, password from mysql.user;
 +
+-------------+-----------------------+-----------+----------+
 +
| User        | plugin                | Host      | Password |
 +
+-------------+-----------------------+-----------+----------+
 +
| mariadb.sys | mysql_native_password | localhost |          |
 +
| root        | mysql_native_password | localhost | invalid  |
 +
| mysql      | mysql_native_password | localhost | invalid  |
 +
| PUBLIC      |                      |          |          |
 +
+-------------+-----------------------+-----------+----------+
 +
4 rows in set (0.002 sec)
  
## Stop instance
+
MariaDB [mysql]> ALTER USER 'root'@'localhost'IDENTIFIED VIA mysql_native_password;
/etc/init.d/mysql stop
 
  
[root@vmsqwarebox ~]# rpm -Uvh MySQL-client-5.6.43-1.el6.x86_64.rpm MySQL-shared-5.6.43-1.el6.x86_64.rpm MySQL-devel-5.6.43-1.el6.x86_64.rpm MySQL-server-5.6.43-1.el6.x86_64.rpm MySQL-shared-compat-5.6.43-1.el6.x86_64.rpm
+
MariaDB [mysql]> SET PASSWORD FOR'root'@'localhost'=PASSWORD('<rootpass>');
warning: MySQL-client-5.6.43-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
 
Preparing...                ########################################### [100%]
 
  1:MySQL-shared-compat    ########################################### [ 20%]
 
Giving mysqld 5 seconds to exit nicely
 
  2:MySQL-server          ########################################### [ 40%]
 
  3:MySQL-devel            ########################################### [ 60%]
 
  4:MySQL-shared          ########################################### [ 80%]
 
  5:MySQL-client          ########################################### [100%]
 
  
## Start instance
+
MariaDB [mysql]> FLUSH PRIVILEGES;
/etc/init.d/mysql start
 
  
 +
MariaDB [mysql]> exit
 
</pre>
 
</pre>
 
<br>
 
<br>

Version actuelle datée du 15 avril 2024 à 14:43

Installation par yum

Activation des repo et installation par dnf.
Exemple pour l’installation d’une MariaDB 10.11 sur Rocky Linux 9.
(Version 10.5 sur CentOS 7 : Installation MariaDB CentOS 7).
(Version 10.6 sur Rocky 8 : Installation MariaDB Rocky 8).

Lister les versions de MariaDB dispo :

dnf module list mariadb

Rocky Linux 9 - AppStream
Name                                   Stream                                  Profiles                                                  Summary
mariadb                                10.5 [d]                                client, galera, server [d]                                MariaDB Module

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled


Forcer la version 10.11 dans la liste du repo :

cd /tmp
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup
./mariadb_repo_setup
vi /etc/yum.repos.d/mariadb.repo

Modifier les lignes pour obtenir ceci :

[mariadb-main]
name = MariaDB Server
baseurl = https://downloads.mariadb.com/MariaDB/mariadb-10.11/yum/rhel/9/x86_64/
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY
gpgcheck = 1
enabled = 1
...
…


Lister les versions de MariaDB dispo :

dnf list mariadb

Available Packages
MariaDB.src                                           10.11.7-1.el9                                                         mariadb-main
mariadb.x86_64                                        3:10.5.22-1.el9_2                                                     appstream


Installation par le repo :

dnf install -y MariaDB-server MariaDB-client MariaDB-common MariaDB-shared MariaDB-backup


Modifications post-installation

Démarrage :

[root@vmsqwarebox tmp]# systemctl start mariadb.service


Changement du mot de passe du user MySQL ‘root’ :

[root@vmsqwarebox tmp]# mariadb-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
haven't set the root password yet, you should just press enter here.

...


Remise du user unix ‘mysql’ dans le groupe dba :

[root@vmsqwarebox mysql]# id mysql
uid=1004(mysql) gid=989(mysql) groups=989(mysql)
[root@vmsqwarebox mysql]# usermod -a -G dba mysql
[root@vmsqwarebox mysql]# id mysql
uid=1004(mysql) gid=989(mysql) groups=989(mysql),1000(dba)


Déplacement de l'instance dans /data :

systemctl stop mariadb.service

cd /var/lib/
mv mysql /data/mysql/.
mv /data/mysql/mysql /data/mysql/MYS_DBA_PRD
ln -s /data/mysql/MYS_DBA_PRD mysql

## Pour les binlog
mkdir -p /data/mysql/MYS_DBA_PRD-binlog
chown mysql:dba /data/mysql/MYS_DBA_PRD-binlog
## Pour les tables temporaires
mkdir -p /backups/mysql/MYS_DBA_PRD-tmpdir
chown mysql:dba /backups/mysql/MYS_DBA_PRD-tmpdir


Modif des limites pour mysql (+ dans le service) :

vi /etc/security/limits.conf
mysql soft nofile 65535
mysql hard nofile 65535

vi /usr/lib/systemd/system/mariadb.service
# Number of files limit. previously [mysqld_safe] open-files-limit
LimitNOFILE=65535


Quelques paramètres conseillés :

[root@vmsqwarebox tmp]# cat /etc/my.cnf.d/server.cnf
[mariadb]
datadir=/data/mysql/MYS_DBA_PRD
log_error=MYS_DBA_PRD.err
max_connections = 100
extra_max_connections = 3
skip_name_resolve = 1
innodb_buffer_pool_size = 1024M
read_buffer_size = 3M
key_buffer_size = 32M
max_allowed_packet = 32M
table_definition_cache = 1000
sort_buffer_size = 32M
join_buffer_size = 64M
#innodb_thread_concurrency = 16 Deprecated: MariaDB 10.5.5 Removed: MariaDB 10.6.0
slow_query_log = 1
slow_query_log_file=MYS_DBA_PRD-slow.log
long_query_time = 2.0
server_id                = 10
binlog_cache_size        = 100M
max_binlog_size          = 250M
# log_bin                  = /data/mysql/MYS_DBA_PRD-binlog/MYSQL_BIN_PROD.log
# log_bin_index            = /data/mysql/MYS_DBA_PRD-binlog/MYSQL_BIN_INDEX_PROD.log
# binlog_format            = MIXED
log_slave_updates        = 1
sync_binlog              = 1
expire_logs_days         = 1
tmp_table_size = 64M
innodb_file_per_table = 1
tmpdir = /backups/mysql/MYS_DBA_PRD-tmpdir


Rechargement de la conf et redémarrage de MariaDB :

systemctl daemon-reload
systemctl start mariadb.service
systemctl enable mariadb.service


Modification du plugin de connexion pour root

root@vmsqwarebox:/root # mysql -uroot -p<rootpass>
MariaDB [(none)]> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> select user, plugin, host, password from mysql.user;
+-------------+-----------------------+-----------+----------+
| User        | plugin                | Host      | Password |
+-------------+-----------------------+-----------+----------+
| mariadb.sys | mysql_native_password | localhost |          |
| root        | mysql_native_password | localhost | invalid  |
| mysql       | mysql_native_password | localhost | invalid  |
| PUBLIC      |                       |           |          |
+-------------+-----------------------+-----------+----------+
4 rows in set (0.002 sec)

MariaDB [mysql]> ALTER USER 'root'@'localhost'IDENTIFIED VIA mysql_native_password;

MariaDB [mysql]> SET PASSWORD FOR'root'@'localhost'=PASSWORD('<rootpass>');

MariaDB [mysql]> FLUSH PRIVILEGES;

MariaDB [mysql]> exit