Use tunststen-replicatior to implement master-slave replication between MySQL instances

Source: Internet
Author: User

Tunsten is an open-source software that can be used to synchronize data between different data sources (the official website is called Real-Time Synchronization). The official website address is http://www.continuent.com /. Its promotional slogans contain a very attractive sentence: "oracle
Goldengate without the price tag. "So I 'd like to try it on a virtual machine. Some people may say that Mysql itself provides master-slave replication, and the performance is better than tunststen-replicatior. Why should we use it? In fact, the biggest selling point of tunsten-replicatior is that it can synchronize data between different data sources, because most of its default configurations are MySQL, therefore, I think it may be initially developed based on MySQL and has the best support for MySQL. for trial use, it is naturally easy to start, then we will study data synchronization between Oracle, MySQL, and PostgreSQL.
Here I have recorded the installation steps and Some Problems and Solutions encountered during the installation process. However, it should be noted that there will be many "Same symptoms and different diseases" problems in the use of computer software. Therefore, these solutions may not be suitable for you. You must determine the root cause of any problems to solve them.
See the https://docs.continuent.com/wiki/display/TEDOC/Tungsten+Replication+Guide for specific installation documentation

 

Virtual Machine Configuration:

MASTER: 192.168.137.100
Oracle Linux 6.4x86
Perconal MySQL 5.5.32
Tunststen-replicator-2.1.0-343.tar.gz(tunststen-replicator-2.1.1-113.tar.gz)

SLAVE: 192.168.137.100
Oracle Linux 6.4x86
Perconal MySQL 5.5.32

 

I. tunsten-replicator system requirements

1. Ping Between Hosts
2. Some specific parameters in the MySQL configuration file my. CNF are required.
Server-id = 1 # required
Log-bin # Must be enabled
Innodb_buffer_pool_size >=512 m
Default-table-type = InnoDB
Innodb_flush_log_at_trx_commit = 1 # This parameter must be set to 2 in the user manual. However, if it is set to 2, an error will be reported during startup. Commit
Max_allowed_packet> = 52 m
3. An operating system user, tunsten, belongs to the MySQL user group.
$ Useradd-G MySQL tunsten
4. MySQL user, tunststen
Mysql> create user tunsten @ '%' identified by '123 ';
Mysql> grant all on *. * To tunsten @ '%' with grant option;
Mysql> flush privileges;
5. MySQL source replicator is not enabled
Mysql> show slave status
Empty set (0.00 Sec)
6. You must be able to start or stop MySQL in the tunsten operating system. You must be able to start or stop MySql in sudo MySQL.
$ Su-Root
$ Chmod U + w/etc/sudoers
$ VI/etc/sudoers
Add tunsten all = (all) All
$ Chmod U-W/etc/sudoers
$ Su-tunsten
Try to close and start the database.
7. The tunsten user of the master host must be able to log on to the slave host through SSH without entering the password.
The method is as follows:
Run:
$ Ssh-keygen-t rsa-f ~ /. Ssh/id_rsa
By default, a pair of public and private keys are generated under/home/tunsten/. Ssh.
Copy the public key to 192.168.137.101,
$ SCP id_rsa.pub tungsten@192.168.137.101:/home/tunststen/. Ssh/192.168.137.100

The copied file name must be the same as the host name.

Run:
$ CD/home/tunststen/. SSH
$ Cat 192.168.137.100> authorized_keys
$ Chmod 644 *

Run
$ SSH tungsten@192.168.137.101.
Log on directly without prompting you to enter the password

2. Install tunsten-Replicator

Log on to 192.168.137.100 with the tunsten user and decompress the replicator Installation File.
$ Tar-zxvf tungsten-replicator-2.1.0-343.tar.gz
$ Tungsten-replicator-2.1.0-343 CD
$ Tools/tungsten-installer -- master-slave \
-- Master-host = 192.168.137.100 \
-- Datasource-user = tungsten \
-- Datasource-Password = 123456 \
-- Service-name = logos \
-- Home-directory =/MySQL/software/Continuent /\
-- Cluster-hosts = 192.168.137.100, 192.168.137.101 \
-- Start-and-Report

 

Here we use the -- master-slave Method for installation. There are three methods for tunsten-Installer:
-- Direct
-- Master-slave
-- Prefetch
For more information about each method, see the official documentation mentioned above.

 

The following "home-directory" indicates the value specified by -- home-directory during installation.

-- Service-name indicates the name of the current synchronization service. A folder with the same name will appear in the home-directory/tunststen-Replicator/log directory, which records logs.
-- Master-Host: Specifies the master host.
-- Datasource-user database user
-- Datasource-Password Database User Logon Password
-- Home-directory
-- Cluster-hosts all hosts in the current cluster
-- The configuration file of datasource-mysql-conf MySQL is not in the default location/etc/My. CNF, you must specify
-- Start-and-Report

 

