In questo tutorial, ti mostreremo come installare e migliorare la sicurezza di MySQL su Ubuntu 18.04. MySQL è uno dei sistemi di gestione di database relazionali open source più popolari e ampiamente utilizzati. Viene utilizzato per la creazione di applicazioni Web come WordPress, Drupal, Joomla e Magento ed è una parte importante degli stack di software di applicazioni Web open source LAMP/LEMP. Al momento della stesura di questo tutorial, l'ultima versione supportata dal repository ufficiale dei pacchetti Ubuntu è MySQL 5.7. Iniziamo.
Requisiti:
- Ai fini di questo tutorial, utilizzeremo un server Ubuntu.
- Accesso root SSH completo o utente con privilegi sudo.
Fase 1:connettiti al tuo server
Prima di iniziare, devi connetterti al tuo server tramite SSH. Per connetterti al tuo server come utente root, usa il seguente comando:
ssh root@IP_ADDRESS -p PORT_NUMBER
Assicurati di sostituire IP_ADDRESS e PORT_NUMBER con l'indirizzo IP del server effettivo e il numero di porta SSH.
Una volta effettuato l'accesso, assicurati che il tuo server sia aggiornato eseguendo i seguenti comandi:
sudo apt update sudo apt upgrade
Fase 2:installa MySQL
Il comando seguente installerà l'ultimo server MySQL 5.7 dai repository ufficiali di Ubuntu:
sudo apt install mysql-server
Il server Web MySQL verrà avviato automaticamente non appena l'installazione è completata.
Per verificare se l'installazione è andata a buon fine e se MySQL è in esecuzione sul tuo server, puoi eseguire il seguente comando:
sudo systemctl status mysql
Dovresti vedere il seguente output sullo schermo:
mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2019-02-08 02:05:27 CST; 2min 4s ago Main PID: 13853 (mysqld) Tasks: 27 (limit: 2321) CGroup: /system.slice/mysql.service └─13853 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
Puoi anche abilitare l'avvio automatico del servizio MySQL al riavvio del server con il seguente comando:
sudo systemctl enable mysql
Puoi anche controllare la versione di MySQL con:
mysql -V
Uscita:
mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper
Fase 3:proteggi MySQL
Per migliorare la sicurezza della nostra installazione di MySQL e impostare una password per il nostro utente root MySQL, dobbiamo eseguire mysql_secure_installation
script, incluso nel pacchetto MySQL.
Per eseguire lo script, eseguire il comando seguente:
sudo mysql_secure_installation
Uscita:
Securing the MySQL server deployment. Connecting to MySQL using a blank password.
Innanzitutto, ti verrà chiesto di configurare il plug-in di convalida della password.
VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No:
Questo plug-in verifica la solidità di una password e consente agli utenti di impostare solo password sufficientemente sicure.
Se abilitarlo o meno dipende interamente da te, ma l'utilizzo di password complesse è sempre altamente raccomandato.
Se scegli "Sì", ti verrà chiesto di scegliere il livello della politica di convalida della password:
There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:
Successivamente, ti verrà chiesto di impostare la password per l'utente root. Immettere e confermare la password per continuare con il passaggio successivo:
Please set the password for root here. New password: Re-enter new password: Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
Dopo aver impostato la password, ti verranno poste altre domande sulla rimozione di utenti anonimi, sul non consentire l'accesso root remoto e sulla rimozione dei database di test. Dovresti rispondere "Sì" a tutti loro:
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y Success. By default, MySQL 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? (Press y|Y for Yes, any other key for No) : Y - Dropping test database... Success. - Removing privileges on test database... Success.
Ricarica le tabelle dei privilegi in modo che tutte le modifiche abbiano effetto:
Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y Success. All done!
Fase 4:accedi a MySQL
Per accedere al tuo server Web MySQL come utente root, puoi eseguire il seguente comando:
sudo mysql -u root -p
e inserisci la password di root MySQL che hai impostato durante la mysql_secure_installation
copione.
Una volta effettuato correttamente l'accesso, dovresti ottenere il seguente output:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
Fase 5:configurazione del server di database MySQL
Se desideriamo apportare ulteriori modifiche, come la modifica delle impostazioni per ottimizzare le prestazioni del nostro server di database, è possibile modificare il file di configurazione predefinito di MySQL che si trova in /etc/mysql/my.cnf
.
sudo nano /etc/mysql/my.cnf
Dopo aver apportato modifiche, è necessario riavviare il server del database:
sudo systemctl restart mysql
Conclusione
Ecco fatto:MySQL 5.7 è stato installato con successo sul tuo Ubuntu 18.04 VPS. Assicurati di controllare il nostro blog per ulteriori tutorial relativi a MySQL, tra cui:
Amministrazione di base del database MySQL su un VPS Linux Parte 1
Amministrazione di base del database MySQL su un VPS Linux Parte 2
Come creare un nuovo utente MySQL e concedere autorizzazioni
Come eseguire il backup e il ripristino del database MySQL
e molti altri...
Ovviamente, se sei uno dei nostri clienti di Ubuntu Hosting, non devi installare MySQL sul tuo VPS Ubuntu 18.04:chiedi semplicemente ai nostri amministratori, siediti e rilassati. I nostri amministratori installeranno immediatamente MySQL su Ubuntu 18.04 per te.
PS. Se ti è piaciuto questo post su come installare MySQL su Ubuntu 18.04 VPS , condividilo con i tuoi amici sui social network utilizzando i pulsanti qui sotto, o lascia semplicemente un commento nella sezione commenti. Grazie.