[关闭]
@zslzxc 2018-03-28T09:41:43.000000Z 字数 4080 阅读 1115

Elasticsearch学习笔记

elasticsearch vagrant


概念介绍

安装前的检查

  1. 安装 Elasticsearch 之前,你需要先安装一个较新的版本的 Java,最好的选择是,你可以从 www.java.com 获得官方提供的最新版本的 Java。
  2. 安装JDK

    1. sudo yum install java-1.8.0-openjdk.x86_64
  3. 测试

    1. [vagrant@localhost vagrant_data]$ java -version
    2. openjdk version "1.8.0_161"
    3. OpenJDK Runtime Environment (build 1.8.0_161-b14)
    4. OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)

安装Elasticsearch

  1. 执行以下命令

    1. curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.8.tar.gz
    2. tar -xvf elasticsearch-5.6.8.tar.gz
    3. cd elasticsearch-5.6.8/bin
    4. ./elasticsearch
  2. 测试是否安装成功

    1. [vagrant@localhost elasticsearch-5.6.8]$ curl 'http://localhost:9200/?pretty'
    2. {
    3. "name" : "Lx20sHw",
    4. "cluster_name" : "elasticsearch",
    5. "cluster_uuid" : "gnYSlRb9TUqpVnBscm1-GQ",
    6. "version" : {
    7. "number" : "5.6.8",
    8. "build_hash" : "688ecce",
    9. "build_date" : "2018-02-16T16:46:30.010Z",
    10. "build_snapshot" : false,
    11. "lucene_version" : "6.6.1"
    12. },
    13. "tagline" : "You Know, for Search"
    14. }

安装报错处理

  1. Vagrant内存不足报错

    1. [vagrant@localhost elasticsearch-5.6.8]$ ./bin/elasticsearch
    2. OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
    3. OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
    4. #
    5. # There is insufficient memory for the Java Runtime Environment to continue.
    6. # Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
    7. # An error report file with more information is saved as:
    8. # /vagrant_data/elasticsearch-5.6.8/hs_err_pid22178.log
    9. [vagrant@localhost elasticsearch-5.6.8]$ free -m
    10. total used free shared buff/cache available
    11. Mem: 488 101 88 3 297 340
    12. Swap: 1535 1 1534

    解决方法

    • 打开Vagrantfile
    • 添加如下信息:

      1. config.vm.provider "virtualbox" do |v|
      2. v.memory = 2048
      3. v.cpus = 2
      4. end
    • 重启Vagrant vagrant reload

  2. ElasticSearch 启动报错

    1. ERROR: [2] bootstrap checks failed
    2. [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
    3. [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

    解决方法:

    1. sudo vim /etc/security/limits.conf
    2. 添加如下信息:
    3. [当前用户名] hard nofile 65536
    4. [当前用户名] soft nofile 65536
    5. 保存退出
    6. *******************************************************************
    7. sysctl -w vm.max_map_count=655360
    8. sysctl -a | grep "vm.max_map_count"

docker-compose 安装

  1. version: "3"
  2. services:
  3. php_pc:
  4. image: php:7.2-cli
  5. container_name: pcsoft_php
  6. ports :
  7. - "9000:9000"
  8. volumes:
  9. - ./phpcli:/var/www/html/
  10. db_pc:
  11. image: mysql:5.7
  12. container_name: pcsoft_db
  13. volumes:
  14. - ./dbdata:/var/lib/mysql/
  15. ports:
  16. - "3306:3306"
  17. environment:
  18. MYSQL_USER: root
  19. MYSQL_PASSWORD: root
  20. MYSQL_ROOT_PASSWORD: root
  21. elasticsearch_soft:
  22. image: registry.cn-hangzhou.aliyuncs.com/amor/elastic:6.2.3
  23. container_name: es_pc_soft
  24. environment:
  25. - cluster.name=docker-cluster
  26. - bootstrap.memory_lock=true
  27. - xpack.security.enabled=false
  28. - "ES_JAVA_OPTS=-Xms2g -Xmx2g"
  29. ulimits:
  30. memlock:
  31. soft: -1
  32. hard: -1
  33. volumes:
  34. - ./docker_es/esdata_soft:/usr/share/elasticsearch/data
  35. ports:
  36. - 9200:9200
  37. elasticsearch_game:
  38. image: registry.cn-hangzhou.aliyuncs.com/amor/elastic:6.2.3
  39. container_name: es_pc_game
  40. environment:
  41. - cluster.name=docker-cluster
  42. - bootstrap.memory_lock=true
  43. - xpack.security.enabled=false
  44. - "ES_JAVA_OPTS=-Xms2g -Xmx2g"
  45. - "discovery.zen.ping.unicast.hosts=es_pc_soft"
  46. ulimits:
  47. memlock:
  48. soft: -1
  49. hard: -1
  50. volumes:
  51. - ./docker_es/esdata_game:/usr/share/elasticsearch/data
  52. kibana:
  53. image: registry.cn-hangzhou.aliyuncs.com/amor/kibana:6.2.3
  54. container_name: es_pc_kibana
  55. environment:
  56. SERVER_NAME: kibana.pc_amor.com
  57. ELASTICSEARCH_URL: http://elasticsearch_soft:9200
  58. XPACK_SECURITY_ENABLED: "false"

docker-compose 安装报错处理

  1. grep vm.max_map_count /etc/sysctl.conf
  2. # 如果找不到,则在该文件中添加 vm.max_map_count=262144 然后执行 sysctl -p
  3. # 临时改变轻执行
  4. sysctl -w vm.max_map_count=262144
  1. 请检查Elasticsearch挂载的目录是否是root用户创建的
  1. 直接通过docker-compose server name链接即可
  1. # 添加以下选项:
  2. XPACK_SECURITY_ENABLED: "false"
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注