全文搜索引擎 Elasticsearch

2019-12-17  本文已影响0人  胡乱唱歌ing

1.安装java8

yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel -y

2.安装 Elastic

$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.1.zip
$ unzip elasticsearch-5.5.1.zip
$ cd elasticsearch-5.5.1/ 

3.启动elasticsearch

#我安装的目录为/usr/local/elasticsearch-5.5.1
cd /usr/local/elasticsearch-5.5.1
./bin/elasticsearch #启动

4.启动遇到的问题

1.报内存不足

# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 201326592 bytes for committing reserved memory.

解决方法

vi  config/jvm.options 
#修改 -Xms2g   --> -Xms256m  -Xmx2g-->-Xmx256m  因为我的虚拟机只分配了1GB内存所以这里我调整为256MB

2.启动是报不能run as root

 java.lang.RuntimeException: can not run elasticsearch as root

解决方法

groupadd elasticsearch #创建用户组
useradd -s /sbin/nologin -M -g elasticsearch elasticsearch #创建用户

vi /usr/lib/systemd/system/elasticsearch.service  #编写elasticsearch启动脚本
写入以下内容
[Unit]                                                                                                                       
Description= elasticsearch service                                                                                           
                                                                                                                             
[Service]                                                                                                                    
                                                                                                                             
Type=forking                                                                                                                 
User=elasticsearch                                                                                                           
Group=elasticsearch                                                                                                          
ExecStart=/usr/local/elasticsearch-5.5.1/bin/elasticsearch  -d                                                                 
ExecStop=/usr/local/elasticsearch-5.5.1/bin/elasticsearch stop                                                               
#Restart=always                                                                                                              
                                                                                                                             
[Install]                                                                                                                    
WantedBy=multi-user.target 

修改启动脚本配置

echo 'START_DAEMON=true
ES_USER=elasticsearch
ES_GROUP=elasticsearch'  >> ./bin/elasticsearch

#加入systemctl  管理 我的环境是centos7
systemctl enable elasticsearch
systemctl start elasticsearch #启动服务

5.查看是否启动OK

[root@localhost scripts]# curl localhost:9200
{
  "name" : "Fims7MP",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "p4xajhYZTgeFe2r4YoUIMA",
  "version" : {
    "number" : "5.5.1",
    "build_hash" : "19c13d0",
    "build_date" : "2017-07-18T20:44:24.823Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}

6.安装中文分词插件# **[elasticsearch-analysis-ik](https://github.com/medcl/elasticsearch-analysis-ik/tree/v5.5.1

)**

1.download or compile

*   optional 1 - download pre-build package from here: [https://github.com/medcl/elasticsearch-analysis-ik/releases](https://github.com/medcl/elasticsearch-analysis-ik/releases)

unzip plugin to folder your-es-root/plugins/

*   optional 2 - use elasticsearch-plugin to install ( supported from version v5.5.1 ):
 ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.1/elasticsearch-analysis-ik-5.5.1.zip

7.安装中文分词 两个分词插件2选一吧 [smartcn] (https://www.elastic.co/guide/en/elasticsearch/plugins/current/analysis-smartcn.html)

sudo bin/elasticsearch-plugin install analysis-smartcn

参考

https://www.ruanyifeng.com/blog/2017/08/elasticsearch.html

上一篇下一篇

猜你喜欢

热点阅读