-
Notifications
You must be signed in to change notification settings - Fork 153
QuickStart
王超 edited this page Mar 9, 2018
·
4 revisions
- jdk 1.8+
- Mysql 和 Elasticsearch 5.0+
- canal v1.0.24(本服务基于canal,首先确保安装好canal并确保能正常工作。canal安装说明)
访问https://github.com/starcwang/canal_mysql_elasticsearch_sync/releases 并下载。比如以1.0.0为例
wget https://github.com/starcwang/canal_mysql_elasticsearch_sync/releases/download/1.0.0/canal-mysql-elasticsearch-sync-1.0.0.tar.gz
或者自己clone下源码编译
git clone [email protected]:starcwang/canal_mysql_elasticsearch_sync.git
cd canal_mysql_elasticsearch_sync;
mvn clean package -Dmaven.test.skip -Denv=release
mkdir canal_mysql_elasticsearch_sync
tar zxvf canal-mysql-elasticsearch-sync-*.tar.gz -C canal_mysql_elasticsearch_sync
cd canal_mysql_elasticsearch_sync
ls
这时可以看到项目目录结构
- bin:启动和关闭服务的脚本
- logs:服务日志
- lib:服务依赖的jar包
- conf:服务配置文件
vim conf/application.properties
# 服务名
spring.application.name=canal_mysql_elasticsearch_sync
# 服务端口号
server.port=8828
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# 数据库配置,不用写database名
spring.datasource.url=jdbc:mysql://127.0.0.1:3306?characterSet=utf8mb4&useSSL=false
# 账号
spring.datasource.username=root
# 密码
spring.datasource.password=123456
spring.datasource.dbcp2.max-idle=10
spring.datasource.dbcp2.min-idle=5
spring.datasource.dbcp2.initial-size=2
spring.datasource.dbcp2.validation-query=SELECT 1
spring.datasource.dbcp2.test-while-idle=true
mybatis.config-location=classpath:mybatis/mybatis-config.xml
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml
# canal配置
canal.host=127.0.0.1
canal.port=11111
canal.destination=example
canal.username=
canal.password=
# elasticsearch配置
elasticsearch.cluster.name=my-elasticsearch
elasticsearch.host=127.0.0.1
elasticsearch.port=9300
vim conf/mapping.properties
# 配置数据库和Elasticsearch所对应的映射关系
# 格式:dbEsMapping[${database}.${table}]=${index}.${type}
dbEsMapping[test_info.user]=test_info.user
dbEsMapping[test_info.admin]=test_info2.admin
# 配置数据库主键列名,默认为id
# 格式:tablePrimaryKeyMap[${database}.${table}]=${primaryKey}
tablePrimaryKeyMap[test_info.user]=id
tablePrimaryKeyMap[test_info.admin]=pk
sh bin/start.sh
等待大约30s,请求端口查看服务是否启动成功
http://${ip}:${port}
vim logs/info.log
sh bin/stop.sh
enjoy it!