Lompat ke konten Lompat ke sidebar Lompat ke footer

Cara membuat database server mariadb pada CentOS 7

Server database adalah sebuah server yang dapat menyimpan sebuah basis data yang diperlukan untuk kebutuhan tertentu seperti untuk program, untuk data-data disebuah organisasi/sekolah dan perusahaan. Kita dapat membuat sebuah server database kita sendiri, pada sistem operasi CentOS 7, untuk membuat server database, pada server tersebut kita memerlukan aplikasi yang dapat menyediakan layanan database.

Aplikasi penyedia database yang saya bahas kali ini adalah MariaDB, aplikasi ini terdapat pada repositori SCLo, maka sebelum dapat menginstall MariaDB kita harus menginstall repo SCLo pada server yang akan kita konfigurasi.

Berikut ini adalah topologi server yang akan saya konfigurasi :

Topologi

Cara membuat database server mariadb pada CentOS 7

Node01 DB Server

1. Install repo centos sclo terlebih dahulu, karena mariadb terdapat pada repo tersebut, jika pada repo centos default versinya masih yang 5.5, Setelah itu baru install mariadb.
[root@node01 ~]# yum -y install centos-release-scl-rh centos-release-scl
[root@node01 ~]# yum --enablerepo=centos-sclo-rh -y install rh-mariadb102-mariadb-server
2. Setelah terinstall, berhubung aplikasi yang berasal dari repo sclo diinstall pada direktori /opt kita perlu melakukan load environtment agar mariadb dapat digunakan.
[root@node01 ~]# mysql #belum bisa digunakan
-bash: mysql: command not found

#kita aktifkan

[root@node01 ~]# scl enable rh-mariadb102 bash
[root@node01 ~]# mysql -V #baru bisa digunakan
mysql  Ver 15.1 Distrib 10.2.8-MariaDB, for Linux (x86_64) using  EditLine wrapper

#Buat agar otomatis terload saat booting

[root@node01 ~]# vi /etc/profile.d/rh-mariadb102.sh
#!/bin/bash

source /opt/rh/rh-mariadb102/enable
export X_SCLS="`scl enable rh-mariadb102 'echo $X_SCLS'`"
3. Edit file konfigurasi /etc/opt/rh/rh-mariadb102/my.cnf.d/mariadb-server.cnf untuk menentukan character set.
[root@node01 ~]# vi /etc/opt/rh/rh-mariadb102/my.cnf.d/mariadb-server.cnf
.......
[mysqld]
datadir=/var/opt/rh/rh-mariadb102/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/opt/rh/rh-mariadb102/log/mariadb/mariadb.log
pid-file=/run/rh-mariadb102-mariadb/mariadb.pid
character-set-server=utf8
.......
4. Jalankan dan aktifkan service mariadb server.
[root@node01 ~]# systemctl start rh-mariadb102-mariadb
[root@node01 ~]# systemctl enable rh-mariadb102-mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/rh-mariadb102-mariadb.service to /usr/lib/systemd/system/rh-mariadb102-mariadb.service.
5. Kemudian lakukan konfigurasi awal untuk menentukan root password dan yang lainnya.
[root@node01 ~]# 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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): #kosongkan
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:  #root 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 #ingin user root dapat diakses komputer lain atau tidak
 ... 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!
6. Setelah itu kita sudah dapat menggunakan server database ini.
[root@node01 ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.2.8-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | ::1       | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
+------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> create database testdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| testdb             |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> 
7. Agar server dapat diakses dari luar kita perlu membuka firewall mysql.
[root@node01 ~]# firewall-cmd --add-service=mysql --permanent
success
[root@node01 ~]# firewall-cmd --reload
success
8. Untuk melihat error, log pada mariadb bisa menggunakan perintah dibawah ini.
[root@node01 ~]# tail -f /var/opt/rh/rh-mariadb102/log/mariadb/mariadb.log 
2018-06-29  8:49:39 140492900100288 [Note] InnoDB: Waiting for purge to start
2018-06-29  8:49:39 140492900100288 [Note] InnoDB: 5.7.19 started; log sequence number 1620266
2018-06-29  8:49:39 140491962164992 [Note] InnoDB: Loading buffer pool(s) from /var/opt/rh/rh-mariadb102/lib/mysql/ib_buffer_pool
2018-06-29  8:49:39 140491962164992 [Note] InnoDB: Buffer pool(s) load completed at 180629  8:49:39
2018-06-29  8:49:39 140492900100288 [Note] Plugin 'FEEDBACK' is disabled.
2018-06-29  8:49:40 140492900100288 [Note] Server socket created on IP: '::'.
2018-06-29  8:49:40 140492900100288 [Note] Reading of all Master_info entries succeded
2018-06-29  8:49:40 140492900100288 [Note] Added new Master_info '' to hash table
2018-06-29  8:49:40 140492900100288 [Note] /opt/rh/rh-mariadb102/root/usr/libexec/mysqld: ready for connections.
Version: '10.2.8-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
Sampai disini saja postingan saya kali ini,
Sekian terima kasih.
Bona Pasogit
Bona Pasogit Content Creator, Video Creator and Writer

Posting Komentar untuk "Cara membuat database server mariadb pada CentOS 7"

close