Detailed process of using mysqld_multi to deploy a single-host multi-instance

Source: Internet
Author: User
Tags crc32 automake

Detailed process of using mysqld_multi to deploy a single-host multi-instance

With the development of hardware, multi-core Linux systems have become a general trend, while MySQL is a single-process multi-thread, so the exploitation of multi-process is not very high, although MySQL 5.6 has improved a lot in this aspect, it has not reached 100%. to make full use of system resources, MySQL has its own supplement, that is, it can deploy multiple instances, one instance and one port.

1. Prepare the mysql Environment

Mysql reference and source package for source code installation:

1.1. Prepare the installation environment

Groupaddmysql
Useradd-g mysql
Autoreconf -- force -- install
Libtoolize -- automake -- force
Automake -- force -- add-missing
Yuminstall-y libtoolize
Yuminstall cmake-y
Yuminstall gcc-c ++-y
Yuminstall-y ncurses-devel.x86_64
Yuminstall-y cmake. x86_64
Yuminstall-y libaio. x86_64
Yuminstall-y bison. x86_64
Yuminstall-y gcc-c ++. x86_64
Yuminstall make-y

1.2. Create the mysql compiling root directory

Mkdir-p/usr/local/mysql

1.3 decompress the source code package

Tar-xvf mysql-5.6.12.tar.gz

Cd mysql-5.6.12

1.4. Compile and install

Timecmake. -DCMAKE_INSTALL_PREFIX =/usr/local/mysql-DMYSQL_DATADIR =/home/data/mysql/data-DWITH_INNOBASE_STORAGE_ENGINE = 1-DMYSQL_UNIX_ADDR =/usr/local/mysql. sock-DMYSQL_USER = mysql-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_general_ci

Since time make takes a long time, it has been installed in advance

Timemake

Timemake install

2. Prepare the first instance 3307

2.1 create a directory

Mkdir/usr/local/mysql3307
Chown-R mysql. mysql/usr/local/mysql3307/
Mkdir-p/home/data/mysql3307/data
Chown-R mysql. mysql/home/data/mysql3307
Chown-R mysql. mysql/home/data/mysql3307/data
Mkdir-p/home/data/mysql3307/binlog
Chown-R mysql. mysql/home/data/mysql3307
Mkdir-p/home/data/mysql3307/relay_log/
Chown-R mysql. mysql/home/data/mysql3307/

2.2 configuration file

[Mysqld_multi]

Mysqld =/usr/local/mysql/bin/mysqld_safe

Mysqladmin =/usr/local/mysql/bin/mysqladmin

Log =/home/mysql/mydata/log/mysqld_multi.log

[Mysqld1]

Socket =/usr/local/mysql3307/mysql. sock
Port = 3307
Pid-file =/usr/local/mysql3307/mysqld. pid
Datadir =/home/data/mysql3307/data
Log_bin =/home/data/mysql3307/binlog
Servers-id = 1230
Relay_log =/home/data/mysql3307/relay_log/mysql-relay-bin
Log_slave_updates = 1
Read_only = 0
Innodb_buffer_pool_size = 128 M
Innodb_flush_log_at_trx_commit = 0

2.3 initialize the database

/Usr/local/mysql/scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/home/data/mysql3307/data

3. Prepare the second instance 3308

3.1 create a directory

Mkdir/usr/local/mysql3308
Chown-R mysql. mysql/usr/local/mysql3308/
Mkdir-p/home/data/mysql3308/data
Chown-R mysql. mysql/home/data/mysql3308
Chown-R mysql. mysql/home/data/mysql3308/data
Mkdir-p/home/data/mysql3308/binlog
Chown-R mysql. mysql/home/data/mysql3308
Mkdir-p/home/data/mysql3308/relay_log/
Chown-R mysql. mysql/home/data/mysql3308/

3.2 configuration file

[Mysqld2]

Socket =/usr/local/mysql3308/mysql. sock

Port = 3308

Pid-file =/usr/local/mysql3308/mysqld. pid

Datadir =/home/data/mysql3308/data

 

Log_bin =/home/data/mysql3308/binlog

Servers-id = 2230

Relay_log =/home/data/mysql3308/relay_log/mysql-relay-bin

Log_slave_updates = 1

Read_only = 0

 

Innodb_buffer_pool_size = 128 M

Innodb_flush_log_at_trx_commit = 0

3.3 initialize the database

