High concurrent access, massive data optimized for M Mysql database

1. optimized code and frame

2. Distributed Load Balancing

2. M ysql master-slave configuration, separate read and write

3. The database sub-library (vertical division) part table (horizontal split)

Sub-libraries: a table in the database according to the type divided into different databases, such as divided into a user database, product database, order database

Part tables: a specific database table, huge amounts of data can be divided according to the order of multi-level tables, the table data structures the same as the user table may be divided according to the order of 100,000, and each table data will not be more than 100,000.

 

For large sites large number of concurrent access software solutions, in addition to achieving load balancing in distributed sites is not enough. To the data service layer, data access layer, or if traditional data structures, or just simply rely on a server to carry so many database connections, the database will inevitably crashes, data loss, the consequences even more disastrous. At this time, we will consider how to reduce the database connection, on the one hand the use of good code framework, to optimize the code, using excellent technologies such as data cache: memcached, if funds are huge, it is bound to think of assuming the server group to share the main pressure on the database. Ok cut today microblogging theme, use MySQL master-slave configuration, read and write separation, reducing database stress. In this way, there are a lot of sites in use today, is not a new thing, to sum up today, facilitate learning reference.

Overview: erection of a Master server (win8.1 system, Ip: 192.168.0.104), erection of two Slave servers (virtual machine - a Ubuntu, a Windows Server 2003)

Principle: master (Master) responsible for the site NonQuery operation, from the server is responsible for the Query operation, the user can model the site functional block fixed Slave access server, or write their own pool or queue, consisting of the connection from the server to request allocation. Master and slave server using the MySQL binary log files, synchronize data. Binary logs generated by the master server, database synchronization acquisition response from the server.

Implementation:

1, the main server are fitted from the MySQL database, windows system I is mysql_5.5.25.msi installed version, Ubuntu is installed mysql-5.6.22-linux-glibc2.5-i686.tar

windows install mysql not talk about, and generally people on earth should be. I say a little about Ubuntu MySQL installation, I suggest not to download and install online or offline installation good. You can refer to   http://www.linuxidc.com/Linux/2013-01/78716.htm  who do not know the brother or sister, written in accordance with this good can be installed on. Several phenomena may occur at the time of installation, you can refer to solve it:

(1) If you are not logged in as root, it is recommended su - root to switch to Root users to install, it is not always the sudo.

(2) storing mysql-extracting file folder, the folder name into the best mysql

(3) When ./support-files/mysql.server start startup MySQL, you may see a warning, the Chinese meaning is when you start to read the file services running, ignoring the my.cnf file, it is because my.cnf file permissions have a problem, mysql considers the file is dangerous not performed. But mysql will start successfully, but if the following configuration parameters from the server to modify my.cnf file, you will find the file to turn over, but when the service is restarted after configuration changes not perform, and you list what the mysql folder You will find a lot .my.cnf.swp and other intermediate files. The reason for this is because when my.cnf MySQL starts without reading. Then as long as the my.cnf file permissions to change permissions my_new.cnf like it Ok, the command: chmod 644 my.cnf on Ok

(4) Ubuntu does not modify the content of the document Vim, Vim is best to install on, apt-get install vim, otherwise expected to be crazy.

At this time I believe MySQL installation should go up.

2, the master server configuration Master

(1) Master MySQL created on a user 'repl', and allow other servers via remote access Slave Master, the read binary logs user, data synchronization.

  Create a database user for reading logs

(2) find the MySQL installation folder modification my.Ini file. There are several log mysql way, this is not the focus of today. As long as we start binary logging log-bin just ok.

 In [mysqld] add the following lines of code below

  View Code

(3) View Log

mysql> SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000001 | 1285 | | |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

Restart MySQL service

3. Configure Slave from the server (windows)

(1) find the MySQL installation folder modify my.ini file in the [mysqld] add the following lines of code below

  my.cnf Configuration

Restart MySQL service

(2) Master connector

change master to master_host = '192.168.0.104' , // Master server Ip
MASTER_PORT = 3306,
MASTER_USER = 'the repl',
master_password = 'MySQL', 
log master_log_file = 'master-bin.000001', // Master server generated
master_log_pos = 0;

(3) Start Slave

start slave;

4, Slave from the server (Ubuntu)

(1) find the MySQL installation folder modify my.cnf file, vim my.cnf

 s

 

(2) ./support-files/myql.server restart to restart the MySQL service, ./bin/mysql into the MySQL command window 

(3) Master connector

change master to master_host = '192.168.0.104' , // Master server Ip
MASTER_PORT = 3306,
MASTER_USER = 'the repl',
master_password = 'MySQL', 
log master_log_file = 'master-bin.000001', // Master server generated
master_log_pos = 0;

(4) Start Slave

start slave;

OK all configurations are completed, this time we can be tested in the Master Mysql because when Master mysql us to monitor all the operations log, so any change in the operation of your primary database server, will be synchronized to the server. Creating a database, table, try it. . .

Guess you like

Origin www.cnblogs.com/HKROnline-SyncNavigator/p/10972514.html