After the installation is complete, a set of tunsten-replicator will appear in the home-directory of the master and slave.

Home-directory/tunststen/tunsten-Replicator/bin/replicator START | stop | status Start and Stop replicator. After the replicator is installed according to the preceding parameters, if no problem exists, the replicator is automatically started on both the master and slave.
Run the following command to view the synchronization status (I will execute them on the master ):
Home-directory/tunststen/tunsten-Replicator/bin/trepctl-host 192.168.137.100 services
Processing Services Command...
NAME value
---------
Appliedlastseqno: 9
Appliedlatency: 0.334
Role: Master
Servicename: Logos
Servicetype: Local
Started: True
State: Online
Finished Services Command...

 

Home-directory/tunststen/tunsten-Replicator/bin/trepctl-host 192.168.137.101 services
Processing Services Command...
NAME value
---------
Appliedlastseqno: 9
Appliedlatency: 26.896
Role: slave
Servicename: Logos
Servicetype: Local
Started: True
State: Online
Finished Services Command...

 

If the appliedlatency parameter is too large (indicating synchronization latency), run the following command to recreate the heartbeat connection.
Home-directory/tunststen/tunsten-Replicator/bin/trepctl heartbeat

Iii. Problems Encountered during installation
Once again, to solve the problem, we must "prescribe the right medicine". There are many situations where the same disease is different. Only by finding the root of the problem can we truly solve the problem.
I do not have a deep understanding of Linux, so if there are many problems with better solutions, please kindly advise me

1. Error reported. Ruby is not installed
Solution: Yum install Ruby

 

2. An error is reported. For example, 192.168.137.101> failed: which MySQL, the tungsten user on 192.168.137.101 cannot find MySQL under $ path using the which command
Because my MySQL is compiled and installed by source code and is not in the default location, I added the MySQL path to the path. I logged on with the tunsten user and executed which MySQL.
In Linux, there are three environment variables. I finally modified/etc/profile to add mysql-related environment variables to solve this problem.

 

3. error, 192.168.137.101> unable to connect to the MySQL server using
Tungsten@192.168.137.101: 3306 (with password ).
The reason is that the user using the tunsten database on 192.168.137.101 cannot log on to the local MySQL.
Solution:
Mysql> create user tunsten @ 'localhost' identified by '123 ';
Query OK, 0 rows affected (0.00 Sec)

Mysql> grant all on *. * To tunsten @ 'localhost' identified by '000000' with grant option;
Query OK, 0 rows affected (0.00 Sec)

Mysql> flush privileges;
Query OK, 0 rows affected (0.00 Sec)

 

4. error, 192.168.137.101> failed: mkdir-P/MySQL/software/Continuent/
That is to say, the tunsten user of 192.168.137.101 does not have the permission to create this directory.
Solution: create a directory manually or grant permissions.
# Mkdir/MySQL/software/Continuent
# Chown tunsten: MySQL/software/Continuent

 

5. error, 192.168.137.101> the MySQL Config File '/etc/My. CNF' does not exist
Solution: Use -- datasource-mysql-conf to specify the location of the MySQL configuration file on the slave server.

 

6. startup failed
[Tunsten @ node1 bin] $./replicator start
Starting tunsten replicator service...
Waiting for tunsten replicator service ......
Warning: tunsten replicator service may have failed to start.

Check the log file home-directory/tunststen-Replicator/log/trepsvc. log to see the error
This is because of the Host Name ing problem.
Info | JVM 1 | 23:07:37 | 23:07:37, 066 [-wrappersimpleappmain] info management. replicationservicemanager exce
Ption when trying to get the host name from the environment, reason = java.net. unknownhostexception: node1.localdomain: node1.localdomain: Na
Me or service not known

So I modified the/etc/hosts file on 192.168.137.100.
Added ing
192.168.137.100 node1.localdomain
And the/etc/hosts file on 192.168.137.101.
Add
192.168.137.101 node2.localdomain

 

7. An error is reported on slave:
[Tungsten @ node1 bin] $./trepctl-host 192.168.137.101 services
Processing Services Command...
NAME value
---------
Appliedlastseqno:-1
Appliedlatency:-1.0.
Role: slave
Servicename: Logos
Servicetype: Unknown
Started: True
State: offline: Error
Finished Services Command...

Check the log file on 192.168.137.101 and find "variable 'SQL _ mode' can't be set to the value of 'invalid _ dates '"
It has been confirmed that it is a bug, and we will continue the experiment in the pipeline (that is, the version I wrote in the brackets above ).

 

 

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.