/Usr/local/mysql/scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/home/data/mysql3308/data

4. Prepare the third instance 3309

4.1 create a directory

Mkdir/usr/local/mysql3309
Chown-R mysql. mysql/usr/local/mysql3309/
Mkdir-p/home/data/mysql3309/data
Chown-R mysql. mysql/home/data/mysql3309
Chown-R mysql. mysql/home/data/mysql3309/data
Mkdir-p/home/data/mysql3309/binlog
Chown-R mysql. mysql/home/data/mysql3309
Mkdir-p/home/data/mysql3309/relay_log/
Chown-R mysql. mysql/home/data/mysql3309/

4.2 configuration file

[Mysqld3]

Socket =/usr/local/mysql3309/mysql. sock

Port = 3309

Pid-file =/usr/local/mysql3309/mysqld. pid

Datadir =/home/data/mysql3309/data

 

Log_bin =/home/data/mysql3309/binlog

Servers-id = 3230

Relay_log =/home/data/mysql3309/relay_log/mysql-relay-bin

Log_slave_updates = 1

Read_only = 0

 

Innodb_buffer_pool_size = 128 M

Innodb_flush_log_at_trx_commit = 0

4.3 initialize the database

/Usr/local/mysql/scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/home/data/mysql3309/data

The initialization information is as follows:

[Mysql @ data02 ~] $/Usr/local/mysql/scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/home/data/mysql3309/data
WARNING: cocould not write to config file/usr/local/mysql/my-new.cnf: insufficient Permissions
 
Installing MySQL system tables... 2015-05-14 09:31:20 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use -- explicit_defaults_for_timestamp server option (see documentation for more details ).
09:31:20 12307 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)
 
09:31:20 12307 [Warning] Buffered warning: Changed limits: table_cache: 431 (requested 2000)
 
09:31:20 12307 [Note] InnoDB: The InnoDB memory heap is disabled
09:31:20 12307 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
09:31:20 12307 [Note] InnoDB: Compressed tables use zlib 1.2.3
09:31:20 12307 [Note] InnoDB: Using CPU crc32 instructions
09:31:20 12307 [Note] InnoDB: Initializing buffer pool, size = 128.0 M
09:31:20 12307 [Note] InnoDB: Completed initialization of buffer pool
09:31:20 12307 [Note] InnoDB: The first specified data file./ibdata1 did not exist: a new database to be created!
09:31:20 12307 [Note] InnoDB: Setting file./ibdata1 size to 12 MB
09:31:20 12307 [Note] InnoDB: Database physically writes the file full: wait...
09:31:20 12307 [Note] InnoDB: Setting log file./ib_logfile101 size to 48 MB
09:31:20 12307 [Note] InnoDB: Setting log file./ib_logfile1 size to 48 MB
09:31:21 12307 [Note] InnoDB: Renaming log file./ib_logfile101 to./ib_logfile0
09:31:21 12307 [Warning] InnoDB: New log files created, LSN = 45781
09:31:21 12307 [Note] InnoDB: Doublewrite buffer not found: creating new
09:31:21 12307 [Note] InnoDB: Doublewrite buffer created
09:31:21 12307 [Note] InnoDB: 128 rollback segment (s) are active.
09:31:21 12307 [Warning] InnoDB: Creating foreign key constraint system tables.
09:31:21 12307 [Note] InnoDB: Foreign key constraint system tables created
09:31:21 12307 [Note] InnoDB: Creating tablespace and datafile system tables.
09:31:21 12307 [Note] InnoDB: Tablespace and datafile system tables created.
09:31:21 12307 [Note] InnoDB: Waiting for purge to start
09:31:21 12307 [Note] InnoDB: 5.6.12 started; log sequence number 0
09:31:21 12307 [Note] Binlog end
09:31:21 12307 [Note] InnoDB: FTS optimize thread exiting.
09:31:21 12307 [Note] InnoDB: Starting shutdown...
09:31:22 12307 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
 
Filling help tables... 2015-05-14 09:31:22 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use -- explicit_defaults_for_timestamp server option (see documentation for more details ).
09:31:22 12332 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)
 
09:31:22 12332 [Warning] Buffered warning: Changed limits: table_cache: 431 (requested 2000)
 
