elasticsearch的安装、部署

https://blog.csdn.net/lubin2016/article/details/81606753node

 

1. elasticsearch的安装

1.1 集群规划

上传elasticsearch的tar.gz包至规划的集群各节点的目录下(规划两个节点rc-fhcb-10-es001,rc-fhcb-10-es002),如:本项目安装在/opt/fhcb/目录下

注意:建议elasticsearch的安装包在集群中各节点目录一致linux

1.2 修改配置文件

修改安装包下config目录下的配置文件elasticsearch.yml(集群每一个节点)git

 1 # 集群的名称  2 cluster.name: elasticsearch  3 # 节点名称  4 node.name: es-node-01  5 # 配置文件的位置  6 path.conf: /opt/fhcb/elasticsearch-1.6.0/config  7 # 该节点存储的索引数据  8 path.data: /opt/fhcb/elasticsearch-1.6.0/data  9 # 临时工做目录 10 path.work: /opt/fhcb/elasticsearch-1.6.0/work 11 # 日志文件位置 12 path.logs: /opt/fhcb/elasticsearch-1.6.0/logs 13 # 插件安装目录 14 path.plugins: /opt/fhcb/elasticsearch-1.6.0/plugins 15 # 设置该节点绑定的ip地址 16 network.bind_host: rc-fhcb-10-es001 17 # 设置其它节点与该节点交互的ip地址 18 network.publish_host: rc-fhcb-10-es001 network.host: rc-fhcb-10-es001 # 设置tcp协议端口号 19 transport.tcp.port: 9300 20 # 设置http协议端口号 21 http.port: 9200 22 # 经过配置这个参数来防止集群脑裂现象 (集群总节点数量/2)+1 discovery.zen.minimum_master_nodes: 2 23 # 默认设置为3s,此参数值为集群发现其它节点ping链接的超时时间,为避免网络延时,致使报错,故设置稍大些 24 discovery.zen.ping.timeout: 40s 25 # 设置是否打开多播发现节点,默认为true discovery.zen.ping.multicast.enabled: false 26 # 在es1.x中默认使用的是组播(multicast)协议,默认会自动发现同一网段的es节点组建集群, 27 # 在es2.x中默认使用的是单播(unicast)协议,想要组建集群的话就须要在这指定要发现的节点信息了。 28 discovery.zen.ping.unicast.hosts: ["rc-fhcb-10-es001", "rc-fhcb-10-es002"]

其它,节点下配置修改与上面大体相同,只是如下几个参数值不一样:github

1 node.name: es-node-02 2 network.bind_host: rc-fhcb-10-es002 3 network.publish_host: rc-fhcb-10-es002 4 network.host: rc-fhcb-10-es002

1.3 启动elasticsearch集群

在bin目录下,后台启动elasticsearch(集群每一个节点)web

方式一sql

./elasticsearch -d -Xms8g -Xmx8g

注意:参数-Xms8g -Xmx8g为ES使用的堆内存,具体大小应根据机器的配置肯定,建议不要超过物理内存的一半,也不要超过32G;npm

方式二json

1 在修改/etc/profile文件,添加以下内容 2 export ES_HEAP_SIZE=8g 3 
4 而后在ES安装目录的bin目录下启动 5 ./elasticsearch -d

1.4 插件安装(在线安装)

插件的安装没必要每一个节点都进行安装,进入到安装节点的elasticsearch安装目录的bin目录下网络

BigDesk Plugin : 对集群中es状态进行监控app

./plugin -install lukas-vlcek/bigdesk

Elasticsearch Head Plugin插件

./plugin -install mobz/elasticsearch-head

Elasticsearch Sql 插件

./plugin install NLPchina/elasticsearch-sql -u https://github.com/NLPchina/elasticsearch-sql/releases/download/1.4.6/elasticsearch-sql-1.4.6.zip

注意:sql插件重启后生效

Elasticsearch kopf插件

