安装方式

curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.2.tar.gz

或者官网安装

https://www.elastic.co/cn/downloads/

下载后直接解压到  你的path文件里

tar -zxvf xxxxxxxxxx

修改 elasticsearch.yml 

cluster.name: 集群名 #集群的名字 
        node.name:  节点名称 #节点名称
        index.number_of_shards: 5  #索引分片个数,默认为5片  
        index.number_of_replicas: 1  #索引副本个数,默认为1个副本  
        path.data: /app/es/data  #数据存储目录(多个路径用逗号分隔)
        path.logs: /app/es/logs  #日志目录  
        network.host: 192.168.40.133  #修改一下ES的监听地址,这样别的机器才可以访问
        transport.tcp.port: 9300  #设置节点间交互的tcp端口(集群),默认是9300
        http.port: 9200  #监听端口(默认的就好)  
        # 增加新的参数,这样head插件才可以访问es  
        http.cors.enabled: true  
        http.cors.allow-origin: "*"   

# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
# 集群名称
cluster.name: log_cluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# 节点名称
node.name: node_01
# 是否可以为主节点
node.master: true
# 是否可以为数据节点
node.data: true
# 允许在对文档进行索引之前进行预处理
node.ingest: true
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# 数据存储目录,默认在es目录下data
#path.data: /path/to/data
#
# Path to log files:
#
# 日志存储目录,默认在es目录下logs
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
# 锁定物理内存地址,防止es内存被交换出去,也就是避免es使用swap交换分区,频繁的交换,会导致IOPS变高
bootstrap.memory_lock: true
# 禁止检测SecComp
bootstrap.system_call_filter: false
# 当前机器ip地址,0.0.0.0 代表当前
network.host: 10.10.0.1
# 是否使用http协议对外提供服务,默认为true,开启
http.enabled: true
# 设置对外服务的http端口,默认为9200
http.port: 9200
# 设置节点间交互的tcp端口,默认是9300
transport.tcp.port: 9300
# 设置是否压缩tcp传输时的数据,默认为false,不压缩
transport.tcp.compress: true
#
# For more information, consult the network module documentation.
http.cors.enabled: true
http.cors.allow-origin: "*"
#
# --------------------------------- Discovery ----------------------------------
#
# 设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点
discovery.zen.ping.unicast.hosts: ["10.10.0.1:9300","10.10.0.2:9300","10.10.0.3:9300"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
# 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,(total number of master-eligible nodes / 2 + 1)
discovery.zen.minimum_master_nodes: 1
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
# ---------------------------------- Cache  -----------------------------------# 启用脚本 默认painless
cluster.routing.allocation.same_shard.host: true
#
# TODO 集群搭建好后配置
#
#
# #超时时间
discovery.zen.ping_timeout: 5s
discovery.zen.fd.ping_timeout: 5s
#
# #禁止自动创建索引
action.auto_create_index: true
#
# # 一个集群中的N个节点启动后,才允许进行恢复处理
gateway.recover_after_nodes: 1
# #
# # 设置初始化恢复过程的超时时间,超时时间从上一个配置中配置的N个节点启动后算起
gateway.recover_after_time: 5m
# #
# # 设置这个集群中期望有多少个节点.一旦这N个节点启动(并且recover_after_nodes也符合),
# # 立即开始恢复过程(不等待recover_after_time超时)
gateway.expected_nodes: 2
# # 线程池
thread_pool.search.size: 100
thread_pool.search.queue_size: 1000 

修改系统配置  

/etc/security/limits.conf

/etc/sysctl.conf

修改elasticsearch运行内存jvm.options
        -Xmx=512m -Xms=512m
修改系统参数
        vi /etc/security/limits.conf
                    *       soft     nproc          65536
                    *       hard    nproc          65536
                    *       soft     nofile           65536
                    *       hard    nofile           65536
                vi /etc/sysctl.conf
                    vm.max_map_count= 262144

修改完需要  sysctl -p    然后reboot重启

[root@hadoop004 ~]# vi /etc/security/limits.conf添加
*               soft    nofile          65536
*               hard    nofile          65536
*               soft    nproc           4096
*               hard    nproc           4096[root@hadoop004 ~]# vim /etc/sysctl.confvm.max_map_count = 655360[root@hadoop004 ~]# sysctl -p[root@hadoop004 ~]# reboot

运行  ./elasticsearch -d     加d是后台运行

[hadoop@hadoop004 bin]$ ./elasticsearch

启动后看下  localhost:9200   显示这个json就是启动成功了

注意:es的启动不能是root账户,需要给个其他账户es文件夹下所有权限

elasticsearch不能使用root启动问题解决

问题:

  es安装好之后,使用root启动会报错:can not run elasticsearch as root

[root@iZbp1bb2egi7w0ueys548pZ bin]# ./elasticsearch
[2019-01-21T09:50:59,387][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as rootat org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:134) ~[elasticsearch-6.0.0.jar:6.0.0]at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:121) ~[elasticsearch-6.0.0.jar:6.0.0]at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:69) ~[elasticsearch-6.0.0.jar:6.0.0]at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) ~[elasticsearch-6.0.0.jar:6.0.0]at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-6.0.0.jar:6.0.0]at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.0.0.jar:6.0.0]at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.0.0.jar:6.0.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as rootat org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.0.0.jar:6.0.0]at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.0.0.jar:6.0.0]at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:322) ~[elasticsearch-6.0.0.jar:6.0.0]at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:130) ~[elasticsearch-6.0.0.jar:6.0.0]... 6 more

