您的位置:首页 > 其它

ElasticSearch 安装配置

2015-03-13 10:25 417 查看

1. 安装ElasticSearch

# wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.4.tar.gz
# tar -xvf elasticsearch-1.4.4.tar.gz

2. 安装插件

2.1 安装ElasticSearch

Marvel是ElasticSearch的监控工具,可通过插件方式下载。
# cd elasticsearch-1.4.4
# ./bin/plugin -i elasticsearch/marvel/latest

2.2 安装ServiceWapper

ServiceWrapper可后台启动,停止服务

# wget https://github.com/elasticsearch/elasticsearch-servicewrapper/archive/master.zip # unzip master -d ./
# mv elasticsearch-servicewrapper-master/service elasticsearch-1.4.4/bin/
# rm -Rf elasticsearch-servicewrapper-master
bin/service/elasticsearch有如下命令可用:

console 在前台运行es
start 在后台运行es
stop 停止es
install 使es作为服务在服务器启动时自动启动
remove 取消启动时自动启<pre name="code" class="plain"># bin/plugin --install mobz/elasticsearch-head



在service目录下有个elasticsearch.conf配置文件,可配置java相关的运行环境参数。

2.3 安装Head

# ./bin/plugin --install mobz/elasticsearch-head

2.4 安装BigDesk

# ./bin/plugin --install lukas-vlcek/bigdesk

2.5 安装ik分词插件

# cd plugins
# mkdir analysis-ik
# cd analysis-ik

由于网上的jar存在问题,需要从Github上下载最新的源码,用Maven编译后,再将target/release/elasticsearch-analysis-ik-1.2.9.zip上传至服务器的ES_HOME/plugins/analysis-ik目录,并解压此zip包后,删除zip包。

将源码下的config/ik目录拷贝至ES_HOME/conf下,这是词典配置文件。

启用分词插件,编辑ES_HOME/conf/elasticsearch.yml,加入以下内容:
index:
analysis:
analyzer:
ik:
alias: [news_analyzer_ik,ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
index.analysis.analyzer.default.type : "ik"
安装好插件后,要使用插件起作用,必须创建索引。
# curl -XPUT http://localhost:9200/index # curl -XPOST http://localhost:9200/index/fulltext/ 4000
_mapping -d'
{
"fulltext": {
"_all": {
"analyzer": "ik"
},
"properties": {
"content": {
"type" : "string",
"boost" : 8.0,
"term_vector" : "with_positions_offsets",
"analyzer" : "ik",
"include_in_all" : true
}
}
}
}'
测试:
# curl 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d '
{
"text":"我是中国人"
}'
结果如下:
{
"tokens": [
{
"token": "我",
"start_offset": 0,
"end_offset": 1,
"type": "CN_CHAR",
"position": 1
}
,
{
"token": "中国人",
"start_offset": 2,
"end_offset": 5,
"type": "CN_WORD",
"position": 2
}
,
{
"token": "中国",
"start_offset": 2,
"end_offset": 4,
"type": "CN_WORD",
"position": 3
}
,
{
"token": "国人",
"start_offset": 3,
"end_offset": 5,
"type": "CN_WORD",
"position": 4
}
]
}


3. 运行ElasticSearch

./bin/service/elasticsearch start
可新建一个窗口,测试是否启动成功。
# curl 'http://localhost:9200/?pretty'
{
"status" : 200,
"name" : "George Washington Bridge",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "1.4.4",
"build_hash" : "c88f77ffc81301dfa9dfd81ca2232f09588bd512",
"build_timestamp" : "2015-02-19T13:05:36Z",
"build_snapshot" : false,
"lucene_version" : "4.10.3"
},
"tagline" : "You Know, for Search"
}
#
开启防火墙端口9200,9300,在浏览器键入:http://ip:9200/_plugin/marvel

4. 集群配置

ElasticSearch的集群可自发现,只要配置相同的集群名称,默认为组播发现机制,默认情况下:

http 端口:9200 需要打开给调用
数据传输端口:9300 用于集群之间交换数据
组播端口(UDP):54328

上述端口一定不要让防火墙阻断,否则,无法完成集群。

编辑每个ElasticSearch/config/elasticsearch.yml,加入以下代码:
cluster.name: elasticsearch-cluster
node.name: "es-node1"
第一行表示集群名称,一个集群内的所有结点相同,后面是结点在集群内的名称,每个结点不一样,建议配置,不配置会自动分配一个随机名称。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  elasticsearch