09:31:22 12332 [Note] InnoDB: The InnoDB memory heap is disabled
09:31:22 12332 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
09:31:22 12332 [Note] InnoDB: Compressed tables use zlib 1.2.3
09:31:22 12332 [Note] InnoDB: Using CPU crc32 instructions
09:31:22 12332 [Note] InnoDB: Initializing buffer pool, size = 128.0 M
09:31:22 12332 [Note] InnoDB: Completed initialization of buffer pool
09:31:22 12332 [Note] InnoDB: Highest supported file format is Barracuda.
09:31:22 12332 [Note] InnoDB: 128 rollback segment (s) are active.
09:31:22 12332 [Note] InnoDB: Waiting for purge to start
09:31:22 12332 [Note] InnoDB: 5.6.12 started; log sequence number 1625977
09:31:22 12332 [Note] Binlog end
09:31:22 12332 [Note] InnoDB: FTS optimize thread exiting.
09:31:22 12332 [Note] InnoDB: Starting shutdown...
09:31:24 12332 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
 
To start mysqld at boot time you have to copy
Support-files/mysql. server to the right place for your system
 
Please remember to set a password for the MySQL root USER!
To do so, start the server, then issue the following commands:
 
/Usr/local/mysql/bin/mysqladmin-u root password 'new-password'
/Usr/local/mysql/bin/mysqladmin-u root-h data02 password 'new-password'
 
Alternatively you can run:
 
/Usr/local/mysql/bin/mysql_secure_installation
 
Which will also give you the option of removing the test
Databases and anonymous user created by default. This is
Stronugly recommended for production servers.
 
See the manual for more instructions.
 
You can start the MySQL daemon:
 
Cd.;/usr/local/mysql/bin/mysqld_safe &
 
You can test the MySQL daemon with mysql-test-run.pl
 
Cd mysql-test; perl mysql-test-run.pl
 
Please report any problems with the./bin/mysqlbug script!
 
The latest information about MySQL is available on the web
 
Http://www.mysql.com
 
Support MySQL by buying support/licenses at http://shop.mysql.com
 
WARNING: cocould not copy config file template/usr/local/mysql/support-files/my-default.cnf
/Usr/local/mysql/my-new.cnf, may not have access rights to do so.
You may want to copy the file manually, or create your own,
It will then be used by default by the server when you start it.
 
WARNING: Default config file/etc/my. cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use
-- Defaults-file argument to mysqld_safe when starting the server

5. Start a multi-instance Database

Mkdir-p/home/mysql/data/log

[Mysql @ data02 data] $ mysqld_multi -- defaults-extra-file =/etc/my. cnf start 1, 2, 3

[Mysql @ data02 data] $

Background log information:

Starting MySQL servers
150514 09:36:14 mysqld_safe Logging to '/home/data/mysql3309/data/data02.err '.
150514 09:36:15 mysqld_safe Logging to '/home/data/mysql3308/data/data02.err '.
150514 09:36:15 mysqld_safe Logging to '/home/data/mysql3307/data/data02.err '.
150514 09:36:15 mysqld_safe Starting mysqlddaemon with databases from/home/data/mysql3308/data
150514 09:36:15 mysqld_safe Starting mysqlddaemon with databases from/home/data/mysql3307/data
150514 09:36:15 mysqld_safe Starting mysqlddaemon with databases from/home/data/mysql3309/data

6. view multiple instances

[Mysql @ data02 ~] $ Mysqld_multi -- defaults-extra-file =/etc/my. cnf report

Reporting MySQL servers

MySQL server from group: mysqld1 is running

MySQL server from group: mysqld2 is running

MySQL server from group: mysqld3 is running

[Mysql @ data02 ~] $

 

Background log information:

Reporting MySQL servers

MySQL server from group: mysqld1 is running

MySQL server from group: mysqld2 is running

MySQL server from group: mysqld3 is running

7. Stop multiple instances

Mysqld_multi -- defaults-extra-file =/etc/my. cnf stop 1, 2, 3

Background log information:

Stopping MySQL servers

150514 09:35:43 mysqld_safe mysqld from pidfile/usr/local/mysql3309/mysqld. pid ended

150514 09:35:43 mysqld_safe mysqld from pidfile/usr/local/mysql3307/mysqld. pid ended

150514 09:35:43 mysqld_safe mysqld from pidfile/usr/local/mysql3308/mysqld. pid ended

8. log on to the mysql instance

You can log on to your mysql instance by specifying the socket to be started, as shown below:

[Mysql @ data02 ~] $ Mysql -- socket =/usr/local/mysql3308/mysql. sock

