Instalasi MariaDB pada sistem operasi Linux¶
Persiapan¶
Sistem operasi yang didukung sampai saat ini oleh MariaDB diantaranya adalah:
- CentOS & RHEL: 7 & 8
- Debian: 9 & 10
- Ubuntu LTS: 18.04 & 20.04
Proses¶
Repositori MariaDB¶
Semua perintah instalasi dan konfigurasi, dieksekusi sebagai root
sudo su
Paket / repositori instalasi InfluxDB
```bash tab=”RHEL/CentOS 7”
tee /etc/yum.repos.d/mariadb.repo <<EOF
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
```bash tab="RHEL/CentOS 8"
tee /etc/yum.repos.d/mariadb.repo <<EOF
[mariadb]
name = MariaDB 10.5
baseurl = http://yum.mariadb.org/10.5/centos8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
```bash tab=”Debian”
```bash tab="Ubuntu"
Instalasi MariaDB¶
Variable
IP_PRIVAT_DB="10.20.30.101"
Via paket repositori
```bash tab=”RHEL/CentOS 7”
yum install -y MariaDB-server MariaDB-client mariadb-backup
```bash tab="RHEL/CentOS 8"
dnf install -y MariaDB-server MariaDB-client MariaDB-backup
bash tab="Debian & Ubuntu"
Mengatur set karakter (charset) bawaan MariaDB
```bash tab=”Charset”
tee /etc/my.cnf.d/charaset.cnf <<EOF
[mysqld]
character-set-server = utf8mb4
[client]
default-character-set = utf8mb4
EOF
```
Mengubah antarmuka jaringan peladen MariaDB agar dapat diakses secara jarak jauh dari peladen aplikasi
grep bind-address /etc/my.cnf.d/server.cnf
#
cp -v /etc/my.cnf.d/server.cnf{,.`date +%Y%m%d%H%M`}
sed --in-place "s/^#bind-address=.*/bind-address=${IP_PRIVAT_DB}/g" \
/etc/my.cnf.d/server.cnf
Mengaktifkan layanan MariaDB
bash tab="SystemD" systemctl enable --now mariadb
Melihat versi
```bash tab=”Eksekusi”
mariadb –version
```bash tab="Hasil"
mariadb Ver 15.1 Distrib 10.5.4-MariaDB, for Linux (x86_64) using readline 5.1
Inisiasi dan mengamankan MariaDB¶
Mengamankan MariaDB
```bash tab=”Eksekusi”
mysql_secure_installation
```bash tab="Hasil"
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!
Penyelesaian¶
Optimasi MariaDB¶
Variabel
IP_PRIVAT_DB="10.20.30.1"
mariadb.cnf
tee /etc/my.cnf.d/mariadb.cnf <<EOF
[mariadb]
# interface IPv4 address
bind-address = $IP_PRIVAT_DB
# By default, on MariaDB, performance schema is disabled by default
default_storage_engine = InnoDB
performance_schema = on
# table per .ibd file
innodb_file_per_table = 1
# 50-80% of server memory
innodb_buffer_pool_size = 2G
# 1 per GB innodb_buffer_pool_size
innodb_buffer_pool_instances = 2
# default 8M
innodb_log_buffer_size = 32M
innodb_log_file_size = 128M
# DO default for standard Block Storage Volume
innodb_io_capacity = 5000
# Metadata statistic updates can impact strongly performance of database servers
innodb_stats_on_metadata = 0
# small 100-200, larger 500-800. 75 per 1GB
max_connections = 225
thread_handling = pool-of-threads
# 100 - ((Threads_created / Connections) * 100)
#thread_cache_size =
thread_stack = 192K
# Total CPU core
thread_pool_size = 2
# high precision timestamp, at a small performance cost
thread_pool_exact_stats = 1
# Number of threads per core. Stick to the defaults
thread_pool_oversubscribe = 3
# Disable MySQL Reverse DNS Lookups
skip-name-resolve = 1
# starter 64M for query_cache_size, 200-300 MB should be more than enough
query_cache_type = 1
query_cache_limit = 256K
query_cache_min_res_unit = 2K
query_cache_size = 64M
# 64M for every GB of RAM
tmp_table_size = 192M
max_heap_table_size = 192M
# set to 1% of RAM
max_allowed_packet = 32M
# debug slow queries
slow-query-log = 1
slow-query-log-file = /var/lib/mysql/mysql-slow.log
long_query_time = 1
# Check for idle Connections, the default value is 28800 seconds
wait_timeout = 60
# Port to connect when node is fully choked
extra_port = 6033
extra_max_connections = 10
EOF
open flie limit
tee /etc/security/limits.conf <<EOF
mysql soft nofile 65535
mysql hard nofile 65535
EOF