Thursday, October 12, 2017

.::: Install MariaDB 10.1 On Centos/Rhel 7 Using Yum Repository :::.

MariaDB Server is one of the most popular database servers in the world. It’s made by the original developers of MySQL and guaranteed to stay open source. Notable users include Wikipedia, WordPress.com and Google.

MariaDB turns data into structured information in a wide array of applications, ranging from banking to websites. It is an enhanced, drop-in replacement for MySQL. MariaDB is used because it is fast, scalable and robust, with a rich ecosystem of storage engines, plugins and many other tools make it very versatile for a wide variety of use cases.

MariaDB is developed as open source software and as a relational database it provides an SQL interface for accessing data. The latest versions of MariaDB also include GIS and JSON features.

1. Add MariaDB Yum Repository
Start by adding the MariaDB YUM repository file MariaDB.repo for RHEL/CentOS and Fedora systems.
# vi /etc/yum.repos.d/MariaDB.repo

Now add the following lines to your respective Linux distribution version as shown.

On CentOS 7

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

On RHEL 7

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/rhel7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

[root@TeguhLab data]# cat /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

[root@TeguhLab data]#

2. Install MariaDB in CentOS 7
# yum -y install MariaDB-server MariaDB-client

3. Start Mariadb & enable automatic start

# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb

[root@TeguhLab data]# systemctl enable mariadb
[root@TeguhLab data]# systemctl start mariadb
[root@TeguhLab data]# systemctl status mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Thu 2017-10-12 15:05:13 WIB; 6s ago
  Process: 3524 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 3473 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
  Process: 3459 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 3493 (mysqld)
   Status: "Taking your SQL requests now..."
   CGroup: /system.slice/mariadb.service
           └─3493 /usr/sbin/mysqld

Oct 12 15:05:13 TeguhLab mysqld[3493]: 2017-10-12 15:05:13 139706611513536 [Note] InnoDB: Highest supported file for...acuda.
Oct 12 15:05:13 TeguhLab mysqld[3493]: 2017-10-12 15:05:13 139706611513536 [Note] InnoDB: 128 rollback segment(s) are active.
Oct 12 15:05:13 TeguhLab mysqld[3493]: 2017-10-12 15:05:13 139706611513536 [Note] InnoDB: Waiting for purge to start
Oct 12 15:05:13 TeguhLab mysqld[3493]: 2017-10-12 15:05:13 139706611513536 [Note] InnoDB:  Percona XtraDB (http://ww...616717
Oct 12 15:05:13 TeguhLab mysqld[3493]: 2017-10-12 15:05:13 139706611513536 [Note] Plugin 'FEEDBACK' is disabled.
Oct 12 15:05:13 TeguhLab mysqld[3493]: 2017-10-12 15:05:13 139705827981056 [Note] InnoDB: Dumping buffer pool(s) not...tarted
Oct 12 15:05:13 TeguhLab mysqld[3493]: 2017-10-12 15:05:13 139706611513536 [Note] Server socket created on IP: '::'.
Oct 12 15:05:13 TeguhLab mysqld[3493]: 2017-10-12 15:05:13 139706611513536 [Note] /usr/sbin/mysqld: ready for connections.
Oct 12 15:05:13 TeguhLab mysqld[3493]: Version: '10.1.28-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  ...Server
Oct 12 15:05:13 TeguhLab systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@TeguhLab data]#

4. Setting password root & Secure MariaDB
# mysqladmin -u root password 'root'
# mysql_secure_installation

[root@TeguhLab data]# 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):
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.  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] n
 ... skipping.

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!
[root@TeguhLab data]#

5. Check certain MariaDB features
# mysql -V
# mysqld ---print-defaults
# mysql -u root -p


[root@TeguhLab data]# mysql -V
mysql  Ver 15.1 Distrib 10.1.28-MariaDB, for Linux (x86_64) using readline 5.1
[root@TeguhLab data]# mysqld ---print-defaults
2017-10-12 15:07:31 139664944203968 [Note] mysqld (mysqld 10.1.28-MariaDB) starting as process 3602 ...
mysqld: Please consult the Knowledge Base to find out how to run mysqld as root!
2017-10-12 15:07:31 139664944203968 [ERROR] Aborting

[root@TeguhLab data]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.1.28-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)]>

6. Create Database & user (example for Cacti version 1.0)
create user 'cactiuser' identified by 'cactipwd';
create database cacti;
grant all privileges on cacti.* to 'cactiuser'@'%' identified by 'cactipwd' with grant option;
GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
FLUSH PRIVILEGES;

create user 'cactiuser' identified by 'cactipwd';
create database cacti;
GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactipwd';
GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
FLUSH PRIVILEGES;

[root@TeguhLab data]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.1.28-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)]>
MariaDB [(none)]> create user 'cactiuser' identified by 'cactipwd';
user 'cactiuser' identified by 'cactipwd';
create database cacti;
GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactipwd';
GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
FLUSH PRIVILEGES;Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> create database cacti;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on cacti.* to 'cactiuser'@'%' identified by 'cactipwd' with grant option;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
ERROR 1133 (28000): Can't find any matching row in the user table
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>
MariaDB [(none)]> create user 'cactiuser' identified by 'cactipwd';
ERROR 1396 (HY000): Operation CREATE USER failed for 'cactiuser'@'%'
MariaDB [(none)]> create database cacti;
ERROR 1007 (HY000): Can't create database 'cacti'; database exists
MariaDB [(none)]> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactipwd';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]>

7. Tunning my.cnf/server.cnf & client (example for Cacti version 1.0)
# cat /etc/my.cnf.d/client.cnf
# cat /etc/my.cnf.d/server.cnf


[root@TeguhLab data]# cat /etc/my.cnf.d/client.cnf
#
# These two groups are read by the client library
# Use it for options that affect all clients, but not the server
#

[client]
default-character-set=utf8

# This group is not read by mysql client library,
# If you use the same .cnf file for MySQL and MariaDB,
# use it for MariaDB-only client options
[client-mariadb]

[root@TeguhLab data]# 


[root@TeguhLab data]# cat /etc/my.cnf.d/server.cnf
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

# this is read by the standalone daemon and embedded servers
[server]

# this is only for the mysqld standalone daemon
[mysqld]
collation-server = utf8_general_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
max_heap_table_size = 500M
max_allowed_packet = 16777216
tmp_table_size = 64M
join_buffer_size = 64M
innodb_file_per_table = on
innodb_doublewrite = off
innodb_additional_mem_pool_size = 80M
innodb_flush_log_at_trx_commit = 2
innodb_buffer_pool_size = 2420M
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads = 16


# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

# this is only for embedded server
[embedded]

# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]

# This group is only read by MariaDB-10.1 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.1]

[root@TeguhLab data]#


[root@TeguhLab data]# systemctl restart mariadb
[root@TeguhLab data]#

No comments:

Post a Comment

Popular Posts