MYSQL数据同步到ES7
**
概述
**
現(xiàn)在的項(xiàng)目數(shù)據(jù)量越來(lái)越大,全文檢索功能使用場(chǎng)景也越來(lái)越普遍。
而我們一般的生產(chǎn)數(shù)據(jù)是在mysql,或其它一些數(shù)據(jù)庫(kù),
我們的產(chǎn)品數(shù)據(jù)就是mysql,而又要使用全文檢索,
所以要把mysql 數(shù)據(jù)同步到es,再進(jìn)行全文檢索功能。
現(xiàn)在簡(jiǎn)單把數(shù)據(jù)同步的配置及遇到的問(wèn)題羅列如下:
數(shù)據(jù)流程圖
mysql -> adapter -> es
安裝步驟不再累述,需要安裝以下軟件。
1.安裝 es,
2.安裝 canal.adapter
3.安裝 canal.deployer
4.安裝 zookeeper
數(shù)據(jù)流同步過(guò)程中,需要配置的地方:
(dev 開(kāi)發(fā)環(huán)境示例)
1.adapter:
application.yml
canal.conf:
mode: tcp # kafka rocketMQ
canalServerHost: 172.16.1.2:11111
zookeeperHosts: 172.16.1.2:2181
mqServers: 172.16.1.2:9876 #or rocketmq
srcDataSources:
defaultDS:
url: jdbc:mysql://172.16.1.203:33306/nuocheng?useUnicode=true
username: canal
password: canal.1qaz
canalAdapters:
- instance: example # canal instance Name or mq topic name
groups:- groupId: g1
outerAdapters:- name: es7
key: es204
hosts: 172.16.1.2:9200
properties:
mode: rest # or rest
cluster.name: my-application
- name: es7
- groupId: g1
3.安裝 canal.deployer
vi canal.properties
canal.ip = 172.16.1.2
canal.port = 11111
canal.metrics.pull.port = 11112
canal.zkServers = 172.16.1.2
vi example/instalce.properties
# username/password canal.instance.dbUsername=canal canal.instance.dbPassword=canal.123456 canal.instance.connectionCharset = UTF-8 canal.instance.defaultDatabaseName = nuocheng(重建立索引全量生成數(shù)據(jù))
重建立索引:
curl -XDELETE http://172.16.1.2:9200/nt_product
curl -XDELETE http://172.16.1.2:9200/nt_news
curl -XDELETE http://172.16.1.2:9200/nt_plan
curl -XPUT -H “Content-Type: application/json” http://172.16.1.2:9200/nt_product?include_type_name=true -d “@nt_product.json”
curl -XPUT -H “Content-Type: application/json” http://172.16.1.2:9200/nt_news?include_type_name=true -d “@nt_news.json”
curl -XPUT -H “Content-Type: application/json” http://172.16.1.2:9200/nt_plan?include_type_name=true -d “@nt_plan.json”
全量同步一次數(shù)據(jù)
curl http://172.16.1.204:38081/etl/es/nt_product.yml -XPOST
curl http://172.16.1.204:38081/etl/es/nt_news.yml -XPOST
curl http://172.16.1.204:38081/etl/es/nt_plan.yml -XPOST
#########################################################################
(使用導(dǎo)出導(dǎo)入方式重新生成數(shù)據(jù))
ES 同級(jí)后,數(shù)據(jù)的導(dǎo)入導(dǎo)出:
1.安裝 elasticdump:
npm install elasticdump -g elasticdump --version 6.33.4 ---- 出錯(cuò)解決方法 [root@nctest004 ~]# elasticdump --version/usr/lib/node_modules/elasticdump/lib/processor.js:40async _loop (limit, offset, totalWrites) {^^^^^SyntaxError: Unexpected identifierat createScript (vm.js:56:10)at Object.runInThisContext (vm.js:97:10)at Module._compile (module.js:549:28)at Object.Module._extensions..js (module.js:586:10)at Module.load (module.js:494:32)at tryModuleLoad (module.js:453:12)at Function.Module._load (module.js:445:3)at Module.require (module.js:504:17)at require (internal/module.js:20:19)at Object.<anonymous> (/usr/lib/node_modules/elasticdump/elasticdump.js:3:28) --------------------------- 安裝出錯(cuò) ----------------------- 原因是資源的問(wèn)題,要配置淘寶鏡像 npm config set registry https://registry.npm.taobao.org 配置完成后檢驗(yàn)是否成功 npm config get registry 重新安裝 npm install nrm -g 查看所用的鏡像 nrm ls 安裝成功解決辦法: #升級(jí)nodejs [root@localhost ~]# npm install -g n [root@localhost ~]# n latest2.導(dǎo)出數(shù)據(jù):
elasticdump --input=http://172.16.1.2:9200/nt_product --output=/opt/download/nt_product.json --type=data3:刪除數(shù)據(jù):
curl --location --request DELETE 'http://172.16.1.2:9200/rangetest'4.導(dǎo)入數(shù)據(jù)
elasticdump --input=/opt/download/nt_product.json --output=http://172.16.1.2:9200/nt_product --type=data總結(jié)
以上是生活随笔為你收集整理的MYSQL数据同步到ES7的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: MySQL5.7新特性——在线收缩und
- 下一篇: MySQL -> ES 数据同步 配置步