./plugin -install lmenezes/elasticsearch-kopf

注意:以上安装方式都是在线安装,安装节点必须能链接互联网

查看head页面索引http://10.13.11.21:9200/_plugin/head/

查看sql页面:http://10.13.11.21:9200/_plugin/sql/

关闭elasticsearch

前台运行,经过”CTRL+C“组合键来终止elasticsearch的运行

后台运行,经过“kill -9 进程号”中止运行

经过REST API接口关闭整个集群:

curl -XPOST http://主机ip:9200/_cluster/nodes/_shutdown

经过以下命令来关闭单个节点:

curl -XPOST http://主机ip:9200/_cluster/nodes/节点标志符(如:es-node-01)/_shutdown

1.5 插件安装(离线安装)

head插件

下载地址:https://github.com/mobz/elasticsearch-head

./plugin --install head --url file:///opt/softwares/elasticsearch-head-master.zip

sql插件

下载地址:https://github.com/NLPchina/elasticsearch-sql

./plugin --install sql --url file:///opt/softwares/elasticsearch-sql-1.4.6.zip

注意:sql插件重启后生效

bigdesk插件

下载地址:https://github.com/lukas-vlcek/bigdesk

./plugin --install bigdesk --url file:///opt/softwares/bigdesk-master.zip

kopf插件

下载地址:https://github.com/lmenezes/elasticsearch-kopf

./plugin --install kopf --url file:///opt/softwares/elasticsearch-kopf-master.zip

2. 数据导入导出工具elasticdump工具的安装

2.1 安装nodejs插件

方式一:在线安装

1 yum -y install epel-release 2 yum -y install nodejs 3 yum -y install npm

方式二:离线安装

下载地址:https://nodejs.org/dist/latest-v8.x

下载nodejs的安装包(xxx.tar.gz),解压到指定目录;

配置nodejs的环境变量

1 export NODE_HOME=/opt/fhcb/node-v8.11.3-linux-x64 2 export PATH=$NODE_HOME/bin:$PATH

验证

1 npm -v 2 node -v

2.2 安装elasticdump

方式一:(在线)

1 npm install elasticdump # 局部安装,elasticdump安装在当前目录 2 #或 3 npm install elasticdump -g  # -g表示全局安装

注意: 此方式安装elasticdump须要联网
方式二:(离线)

1 # 前提条件:已经安装好node,npm 2 直接将已经安装好的node_modules安装包拷贝到须要安装的机器上便可

2.3 导出数据

进入elasticdump的安装目录node_modules,而后进入elasticdump/bin目录下操做;

./elasticdump --input http://10.13.11.21:9200/10news_f_hot_news_toplist --output /root/datas/10news_f_hot_news_toplist.json --type=data

注意:导出目录/root/datas必须存在,不然报错;

–type参数:analyzer,拷贝analyzer分词

–type参数:mapping,拷贝映射

–type参数:data,拷贝数据

导出特定内容的数据

 1 ./elasticdump --input http://192.168.102.108:9200/web_page_news_info_09 --output /root/datas/web_page_news_info_09.json --type=data  2 --searchBody  3 '  4 {  5  "from": 0,  6  "size": 200,  7  "query": {  8  "filtered": {  9  "filter": { 10  "bool": { 11  "must": { 12  "query": { 13  "match": { 14  "orgcode": { 15  "query": "FHCB00001", 16  "type": "phrase" 17  } 18  } 19  } 20  } 21  } 22  } 23  } 24  } 25 } 26 ' 27 # 导出web_page_news_info_09.json表中,orgcode字段为FHCB00001的记录

2.4 导入数据

./elasticdump --input /opt/data/web_page_book_summary_09.json --output http://10.13.11.21:9200 --type=data

注意:可使用elasticdump –help查看插件的一些经常使用命令

3. IK中文分词器

3.1 安装ik分词器(ES集群每一个节点)

