MySQLケースコンバット-MySQLデータベースのマルチインスタンスデプロイメント

序文

この環境は、
特定の構築のためにMySQL-5.7.14を構築するためのCentos7.8システムに基づいています。MySQL-5.7.14環境構築を参照してください。

多くの場合、同じサーバーに複数のアプリケーションデータベースを展開しますが、それらが同じデータベースサービスに展開されると、その後の製品の更新、アップグレード、およびメンテナンスによって多くの不便が発生します。影響。したがって、MySQLマルチインスタンスデプロイメントはこの問題を解決します。複数のアプリケーションデータベースサービスを独立して実行します。オンラインビジネスの効率的で安定した安全な運営を確保します。


環境要件:mysql-5.7.14ユニバーサルバイナリまたはソースコードのデプロイ

1つは、mysqldの個別の構成ファイルのデプロイメントです。

注:このデプロイメントは、mysqlソース環境のインストールに基づいています

2つのmysqlサービス
ポートのマルチインスタンスデプロイメントは、3306、3307
データベースディレクトリ:/ mysql / 330 {6,7} / date
パブリックベースのディレクトリ:/ usr / local / mysql

# 禁用数据库服务
[root@mysql-source_code ~]# systemctl stop mysqld
[root@mysql-source_code ~]# systemctl disable mysqld

# 创建多实例服务目录
[root@mysql-source_code ~]# mkdir /mysql/330{6,7}/data -p

# 分别提供配置文件
[root@mysql-source_code ~]# vim /mysql/3306/my.cnf
[client]
port = 3306
socket = /mysql/3306/mysql.sock

[mysqld]
user = mysql
port = 3306
socket = /mysql/3306/mysql.sock
basedir = /usr/local/mysql
datadir = /mysql/3306/data
server-id = 5

[mysqldump]
quick
max_allowed_packet = 16M

[mysqld_safe]
log-error=/mysql/3306/mysql_3306.err
pid-file=/mysql/3306/mysqld.pid


[root@mysql-source_code ~]# vim /mysql/3307/my.cnf
[client]
port = 3307
socket = /mysql/3307/mysql.sock

[mysqld]
user = mysql
port = 3307
socket = /mysql/3307/mysql.sock
basedir = /usr/local/mysql
datadir = /mysql/3307/data
server-id = 6

[mysqldump]
quick
max_allowed_packet = 16M

[mysqld_safe]
log-error=/mysql/3307/mysql_3307.err
pid-file=/mysql/3307/mysqld.pid


# 修改权限
[root@mysql-source_code ~]# chown -R mysql.mysql /mysql

# 初始化mysqld服务
[root@mysql-source_code ~]# /usr/local/mysql/bin/mysqld --initialize --datadir=/mysql/3306/data \
> --basedir=/usr/local/mysql --user=mysql
[root@mysql-source_code ~]# /usr/local/mysql/bin/mysqld --initialize --datadir=/mysql/3307/data \
> --basedir=/usr/local/mysql --user=mysql

# 启动服务
[root@mysql-source_code ~]# mysqld_safe --defaults-file=/mysql/3306/my.cnf &
[root@mysql-source_code ~]# mysqld_safe --defaults-file=/mysql/3307/my.cnf &

# 查看mysqld服务端口、进程状况
[root@mysql-source_code ~]# netstat -lnutp | grep 330
tcp6       0      0 :::3306                 :::*                    LISTEN      2087/mysqld         
tcp6       0      0 :::3307                 :::*                    LISTEN      2288/mysqld 

[root@mysql-source_code ~]# ps aux | grep  mysqld
root       1914  0.0  0.0 113416  1584 pts/0    S    21:59   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/mysql/3306/my.cnf
mysql      2087  0.3  9.9 1833568 185824 pts/0  Sl   21:59   0:02 /usr/local/mysql/bin/mysqld --defaults-file=/mysql/3306/my.cnf --basedir=/usr/local/mysql --datadir=/mysql/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysql/3306/mysql_3306.err --pid-file=/mysql/3306/mysqld.pid --socket=/mysql/3306/mysql.sock --port=3306
root       2115  0.0  0.0 113416  1588 pts/0    S    22:00   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/mysql/3307/my.cnf
mysql      2288  0.3  9.8 1833568 183540 pts/0  Sl   22:00   0:03 /usr/local/mysql/bin/mysqld --defaults-file=/mysql/3307/my.cnf --basedir=/usr/local/mysql --datadir=/mysql/3307/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysql/3307/mysql_3307.err --pid-file=/mysql/3307/mysqld.pid --socket=/mysql/3307/mysql.sock --port=3307
root       2390  0.0  0.0 112812   972 pts/0    S+   22:15   0:00 grep --color=auto mysqld

