使用tungsten將mysql的資料同步到hadoop

來源:互聯網
上載者:User

標籤:style   blog   http   ar   io   color   os   使用   sp   

  • 背景

線上有很多的資料庫在運行,後台需要一個分析使用者行為的資料倉儲。目前比較流行的是mysql和hadoop平台。

現在的問題是,如何將線上的mysql資料即時的同步到hadoop中,以供分析。這篇文章就是利用tungsten-replicator來實現。

 

  • 環境

由於tungsten-replicator依賴ruby和gem。需要安裝

yum install rubyyum install rubygemsgem install json

其中json模組可能因為gfw的原因,需要手動下載到本地,然後使用gem本地安裝
yum install ruby-devel
gem install --local json-xxx.gem
 

 

安裝好mysql,地址是 192.168.12.223:3306 ,資料庫配置好許可權

安裝好hadoop 2.4 ,hdfs的地址是 192.168.12.221:9000

 

  • 配置

先在mysql的機器上,進入到tungsten-replicator目錄下執行,並且啟動tungsten,可以使用trepctl thl 等命令查看服務的狀態

./tools/tpm install mysql1 --master=192.168.12.223 --install-directory=/user/app/tungsten/mysql1 --datasource-mysql-conf=/user/data/mysql_data/my-3306.cnf --replication-user=stats --replication-password=stats_dh5 --enable-heterogenous-master=true --net-ssh-option=port=20460  --property=replicator.filter.pkey.addColumnsToDeletes=true --property=replicator.filter.pkey.addPkeyToInserts=true 

mysql1/tungsten/cluster-home/bin/startall 

 

到hadoop的機器上,,進入到tungsten-replicator目錄下執行,並且啟動tungsten,可以使用trepctl thl 等命令查看服務的狀態

./tools/tpm install hadoop1 --batch-enabled=true --batch-load-language=js --batch-load-template=hadoop --datasource-type=file --install-directory=/user/app/tungsten/hadoop1 --java-file-encoding=UTF8 --java-user-timezone=GMT --master=192.168.12.223 --members=192.168.12.221 --property=replicator.datasource.applier.csvType=hive --property=replicator.stage.q-to-dbms.blockCommitInterval=1s --property=replicator.stage.q-to-dbms.blockCommitRowCount=1000 --skip-validation-check=DatasourceDBPort --skip-validation-check=DirectDatasourceDBPort --skip-validation-check=HostsFileCheck --skip-validation-check=InstallerMasterSlaveCheck --skip-validation-check=ReplicationServicePipelines --rmi-port=25550 

 

可以在hadoop的檔案系統上,查看對應的目錄下是否產生了mysql對應的庫。如下所示:

 

└── user............    └── tungsten        └── staging            └── hadoop1                └── db1                    ├── x1                    │   ├── x1-14.csv                    │   └── x1-3.csv                    └── x2                        ├── x2-115.csv                        ├── x2-15.csv                        ├── x2-16.csv                        ├── x2-17.csv                        └── x2-18.csv

 

最後還需要將staging的資料merge到hive中,建立hive的表結構,並且讓資料能夠被hive查詢,這裡使用continuent-tools-hadoop工具裡面的load-reduce-check指令碼,在使用之前,先需要配置好hive的環境變數,並且啟動hiveservice在10000連接埠上。拷貝如下的jar包到bristlecone的lib-ext目錄

 

 cp -v /user/app/hive/apache-hive-0.13.1-bin/lib/hive-jdbc-0.13.1.jar /user/app/tungsten/hadoop1/tungsten/bristlecone/lib-ext/ cp -v /user/app/hive/apache-hive-0.13.1-bin/lib/hive-exec-0.13.1.jar /user/app/tungsten/hadoop1/tungsten/bristlecone/lib-ext/ cp -v /user/app/hive/apache-hive-0.13.1-bin/lib/hive-service-0.13.1.jar /user/app/tungsten/hadoop1/tungsten/bristlecone/lib-ext/ cp -v /user/app/hive/apache-hive-0.13.1-bin/lib/httpclient-4.2.5.jar /user/app/tungsten/hadoop1/tungsten/bristlecone/lib-ext/ cp -v /user/app/hive/apache-hive-0.13.1-bin/lib/commons-httpclient-3.0.1.jar /user/app/tungsten/hadoop1/tungsten/bristlecone/lib-ext/ cp -v /user/app/hive/apache-hive-0.13.1-bin/lib/httpcore-4.2.5.jar /user/app/tungsten/hadoop1/tungsten/bristlecone/lib-ext/ cp -v /user/app/hadoop/hadoop-2.4.0-onenode/share/hadoop/common/hadoop-common-2.4.0.jar /user/app/tungsten/hadoop1/tungsten/bristlecone/lib-ext/ cp -v /user/app/hadoop/hadoop-2.4.0-onenode/share/hadoop/common/lib/slf4j-* /user/app/tungsten/hadoop1/tungsten/bristlecone/lib-ext/

 

然後執行如下的命令:

第一次,或者以後增加了表,或者表結構發生了變化./bin/load-reduce-check -v -U jdbc:mysql:thin://192.168.12.223:3306/ -u stats -p stats_dh5 --schema db1 --service=hadoop1 -r /user/app/tungsten/hadoop1  --no-compare

如果表結構沒有發生變化,只需要重新裝載資料的話,可以執行如下的命令./bin/load-reduce-check -v -U jdbc:mysql:thin://192.168.12.223:3306/ -u stats -p stats_dh5 --schema db1 --service=hadoop1 -r /user/app/tungsten/hadoop1 --no-base-ddl --no-staging-ddl --no-meta

只想比較資料,不過貌似compare很卡./bin/load-reduce-check -v -U jdbc:mysql:thin://192.168.12.223:3306/ -u stats -p stats_dh5 --schema db1 --service=hadoop1 -r /user/app/tungsten/hadoop1 --no-base-ddl --no-staging-ddl --no-meta --no-materialize

 

  • 參考

tungsten-replicator-3.0.pdf   中的  3.4. Deploying MySQL to Hadoop Replication

https://github.com/continuent/continuent-tools-hadoop

使用tungsten將mysql的資料同步到hadoop

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.