ElasticSearch及插件安装,集群安装
来源:互联网 发布:生物多样性监测网络 编辑:程序博客网 时间:2024/05/22 02:22
ElasticSearch及插件安装
1 ElasticSearch安装
1.1 安装环境依赖
安装elasticsearch时需要安装java7,推荐使用Oracle JDK 1.7.0_55版本。
1.2 程序安装
(1) 下载elasticsearch程序elasticsearch-1.3.1.tar.gz,
解压程序tar zvxf elasticsearch-1.3.1.tar.gz
安装目录/usr/local/es/elasticsearch-1.3.1
(2) 运行
/usr/local/es/elasticsearch-1.3.1/bin/elasticsearch -d
(3) 验证
http://ip:{http.port}
默认为http://localhost:9200
(4) 停止
curl -XPOST http://localhost:9200/_cluster/nodes/_shutdown
(5) 配置文件
/usr/local/es/elasticsearch-1.3.1/config/ elasticsearch.yml
/usr/local/es/elasticsearch-1.3.1/bin/elasticsearch.in.sh
这两个主要的配置文件使用默认即可,不必修改即可启动并使用ElasticSearch服务。配置文件的参数内容将在“集群”安装部分介绍。
1.3 集群
(1) 安装3台ES结点
每个结点的安装方式和上面安装的/usr/local/es/elasticsearch-1.3.1相同,不同的只是不能完全使用默认配置,要作修改。
目录分别为:
node3:
/usr/local/es3/elasticsearch-1.3.1
node4:
/usr/local/es4/elasticsearch-1.3.1
node5:
/usr/local/es5/elasticsearch-1.3.1
(2) 配置JVM内存参数
以/usr/local/es3/elasticsearch-1.3.1为例,其他结点配置操作完全相同。
vi /usr/local/es3/elasticsearch-1.3.1/bin/elasticsearch.in.sh
打开文件并找到如下的部分:
if [ "x$ES_MIN_MEM" = "x" ]; then
ES_MIN_MEM=256m
fi
if [ "x$ES_MAX_MEM" = "x" ]; then
ES_MAX_MEM=1g
fi
if [ "x$ES_HEAP_SIZE" != "x" ]; then
ES_MIN_MEM=$ES_HEAP_SIZE
ES_MAX_MEM=$ES_HEAP_SIZE
fi
ES_MIN_MEM表示elasticsearch运行时分配的初始内存大小
ES_MAX_MEM表示elasticsearch运行时最大可分配的内存大小
内存大小的分配视结点机器的实际内存而定。
例如,可以将ES_MIN_MEM=256m修改为ES_MIN_MEM=1g,让ES_MIN_MEM和ES_MAX_MEM大小一样。
(3) 配置集群参数
结点/usr/local/es3/elasticsearch-1.3.1
vi /usr/local/es3/elasticsearch-1.3.1/config/elasticsearch.yml
编辑内容并保存。
###集群名称,同一集群下的结点配置必须使用相同的cluster.name
cluster.name: tuna_nodes
###结点名称,集群下的结点node.name不能重复
node.name: node3
###集群中的master结点失效后,当前结点能否有机会参与选举成为master结点
node.master: true
###当前结点上是否存放索引结构数据
node.data: true
###索引可存储的主分片数
index.number_of_shards: 3
###每个主分片拥有的副本数
index.number_of_replicas: 2
###配置文件目录
path.conf: /usr/local/es3/elasticsearch-1.3.1/config
###索引数据目录
path.data: /usr/local/es3/elasticsearch-1.3.1/data
###临时文件目录
path.work: /usr/local/es3/elasticsearch-1.3.1/work
###日志文件目录
path.logs: /usr/local/es3/elasticsearch-1.3.1/logs
###插件目录
path.plugins: /usr/local/es3/elasticsearch-1.3.1/plugins
###当前结点绑定的地址,以及其他结点或外部访问它的地址
network.host: 192.168.5.137
###应用客户端连接结点的端口
transport.tcp.port: 9303
###http方式访问的端口,通常用于控制台管理
http.port: 9203
###分词器集成,这里是IK分词器
index:
analysis:
analyzer:
ik:
alias: [ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
ik_max_word:
type: ik
use_smart: false
ik_smart:
type: ik
use_smart: true
index.analysis.analyzer.default.type: ik
结点/usr/local/es4/elasticsearch-1.3.1
vi /usr/local/es4/elasticsearch-1.3.1/config/elasticsearch.yml
编辑内容并保存。
cluster.name: tuna_nodes
node.name: node4
node.master: true
node.data: true
index.number_of_shards: 3
index.number_of_replicas: 2
path.conf: /usr/local/es4/elasticsearch-1.3.1/config
path.data: /usr/local/es4/elasticsearch-1.3.1/data
path.work: /usr/local/es4/elasticsearch-1.3.1/work
path.logs: /usr/local/es4/elasticsearch-1.3.1/logs
path.plugins: /usr/local/es4/elasticsearch-1.3.1/plugins
network.host: 192.168.5.137
transport.tcp.port: 9304
http.port: 9204
index:
analysis:
analyzer:
ik:
alias: [ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
ik_max_word:
type: ik
use_smart: false
ik_smart:
type: ik
use_smart: true
index.analysis.analyzer.default.type: ik
结点/usr/local/es5/elasticsearch-1.3.1
vi /usr/local/es5/elasticsearch-1.3.1/config/elasticsearch.yml
编辑内容并保存。
cluster.name: tuna_nodes
node.name: node5
node.master: true
node.data: true
index.number_of_shards: 3
index.number_of_replicas: 2
path.conf: /usr/local/es5/elasticsearch-1.3.1/config
path.data: /usr/local/es5/elasticsearch-1.3.1/data
path.work: /usr/local/es5/elasticsearch-1.3.1/work
path.logs: /usr/local/es5/elasticsearch-1.3.1/logs
path.plugins: /usr/local/es5/elasticsearch-1.3.1/plugins
network.host: 192.168.5.137
transport.tcp.port: 9305
http.port: 9205
index:
analysis:
analyzer:
ik:
alias: [ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
ik_max_word:
type: ik
use_smart: false
ik_smart:
type: ik
use_smart: true
index.analysis.analyzer.default.type: ik
(4) 依次启动结点服务
/usr/local/es3/elasticsearch-1.3.1/bin/elasticsearch -d
/usr/local/es4/elasticsearch-1.3.1/bin/elasticsearch -d
/usr/local/es5/elasticsearch-1.3.1/bin/elasticsearch –d
查看进程:
ps -aux |grep elasticsearch
查看端口:
netstat -tunlp
(5) 查看集群状态
这里访问node3,/usr/local/es3/elasticsearch-1.3.1
curl -XGET 'http://192.168.5.137:9203/_cluster/health?pretty=true'
status字段提供的值反应了集群整体的健康程度。
green:所有的主分片(Primary Shard)和副本分片(Replica Shard)都处于活动状态
yellow:所有的主分片都处于活动状态,但是并不是所有的副本分片都处于活跃状态
red:不是所有的主分片都处于活动状态
查看结点node3状态:
curl -XGET 'http://192.168.5.137:9203/_nodes/node3/stats?pretty=true'
1.4 插件安装之Head
elasticsearch-head是一个elasticsearch的集群管理工具,它是完全由html5编写的独立网页程序,你可以通过插件把它集成到es.
插件安装方法
(1) https://github.com/mobz/elasticsearch-head下载elasticsearch-head-master.zip解压。
(2) 建立elasticsearch-1.3.1\plugins\head\_site文件
(3) 将解压后的elasticsearch-head-master文件夹下的文件copy到_site
(4) 启动运行es
(5) 浏览器打开http://192.168.5.137:9203/_plugin/head/
2 ElasticSearch操作样例
2.1 索引
2.1.1 插入索引
curl -XPUT 'http://localhost:9200/twitter/user/kimchy' -d '{ "name" : "Shay Banon" }'
curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '
{
"user": "kimchy",
"postDate": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}'
curl -XPUT 'http://localhost:9200/twitter/tweet/2' -d '
{
"user": "kimchy",
"postDate": "2009-11-15T14:12:12",
"message": "Another tweet, will it be indexed?"
}'
2.1.2 获得索引值
curl -XGET 'http://localhost:9200/twitter/user/kimchy?pretty=true'
curl -XGET 'http://localhost:9200/twitter/tweet/1?pretty=true'
curl -XGET 'http://localhost:9200/twitter/tweet/2?pretty=true'
2.2 检索
curl -XGET 'http://localhost:9200/twitter/tweet/_search?q=user:kimchy&pretty=true'
2.2.1 使用JSON查询语言检索
curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty=true' -d '
{
"query" : {
"match" : { "user": "kimchy" }
}
}'
2.2.2 检索所有存储
curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d '
{
"query" : {
"matchAll" : {}
}
}'
2.2.3 范围检索
curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d '
{
"query" : {
"range" : {
"postDate" : { "from" : "2009-11-15T13:00:00", "to" : "2009-11-15T14:00:00" }
}
}
}'
3 IK分词器安装
3.1 下载IK分词器
下载IK相关配置词典文件到config目录:
http://github.com/downloads/medcl/elasticsearch-analysis-ik/ik.zip (解压到config目录下)
ik.jar放入拷贝到ES_HOME/plugins/analysis-ik目录下面,如果没有该目录,则先创建该目录。
3.2 Elasticsearch中配置Ik
打开ES_HOME/config/elasticsearch.yml文件,在文件最后加入如下内容:
查看文本打印
index:
analysis:
analyzer:
ik:
alias: [ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
ik_max_word:
type: ik
use_smart: false
ik_smart:
type: ik
use_smart: true
index.analysis.analyzer.default.type: ik
3.3 Ik分词器测试
1、创建一个索引,名为index,查看文本打印
curl -XPUT http://localhost:9200/index
2、为索引index创建mapping,查看文本打印
curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'
{
"fulltext": {
"_all": {
"analyzer": "ik"
},
"properties": {
"content": {
"type" : "string",
"boost" : 8.0,
"term_vector" : "with_positions_offsets",
"analyzer" : "ik",
"include_in_all" : true
}
}
}
}'
3、测试,查看文本打印
curl 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d '
{
"text":"世界如此之大"
}'
显示结果如下,查看文本打印
{
"tokens" : [ {
"token" : "text",
"start_offset" : 4,
"end_offset" : 8,
"type" : "ENGLISH",
"position" : 1
}, {
"token" : "世界",
"start_offset" : 11,
"end_offset" : 13,
"type" : "CN_WORD",
"position" : 2
}, {
"token" : "如此",
"start_offset" : 13,
"end_offset" : 15,
"type" : "CN_WORD",
"position" : 3
}, {
"token" : "之大",
"start_offset" : 15,
"end_offset" : 17,
"type" : "CN_WORD",
"position" : 4
} ]
}
1 ElasticSearch安装
1.1 安装环境依赖
安装elasticsearch时需要安装java7,推荐使用Oracle JDK 1.7.0_55版本。
1.2 程序安装
(1) 下载elasticsearch程序elasticsearch-1.3.1.tar.gz,
解压程序tar zvxf elasticsearch-1.3.1.tar.gz
安装目录/usr/local/es/elasticsearch-1.3.1
(2) 运行
/usr/local/es/elasticsearch-1.3.1/bin/elasticsearch -d
(3) 验证
http://ip:{http.port}
默认为http://localhost:9200
(4) 停止
curl -XPOST http://localhost:9200/_cluster/nodes/_shutdown
(5) 配置文件
/usr/local/es/elasticsearch-1.3.1/config/ elasticsearch.yml
/usr/local/es/elasticsearch-1.3.1/bin/elasticsearch.in.sh
这两个主要的配置文件使用默认即可,不必修改即可启动并使用ElasticSearch服务。配置文件的参数内容将在“集群”安装部分介绍。
1.3 集群
(1) 安装3台ES结点
每个结点的安装方式和上面安装的/usr/local/es/elasticsearch-1.3.1相同,不同的只是不能完全使用默认配置,要作修改。
目录分别为:
node3:
/usr/local/es3/elasticsearch-1.3.1
node4:
/usr/local/es4/elasticsearch-1.3.1
node5:
/usr/local/es5/elasticsearch-1.3.1
(2) 配置JVM内存参数
以/usr/local/es3/elasticsearch-1.3.1为例,其他结点配置操作完全相同。
vi /usr/local/es3/elasticsearch-1.3.1/bin/elasticsearch.in.sh
打开文件并找到如下的部分:
if [ "x$ES_MIN_MEM" = "x" ]; then
ES_MIN_MEM=256m
fi
if [ "x$ES_MAX_MEM" = "x" ]; then
ES_MAX_MEM=1g
fi
if [ "x$ES_HEAP_SIZE" != "x" ]; then
ES_MIN_MEM=$ES_HEAP_SIZE
ES_MAX_MEM=$ES_HEAP_SIZE
fi
ES_MIN_MEM表示elasticsearch运行时分配的初始内存大小
ES_MAX_MEM表示elasticsearch运行时最大可分配的内存大小
内存大小的分配视结点机器的实际内存而定。
例如,可以将ES_MIN_MEM=256m修改为ES_MIN_MEM=1g,让ES_MIN_MEM和ES_MAX_MEM大小一样。
(3) 配置集群参数
结点/usr/local/es3/elasticsearch-1.3.1
vi /usr/local/es3/elasticsearch-1.3.1/config/elasticsearch.yml
编辑内容并保存。
###集群名称,同一集群下的结点配置必须使用相同的cluster.name
cluster.name: tuna_nodes
###结点名称,集群下的结点node.name不能重复
node.name: node3
###集群中的master结点失效后,当前结点能否有机会参与选举成为master结点
node.master: true
###当前结点上是否存放索引结构数据
node.data: true
###索引可存储的主分片数
index.number_of_shards: 3
###每个主分片拥有的副本数
index.number_of_replicas: 2
###配置文件目录
path.conf: /usr/local/es3/elasticsearch-1.3.1/config
###索引数据目录
path.data: /usr/local/es3/elasticsearch-1.3.1/data
###临时文件目录
path.work: /usr/local/es3/elasticsearch-1.3.1/work
###日志文件目录
path.logs: /usr/local/es3/elasticsearch-1.3.1/logs
###插件目录
path.plugins: /usr/local/es3/elasticsearch-1.3.1/plugins
###当前结点绑定的地址,以及其他结点或外部访问它的地址
network.host: 192.168.5.137
###应用客户端连接结点的端口
transport.tcp.port: 9303
###http方式访问的端口,通常用于控制台管理
http.port: 9203
###分词器集成,这里是IK分词器
index:
analysis:
analyzer:
ik:
alias: [ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
ik_max_word:
type: ik
use_smart: false
ik_smart:
type: ik
use_smart: true
index.analysis.analyzer.default.type: ik
结点/usr/local/es4/elasticsearch-1.3.1
vi /usr/local/es4/elasticsearch-1.3.1/config/elasticsearch.yml
编辑内容并保存。
cluster.name: tuna_nodes
node.name: node4
node.master: true
node.data: true
index.number_of_shards: 3
index.number_of_replicas: 2
path.conf: /usr/local/es4/elasticsearch-1.3.1/config
path.data: /usr/local/es4/elasticsearch-1.3.1/data
path.work: /usr/local/es4/elasticsearch-1.3.1/work
path.logs: /usr/local/es4/elasticsearch-1.3.1/logs
path.plugins: /usr/local/es4/elasticsearch-1.3.1/plugins
network.host: 192.168.5.137
transport.tcp.port: 9304
http.port: 9204
index:
analysis:
analyzer:
ik:
alias: [ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
ik_max_word:
type: ik
use_smart: false
ik_smart:
type: ik
use_smart: true
index.analysis.analyzer.default.type: ik
结点/usr/local/es5/elasticsearch-1.3.1
vi /usr/local/es5/elasticsearch-1.3.1/config/elasticsearch.yml
编辑内容并保存。
cluster.name: tuna_nodes
node.name: node5
node.master: true
node.data: true
index.number_of_shards: 3
index.number_of_replicas: 2
path.conf: /usr/local/es5/elasticsearch-1.3.1/config
path.data: /usr/local/es5/elasticsearch-1.3.1/data
path.work: /usr/local/es5/elasticsearch-1.3.1/work
path.logs: /usr/local/es5/elasticsearch-1.3.1/logs
path.plugins: /usr/local/es5/elasticsearch-1.3.1/plugins
network.host: 192.168.5.137
transport.tcp.port: 9305
http.port: 9205
index:
analysis:
analyzer:
ik:
alias: [ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
ik_max_word:
type: ik
use_smart: false
ik_smart:
type: ik
use_smart: true
index.analysis.analyzer.default.type: ik
(4) 依次启动结点服务
/usr/local/es3/elasticsearch-1.3.1/bin/elasticsearch -d
/usr/local/es4/elasticsearch-1.3.1/bin/elasticsearch -d
/usr/local/es5/elasticsearch-1.3.1/bin/elasticsearch –d
查看进程:
ps -aux |grep elasticsearch
查看端口:
netstat -tunlp
(5) 查看集群状态
这里访问node3,/usr/local/es3/elasticsearch-1.3.1
curl -XGET 'http://192.168.5.137:9203/_cluster/health?pretty=true'
status字段提供的值反应了集群整体的健康程度。
green:所有的主分片(Primary Shard)和副本分片(Replica Shard)都处于活动状态
yellow:所有的主分片都处于活动状态,但是并不是所有的副本分片都处于活跃状态
red:不是所有的主分片都处于活动状态
查看结点node3状态:
curl -XGET 'http://192.168.5.137:9203/_nodes/node3/stats?pretty=true'
1.4 插件安装之Head
elasticsearch-head是一个elasticsearch的集群管理工具,它是完全由html5编写的独立网页程序,你可以通过插件把它集成到es.
插件安装方法
(1) https://github.com/mobz/elasticsearch-head下载elasticsearch-head-master.zip解压。
(2) 建立elasticsearch-1.3.1\plugins\head\_site文件
(3) 将解压后的elasticsearch-head-master文件夹下的文件copy到_site
(4) 启动运行es
(5) 浏览器打开http://192.168.5.137:9203/_plugin/head/
2 ElasticSearch操作样例
2.1 索引
2.1.1 插入索引
curl -XPUT 'http://localhost:9200/twitter/user/kimchy' -d '{ "name" : "Shay Banon" }'
curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '
{
"user": "kimchy",
"postDate": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}'
curl -XPUT 'http://localhost:9200/twitter/tweet/2' -d '
{
"user": "kimchy",
"postDate": "2009-11-15T14:12:12",
"message": "Another tweet, will it be indexed?"
}'
2.1.2 获得索引值
curl -XGET 'http://localhost:9200/twitter/user/kimchy?pretty=true'
curl -XGET 'http://localhost:9200/twitter/tweet/1?pretty=true'
curl -XGET 'http://localhost:9200/twitter/tweet/2?pretty=true'
2.2 检索
curl -XGET 'http://localhost:9200/twitter/tweet/_search?q=user:kimchy&pretty=true'
2.2.1 使用JSON查询语言检索
curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty=true' -d '
{
"query" : {
"match" : { "user": "kimchy" }
}
}'
2.2.2 检索所有存储
curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d '
{
"query" : {
"matchAll" : {}
}
}'
2.2.3 范围检索
curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d '
{
"query" : {
"range" : {
"postDate" : { "from" : "2009-11-15T13:00:00", "to" : "2009-11-15T14:00:00" }
}
}
}'
3 IK分词器安装
3.1 下载IK分词器
下载IK相关配置词典文件到config目录:
http://github.com/downloads/medcl/elasticsearch-analysis-ik/ik.zip (解压到config目录下)
ik.jar放入拷贝到ES_HOME/plugins/analysis-ik目录下面,如果没有该目录,则先创建该目录。
3.2 Elasticsearch中配置Ik
打开ES_HOME/config/elasticsearch.yml文件,在文件最后加入如下内容:
查看文本打印
index:
analysis:
analyzer:
ik:
alias: [ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
ik_max_word:
type: ik
use_smart: false
ik_smart:
type: ik
use_smart: true
index.analysis.analyzer.default.type: ik
3.3 Ik分词器测试
1、创建一个索引,名为index,查看文本打印
curl -XPUT http://localhost:9200/index
2、为索引index创建mapping,查看文本打印
curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'
{
"fulltext": {
"_all": {
"analyzer": "ik"
},
"properties": {
"content": {
"type" : "string",
"boost" : 8.0,
"term_vector" : "with_positions_offsets",
"analyzer" : "ik",
"include_in_all" : true
}
}
}
}'
3、测试,查看文本打印
curl 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d '
{
"text":"世界如此之大"
}'
显示结果如下,查看文本打印
{
"tokens" : [ {
"token" : "text",
"start_offset" : 4,
"end_offset" : 8,
"type" : "ENGLISH",
"position" : 1
}, {
"token" : "世界",
"start_offset" : 11,
"end_offset" : 13,
"type" : "CN_WORD",
"position" : 2
}, {
"token" : "如此",
"start_offset" : 13,
"end_offset" : 15,
"type" : "CN_WORD",
"position" : 3
}, {
"token" : "之大",
"start_offset" : 15,
"end_offset" : 17,
"type" : "CN_WORD",
"position" : 4
} ]
}
0 0
- ElasticSearch及插件安装,集群安装
- ElasticSearch集群搭建及插件安装
- Elasticsearch 5.x_Elasticsearch集群及插件安装
- Docker安装Elasticsearch 5.6.3集群及head 5插件
- elasticsearch集群安装配置_插件安装
- Centos7安装Elasticsearch及集群
- elasticsearch及head插件安装
- Elasticsearch及插件安装教程
- elasticsearch 及elasticsearch-head插件安装
- elasticsearch系列-elasticsearch及插件安装
- ElasticSearch集群安装及配置方法
- Elasticsearch安装分词插件IK及问题解决
- elasticsearch-5.6.0及head插件安装
- ElasticSearch 5.0及head插件安装
- Elasticsearch配置及head插件安装
- elasticsearch插件安装之--linux下安装及head插件
- Ambari-Hadoop集群、Elasticsearch集群及nginx安装
- 安装Elasticsearch集群
- 站点标题应该怎样写才能增加浏览?
- Unity立体几何 点到直线距离计算
- 学习感触
- 【编译原理】【语言基础】
- javascript HTML DOM listener
- ElasticSearch及插件安装,集群安装
- CCF-CAP 201312-1 出现次数最多的数 答案
- 第99讲:手动Artifacts打包并运行SBT开发Akka第一个案例学习笔记
- Python+OpenCV学习(8)---Harris_corner
- 通过gdb快速定位“段错误”的位置
- 欢迎使用CSDN-markdown编辑器
- 每天开电脑的第一件事
- Linux 系统分析 20150912
- CentOs安装redis