MySQL multi-instance application

MySQL multi-instance application

First, what is multi-instance MySQL? What role have multi-instance? Multi-instance application scenarios?

MySQL multi-instance: Refers to a MySQL program to manage multiple sets of data instances and databases, each set of data is supported by one instance, the instance is the equivalent of a company, this is the company's data management system and rules.

The role of multi-instance:
1, multi-instance generally in the company, then do the test environments, but also to do a backup database use.
2, can effectively utilize resources on this server.
3, can save server resources.
4, do high availability, load balancing is used, the general use in MyCAT, MHA, Atlas and other infrastructure.

Multi-instance applications to which scenario:
1, generally large enterprises to experiment will use a multi-instance environment testing, data testing, development, testing and so on.
2, tight funding small companies can reduce the cost of test service brings.
3, concurrency is not large machines can also be used, or have the resources remaining machines can also be used.
4, DBA database availability, performance, load balancing will be used to test.

Second, multi-instance environment ready

Environment: VMware virtual machines can be, if it is not under the following configurations can be appropriately reduced.

1, the system: CentOS Linux release 8.0.1905 (Core) mysql Version: 5.7.20
2, memory: 16GB
. 3, the CPU: 4 processor cores
4, the network: bridge mode to
5, disk size: size appropriate to , you can generally 20G

Environmental ready for operation after the following:

[root@hdfeng ~]# mkdir -p /opt/data/330{7,8,9}/data		创建实例数据目录
cat >/opt/data/3307/my.cnf <<EOF
[mysqld]
basedir=/opt/mysql
datadir=/opt/data/3307/data
socket=/opt/data/3307/mysql.sock
log_error=/opt/data/3307/mysql.log
port=3307
server_id=7
log_bin=/opt/data/3307/mysql-bin
[mysql]
socket=/opt/data/3307/mysql.sock
prompt=3307[\\d]>
EOF

cat > /opt/data/3308/my.cnf <<EOF
[mysqld]
basedir=/opt/mysql
datadir=/opt/data/3308/data
socket=/opt/data/3308/mysql.sock
log_error=/opt/data/3308/mysql.log
port=3308
server_id=8
log_bin=/opt/data/3308/mysql-bin
[mysql]
socket=/opt/data/3308/mysql.sock
prompt=3308[\\d]>
EOF

cat > /opt/data/3309/my.cnf <<EOF
[mysqld]
basedir=/opt/mysql
datadir=/opt/data/3309/data
socket=/opt/data/3309/mysql.sock
log_error=/opt/data/3309/mysql.log
port=3309
server_id=9
log_bin=/opt/data/3309/mysql-bin
[mysql]
socket=/opt/data/3309/mysql.sock
prompt=3309[\\d]>
EOF
初始化三套数据库:
mv /etc/my.cnf /etc/my.cnf.backup_basic
mysqld --initialize-insecure  --user=mysql --datadir=/opt/data/3307/data --basedir=/opt/mysql
mysqld --initialize-insecure  --user=mysql --datadir=/opt/data/3308/data --basedir=/opt/mysql
mysqld --initialize-insecure  --user=mysql --datadir=/opt/data/3309/data --basedir=/opt/mysql

Systemd CentOS8 used to manage, as follows:

[root@hdfeng mysql]# cd /etc/systemd/system/

Because there mysqld before-configured in the directory, so long as the change in the name, then you can use, but you need to modify the inside ExecStart configuration, configuration is as follows (3 instances you will need to create three service):
Here Insert Picture Description

vim mysql3307/3308/3309.service
ExecStart=/opt/mysql/bin/mysqld --defaults-file=/opt/data/3307/3308/3309/my.cnf

After modifications are complete, authorize instance directory, or not start.

chown -R mysql.mysql /opt/data/* 
启动数据库实例
[root@hdfeng system]# systemctl start mysqld3307/3308/3309

After starting to see multiple instances Mysql monitoring state and non-interactive viewing ID:

[root@hdfeng system]# netstat -nlp | grep 330
tcp6       0      0 :::3306                 :::*                    LISTEN      866/mysqld
tcp6       0      0 :::3307                 :::*                    LISTEN      2674/mysqld
tcp6       0      0 :::3308                 :::*                    LISTEN      2506/mysqld
tcp6       0      0 :::3309                 :::*                    LISTEN      2537/mysqld
unix  2      [ ACC ]     STREAM     LISTENING     59519    2537/mysqld          /opt/data/3309/mysql.sock
unix  2      [ ACC ]     STREAM     LISTENING     59754    2674/mysqld          /opt/data/3307/mysql.sock
unix  2      [ ACC ]     STREAM     LISTENING     58148    2506/mysqld          /opt/data/3308/mysql.sock
mysql -S /opt/data/3307/3308/3309/mysql.sock -e 'select @@server_id'查看实例ID,能查看到即数据库多实例搭建成功!
[root@hdfeng system]# mysql -S /opt/data/3307/mysql.sock -e 'select @@server_id'
+-------------+
| @@server_id |
+-------------+
|           7 |
+-------------+

Close multi-instance:

sytemctl stop mysqld3307/3308/3309 关闭即可

The next will be talked about in these multi-instance high availability, high performance, load balancing!
This issue, then you talk about the content, how is wrong, or where there do not understand, little friends are welcome message! ! Thank you!

Released three original articles · won praise 1 · views 436

Guess you like

Origin blog.csdn.net/fhdsece/article/details/104202610