# yum install java-1.6.0-openjdk ruby
# rpm -Uvh download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh rpms.famillecollet.com/enterprise/remi-release-6.rpm
# yum --enablerepo=remi install mysql mysql-server
# vim /etc/my.cnf
… # “” server-id = 1 # log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 10 # MongoDB “ROW” binlog_format = ROW # max_binlog_size = 256M # sync_binlog = 1 ...
# chkconfig --level 35 mysqld on
# service mysqld start
# mysql_secure_installation
Enter current password for root (enter for none): Change the root password? [Y/n] y New password: SomeSecretPasswD Re-enter new password: SomeSecretPasswD Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y
# mysql -u root -p
# mysql > grant all on *.* to tungsten identified by 'password' with grant option;
Query OK, 0 rows affected (0.01 sec)
# vim /etc/yum.repos.d/mongodb.repo
[mongodb] name=MongoDB Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/ gpgcheck=0 enabled=1
# yum install mongo-10gen mongo-10gen-server
# chkconfig --level 35 mongodb on
# service mongodb start
# mongo
MongoDB shell version: 2.4.3
connecting to: test
> show dbs
local 0.078125GB
# cd /opt
# mkdir replicator
# cd replicator
# mkdir mysql # -
# mkdir mongodb #
# wget tungsten-replicator.googlecode.com/files/tungsten-replicator-2.2.0-292.tar.gz
# tar -xzf tungsten-replicator-2.2.0-292.tar.gz
# mv tungsten-replicator-2.2.0-292/ tungsten-replicator/
# vim master-installer.sh
cd /opt/replicator/tungsten-replicator ./tools/tungsten-installer --master-slave -a \ --datasource-type=mysql \ --master-host=127.0.0.1 \ --datasource-user=tungsten \ --datasource-password=password \ --datasource-mysql-conf=/etc/my.cnf --datasource-log-directory=/var/log/mysql/ --datasource-port=3306 \ --service-name=mongodb \ --home-directory=/opt/replicator/mysql \ --cluster-hosts=127.0.0.1 \ --thl-port=10001 \ --rmi-port=11001 \ --java-file-encoding=UTF8 \ --mysql-use-bytes-for-string=false \ --mysql-enable-enumtostring=true \ --mysql-enable-settostring=true \ --svc-extractor-filters=colnames,pkey \ --svc-parallelization-type=none --start-and-report
--svc-extractor-filters=replicate \ "--property=replicator.filter.replicate.do=db1.table1,db2.table2,dbN.tableN" \
Accordingly, instead of db1.table1, etc., specify your bases and tables, which you will need to replicate.
# sh master-installer.sh
INFO >> 127_0_0_1 >> Getting services listThe wizard is ready, now you can connect one or several slaves to it - MySQL or PostgreSQL for example. But our goal is replication with MongoDB, let's move on to it.
INFO >> 127_0_0_1 >> ...
Processing services command ...
NAME VALUE
- - appliedLastSeqno: 0
appliedLatency: 1.218
role: master
serviceName: mongodb
serviceType: local
started: true
state: ONLINE
Finished services command ...
# vim slave-installer.sh
cd /opt/replicator/tungsten-replicator tools/tungsten-installer --master-slave -a \ --datasource-type=mongodb \ --master-host=127.0.0.1 \ --service-name=mongodb \ --home-directory=/opt/replicator/mongodb \ --cluster-hosts=127.0.0.1 \ --datasource-port=27017 \ --master-thl-port=10001 \ --thl-port=10002 \ --rmi-port=11002 \ --java-file-encoding=UTF8 \ --skip-validation-check=InstallerMasterSlaveCheck \ --svc-parallelization-type=none --start-and-report
Note that I am replicating on one host, if you need to replicate to another host, do not forget to specify the correct host address on which you have a master and open the corresponding ports in the firewall (thl-port, rmi-port).
# sh slave-installer.sh
WARN >> 127.0.0.1 >> Currently she is in mongodbIf you see the status “ONLINE” in the “state” line, then the installation was successful and you can try to check if the replication is working.
INFO >> 127_0_0_1 >> Getting services list
INFO >> 127_0_0_1 >> Processing services command ...
NAME VALUE
- - appliedLastSeqno: 0
appliedLatency: 0.5
role: slave
serviceName: mongodb
serviceType: local
started: true
state: ONLINE
Finished services command ...
mysql> create schema testdb;
mysql> use testdb;
mysql> create table testrepl (id int not null primary key, name char(20), date date);
Query OK, 0 rows affected (0.00 sec)
mysql> insert into testrepl values (1, 'Vasya', '1965-01-01');
Query OK, 1 row affected (0.00 sec)
mysql> insert into testrepl values (2, 'Petya', '1991-02-02');
Query OK, 1 row affected (0.00 sec)
> show dbs
local 0.078125GB
testdb 0.203125GB
tungsten_mongodb 0.203125GB
> use testdb
switched to db testdb
> show collections
testrepl
system.indexes
> db.testdb.find()
{ "_id" : “01”, "id" : "1", "name" : "Vasya", "date" : "1965-01-01" }
{ "_id" : “02”, "id" : "2", "name" : "Petya", "date" : "1991-02-02" }
mysql> update testrepl set name = 'Vasya P' where id =1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
> db.testrepl.find()
{ "_id" : “01”, "id" : "1", "name" : "Vasya P", "d" : "1965-01-01" }
{ "_id" : “02”, "id" : "2", "name" : "Petya", "date" : "1991-02-02" }
mysql> delete from testrepl where id =2;
Query OK, 1 row affected (0.00 sec)
> db.myfirst.find()
{ "_id" : “01”, "id" : "1", "name" : "Vasya P", "d" : "1965-01-01" }
# cd /opt/replicator/
# ./mongodb/tungsten/tungsten-replicator/bin/trepctl status
# ./mysql/tungsten/tungsten-replicator/bin/trepctl status
Source: https://habr.com/ru/post/211218/