Linux上搭建Elasticsearch服务器并同步数据库
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux上搭建Elasticsearch服务器并同步数据库相关的知识,希望对你有一定的参考价值。
1.准备工作
下载Elasticsearch版本号2.3.4 https://www.elastic.co/downloads/past-releases/elasticsearch-2-3-4 ,
2.运行Elasticsearch
解压
tar vxf elasticsearch-2.3.4.tar
Elasticsearch已经准备就绪,执行以下命令可在前台启动:
./bin/elasticsearch
如果想在后台以守护进程模式运行,添加 -d 参数
./bin/elasticsearch -d
打开另一个终端进行测试:
curl -XGET "http://127.0.0.1:9200/?pretty"
你能看到以下返回信息:
{ "name": "Nico Minoru", "cluster_name": "elasticsearch", "version": { "number": "2.3.4", "build_hash": "e455fd0c13dceca8dbbdbb1665d068ae55dabe3f", "build_timestamp": "2016-06-30T11:24:31Z", "build_snapshot": false, "lucene_version": "5.5.0" }, "tagline": "You Know, for Search" }
这说明你的ELasticsearch集群已经启动并且正常运行.
3.添加ik中文分词
在elasticsearch/plugins/下创建文件夹ik ,将elasticsearch-analysis-ik.zip 解压到下面
4.创建 索引mapping同步数据库
编写脚本.sh
#删除索引 curl -XDELETE ‘http://127.0.0.1:9200/gsdata‘ #创建Mapping curl -XPUT "http://127.0.0.1:9200/gsdata" -d‘ { "mappings":{ "egov_basc_jbxx":{ "_all": { "analyzer": "ik_max_word", "search_analyzer": "ik_max_word", "term_vector": "no", "store": "false" }, "dynamic":false, "properties": { "id":{ "type":"string" }, "entname":{ "type":"string", "analyzer":"ik_smart" }, "lerep":{ "type":"string", "analyzer":"ik_max_word" }, "poscope":{ "type":"string", "analyzer":"ik_smart" }, "econat":{ "type":"string", "analyzer":"ik_smart" }, "esdate":{ "type":"date" }, "regcap":{ "type":"integer" }, "state":{ "type":"string" } } } } }‘ #同步数据 DIR=/home/search/elasticsearch-jdbc-2.3.4.0 bin=${DIR}/bin lib=${DIR}/lib JAVA_HOME=/home/search/jdk1.8.0_111 echo ‘ { "type" : "jdbc", "jdbc" : { "url" : "jdbc:oracle:thin:@//127.0.0.1:1521/ORCL", "user" : "intgdata", "password" : "intgdata", "sql" : "SELECT ID as \"id\" , ENTNAME as \"entname\" , LEREP as \"lerep\", OPSCOPE as \"poscope\", ECONAT as \"econat\", ESTDATE as \"esdate\" ,REGCAP as \"regcap\" ,STATE as \"state\" FROM EGOV_BASC_JBXX ", "treat_binary_as_string" : true, "index" : "gsdata", "type": "egov_basc_jbxx", "elasticsearch" : { "cluster" : "elasticsearch", "host" : "127.0.0.1", "port" : 9300 } } } ‘ | ${JAVA_HOME}/bin/java \ -cp "${lib}/*" -Dlog4j.configurationFile=${bin}/log4j2.xml org.xbib.tools.Runner org.xbib.tools.JDBCImporter
备注:因为这个版本elasticsearch-jdbc必须要1.8以上的版本,所以可以指定jdk去运行
5.运行脚本.sh
6.查看数据是否录入
curl -XPOST ‘http://localhost:9200/_search‘
以上是关于Linux上搭建Elasticsearch服务器并同步数据库的主要内容,如果未能解决你的问题,请参考以下文章
syslog+rsyslog+logstash+elasticsearch+kibana搭建日志收集
Linux系统:Centos7下搭建ElasticSearch中间件,常用接口演示
Linux系统:centos7下搭建ElasticSearch中间件,常用接口演示
#私藏项目实操分享# Linux开发环境搭建CentOs7之五ELASTICSEARCH集群部署
ElasticSearch-02-使用Docker在Mac系统上搭建两个节点的ElasticSearch集群(并同时创建kibana,cerebro两个容器)