原因:

  为了安全不允许使用root用户启动

解决:

  es5之后的都不能使用添加启动参数或者修改配置文件等方法启动了,必须要创建用户

  1、创建用户:elasticsearch

[root@iZbp1bb2egi7w0ueys548pZ bin]# adduser elasticsearch

  2、创建用户密码,需要输入两次

[root@iZbp1bb2egi7w0ueys548pZ bin]# passwd elasticsearch

  3、将对应的文件夹权限赋给该用户

[root@iZbp1bb2egi7w0ueys548pZ local]# chown -R elasticsearch elasticsearch-6.0.0

  4、切换至elasticsearch用户

[root@iZbp1bb2egi7w0ueys548pZ etc]# su elasticsearch

  5、进入启动目录启动 /usr/local/elasticsearch-6.0.0/bin  使用后台启动方式:./elasticsearch -d

[elasticsearch@vmt10003 bin]$ ./elasticsearch -d

  6、启动后测试

  输入curl ip:9200,如果返回一个json数据说明启动成功

可能遇到的问题

  1、启动后访问ip:9200没有显示json

  

[root@iZbp1bb2egi7w0ueys548qZ ~]# curl 10.132.131.51:9200
curl: (7) Failed connect to 10.132.131.51:9200; Connection refused

  解决:

  修改elasticsearch.yml文件,添加

  network.host: 0.0.0.0

  再次启动就可以了

[root@iZbp1bb2egi7w0ueys548qZ ~]# curl 10.132.131.51:9200
{"name" : "dMD7fZd","cluster_name" : "elasticsearch","cluster_uuid" : "Cy4a99t2Sw2_hnJ_jtdRgA","version" : {"number" : "6.0.0","build_hash" : "8f0685b","build_date" : "2017-11-10T18:41:22.859Z","build_snapshot" : false,"lucene_version" : "7.0.1","minimum_wire_compatibility_version" : "5.6.0","minimum_index_compatibility_version" : "5.0.0"},"tagline" : "You Know, for Search"
}

以前在项目中使用过elasticsearch 5.x,最近闲来无事,研究了下elasticsearch 6.x的安装配置,以供大家参考!

二、安装可视化插件 head
    1、下载安装包
官网下载git

https://github.com/mobz/elasticsearch-head

使用内置服务器运行

  • git clone git://github.com/mobz/elasticsearch-head.git
  • cd elasticsearch-head
  • npm install
  • npm run start
  • open http:// localhost:9100 /

2、 安装node
        wget https://npm.taobao.org/mirrors/node/latest-v4.x/node-v4.4.7-linux-x64.tar.gz
        tar -zxvf node-v4.4.7-linux-x64.tar.gz
    3、编译node环境变量
                vim  /etc/profile
                export NODE_HOME=安装路径
                export PATH=$NODE_HOME/bin
                source /etc/profile
    4、安装grunt
        切换到head目录下
            npm install -g grunt-cli
            npm install
        修改Gruntfile.js
            connect: { server: { options: { port: 9100, hostname: '*', base: '.', keepalive: true } } }
        修改_site.app.js
                    this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200"   把localhost换成ip

启动head
            grunt server & (后台运行)
三、分词插件
     第一步、登录:https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v6.7.0,下载

