多实例配置 ---mysql/linux

多实例的概念
什么是多实例?
– 在一台物理主机上运行多个数据库服务


• 为什么要使用多实例?
– 节约运维成本
– 提高硬件利用率


配置步骤
• 配置步骤说明
– 安装支持多实例服务的软件包
具体配置(解压软件,修改目录名,修改 PATH 变量)
– 修改主配置文件
– 根据配置文件做相应设置
– 初始化授权库
– 启动服务
– 客户端访问


实验概要:在主机70上先安装成功mysql,然后在把mysql禁用掉。做此操作的目的在于得到相应的mysql安装过程自动创建的mysql用户的相关的配置。在禁用掉mysql后,安装支持多实例的mysql包。本文将在一台上进行两个实例的搭建。在搭建过程中需要创建一个空文件作为存相应实例数据库的文件夹。然后对实例进行初始化,并开启相应的实例。


1.配置mysql数据库
[root@host70 ~]# tar -xf mysql-5.7.17.tar 
[root@host70 ~]# ls
anaconda-ks.cfg
initial-setup-ks.cfg
mysql-5.7.17.tar
mysql-community-client-5.7.17-1.el7.x86_64.rpm
mysql-community-common-5.7.17-1.el7.x86_64.rpm
mysql-community-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64.rpm
mysql-community-server-5.7.17-1.el7.x86_64.rpm
mysql-community-test-5.7.17-1.el7.x86_64.rpm
[root@host70 ~]# yum -y install perl-JSON
[root@host70 ~]# rpm -Uvh mysql-community-*rpm
[root@host70 ~]# systemctl start mysqld
[root@host70 ~]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@host70 ~]# ps -C mysqld
  PID TTY          TIME CMD
 4567 ?        00:00:00 mysqld
[root@host70 ~]# ss -untlp | grep mysqld
tcp    LISTEN     0      80       :::3306                 :::*                   users:(("mysqld",pid=4567,fd=18))
[root@host70 ~]# grep password /var/log/mysqld.log 
2018-07-06T02:01:51.560583Z 1 [Note] A temporary password is generated for root@localhost: nEntSiYG2%)H
2018-07-06T02:03:18.385486Z 0 [Note] Shutting down plugin 'validate_password'
2018-07-06T02:03:19.719142Z 0 [Note] Shutting down plugin 'sha256_password'
2018-07-06T02:03:19.719148Z 0 [Note] Shutting down plugin 'mysql_native_password'
[root@host70 ~]# vim /etc/my.cnf
[root@host70 ~]# systemctl restart mysqld
[root@host70 ~]# mysql  -uroot -p'nEntSiYG2%)H' 
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17


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.01 sec)


mysql> exit
Bye
[root@host70 ~]# mysql  -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17 MySQL Community Server (GPL)


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> ^C
mysql> 
mysql> exit
Bye
[root@host70 ~]# systemctl stop mysqld.service 
[root@host70 ~]# systemctl disable mysqld
Removed symlink /etc/systemd/system/multi-user.target.wants/mysqld.service.








2.配置支多实例的mysql


[root@host70 ~]# rpm -qa | grep -i mysql
mysql-community-client-5.7.17-1.el7.x86_64
mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64
mysql-community-test-5.7.17-1.el7.x86_64
mysql-community-common-5.7.17-1.el7.x86_64
mysql-community-devel-5.7.17-1.el7.x86_64
mysql-community-libs-compat-5.7.17-1.el7.x86_64
mysql-community-libs-5.7.17-1.el7.x86_64
mysql-community-embedded-5.7.17-1.el7.x86_64
mysql-community-embedded-compat-5.7.17-1.el7.x86_64
mysql-community-embedded-devel-5.7.17-1.el7.x86_64
mysql-community-server-5.7.17-1.el7.x86_64






[root@host70 ~]# ls
anaconda-ks.cfg
initial-setup-ks.cfg
mysql-5.7.17.tar
mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
mysql-community-client-5.7.17-1.el7.x86_64.rpm
mysql-community-common-5.7.17-1.el7.x86_64.rpm
mysql-community-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64.rpm
mysql-community-server-5.7.17-1.el7.x86_64.rpm
mysql-community-test-5.7.17-1.el7.x86_64.rpm






[root@host70 ~]# tar -zxf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz 
[root@host70 ~]# ls
anaconda-ks.cfg
initial-setup-ks.cfg
mysql-5.7.17.tar
mysql-5.7.20-linux-glibc2.12-x86_64
mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
mysql-community-client-5.7.17-1.el7.x86_64.rpm
mysql-community-common-5.7.17-1.el7.x86_64.rpm
mysql-community-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-5.7.17-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.17-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.17-1.el7.x86_64.rpm
mysql-community-server-5.7.17-1.el7.x86_64.rpm
mysql-community-test-5.7.17-1.el7.x86_64.rpm










