MariaDB 10 CentOS 7 Moving Data

The new "minimal" CentOS 7 installation along with MariaDB 10. I have an additional mounted mirrored volume that I want to use for datadir. The startup sequence is beautiful and usually ends when my.cnf [mysqld] is commented out. I copied the data.

sudo cp -R -p /var/lib/mysql/* /mnt/mysql/ 

The permissions are identical to the permissions of the original. The volume is in / etc / fstab and mounts normally /dev/sdb1 /mnt/mysql xfs defaults 0 0

 [ root@femur mysql]# ls -la total 110632 drwxr-xr-x. 5 mysql mysql 4096 Oct 20 15:27 . drwxr-xr-x. 3 root root 18 Oct 16 16:46 .. -rw-rw----. 1 mysql mysql 16384 Oct 20 15:27 aria_log.00000001 -rw-rw----. 1 mysql mysql 52 Oct 20 15:27 aria_log_control -rw-r-----. 1 mysql root 7005 Oct 20 13:49 femur.err -rw-rw----. 1 mysql mysql 12582912 Oct 20 15:27 ibdata1 -rw-rw----. 1 mysql mysql 50331648 Oct 20 15:27 ib_logfile0 -rw-rw----. 1 mysql mysql 50331648 Oct 20 12:21 ib_logfile1 -rw-rw----. 1 mysql mysql 0 Oct 20 12:22 multi-master.info drwx--x--x. 2 mysql mysql 4096 Oct 20 12:21 mysql drwx------. 2 mysql mysql 4096 Oct 20 13:37 performance_schema drwxr-xr-x. 2 mysql mysql 6 Oct 20 12:21 test 

this is in my.cnf

 !includedir /etc/my.cnf.d [mysqld] log_error = /var/log/mysql-error.log user = mysql datadir = /mnt/mysql socket = /mnt/mysql/mysql.sock 

This is what I get when I try to run it ...

 '[ root@femur mysql]# sudo systemctl start mysql.service Job for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.' 

None of these two files say a lot, but it is in / var / log / mysql -error.log

 141020 16:07:09 mysqld_safe Starting mysqld daemon with databases from /mnt/mysql 141020 16:07:09 [Warning] Can't create test file /mnt/mysql/femur.lower-test 141020 16:07:09 [Note] InnoDB: Using mutexes to ref count buffer pool pages 141020 16:07:09 [Note] InnoDB: The InnoDB memory heap is disabled 141020 16:07:09 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 141020 16:07:09 [Note] InnoDB: Memory barrier is not used 141020 16:07:09 [Note] InnoDB: Compressed tables use zlib 1.2.7 141020 16:07:09 [Note] InnoDB: Using Linux native AIO 141020 16:07:09 [Note] InnoDB: Using CPU crc32 instructions 141020 16:07:09 [Note] InnoDB: Initializing buffer pool, size = 128.0M 141020 16:07:09 [Note] InnoDB: Completed initialization of buffer pool 2014-10-20 16:07:09 7f6cb59c9880 InnoDB: Operating system error number 13 in a file operation. InnoDB: The error means mysqld does not have the access rights to InnoDB: the directory. 141020 16:07:09 [ERROR] InnoDB: os_file_get_status() failed on './ibdata1'. Can't determine file permissions 141020 16:07:09 [ERROR] InnoDB: The system tablespace must be writable! 141020 16:07:09 [ERROR] Plugin 'InnoDB' init function returned error. 141020 16:07:09 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 141020 16:07:09 [ERROR] mysqld: File '/mnt/mysql/aria_log_control' not found (Errcode: 13 "Permission denied") 141020 16:07:09 [ERROR] mysqld: Got error 'Can't open file' when trying to use aria control file '/mnt/mysql/aria_log_control' 141020 16:07:09 [ERROR] Plugin 'Aria' init function returned error. 141020 16:07:09 [ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed. 141020 16:07:09 [Note] Plugin 'FEEDBACK' is disabled. 141020 16:07:09 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it. 141020 16:07:09 [ERROR] Unknown/unsupported storage engine: InnoDB 141020 16:07:09 [ERROR] Aborting 141020 16:07:09 [Note] /usr/sbin/mysqld: Shutdown complete 141020 16:07:09 mysqld_safe mysqld from pid file /mnt/mysql/femur.pid ended 

http://www.reddit.com/r/linuxadmin/comments/2ebhpf/adventures_in_moving_mariadb_data_folder/ helped a bit, but I could not get it to work.

Any help would be greatly appreciated.

+6
source share
3 answers

The problem is really SELinux; You need to do three things before MariaDB / MySQL starts with CentOS 7:

  • Make sure user: mysql:mysql group mysql:mysql
  • Set SELinux tag to mysqld_db_t
  • Set SELinux user to system_u

It is as simple as:

 chcon -Rt mysqld_db_t /database/db chcon -Ru system_u /database/db chown -R mysql:mysql /database/db 

All I needed to do after connecting the drive is below:

 cfdisk /dev/sdb pvcreate /dev/sdb1 vgcreate database /dev/sdb1 lvcreate -l 100%FREE -n db database mkfs.ext4 /dev/database/db mkdir /database mount /database mkdir /database/db chcon -Rt mysqld_db_t /database/db chcon -Ru system_u /database/db chown -R mysql:mysql /database/db systemctl start mariadb 
+16
source

Well, that was interesting ...

It turns out that CentOS 7 sets the “minimum” to SELinux, which seems to prevent mysql from writing to the mounted mirror set. I was looking for security features that I might not have thought of, and found them there in the docs. Earlier, I thought (obviously wrongly) that SELinux was a distribution, not a module. As soon as I checked the test to see if there is ...

 getenforce 

I temporarily disabled it for testing.

 setenforce 0 

Finally, I was able to run MariaDB with the directory in the mirrored set as datadir and without errors. To make this change permanent (since this server is behind the firewall), in / etc / selinux / config I did

 - SELINUX=enforcing + SELINUX=disabled 

Hope this helps someone else. Excellent day!

+6
source

I found this walkthrough for me: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/SELinux_Users_and_Administrators_Guide/sect-Managing_Confined_Services-MariaDB-Confml_

You must install: yum install policycoreutils-python

Guide:

View SELinux context for default database for mysql:

 ~]# ls -lZ /var/lib/mysql drwx------. mysql mysql system_u:object_r:mysqld_db_t:s0 mysql 

This displays mysqld_db_t, which is the default context element for the location of the database files. This context must be applied manually to the new database location that will be used in this example in order for it to function properly.

Stop the mysqld daemon:

 ~]# systemctl stop mariadb.service 

Create a new directory for the new database location. This example uses / mysql /:

 ~]# mkdir -p /mysql 

Copy the database files from the old location to the new location:

 ~]# cp -R /var/lib/mysql/* /mysql/ 

Change ownership of this location to allow access to the mysql user and group. This sets up the traditional Unix permissions that SELinux will still observe:

 ~]# chown -R mysql:mysql /mysql 

Run the following command to see the initial context of the new directory:

 ~]# ls -lZ /mysql drwxr-xr-x. mysql mysql unconfined_u:object_r:usr_t:s0 mysql 

The usr_t context of this newly created directory is currently not suitable for SELinux as the location of the MariaDB database files. When the context is changed, MariaDB will be able to function normally in this area.

Open the MariaDB main configuration file / etc / my.cnf with a text editor and change the datadir parameter to refer to the new location. In this example, the value to be entered is / mysql:

 [mysqld] datadir=/mysql 

Save this file and exit.

Run mysqld. The service should not start, and the failure message will be written to the / var / log / messages file:

 ~]# systemctl start mariadb.service 

Work for mariadb.service failed. See "Systemctl status postgresql.service" and "journalctl -xn" for details.

However, if the audit daemon is started and the setroubleshoot service is running with it, the failure will be written to the /var/log/audit/audit.log file: SELinux prevents / usr / libexec / mysqld from “writing” access to / mysql. For complete SELinux messages. run sealert -l b3f01aff-7fa6-4ebe-ad46-abaef6f8ad71

The reason for this failure is that / mysql / is incorrectly marked for MariaDB data files. SELinux stops MariaDB from accessing content marked as usr_t. Follow these steps to resolve this issue:

Run the following command to add a context mapping for / mysql /. Please note that semanageutility is not installed by default. If it is not on your system, install policycoreutils-pythonpackage.

 **~]# semanage fcontext -a -t mysqld_db_t "/mysql(/.*)?"** 

This mapping is written to / etc / selinux / targeted / contexts / files / file _contexts.local:

 ~]# grep -i mysql /etc/selinux/targeted/contexts/files/file_contexts.local 

/ MySQL (/.*)? system_u: object_r: mysqld_db_t: s0

Now use the restorecon utility to apply this context mapping to the running system:

 **~]# restorecon -R -v /mysql** 

Now that / mysql / location is tagged with the appropriate context for MariaDB, mysqldstarts:

 ~]# systemctl start mariadb.service 

Confirm that the context has changed for / mysql /:

 ~]$ ls -lZ /mysql drwxr-xr-x. mysql mysql system_u:object_r:mysqld_db_t:s0 mysql 

The location has been changed and marked, and mysqld has started successfully. At this point, all running services should be tested to confirm normal operation.

0
source

Source: https://habr.com/ru/post/976998/


All Articles