一. 简介
二. 下载软件包
ElasticSearch下载
官网:https://download.elasticsearch.org/
三. 安装部署
创建worker用户,下载安装包到/home/worker/soft
下
[worker@222 soft]$ ll
total 206224
-rw-r----- 1 worker worker 29007342 Feb 29 16:52 elasticsearch-2.1.1.tar.gz
-rw-r----- 1 worker worker 899251 Mar 18 15:36 elasticsearch-head-master.zip
-rw-r----- 1 worker worker 181260798 Dec 23 05:31 jdk-8u65-linux-x64.gz
安装JDK
#创建目录,解压移动JDK到新建目录下
cd /home/worker/soft/
mkdir -p /home/worker/usr/local/
tar -xf jdk-8u65-linux-x64.gz
mv jdk1.8.0_65 /home/worker/usr/local/
#添加环境变量
vim ~/.bash_profile
export PATH
export JAVA_HOME=/home/worker/usr/local/jdk1.8.0_65
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
#修改最大文件打开数
sudo vim /etc/security/limits.d/90-nproc.conf
worker soft nproc 65535
安装Elasticsearch
#解压文件,移动到指定目录下
[worker@222 soft]$ tar -xf elasticsearch-2.1.1.tar.gz
[worker@222 soft]$ mv elasticsearch-2.1.1 /home/worker/opt/
[worker@222 soft]$ ln -s /home/worker/opt/elasticsearch-2.1.1/ /home/worker/opt/elasticsearch
[worker@222 soft]$ ll /home/worker/opt/elasticsearch
lrwxrwxrwx 1 worker worker 37 Mar 19 02:42 /home/worker/opt/elasticsearch -> /home/worker/opt/elasticsearch-2.1.1/
#修改集群配置文件
/home/worker/opt/elasticsearch/config
vim elasticsearch.yml
cluster.name: my-application
node.name: node-1
discovery.zen.ping.unicast.hosts: ["host1", "host2"]
discovery.zen.minimum_master_nodes: 3
**备注:每个节点的node.name的名字不同**
#配置开机启动
echo '/home/worker/opt/elasticsearch/bin/elasticsearch -d' >> /e tc/rc.local
echo 'export PATH=/home/worker/opt/elasticsearch/bin/elasticsearch:$PATH' >> ~/.bash_profile
#配置启动关闭脚本
#!/bin/bash
start(){
/home/worker/opt/elasticsearch/bin/elasticsearch -d
}
stop(){
ps -ef|grep elasticsearch|grep -v grep |awk '{print $2}'|xargs kill -9
}
restart(){
/home/worker/opt/elasticsearch/bin/elasticsearch -d && ps -ef|grep elasticsearch|grep -v grep |awk '{print $2}'|xargs kill -9
}
case $1 in
start)
echo 'start elasticsearch.'
;;
stop)
echo 'stop elasticsearch.'
;;
restart)
echo 'restart elasticsearch.'
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
#优化配置
ES_HEAP_SIZE=2048m
MAX_OPEN_FILES=65535
安装ik分词插件
#创建ik目录,将zip包解压到目录
mkdir /home/worker/soft/ik
cd /home/worker/soft/ik
unzip ../elasticsearch-analysis-ik-1.7.0.zip
#拷贝ik目录到elasticsearch配置文件下
cp -r config/ik /home/worker/opt/elasticsearch/config/
#重启elasticsearch服务
/home/worker/opt/elasticsearch/bin/elasticsearch -d && ps -ef|grep elasticsearch|grep -v grep |awk '{print $2}'|xargs kill -9
安装Elasticsearch-head
#解压zip包到plugins目录下
cd /home/worker/opt/elasticsearch/plugins
unzip /home/worker/soft/elasticsearch-head-master.zip
#移动elasticsearch-head-master到head目录下
mv elasticsearch-head-master head
#重启elasticsearch服务
/home/worker/opt/elasticsearch/bin/elasticsearch -d && ps -ef|grep elasticsearch|grep -v grep |awk '{print $2}'|xargs kill -9
#测试
http://localhost:9200/_plugin/head/
四. 测试ik分词效果
创建一个索引,名为index
curl -XPUT http://localhost:9200/index
为索引index创建mapping
{
"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" : "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
} ]
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章