MariaDB single-machine multi-instance deployment process record

It is rare to deploy multiple instances of a back-end storage system on a single machine. Basically, it is deployed in the form of a dedicated server (Dedicated Server). Therefore, single-machine multi-instance is basically relatively common in the test environment. In addition, I personally think that there is another scenario in the production server that may use a single machine with multiple instances. For example, in the architecture of the front-end MySQL proxy service, in order to make it easier to migrate in the future, and the single-machine single-multiple instance does not have much performance degradation compared with the single-machine single-instance, it is still worth a try. After all, in the future performance adjustment, as long as the server is added and the data is migrated, there is no need to rebuild the database and build the table, and there is no problem of data redeployment.

This article will record the process of deploying multiple instances of MariaDB on CentOS7.

The first step is to install the system, update the system, and install the latest version of MariaDB (the process is omitted).

The second step, adjust the system parameter fs.aio-max-nr

$ cat /etc/sysctl.conf

# Increase size of file handles and inode cache
fs.file-max = 2097152
fs.aio-max-nr = 2097152

Not increasing this parameter may result in a warning when the MariaDB switch option innodb_use_native_aio is turned on. The specific location is /etc/sysctl.conf. After the modification is completed, execute sysctl -p to make the configuration take effect.

The third step is to create a directory and initialize each instance.

$ mkdir /opt/data{0,1} && chown mysql:mysql /opt/data{0,1}

$ mysql_install_db --datadir=/opt/data0 --user=mysql --force --defaults-file=/opt/init.ini

$ mysql_install_db --datadir=/opt/data1 --user=mysql --force --defaults-file=/opt/init.ini

# init.ini是一个不包含相关路径的一个简易配置,主要设定ibdata大小、ib_logfile数量和大小、undo文件的数量等等

The fourth step, modify the configuration of each instance under the configuration files my.cnf and my.cnf.d

$ cat /etc/my.cnf

[mysqld_multi]
mysqld     = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin

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

$ cat /etc/my.cnf.d/3306.cnf

[mysqld0]
basedir                               = /usr                                        #
character_set_server                  = utf8mb4                                     #
collation_server                      = utf8mb4_unicode_ci                          #
datadir                               = /opt/data0                                  #
default_storage_engine                = InnoDB                                      #
default_time_zone                     = '+8:00'                                     #
event_scheduler                       = 1                                           #
init_connect                          = 'set names utf8mb4;'                        #
lower_case_table_names                = 1                                           #
memlock                               = 0                                           #
pid_file                              = /opt/data0/mysql.pid                        #
port                                  = 3306                                        #
skip_external_locking                 = 1                                           #
socket                                = /opt/data0/mysql.sock                       #
tmpdir                                = /dev/shm                                    #
user                                  = mysql                                       #


general_log                           = 0                                           #
general_log_file                      = /opt/data0/general_query.log                #
log_output                            = FILE                                        #
log_error                             = /opt/data0/mysqld.log                       #
log_warnings                          = 2                                           #
log_queries_not_using_indexes         = 1                                           #
log_slow_admin_statements             = 1                                           #
log_slow_verbosity                    = query_plan                                  #
long_query_time                       = 1                                           #
min_examined_row_limit                = 100                                         #
slow_query_log                        = 1                                           #
slow_query_log_file                   = /opt/data0/slow_query.log                   #


gtid_strict_mode                      = 1                                           #
transaction_isolation                 = READ-COMMITTED                              #


innodb_data_home_dir                  = /opt/data0                                  #
innodb_data_file_path                 = ibdata1:16G:autoextend                      #
innodb_autoextend_increment           = 512                                         #
innodb_buffer_pool_size               = 30G                                         #
innodb_buffer_pool_instances          = 32                                          #
innodb_file_format                    = barracuda                                   #
innodb_file_format_max                = barracuda                                   #
innodb_compression_algorithm          = lzma                                        #
innodb_compression_level              = 6                                           #
innodb_buffer_pool_populate           = 1                                           #
innodb_log_group_home_dir             = /opt/data0                                  #
innodb_file_per_table                 = 1                                           #


innodb_undo_directory                 = /opt/data0                                  #
innodb_undo_logs                      = 128                                         #
innodb_undo_tablespaces               = 12                                          #


binlog_cache_size                     = 4M                                          #
binlog_checksum                       = crc32                                       #
binlog_format                         = row                                         #
expire_logs_days                      = 30                                          #
log_bin                               = /opt/data0/mysql-bin                        #
max_binlog_cache_size                 = 128M                                        #
max_binlog_size                       = 1G                                          #
sync_binlog                           = 1                                           #


max_relay_log_size                    = 1G                                          #
relay_log                             = /opt/data0/relay-bin                        #
relay_log_index                       = /opt/data0/relay-bin.index                  #
relay_log_info_file                   = relay-log.info                              #
relay_log_purge                       = 1                                           #
relay_log_recovery                    = 1                                           #
sync_relay_log                        = 10000                                       #


# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links                        = 0                                           #

The difference between 3307.cnf and 3306.cnf is: the path of all relevant files, the port number to listen on, and the name of the node mysqld1.

Step 5: systemd startup file

$ cat /etc/systemd/system/mariadb\@.service

#
# /etc/systemd/system/[email protected]
#

[Unit]
Description=Multi-Instance MariaDB Service
After=network.target
After=syslog.target


[Install]
WantedBy=multi-user.target


[Service]
User=mysql
Group=mysql
Type=forking
# true is needed for the ExecStartPre
PermissionsStartOnly=true
ExecStartPre=/usr/bin/mkdir -p /opt/data%i
ExecStartPre=/usr/bin/chown mysql:mysql /opt/data%i -R
ExecStart=/usr/bin/mysqld_multi start %i
ExecStop=/usr/bin/mysqld_multi stop %i
LimitNOFILE=102400
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=true

At this point, the MariaDB single-machine multi-instance configuration should be completed. Use systemctl start mariadb@{0,1} to start two instances at the same time, or systemctl start mariadb@0 to start a single instance.

If you encounter startup problems, you can follow the prompts to view the relevant prompts, or check /opt/data{0,1}/mysqld.log to see the system log, and check it step by step.

When you encounter storage bottlenecks, you can migrate the MariaDB service and data corresponding to port 3307 to a new server. The process does not involve data redeployment, and it is relatively easier to migrate.

 

 

 

references:

http://www.anntoin.com/Blog/Tutorials/MultipleDBInstances.html

https://forums.opensuse.org/showthread.php/504526-OS-13-1-MARIADB-Using-multiple-mysql-instance-without-a-supplementary-standalone-database

http://www.fromdual.ch/multi-instance-set-up-with-mysql-enterprise-server-5-7-on-rhel-7-with-systemd

http://unix.stackexchange.com/questions/256285/run-multiple-instances-of-mysql-centos7

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325956514&siteId=291194637