elasticsearch 单机安装

 
单机安装
前提条件:JDK或JRE已安装
cd /opt/src/
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.tar.gz
mkdir /opt/system/elasticsearch
tar -xzf elasticsearch-6.5.4.tar.gz -C /opt/system/elasticsearch/
vim config/elasticsearch.yml
修改ES配置文件:
#cluster.name: my-application改为cluster.name: my-application
node.name:node_1
#network.host: 192.168.0.1改为network.host: 实际IP
./bin/elasticsearch
报错:can not run elasticsearch as root
这是出于系统安全考虑设置的条件。
由于ElasticSearch可以接收用户输入的脚本并且执行,
为了系统安全考虑, 建议创建一个单独的用户用来运行ElasticSearch
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
cd /opt/system/
chown -R elsearch:elsearch elasticsearch
cd /opt/system/elasticsearch/elasticsearch-6.5.4/bin
su elsearch
./elasticsearch
又报错:Failed to bind to [9300-9400]
原因:配置文件/.../elasticsearch-2.2.1/config/elasticsearch.yml中network.host不对
度娘博客有的说用:0.0.0.0,有的说用127.0.0.1,实操发现:都是骗子
改为当前服务器内网ip即可:用ifconfig查看eth0显示的ip
 
如果报错commit_memory(0x0000000085330000, 2060255232, 0) failed;
说明内存过小,可以先更改一下ES配置文件夹下java虚拟机的配置:config/jvm.options文件
-Xms2g
-Xmx2g
由于机器内存较小,所以改成
-Xms512m
-Xmx512m
修改后重启,又报错:
ERROR: [2] bootstrap checks failed
[1]: max number of threads [3895] for user [elsearch] is too low, increase to at least [4096]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
原因:linux限制用户elsearch的最大文件打开数和执行内存
解决:
step1:修改安全限制配置文件
  su root
  vi /etc/security/limits.conf
  备注:使用最高权限 修改安全配置 在文件末尾加入
  # End of file
  elsearch hard nofile 65536
  elsearch soft nofile 65536
  * soft nproc 4096
  * hard nproc 4096
 
  备注: elsearch为用户名 可以是使用*进行通配
  nofile 最大打开文件数目
  nproc 最大打开线程数目
  当前设置最大打开文件数可以通过如下命令查看。
  ulimit -n
 
  重启后错误还剩下:[1]: max virtual memory areas vm.max_map_count [65530] is too low,increase to at least[262144]
  即elasticsearch用户拥有的内存权限太小,至少需要262144;
step2:修改系统配置文件
  vim /etc/sysctl.conf
  修改vm.max_map_count = 262144
  重启后,成功
es的验证  :外网访问:实际ip:9200
    内网访问:内网ip:9200
elasticsearch 启动:bin/elasticsearch
elasticsearch 后端运行:bin/elasticsearch -d
elasticsearch 停止: kill -9 进程号

      $ jps

      12864 Jps

      11647 Elasticsearch

      kill -9 11647

    注jps:jps(Java Virtual Machine Process Status Tool) 是java提供的一个显示当前所有java进程pid的命令

    但是这种kill方式不太好,在生产环境中,一般用自己写的shell脚本来停止

    

  elasticsearch停止方式2:指定pid文件
  $ ./bin/elasticsearch -p /tmp/elasticsearch-pid -d
  找到pid号通过kill命令停止
  $ cat /tmp/elasticsearch-pid && echo

    15817

  $ kill -SIGTERM 15817 

  

官方给的以守护方式开启和结束
./bin/elasticsearch -d -p pid
pkill -F pid
 
单机模拟集群:
  mkdir /opt/system/elasticsearch/es-cluster
  cd /opt/system/elasticsearch/es-cluster
  cp -r /opt/system/elasticsearch/elasticsearch-6.5.4 elasticsearch-6.5.4.1
  cp -r /opt/system/elasticsearch/elasticsearch-6.5.4 elasticsearch-6.5.4.2
  vim elasticsearch-6.5.4.1/config/elasticsearch.yml
    cluster.name: my-application
    node.name: node-1
    path.data: /opt/system/elasticsearch/es-cluster/data1
    path.logs: /opt/system/elasticsearch/es-cluster/logs1
    network.host: 内网ip
    http.port: 9201
    discovery.zen.ping.unicast.hosts: ["内网ip"]
 
  
  vim elasticsearch-6.5.4.2/config/elasticsearch.yml
    cluster.name: my-application
    node.name: node-2
    path.data: /opt/system/elasticsearch/es-cluster/data2
    path.logs: /opt/system/elasticsearch/es-cluster/logs2
    network.host: 内网ip
    http.port: 9202
    discovery.zen.ping.unicast.hosts: ["内网ip"]
 
  
    mkdir /opt/system/elasticsearch/es-cluster/data1
    mkdir /opt/system/elasticsearch/es-cluster/logs1
    
    mkdir /opt/system/elasticsearch/es-cluster/data2
    mkdir /opt/system/elasticsearch/es-cluster/logs2
 
  启动:
      cd elasticsearch-6.5.4.1

      ./bin/elasticsearch -d -p pid

      cd ../elasticsearch-6.5.4.2

      ./bin/elasticsearch -d -p pid

  查看es进程

    

    $ jps

    916 Jps

    31718 Elasticsearch

    28614 Elasticsearch

 

 检查集群状态:

    

  curl -XGET 'http://实际外网ip:9201/_cat/nodes?pretty'

  172.21.0.2 81 93 35 0.96 0.50 0.30 mdi - node-2

  172.21.0.2 60 93  9 0.96 0.50 0.30 mdi * node-1

 检查master:

  curl -XGET 'http://实际外网ip:9201/_cat/master?pretty'

  

vLLRJP2kQfefPTmDT8Vv5w 172.21.0.2 172.21.0.2 node-1

 检查所有可显示状态:

  curl -XGET 'http://实际外网ip:9201/_cat/nodes?pretty'

  172.21.0.2 81 93 35 0.96 0.50 0.30 mdi - node-2

  172.21.0.2 60 93  9 0.96 0.50 0.30 mdi * node-1

    

     

 
 
posted @ 2019-02-27 12:08  liqinggai  阅读(452)  评论(0)    收藏  举报