Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
redhat:database-redhat:start [2017/09/13 17:13] – [Autostart beim booten des Systems] michael | redhat:database-redhat:start [2019/03/08 13:22] (current) – [mysqladmin] michael | ||
---|---|---|---|
Line 4: | Line 4: | ||
MariaDB löste mit RHEL7 / CentOS7 die bis dahin verwendete MySQL-Datenbank ab. Nachfolgend wird aufgezeit, wie man die Mariadb korrekt auf seinem System implementiert / härtet. | MariaDB löste mit RHEL7 / CentOS7 die bis dahin verwendete MySQL-Datenbank ab. Nachfolgend wird aufgezeit, wie man die Mariadb korrekt auf seinem System implementiert / härtet. | ||
- | |||
- | ---- | ||
===== Installation MariaDB ===== | ===== Installation MariaDB ===== | ||
Line 61: | Line 59: | ||
</ | </ | ||
- | ---- | ||
===== Konfiguration MariaDB ===== | ===== Konfiguration MariaDB ===== | ||
Line 128: | Line 125: | ||
</ | </ | ||
- | < | + | < |
150307 22:10:14 mysqld_safe Starting mysqld daemon with databases from / | 150307 22:10:14 mysqld_safe Starting mysqld daemon with databases from / | ||
150307 22:10:14 InnoDB: The InnoDB memory heap is disabled | 150307 22:10:14 InnoDB: The InnoDB memory heap is disabled | ||
Line 182: | Line 179: | ||
</ | </ | ||
- | Möchten wir überprüfen, | + | <panel type=" |
- | - Daemon Überprüfung mit **systemctl**: | + | - Daemon Überprüfung mit **systemctl**: |
| | ||
| | ||
Line 208: | Line 205: | ||
</ | </ | ||
</ | </ | ||
+ | </ | ||
---- | ---- | ||
Line 249: | Line 247: | ||
Unter **RHEL 7** und **CentOS 7** wird als Standard-Firewall die dynamische **firewalld** verwendet. Ein grosser Vorteil der dynamischen Paketfilterregeln ist unter anderem, dass zur Aktivierung der neuen Firewall-Regel(n) nicht der Daemon durchgestartet werden muss und somit alle aktiven Verbindungen kurz getrennt werden. Sondern unsere Änderungen können **on-the-fly** aktiviert oder auch wieder deaktiviert werden. | Unter **RHEL 7** und **CentOS 7** wird als Standard-Firewall die dynamische **firewalld** verwendet. Ein grosser Vorteil der dynamischen Paketfilterregeln ist unter anderem, dass zur Aktivierung der neuen Firewall-Regel(n) nicht der Daemon durchgestartet werden muss und somit alle aktiven Verbindungen kurz getrennt werden. Sondern unsere Änderungen können **on-the-fly** aktiviert oder auch wieder deaktiviert werden. | ||
- | In meinem kleinen Konfigurationsbeispiel hat der '' | + | In meinem kleinen Konfigurationsbeispiel hat der '' |
< | < | ||
Line 263: | Line 261: | ||
'' | '' | ||
- | <WRAP center box 100%> | ||
< | < | ||
# iptables -nvL IN_public_allow | # iptables -nvL IN_public_allow | ||
Line 274: | Line 271: | ||
2656 159K ACCEPT | 2656 159K ACCEPT | ||
</ | </ | ||
- | </ | + | |
'' | '' | ||
- | <WRAP center box 100%> | ||
< | < | ||
# firewall-cmd --zone=public --list-services | # firewall-cmd --zone=public --list-services | ||
Line 286: | Line 282: | ||
mysql ssh | mysql ssh | ||
</ | </ | ||
- | </ | ||
</ | </ | ||
Line 295: | Line 290: | ||
Wie bei der doch grossen Ausgabe beim erstmaligen Start des Datenbank-Daemons angeraten, werden wir nun die __sicherheitsrelevanten Konfigurationsänderungen__ vornehmen. | Wie bei der doch grossen Ausgabe beim erstmaligen Start des Datenbank-Daemons angeraten, werden wir nun die __sicherheitsrelevanten Konfigurationsänderungen__ vornehmen. | ||
- | Hierzu | + | Zuvor, generieren wir jedoch noch einen sicheren DB-Schlüssel für den MariaDB-Root User und speichern ihn unter /root/ mit folgenden Befehl ab: |
+ | |||
+ | < | ||
+ | # openssl rand -base64 30 > / | ||
+ | </ | ||
+ | |||
+ | Anschliessend, | ||
- Datenbankpasswort des MySQL-Datenbankuser **root** setzen | - Datenbankpasswort des MySQL-Datenbankuser **root** setzen | ||
Line 309: | Line 310: | ||
# / | # / | ||
- | <sxh plain; gutter: false;> | + | <sxh plain; gutter: false; |
- | Enter current password for root (enter for none): | + | NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB |
- | Set root password? [Y/n]: Y | + | SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! |
- | New password: | + | |
- | Re-enter new password: | + | In order to log into MariaDB to secure it, we'll need the current |
- | Remove anonymous users? [Y/n]: Y | + | password for the root user. If you've just installed MariaDB, and |
- | Disallow root login remotely? [Y/n]: Y | + | you haven' |
- | Remove test database and access to it? [Y/n]: Y | + | so you should just press enter here. |
- | Reload privilege tables now? [Y/n]: Y | + | |
+ | Enter current password for root (enter for none): | ||
+ | OK, successfully used password, moving on... | ||
+ | |||
+ | Setting the root password ensures that nobody can log into the MariaDB | ||
+ | root user without the proper authorisation. | ||
+ | |||
+ | Set root password? [Y/n] y | ||
+ | New password: | ||
+ | Re-enter new password: | ||
+ | Password updated successfully! | ||
+ | Reloading privilege tables.. | ||
+ | ... Success! | ||
+ | |||
+ | |||
+ | By default, a MariaDB installation has an anonymous user, allowing anyone | ||
+ | to log into MariaDB 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. | ||
+ | production environment. | ||
+ | |||
+ | Remove anonymous users? [Y/n] y | ||
+ | ... Success! | ||
+ | |||
+ | Normally, root should only be allowed to connect from ' | ||
+ | ensures that someone cannot guess at the root password from the network. | ||
+ | |||
+ | Disallow root login remotely? [Y/n] y | ||
+ | ... Success! | ||
+ | |||
+ | By default, MariaDB comes with a database named ' | ||
+ | access. | ||
+ | before moving into a production environment. | ||
+ | |||
+ | Remove test database and access to it? [Y/n] y | ||
+ | - Dropping test database... | ||
+ | ... Success! | ||
+ | - Removing privileges on test database... | ||
+ | ... Success! | ||
+ | |||
+ | Reloading the privilege tables will ensure that all changes made so far | ||
+ | will take effect immediately. | ||
+ | |||
+ | Reload privilege tables now? [Y/n] y | ||
+ | ... Success! | ||
+ | |||
+ | Cleaning up... | ||
+ | |||
+ | All done! If you've completed all of the above steps, your MariaDB | ||
+ | installation should now be secure. | ||
+ | |||
+ | Thanks for using MariaDB! | ||
</ | </ | ||
</ | </ | ||
Line 323: | Line 376: | ||
---- | ---- | ||
+ | <WRAP center box 100%> | ||
+ | ==== Erstellen einer Initialen Datenbank ==== | ||
+ | '' | ||
+ | |||
+ | - Einloggen in die Mariadb als root: < | ||
+ | - Erstellen der ersten Datenbank: <sxh bash: gutter: false> | ||
+ | - Next, we are going to create a new MySQL user account that we will use exclusively to operate on our new database. I am going to call the '' | ||
+ | - At this point, you have a database and user account that are each specifically made for our new environment. However, the user has no access to the database. We need to link the two components together by granting our user access to the database.< | ||
+ | - Now that the user has access to the database, we need to flush the privileges so that MySQL knows about the recent privilege changes that we've made: <sxh bash: gutter: false> | ||
+ | - Once these commands have all been executed, we can exit out of the MySQL command prompt by typing: <sxh plain: gutter: false> | ||
+ | |||
+ | <wrap em> | ||
+ | |||
+ | </ | ||
+ | |||
+ | <WRAP center round tip 100%> | ||
+ | '' | ||
+ | |||
+ | < | ||
+ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
==== Logrotate ==== | ==== Logrotate ==== | ||
Line 464: | Line 540: | ||
</ | </ | ||
- | ---- | + | |
===== Datenbankhandling ===== | ===== Datenbankhandling ===== | ||
Line 470: | Line 546: | ||
Mit Hilfe des Hilfsprogrammes **mysqladmin** aus dem Clientpaket **mysql** können umfangreiche Abfrage gegen unsere Datenbank durchgeführt werden. Startet man das Programm ohne weitere Angaben von Optionen, werden die möglichen Optionen am Bildschirm ausgegeben. | Mit Hilfe des Hilfsprogrammes **mysqladmin** aus dem Clientpaket **mysql** können umfangreiche Abfrage gegen unsere Datenbank durchgeführt werden. Startet man das Programm ohne weitere Angaben von Optionen, werden die möglichen Optionen am Bildschirm ausgegeben. | ||
+ | <WRAP center box 100%> | ||
< | < | ||
# mysqladmin | # mysqladmin | ||
</ | </ | ||
- | <WRAP center round box 100%> | + | <sxh plain; gutter: false;> |
- | <code> | + | |
mysqladmin | mysqladmin | ||
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others. | Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others. | ||
Line 603: | Line 679: | ||
variables | variables | ||
version | version | ||
- | </code> | + | </sxh> |
</ | </ | ||
So können wir z.B. auch die verwendete Version von **MariaDB** abfragen. | So können wir z.B. auch die verwendete Version von **MariaDB** abfragen. | ||
+ | <WRAP center box 100%> | ||
< | < | ||
# mysqladmin version | # mysqladmin version | ||
</ | </ | ||
- | <WRAP center round box 100%> | + | <sxh plain; gutter: false;> |
- | <code> | + | |
mysqladmin | mysqladmin | ||
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others. | Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others. | ||
Line 624: | Line 700: | ||
Threads: 1 Questions: 27 Slow queries: 0 Opens: 1 Flush tables: 2 Open tables: 27 Queries per second avg: 0.002 | Threads: 1 Questions: 27 Slow queries: 0 Opens: 1 Flush tables: 2 Open tables: 27 Queries per second avg: 0.002 | ||
- | </code> | + | </sxh> |
</ | </ | ||
---- | ---- | ||
+ | |||
==== mysql ==== | ==== mysql ==== | ||
Der Zugriff auf unseren MariaDB-Server wird in der Regel mit dem Werkzeug **mysql** vorgenommen. So kann man auch z.B. sehr leicht und einfach den Status unseres Datenbankservers abfragen. | Der Zugriff auf unseren MariaDB-Server wird in der Regel mit dem Werkzeug **mysql** vorgenommen. So kann man auch z.B. sehr leicht und einfach den Status unseres Datenbankservers abfragen. | ||
Line 700: | Line 777: | ||
---- | ---- | ||
+ | |||
==== Datenbank-Dump ==== | ==== Datenbank-Dump ==== | ||
Zur Sicherung unserer MariaDB-Tabellen legen wir uns ein kleines Script an, mit dessen Hilfe wir täglich eine Sicherung der kompletten Datenbank vornehmen können. | Zur Sicherung unserer MariaDB-Tabellen legen wir uns ein kleines Script an, mit dessen Hilfe wir täglich eine Sicherung der kompletten Datenbank vornehmen können. | ||
Line 1019: | Line 1097: | ||
---- | ---- | ||
+ | |||
==== phpMyAdmin ==== | ==== phpMyAdmin ==== | ||
<WRAP center round tip 90%> | <WRAP center round tip 90%> | ||
- | Zur komfortablen Administration unserer **MariaDB unter RHEL 7 und CentOS 7** kann man auf das PHP-Projekt [[http:// | + | '' |
- | Im Kapitel **'' | + | |
+ | '' | ||
</ | </ | ||