Welcome to the MySQL monitor. Commands end with; or \ g.

Your MySQL connection id is 2

Server version: 5.6.12-log Sourcedistribution

Copyright (c) 2000,201 3, Oracle and/or itsaffiliates. All rights reserved.

Oracle is a registered trademark of OracleCorporation and/or its

Affiliates. Other names may be trademarksof their respective

Owners.

Type 'help; 'or' \ H' for help. type' \ C' toclear the current input statement.

Mysql> select @ port;

+ -------- +

| @ Port |

+ -------- +

| 1, 3308 |

+ -------- +

1 row in set (0.00 sec)

Mysql>

Mysql> create database d3308;

Query OK, 1 row affected (0.04 sec)

Mysql>

9. You can build master-slave and master-master services on multiple ports.

9.1. Create an account on instance 3307

Copy account

Grantreplication slave, RELOAD, super on *. * TO repl @ '2017. 192.% 'identified by 'repl _ 100 ';

Backup account

GRANTRELOAD, SUPER, lock tables, replication client, create tablespace on *. * TO 'backup '@ '192. 192. %' identified by '123 ';

Grantall privileges on 'mysql'. * TO 'backup '@ '2017. 192.% ';

Grantevent on *. * TO 'backup '@ '2017. 192.% ';

9.2. synchronize data from the 3307 instance to the 3308 Port

Backup:

/Usr/local/mysql/bin/mysqldump-ubackup -- password = 123456 -- host = 192.168.52.138 -- socket =/usr/local/mysql3307/mysql. sock -- port = 3307-R-E -- skip-opt -- single-transaction -- flush-logs -- master-data = 2 -- add-drop-table -- create-option -- quick -- extended-insert = false -- set-charset -- disable-keys-A>/tmp/alldbfullbackup. SQL

Import:

/Usr/local/mysql/bin/mysql-uroot-p -- socket =/usr/local/mysql3308/mysql. sock -- port = 3308 </tmp/alldbfullbackup. SQL

9.3. Create a copy link on instance 3308

Find the replication point

More/tmp/alldbfullbackup. SQL

Start to create a copy Link

Change master TOMASTER_HOST = '192. 168.52.138 ', MASTER_PORT = 192,

MASTER_USER = 'repl ',

MASTER_PASSWORD = 'repl _ 1234 ',

MASTER_LOG_FILE = 'mysql-bin.000006 ',

MASTER_LOG_POS = 120;

Enable replication

Startslave;

View copy status

Showslave status \ G;

Mysql> show slave status \ G

* *************************** 1. row ***************************

Slave_IO_State: Waiting formaster to send event

Master_Host: 192.168.52.138

Master_User: repl

Master_Port: 3307

Connect_Retry: 60

Master_Log_File: mysql-bin.000011

Read_Master_Log_Pos: 120

Relay_Log_File: mysql-relay-bin.000005

Relay_Log_Pos: 283

Relay_Master_Log_File: mysql-bin.000011

Slave_IO_Running: Yes

Slave_ SQL _Running: Yes

......

Seconds_Behind_Master: 0

10. Manage a single instance

Stop instance 2:

[Root @ data03 ~] # Mysqld_multi -- defaults-extra-file =/etc/my. cnf stop 2

[Root @ data03 ~] #

Background log information:

Stopping MySQL servers

150517 06:53:43 mysqld_safe mysqld from pidfile/usr/local/mysql3308/mysqld. pid ended

Mysqld_multi log file version 2.16; run: July 22, May 17 06:53:48 2015

Start instance 2:

[Root @ data03 ~] # Mysqld_multi -- defaults-extra-file =/etc/my. cnf start 2

[Root @ data03 ~] #

Background log information:

Starting MySQL servers

 

150517 06:53:48 mysqld_safe Logging to '/home/data/mysql3308/data/data03.err '.

150517 06:53:48 mysqld_safe Starting mysqlddaemon with databases from/home/data/mysql3308/data

11. How to use multiple instances

In Multiple instances, resources of each instance are not shared. Therefore, you must allocate the memory, disks, and other resources of each instance properly to avoid the situation of out of memery or full disk.

 

-------------------------------------- Split line --------------------------------------

Install MySQL in Ubuntu 14.04

MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF

Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL

Build a MySQL Master/Slave server in Ubuntu 14.04

Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS

Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04

-------------------------------------- Split line --------------------------------------

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.