Home > other >  Read and write mycat - separation (mysql database)
Read and write mycat - separation (mysql database)

Time:10-08

Separation of Mycat, speaking, reading and writing

Read/write separation, generally there are two ways to achieve 1, the application layer program to realize 2, middleware layer mycat belongs to middleware. Mycat is based on Java language development. Java environment support in application is required.

Advantages of separation of middleware, speaking, reading and writing:
Architecture design more flexible can implement some advanced control on program can rely on some technical means to improve the mysql performance impact on the business code small also security

Understand the mycat
A complete open source, enterprise application development of large database cluster
Supports transactions, ACID it can replace enhanced mysql database
Can be seen as a MySQL cluster enterprise database
A memory cache fusion technology. No technology, HDFS data of the new SQL server
Combined with the traditional database and a new type of distributed data warehouse is a new generation of enterprise database products

The installation of the master services through experiments in configuration

Prepare experimental environment:

Role: hostname, IP address
Mycat and NTP server mysql node 192.168.122.10
The main library server master cong11 192.168.122.15
From the library server slave cong12 192.168.122.14
From the library server slave cong13 192.168.122.25

1, close the firewall, selinux to modify the hostname, do hosts binding
Vim/etc/hosts to modify this file is added to the end () and SCP to another server
192.168.122.10 mysql - node
192.168.122.15 cong11
192.168.122.14 cong12
192.168.122.25 cong13

2 in mysql - node deployment NTP service on the server, for other servers time to proofread.
Install the NTP:
Yum -y install NTP (local Yum source to mount the CD)
The NTP configuration:
Vim/etc/NTP. Conf (modify the configuration files) tail add
Server 127.127.1.0 (and the local system time synchronization)
Fudge 127.127.1.0
Start the NTP service
Systemctl start NTPD

Other server installation ntpdate b package, use ntpdate synchronization time IP address
To be every 10 minutes synchronous planning tasks a

3, the configuration of master-slave replication
Cong11 master server configuration
Create the database HA (deployment good MySQL first, and then log in MySQL)
Mysql> The create database HA;
Mysql> Use HA;
Mysql> The create table T1 (int id, name varchar (20));
Mysql> Insert into T1 values (1, 'Tom1');
Create master-slave synchronization authorized user:
Mysql> To grant the replication slave on *. * 'slave' @ '192.168.30. %' identified by "123456";
Mysql> flush privileges;
Modify the configuration file/etc/my. At the end of CNF add
Server - id=1
The Log - bin=/data/mysql/Log/mysql - bin - master
Binlog - do - db=HA
Sync - binlog=1
Binlog - format=mixed
Restart the mysql
Systemctl restart mysqld, make effective configuration file)

Export database
The Mysqldump uroot - p123456 HA & gt; HA. SQL database file the default home directory (export)
In order to ensure the data consistency to the exported file SCP to another server
Scp/rootHA. SQL [email protected]: ~
Scp/root/HA. SQL [email protected]: ~
And on the two from the server to create HA library, then pour into the database file
Mysql> The create database HA;
Mysql> Use HA;
Mysql> The source/root/HA. SQL
Configuration from the server
Modify the configuration file/etc/my. At the end of CNF add
Server - id=2
Relay - log=/data/mysql/log/Relay - log - bin
Relay - log - index -/data/mysql/log/slave - Relay - bin. The index
Replicate - ignore - db=HA
Restart the mysql service make effective configuration file
Systemctl restart mysqld
A master-slave configuration
Mysql> Change the master to master_host='192.168.122.15', master_user='slave', master_log_file='mysql - bin - master. 000001', mater_log_pos=154;
In the main library server performed on show master status \ G; Get two parameters after
Nysql> Show master status \ G;

On the mysql - node deployment mycat
Install the downloaded package into specified directory under/usr/local
Tar - ZXVF Mycat - server - 1.6.6.1 - release - 20181031195535 - Linux. Tar. Gz - C/usr/local/
Due to Java environment support so also need to install the JDK
Tar - ZXVF JDK - 8 u171 - Linux - x64. Tar. Gz - C/usr/local/
Modify the configuration file/etc/profile file add the
JAVA_HOME=/usr/local/jdk1.8.0 _171
PATH=$JAVA_HOME/bin: $PATH
The CLASSPATH=$JAVA_HOME/jre/lib/ext: $JAVA_HOME/lib/view jar
The export PATH JAVA_HOME CLASSPATH
The source/etc/profile gives effect to the configuration file
Execute Java - version if displaying Java version information is JDK deployed
To/usr/local/mycat/bin/* soft link to the PATH environment variable contains the PATH to the file in
Ln -s mycat/usr/local/bin/*/usr/local/bin/

In/usr/local/mycat/conf/server is configured in the XML file mycatl user account access information is amended as follows:


Edit mycatl schema. The XML configuration file/usr/local/mycat/conf/schema. The XML
Modify the results are as follows:





For the mysql root permission to remote login
Mysql> Grant all on *. * to root @ '192.168.30. %' identified by '123456'.
Mysql> flush privileges; (operating on the main library)

Start mycat service
Mycat start
Netstat anput | grep 8066 if port 8066 is mycat monitoring service normal boot
Mysql node service installed on the mariadb package to login mycat
Mysql -u mycatroot 192.168.122.10 p123456 - h - P 8066
Mysql> Show the databases; If the query correct the service configuration is complete.

CodePudding user response:

The last thread was six years ago
  •  Tags:  
  • GAE
  • Related