MariaDB 10.6’yı Alpine Linux’a yükleme
Gerçek kuruluma başlamadan önce, sistemimizin paket kurulumu için işletim sistemi havuzlarına bağlanabildiğinden emin olmamız gerekir.
APK uygulama listesi önbelleğini güncelleyin:
alpine:~$ sudo apk update
fetch http://nl.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gzfetch http://nl.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
v3.7.3-183-gcc9ad2b48d [http://nl.alpinelinux.org/alpine/v3.7/community]
v20200626-271-gcbcf4f191f [http://nl.alpinelinux.org/alpine/edge/main]
v20200626-267-g3745709556 [http://nl.alpinelinux.org/alpine/edge/community]
OK: 16265 distinct packages available
alpine:~$ sudo apk upgrade
Mariadb ile eşleşen paket adlarını kontrol edin:
$ sudo apk search mariadb
mariadb-static-10.6.4-r1
mariadb-server-utils-10.6.4-r1
mariadb-connector-c-dev-3.1.13-r2
mariadb-bench-10.6.4-r1
mariadb-client-10.6.4-r1
mariadb-10.6.4-r1
mariadb-backup-10.6.4-r1
mariadb-doc-10.6.4-r1
mariadb-openrc-10.6.4-r1
mariadb-dev-10.6.4-r1
acf-mariadb-0.2.0-r5
mariadb-embedded-dev-10.6.4-r1
mariadb-test-10.6.4-r1
mariadb-connector-c-3.1.13-r2
mariadb-embedded-10.6.4-r1
mariadb-mytop-10.6.4-r1
mariadb-plugin-rocksdb-10.6.4-r1
pdns-backend-mariadb-4.5.1-r2
mariadb-common-10.6.4-r1
MariaDB 10.6’yı Alpine Linux’a yükleme
Listeden, MariaDB’nin Alpine Linux depolarında kullanılabilirliğini onaylayabiliriz.
$ sudo apk add mariadb mariadb-common mariadb-client
(1/14) Installing mariadb-common (10.6.4-r1)
(2/14) Installing libaio (0.3.112-r1)
(3/14) Installing ca-certificates (20191127-r7)
(4/14) Installing brotli-libs (1.0.9-r5)
(5/14) Installing nghttp2-libs (1.44.0-r2)
(6/14) Installing libcurl (7.79.1-r0)
(7/14) Installing libgcc (10.3.1_git20210921-r1)
(8/14) Installing linux-pam (1.5.2-r0)
(9/14) Installing pcre2 (10.38-r0)
(10/14) Installing libstdc++ (10.3.1_git20210921-r1)
(11/14) Installing libxml2 (2.9.12-r1)
(12/14) Installing mariadb (10.6.4-r1)
Executing mariadb-10.6.4-r1.pre-install
(13/14) Installing mariadb-openrc (10.6.4-r1)
(14/14) Installing mariadb-client (10.6.4-r1)
Executing busybox-1.34.1-r1.trigger
Executing ca-certificates-20191127-r7.trigger
Kurulumdan sonra ana mysql veritabanını ve /var/lib/mysql
için standartlaştırılmış veri dizini başlatmanız gerekir. Bu, aşağıdaki rc betiğini çalıştırarak yapılabilir.
$ sudo /etc/init.d/mariadb setup
* Creating a new MySQL database ...
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo
Alpine Linux’ta MariaDB veritabanı hizmetini başlatma.
Alpine Linux, başlatma sistemi için OpenRC’yi kullanır. Hizmet şu komut kullanılarak başlatılabilir:
$ sudo rc-service mariadb start
* Caching service dependencies ... [ ok ]
* Starting mariadb ...
211023 08:51:09 mysqld_safe Logging to syslog.
211023 08:51:09 mysqld_safe Starting mariadbd daemon with databases from /var/lib/mysql [ ok ]
Ayrıca, sistem açılışında başlatılacak hizmeti ayarlama.
$ sudo rc-update add mariadb default
* service mariadb added to runlevel default
rc-status komutuyla hizmet durumunu kontrol etme:
$ rc-status default
* service mariadb added to runlevel default
alpine:~$ rc-status default
Runlevel: default
crond [ started ]
chronyd [ started ]
mariadb [ started ]
sshd [ started ]
acpid
Alpine Linux’ta güvenli MariaDB veritabanı sunucusu
Artık hizmet çalıştığına göre, bekleyen tek öğe onu güvence altına alıyor. Root parolası belirlemek, test veritabanını kaldırmak ve root kullanıcısı olarak uzaktan oturum açmaya izin vermemek için aşağıdaki komutu çalıştırın.
$ sudo mysql_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.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the 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. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] 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? [Y/n] y
... Success!
By default, MariaDB 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? [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!
Veritabanı konsoluna parola girmeden erişmeyi denerseniz, erişim reddedildi hatası görüntülenecektir.
$ mysql -u root <ENTER>
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Şimdi tekrar deneyin ama bu sefer şifreyi -p komut seçeneği ile sağlayın.
$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.6.4-MariaDB-debug MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Alpine Linux’ta MariaDB veritabanı kurulumunu test etme
Test veritabanı ve kullanıcı oluşturun.
MariaDB [(none)]> CREATE DATABASE testdb;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| testdb |
+--------------------+
4 rows in set (0.000 sec)
Bir kullanıcı oluşturun ve oluşturulan veritabanına erişim izni verin.
MariaDB [(none)]> CREATE USER testuser@localhost IDENTIFIED BY "STr0ngDBP@ss";
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> GRANT ALL ON testdb.* TO testuser@localhost;
Query OK, 0 rows affected (0.003 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.000 sec)
MariDB konsolundan çıkın ve test kullanıcısı olarak oturum açın.
MariaDB [(none)]> QUIT
Bye
$ mysql -u testuser -p'STr0ngDBP@ss'
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 21
Server version: 10.4.13-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Kullanıcının erişebildiği veritabanlarını listeleyin.
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| testdb |
+--------------------+
2 rows in set (0.000 sec)
MariaDB [(none)]> QUIT
Bye
SONUÇ:
Alpine Linux sanal makinesinde MariaDB veritabanı sunucusunu başarıyla kurduk, yapılandırdık ve başlattık. Ayrıca nasıl veritabanı oluşturabileceğinizi, kullanıcı ve izinleri nasıl ayarlayabileceğinizi gösterdik ve izinler verildiğinde kullanıcının veritabanını görebildiğini doğruladık.