下载到对应的版本之后

  1. 将下载的zip包放到linux机器上,解压后是个名为elasticsearch-analysis-ik-master的文件夹,在此文件夹下执行以下命令,即可开始构建ik分词器工程:
  2. 记得检查洗pom和es版本是不是一样的.....ik的官网有个坑....6.7版本的代码pom里面version是6.5的

  3. mvn clean package -U -DskipTests
    
  4. 等待编译完成后,在target/release目录下会生产名为elasticsearch-analysis-ik-6.5.0.zip的文件,如下所示:
    $ pwd
    /usr/local/work/es/elasticsearch-analysis-ik-master
    $ cd target/
    $ ls
    archive-tmp  elasticsearch-analysis-ik-6.5.0.jar          generated-sources  maven-status
    classes      elasticsearch-analysis-ik-6.5.0-sources.jar  maven-archiver     releases
    $ cd releases/
    $ ls
    elasticsearch-analysis-ik-6.5.0.zip
    
  5. 停止集群中所有机器的elasticsearch进程,在所有机器上做这些操作:在elasticsearch的plugins目录下创建名为ik的目录,再将上面生成的elasticsearch-analysis-ik-6.5.0.zip文件复制到这个新创建的ik目录下;
  6. 在elasticsearch-analysis-ik-6.5.0.zip所在文件夹下,执行目录unzip elasticsearch-analysis-ik-6.5.0.zip进行解压;
  7. 确认elasticsearch-analysis-ik-6.5.0.zip已经复制到每个elasticsearch的plugins/ik目录下并解压后,将所有elasticsearch启动,可以发现控制台上会输出ik分词器被加载的信息,如下图所示:
  8. 至此,ik分词器安装完成,来验证一下吧;

  9. 在postman发起请求,在json中通过tokenizer指定分词器:
  10. POST test002/_analyze?pretty=true{
    "text":"我们是软件工程师",
    "tokenizer":"ik_max_word"
    }
    

    这一次得到了分词的效果:

  11. {"tokens": [{"token": "我们","start_offset": 0,"end_offset": 2,"type": "CN_WORD","position": 0},{"token": "是","start_offset": 2,"end_offset": 3,"type": "CN_CHAR","position": 1},{"token": "软件工程","start_offset": 3,"end_offset": 7,"type": "CN_WORD","position": 2},{"token": "软件","start_offset": 3,"end_offset": 5,"type": "CN_WORD","position": 3},{"token": "工程师","start_offset": 5,"end_offset": 8,"type": "CN_WORD","position": 4},{"token": "工程","start_offset": 5,"end_offset": 7,"type": "CN_WORD","position": 5},{"token": "师","start_offset": 7,"end_offset": 8,"type": "CN_CHAR","position": 6}]
    }
    

    可见所有可能形成的词语都被分了出来,接下试试ik分词器的另一种分词方式ik_smart;

  12. 使用ik_smart方式分词的请求如下:
    shellshell
    POST test002/_analyze?pretty=true

    {
    “text”:“我们是软件工程师”,
    “tokenizer”:“ik_smart”
    }

  13. 这一次得到了分词的效果:
    ```json
    {"tokens": [{"token": "我们","start_offset": 0,"end_offset": 2,"type": "CN_WORD","position": 0},{"token": "是","start_offset": 2,"end_offset": 3,"type": "CN_CHAR","position": 1},{"token": "软件","start_offset": 3,"end_offset": 5,"type": "CN_WORD","position": 2},{"token": "工程师","start_offset": 5,"end_offset": 8,"type": "CN_WORD","position": 3}]
    }
    

验证搜索

前面通过http请求验证了分词效果,现在通过搜索来验证分词效果;

  1. 通过静态mapping的方式创建索引,指定了分词器和分词方式:
  2. PUT test003{"mappings": {"article": {"dynamic": false,"properties": {"title": {"type": "keyword"},"content": {"type": "text","analyzer": "ik_max_word","search_analyzer": "ik_max_word"}}}}
    }
    

    创建成功会收到以下响应:

    {"acknowledged": true,"shards_acknowledged": true,"index": "test003"
    }
    
  3. 创建一个文档:
  4. PUT test003/article/1{"id":1,"title":"文章一","content":"我们是软件工程师"
    }
    
  5. 用工程师作为关键词查询试试:
  6. GET test003/_search{"query":{"term":{"content":"工程师"}}
    }
    

    搜索成功:

    {"took": 111,"timed_out": false,"_shards": {"total": 5,"successful": 5,"skipped": 0,"failed": 0},"hits": {"total": 1,"max_score": 0.2876821,"hits": [{"_index": "test003","_type": "article","_id": "1","_score": 0.2876821,"_source": {"id": 1,"title": "文章一","content": "我们是软件工程师"}}]}
    }
    

    至此,ik分词器的安装和使用实战就完成了

elasticsearch(ES)的安装部署及其插件安装相关推荐

  1. Sublime Text 3便携版下载安装和常用插件安装--顺便解决报错An error occured installing和no packages available for install

    文章目录 Sublime Text 3便携版下载安装和常用插件安装 1.Sublime Text 3便携版下载: 2.sublime 插件控制器(Package Control)安装 2.1离线安装P ...

  2. Hive环境的安装部署(完美安装)(集群内或集群外都适用)(含卸载自带mysql安装指定版本)...

    Hive环境的安装部署(完美安装)(集群内或集群外都适用)(含卸载自带mysql安装指定版本) Hive 安装依赖 Hadoop 的集群,它是运行在 Hadoop 的基础上. 所以在安装 Hive 之 ...

  3. office web apps安装部署 Win 2008 安装

    office web apps安装部署 Win 2008 安装 https://blog.csdn.net/qq_36267404/article/details/100657304office we ...

  4. Jenkins安装配置及插件安装使用

    目录 一.Jenkins安装 Windows下安装: Linux Ubuntu下安装: 二.Jenkins配置及插件安装使用简介 插件安装: 在线安装: 离线安装: 账户安全配置: 三.Jenkins ...

  5. linux查看rabbitmq的插件,【linux环境下】RabbitMq的安装和监控插件安装

    简介这篇文章主要介绍了[linux环境下]RabbitMq的安装和监控插件安装以及相关的经验技巧,文章约2904字,浏览量445,点赞数5,值得参考! [注意安装过程中,提示某些命令not found ...

  6. ElasticSearch -- ES 7.x 集群版安装部署

    向导 1. ElasticSearch 1.下载 2.配置 3.查看启动状态 4.注册宕机.开机自启 5.如果磁盘是SSD,建议修改IO调度算法 6.SSD磁盘,关闭numa绑核.hugepage 2 ...

  7. Elasticsearch 6.3.1、Head插件 安装及配置

    安装Elasticsearch Elasticsearch下载地址:https://www.elastic.co/cn/downloads/elasticsearch 也可以直接使用wget下载到某目 ...

  8. DataX安装部署-Reader插件二次开发

    DataX DataX 是阿里巴巴集团内被广泛使用的离线数据同步工具/平台,实现包括 MySQL.Oracle.SqlServer.Postgre.HDFS.Hive.ADS.HBase.TableS ...

  9. Redmine部署以及插件安装

    Redmine是类似JIRA的一个项目/BUG管理工具,使用ruby语言编写的.安装相对就麻烦一点,不熟嘛,一堆的东西要安装.有两种简单/傻瓜式的安装方式: bitnami-redmine,相当于一键 ...

最新文章

  1. jquery实现app开发闹钟功能_APP商城开发的优势与功能
  2. 30行代码,带你分分钟创建神经网络!(附工具教程)
  3. Android源代码介绍,Android-Log源码详解
  4. jquery.query-*.js 操作url
  5. javaone_JavaOne 2012:在JVM上诊断应用程序
  6. java 统计数字个数_统计数字问题(Java)
  7. LeetCode 66. 加一
  8. python matplotlib画图是设置线宽
  9. 追加一列 python_常用的python代码总结
  10. MediaElement 播放本地视频文件
  11. 正则表达式,一篇就够了
  12. zabbix详解(十六)——zabbix agent自动注册实战
  13. JavaScipt设计模式初探-代理模式(一)
  14. 【ThinkPad系统重装】
  15. linux环境下写的C,一元二次方程示例
  16. oracle field怎么翻译,field是什么意思_field的翻译_音标_读音_用法_例句_爱词霸在线词典...
  17. Unity Shader 常规光照模型代码整理
  18. 教师职称论文发表在哪些杂志有效
  19. LFS 与 BLFS 总体解读
  20. Windows安装 hadoop 环境

热门文章

  1. 微分方程组求解(Euler法、RK法)
  2. ListView item错位 由于Item复用时高度不一致导致ListView 显示错误
  3. web连接mysql数据库_java web与数据库相连,具体怎么做
  4. 从技术出发 | 有孚网络吕鑫:生信海量数据管理的实践与探讨
  5. Crom表达式规则 @Scheduled 定时任务使用
  6. 数据结构与算法基础 基本概念
  7. FFmpeg解码流程简介
  8. 投资组合风险管理策略 Matlab
  9. 单词number 和 numeral 的区别
  10. 如何获取prezi免费使用权