Install db

Материал из pNp Wiki
Перейти к: навигация, поиск

Установка и конфигурирование MariaDB

Предварительные требования

  • Виртуальная машина с двумя сетевыми интерфейсами
  • Установленные пакеты: bash-completion, mariadb-server, mariadb

Конфигурирование MariaDB

После инсталляции необходимо запустить сервис:

[root@vm-01 ~]# systemctl enable mariadb.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@vm-01 ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
[root@vm-01 ~]# systemctl start mariadb
[root@vm-01 ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2018-03-12 12:39:51 MSK; 5s ago
  Process: 19102 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 19023 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 19101 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─19101 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─19260 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/ma...

Mar 12 12:39:49 vm-01 mariadb-prepare-db-dir[19023]: '/usr/bin/mysql_secure_installation'
Mar 12 12:39:49 vm-01 mariadb-prepare-db-dir[19023]: which will also give you the option of removing the test
Mar 12 12:39:49 vm-01 mariadb-prepare-db-dir[19023]: databases and anonymous user created by default.  This is
Mar 12 12:39:49 vm-01 mariadb-prepare-db-dir[19023]: strongly recommended for production servers.
Mar 12 12:39:49 vm-01 mariadb-prepare-db-dir[19023]: See the MariaDB Knowledgebase at http://mariadb.com/kb or the
Mar 12 12:39:49 vm-01 mariadb-prepare-db-dir[19023]: MySQL manual for more instructions.
Mar 12 12:39:49 vm-01 mariadb-prepare-db-dir[19023]: You can start the MariaDB daemon with:
Mar 12 12:39:49 vm-01 mysqld_safe[19101]: 180312 12:39:49 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Mar 12 12:39:49 vm-01 mysqld_safe[19101]: 180312 12:39:49 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Mar 12 12:39:51 vm-01 systemd[1]: Started MariaDB database server.
[root@vm-01 ~]#

Далее следует запустить утилиту /usr/bin/mysql_secure_installation и ответить на вопросы (пароль пользователя root отсутствует, поэтому надо просто нажать Enter):

[root@vm-01 ~]# /usr/bin/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] 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!
[root@vm-01 ~]#

Запуск

Открываем порт в файрволе

[root@vm-01 ~]# firewall-cmd --add-service=mysql --permanent 
success
[root@vm-01 ~]# firewall-cmd --reload
success
[root@vm-01 ~]#

Добавляем директиву port в файл /etc/my.cnf:

[root@vm-01 ~]# cat /etc/my.cnf
[mysqld]
port		= 3306
datadir         = /var/lib/mysql
socket          = /var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

[root@vm-01 ~]#

Перезапускаем сервис:

[root@vm-01 ~]# systemctl restart mariadb
[root@vm-01 ~]# systemctl status -l mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2018-03-12 14:15:27 MSK; 4s ago
  Process: 19870 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 19841 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 19869 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─19869 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─20042 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock --port=3306

Mar 12 14:15:25 vm-01 systemd[1]: Starting MariaDB database server...
Mar 12 14:15:25 vm-01 mysqld_safe[19869]: 180312 14:15:25 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Mar 12 14:15:25 vm-01 mysqld_safe[19869]: 180312 14:15:25 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Mar 12 14:15:27 vm-01 systemd[1]: Started MariaDB database server.
[root@vm-01 ~]#

Проверка

Проверяем слушает ли сервис нужный порт:

[root@vm-01 ~]# ss -tulpan | grep mysql
tcp    LISTEN     0      50        *:3306                  *:*                   users:(("mysqld",pid=20042,fd=14))
[root@vm-01 ~]#

Далее, подключимся клиентом к базе данных:

[root@vm-01 ~]# mysql -u root -ptest1234
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server

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

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

MariaDB [(none)]>

Ссылки