データベースにログインします

--- 3306
[root@mysql-source_code ~]# mysql -uroot -p -S /mysql/3306/mysql.sock
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.14 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 



--- 3307
[root@mysql-source_code ~]# mysql -uroot -p -S /mysql/3307/mysql.sock 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.14

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> alter user root@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> 

マルチインスタンスデータベースを停止します

[root@mysql-source_code ~]# mysqladmin -uroot -p123456 -S /mysql/3306/mysql.sock shutdown
[root@mysql-source_code ~]# mysqladmin -uroot -p123456 -S /mysql/3307/mysql.sock shutdown

2.mysqld共有構成ファイルのデプロイメント

# 禁用运行中的数据库
[root@mysql-source_code ~]# mysqladmin -uroot -p123456 -S /mysql/3306/mysql.sock shutdown
[root@mysql-source_code ~]# mysqladmin -uroot -p123456 -S /mysql/3307/mysql.sock shutdown

# 备份my.cnf文件
[root@mysql-source_code ~]# cp /etc/my.cnf /etc/my.cnf.bak

# 提供配置文件
[root@localhost ~]# cp /etc/my.cnf /etc/my.cnf.bak
[root@localhost ~]# vim /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = root
pass = 123456

[mysqld3306]
socket = /mysql/3306/mysql.sock
port = 3306
pid-file = /mysql/3306/mysql.pid
datadir = /mysql/3306/data
basedir = /usr/local/mysql

[mysqld3307]
socket = /mysql/3307/mysql.sock
port = 3307
pid-file = /mysql/3307/mysql.pid
datadir = /mysql/3307/data
basedir = /usr/local/mysql

# 启动服务
[root@mysql-source_code ~]# mysqld_multi start 3306,3307


# 查看mysqld服务端口、进程状况
[root@mysql-source_code ~]# netstat -lnutp | grep 330
tcp6       0      0 :::3306                 :::*                    LISTEN      2022/mysqld         
tcp6       0      0 :::3307                 :::*                    LISTEN      2223/mysqld 

[root@mysql-source_code ~]# ps aux | grep mysql
root       1849  0.0  0.0 113416  1588 pts/0    S    23:12   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/mysql/3306/my.cnf
mysql      2022  0.2  9.8 1833568 184216 pts/0  Sl   23:12   0:02 /usr/local/mysql/bin/mysqld --defaults-file=/mysql/3306/my.cnf --basedir=/usr/local/mysql --datadir=/mysql/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysql/3306/mysql_3306.err --pid-file=/mysql/3306/mysqld.pid --socket=/mysql/3306/mysql.sock --port=3306
root       2050  0.0  0.0 113416  1588 pts/0    S    23:12   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/mysql/3307/my.cnf
mysql      2223  0.4  9.9 1833568 185988 pts/0  Sl   23:12   0:03 /usr/local/mysql/bin/mysqld --defaults-file=/mysql/3307/my.cnf --basedir=/usr/local/mysql --datadir=/mysql/3307/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysql/3307/mysql_3307.err --pid-file=/mysql/3307/mysqld.pid --socket=/mysql/3307/mysql.sock --port=3307
root       2276  0.0  0.1 133800  2516 pts/1    S+   23:13   0:00 mysql -uroot -p -S /mysql/3307/mysql.sock
root       2470  0.0  0.0 112812   972 pts/0    S+   23:25   0:00 grep --color=auto mysql

データベースにログインします

--- 3306
[root@mysql-source_code ~]# mysql -uroot -p -S /mysql/3306/mysql.sock
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.14 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 

--- 3306
[root@mysql-source_code ~]# mysql -uroot -p -S /mysql/3307/mysql.sock
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.14 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 

マルチインスタンスデータベースを停止します

[root@mysql-source_code ~]# mysqld_multi stop  3306,3307

おすすめ

転載: blog.csdn.net/XY0918ZWQ/article/details/113664968