[root@host70 ~]# mv mysql-5.7.20-linux-glibc2.12-x86_64 /usr/local/mysql
[root@host70 ~]# cd /usr/local/mysql/
[root@host70 mysql]# ls bin
innochecksum       mysqlcheck                  mysql_embedded             mysql_tzinfo_to_sql
lz4_decompress     mysql_client_test_embedded  mysqlimport                mysql_upgrade
myisamchk          mysql_config                mysql_install_db           mysqlxtest
myisam_ftdump      mysql_config_editor         mysql_plugin               perror
myisamlog          mysqld                      mysqlpump                  replace
myisampack         mysqld-debug                mysql_secure_installation  resolveip
my_print_defaults  mysqld_multi                mysqlshow                  resolve_stack_dump
mysql              mysqld_safe                 mysqlslap                  zlib_decompress
mysqladmin         mysqldump                   mysql_ssl_rsa_setup
mysqlbinlog        mysqldumpslow               mysqltest_embedded
[root@host70 mysql]# vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH


       
[root@host70 mysql]# source /etc/profile
[root@host70 mysql]# mv /etc/my.cnf /etc/my.cnf.bak
[root@host70 mysql]# vim /etc/my.cnf
[root@host70 mysql]# mkdir /dir3307
[root@host70 mysql]# mkdir /dir3309
[root@host70 mysql]# chown mysql:mysql /dir330*


[root@host70 mysql]# mysqld
mysqld              mysqld_multi        mysqld_safe         mysqldumpslow       
mysqld-debug        mysqld_pre_systemd  mysqldump   


3.初始化3307端口的mysql服务并开启服务       
[root@host70 mysql]# mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/dir3307 --initialize
2018-07-06T03:44:32.414096Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-07-06T03:44:34.301286Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-07-06T03:44:34.795050Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-07-06T03:44:34.976204Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e645f0fb-80ce-11e8-818a-525400841e14.
2018-07-06T03:44:35.017626Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-07-06T03:44:35.019261Z 1 [Note] A temporary password is generated for root@localhost: )UqXiwVfD9fu
[root@host70 mysql]# ls /dir3307
auto.cnf  ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  sys
[root@host70 mysql]# mysqld_multi   start  1
[root@host70 mysql]# ls /dir3307
auto.cnf        ib_logfile0  mysql                 mysqld.err          sys
ib_buffer_pool  ib_logfile1  mysqld3307.sock       mysqld.pid
ibdata1         ibtmp1       mysqld3307.sock.lock  performance_schema
[root@host70 mysql]# mysql -uroot -p'w9g#O2)o/;BS'  -S /dir3307/mysqld3307.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@host70 mysql]# mysql -uroot -p')UqXiwVfD9fu'  -S /dir3307/mysqld3307.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20


Copyright (c) 2000, 2017, 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> exit
Bye
[root@host70 mysql]# mysql -uroot -p'123456'  -S /dir3307/mysqld3307.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.20 MySQL Community Server (GPL)


Copyright (c) 2000, 2017, 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> exit
Bye






4.初始化3309端口的mysql服务,并开启服务


[root@host70 mysql]# mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/dir3309 --initialize
2018-07-06T03:54:22.306906Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-07-06T03:54:24.196885Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-07-06T03:54:24.681872Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-07-06T03:54:24.859066Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 45deec8f-80d0-11e8-be29-525400841e14.
2018-07-06T03:54:24.899946Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-07-06T03:54:24.901053Z 1 [Note] A temporary password is generated for root@localhost: CaZ)nx>Ou0XK
[root@host70 mysql]# ls /dir3309
auto.cnf  ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  sys
[root@host70 mysql]# mysqld_multi start 2
[root@host70 mysql]# ls /dir3309
auto.cnf        ibdata1      ib_logfile1  mysql            mysqld3309.sock.lock  mysqld.pid          sys
ib_buffer_pool  ib_logfile0  ibtmp1       mysqld3309.sock  mysqld.err            performance_schema
[root@host70 mysql]# mysql -uroot -p'CaZ)nx>Ou0XK'
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[root@host70 mysql]# mysql -uroot -p'CaZ)nx>Ou0XK' -S /dir3309/mysqld3309.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20


Copyright (c) 2000, 2017, 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> exit
Bye


5.关掉实例


[root@host70 ~]# ss -untlp | grep 330*
tcp    LISTEN     0      80       :::3307                 :::*                   users:(("mysqld",pid=5397,fd=16))
tcp    LISTEN     0      80       :::3309                 :::*                   users:(("mysqld",pid=6472,fd=16))


[root@host70 ~]# mysqld_multi --user=root --password 123456 stop 1
[root@host70 ~]# mysqld_multi --user=root --password 123456 stop 2
[root@host70 ~]# ss -untlp | grep 330*







猜你喜欢

转载自blog.csdn.net/zhydream77/article/details/80942528