Overview
MariaDB is one of the most widely deployed open-source relational databases globally that also have NoSQL features, make it more Acceptable and Significant. It is a community-driven and commercially supported fork of the MySQL relational database management system, intended to remain free and open-source software under the GNU General Public License.
In this tutorial, we will learn how to install MariaDB Community Server on Rocky Linux.
Lab Environment
The below table demonstrates the testing lab environment for installation of MariaDB Community Server on Rocky Linux:
Server Machine | Client Machine | |
OS Release | Rocky Linux release 8.4 (Green Obsidian) | Red Hat Enterprise Linux release 8.4 (Ootpa) |
Kernel | 4.18.0-305.10.2.el8_4.x86_64 | 4.18.0-305.7.1.el8_4.x86_64 |
MariaDB Release | 10.6 | 10.6 |
IP Address | 10.100.20.181 | 10.100.20.198 |
Hostname | Server | Client |
Username | Admin | User |
Step 1: Create MariaDB repository
In this tutorial, we will use the recommended method to use the official package repository. For this reason, we add the official repository to our system by executing the following script:
[Admin@Server ~]$ curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bashThen update the server repository:
[Admin@Server ~]$ sudo dnf update -yNow we can see the MariaDB official repository is added to our system:
[Admin@Server ~]$ sudo dnf repolistStep 2: Install MariaDB packages
It is recommended to resolve some of the prerequisite packages’ dependencies before installing MariaDB on Rocky Linux. To install the prerequisite packages run the following command:
[Admin@Server ~]$ sudo dnf install perl-DBI libaio libsepol lsof boost-program-options rsync libpmem tar socat -yIf we do not assign the –repo tag in the installation command, there will be a chance to install MariaDB-server packages from our local repository that provides the OS vendor. To avoid it we need to use –repo tag. Now, run the following command to install the official MongoDB-server packages:
[Admin@Server ~]$ sudo dnf install --repo="mariadb-main" MariaDB-server -yThe main configuration file is /etc/my.cnf and the include directory of this file is /etc/my.cnf.d. And the default directory is /var/lib/mysql.
Step 3: Start MariaDB Instance
After successfully install start the MariaDB instance:
[Admin@Server ~]$ sudo systemctl start mariadb.serviceTo check the status of the service run the following command. The status will be running and active:
[Admin@Server ~]$ sudo systemctl status mariadb.serviceTo run the service automatically at boot time, we need to enable the service as below:
[Admin@Server ~]$ sudo systemctl enable mariadb.serviceStep 4: Secure your deployment
The best practice is to ensure the recommended security before we start using the MariaDB database in the production environment, which ensures our deployment will meet the business-specific requirements and governance. To achieve this run the following command:
[Admin@Server ~]$ sudo mariadb-secure-installationWhen the above command asked or prompted the user input, we will provide the following input:
Enter current password for root (enter for none):
Switch to unix_socket authentication [Y/n] n
Change the root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
Step 5: Connect locally to the MariaDB Instance
Within the MariaDB server, we can use the localhost and default port 3306 to connect locally with the help of mariadb utility:
[Admin@Server ~]$ mariadb -h localhost -p3306 -u root -pStep 6: Connect remotely to the MariaDB Instance
For the security measures, the root user is not allowed to connect remotely. For this reason, we need to create a non-root user in the MariaDB database. So, locally connect to the MariaDB database that describes in the above and create a user named hr as following:
MariaDB [(none)]> CREATE USER hr@'%' IDENTIFIED BY 'p';MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'hr'@'%' WITH GRANT OPTION;
MariaDB [(none)]> FLUSH PRIVILEGES;
Step 7: Install MariaDB-client on Client Machine
If we haven’t a MariaDB repository in our client machine, then we need to install it first. To achieve the purpose, add the repository by running the following command:
[User@Client ~]$ curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bashThen update the repository of our client machine:
[User@Client ~]$ sudo dnf update --allowerasing -yNow, time to install the MariaDB-Client
packages on our client machine:
Step 8: Configure MariaDB server to allowing remote connection
By default, loopback IP 127.0.0.1 is allowed for connecting to the instance that’s why other IPs will not be allowed to connect the instance. To allow the remote connection, we need to add the MariaDB server IP to the /etc/my.cnf.d/server.cnf file as bind-address:
[Admin@Server ~]$ sudo vim /etc/my.cnf.d/server.cnfFind the below section, where we see the bind-address is comment.
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
So, comment out the bind-address and assign the MariaDB server IP:
# Allow server to accept connections on all interfaces.
#
bind-address=10.100.20.181
Here, the MariaDB server IP is 10.100.20.181. Now, this IP allows remote connectivity.
Another task is to add MariaDB port 3306 to the firewall:
[Admin@Server ~]$ sudo firewall-cmd --permanent --add-port=3306/tcp[Admin@Server ~]$ sudo firewall-cmd --reload
Now restart the MariaDB service:
[Admin@Server ~]$ sudo systemctl restart mariadb.serviceNow, we check the connectivity from our client machine:
[User@Client ~]$ mariadb -h 10.100.20.181 -p3306 -u hr -pStep 7: Uninstall the MariaDB
Before uninstall, ensure we must back up our database and store it in another server for future restoration. Because complete uninstall erase everything from our server. To uninstall the package issue the following command:
[Admin@Server ~]$ sudo dnf remove --repo="mariadb-main" MariaDB-server -yAnd lastly, remove the following directories:
[MongoDB@RockyLinuxServer ~]$ rm -rf /etc/my.cnf.d[MongoDB@RockyLinuxServer ~]$ rm -rf /var/lib/mysql
Conclusion
In this tutorial, we learn how to install MariaDB 10.6 in the newborn Rocky Linux 8.4 in detail. Hope it will help you to install and configure MariaDB by yourself. If you have any questions or suggestions, please comment to me and for more tutorials visit my page.
References
In this tutorial, we follow the official docs as reference How to Install MariaDB Server on RHEL 8 / CentOS 8.
Comments
Post a Comment