3.1.1 到github下载分词器源代码,地址为:https://github.com/medcl/elasticsearch-analysis-ik

注意:下载与elasticsearch匹配的分词器源码版本,1.6.x对应的源码版本为1.4.0

3.1.2 解压elasticsearch-analysis-ik-1.4.0.zip,而后编译源码
3.1.3 将解压目录文件中config/ik文件夹复制到ES安装目录config文件夹下
3.1.4 把\target\releases\elasticsearch-analysis-ik-1.4.1.zip 解压到 ES安装目录/plugins/analysis-ik/
3.1.5 将elasticsearch-analysis-ik-1.4.0.jar复制到ES安装目录/lib下
3.1.6 修改ES的配置文件config/elasticsearch.yml,增长ik的配置

 1 index:  2  analysis:  3  analyzer:  4  ik:  5  alias:[ik_analyzer]  6  type:org.elasticsearch.index.analysis.IkAnalyzerProvider  7  ik_max_word:  8  type:ik  9  use_smart:false 10  ik_smart: 11  type:ik 12  use_smart:true 13 index.analysis.analyzer.default.type:ik

注意:全局范围内全部的索引都将受到影响,也能够只对某个索引设置分词器

3.1.7 重启elasticsearch

3.1.8 验证分词效果

 1 #使用分词器  2 http://10.11.2.105:9200/web_page_book_summary_09/_analyze?analyzer=ik_smart&pretty=true&text=中国特社会主义  3 { "tokens" : [ { "token" : "中国特点社会主义", "start_offset" : 0, "end_offset" : 8, "type" : "CN_WORD", "position" : 1 } ] }  4 
 5 #没有使用分词器  6 http://10.13.11.21:9200/web_page_book_summary_09/_analyze?analyzer=standard&pretty=true&text=中国特社会主义  7 {  8  "tokens": [{  9  "token": "中", 10  "start_offset": 0, 11  "end_offset": 1, 12         "type": "<IDEOGRAPHIC>", 13  "position": 1 14  }, { 15  "token": "国", 16  "start_offset": 1, 17  "end_offset": 2, 18         "type": "<IDEOGRAPHIC>", 19  "position": 2 20  }, { 21  "token": "特", 22  "start_offset": 2, 23  "end_offset": 3, 24         "type": "<IDEOGRAPHIC>", 25  "position": 3 26  }, { 27  "token": "色", 28  "start_offset": 3, 29  "end_offset": 4, 30         "type": "<IDEOGRAPHIC>", 31  "position": 4 32  }, { 33  "token": "社", 34  "start_offset": 4, 35  "end_offset": 5, 36         "type": "<IDEOGRAPHIC>", 37  "position": 5 38  }, { 39  "token": "会", 40  "start_offset": 5, 41  "end_offset": 6, 42         "type": "<IDEOGRAPHIC>", 43  "position": 6 44  }, { 45  "token": "主", 46  "start_offset": 6, 47  "end_offset": 7, 48         "type": "<IDEOGRAPHIC>", 49  "position": 7 50  }, { 51  "token": "义", 52  "start_offset": 7, 53  "end_offset": 8, 54         "type": "<IDEOGRAPHIC>", 55  "position": 8 56  }] 57 }

3.2 IK分词器

ik_max_word: 会将文本作最细粒度的拆分,好比会将“中华人民共和国国歌”拆分为“中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,共和,和,国国,国歌”,会穷尽各类可能的组合;
ik_smart: 会作最粗粒度的拆分,好比会将“中华人民共和国国歌”拆分为“中华人民共和国,国歌”。

4. 问题集锦

问题1:由SSL引起的问题

nodejs的npm安装模块时候报错:npm ERR! Error: CERT_UNTRUSTED

解决方案:

npm config set strict-ssl false

问题2:npm安装elasticdump时报错

SyntaxError: Unexpected identifier

解决方案:升级一下nodejs版本

npm install -g n n stable
相关文章
相关标签/搜索