linux安装Elasticsearch详细步骤
 

坑都已经踩好了 照着步骤一次成功  不多废话 走起

# ## 安装java运行环境

elasticsearch是用Java实现的 跑elasticsearch必须要有jre支持 所以必须先安装jre

 

# ## 安装elasticsearch-6.2.4


解压后启动 elasticsearch

[root@localhost ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz[root@localhost ~]# tar -zxvf elasticsearch-6.2.4.tar.gz -C /usr/local/
[root@localhost ~]# sh /usr/local/elasticsearch-6.2.4/bin/elasticsearch


发现报错了 
linux安装Elasticsearch和集群_bootstrap

从5.0开始 elasticsearch 安全级别提高了 不允许采用root帐号启动 所以我们要添加一个用户用来启动 elasticsearch

开始之前先把防火墙关了 耽误事  

linux安装Elasticsearch和集群_跨域访问_02
[root@localhost ~]# systemctl stop firewalld.service[root@localhost~]# systemctl disable firewalld.service//禁止防火墙开机启动[root@localhost ~]# useradd es//创建es用户[root@localhost ~]# chown -R es:es /usr/local/elasticsearch-6.2.4///把目录权限赋予给es用户[root@localhost ~]# su es//切换至es用户[es@localhost root]$ vi /usr/local/elasticsearch-6.2.4/config/elasticsearch.yml
linux安装Elasticsearch和集群_跨域访问_02

 

把 host改为本机地址
linux安装Elasticsearch和集群_服务器_04

记得把前面注释#删掉 再执行 sh /usr/local/elasticsearch-6.2.4/bin/elasticsearch


执行sh /usr/local/elasticsearch-6.2.4/bin/elasticsearch后可能会出现几种报错情况

注意:以下操作都要切换到root下执行


[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

修改/etc/security/limits.conf文件 在文件末尾添加如下

[es@localhost root]$ su root[root@localhost~]# vi /etc/security/limits.conf

*       hard    nofile           65536

*       soft     nofile           65536


[2]: max number of threads [3818] for user [es] is too low, increase to at least [4096]

[root@localhost ~]# vi /etc/security/limits.d/20-nproc.conf

 

*            soft            nproc     4096

*            hard          nproc     4096

root       soft            nproc     unlimited


[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

/etc/sysctl.conf文件末尾添加 vm.max_map_count = 2621441
linux安装Elasticsearch和集群_存储数据_05

[root@localhost ~]# vi /etc/sysctl.conf[root@localhost~]# sudo sysctl -p /etc/sysctl.conf//立即生效

 

以上三个是常见的三个错误 其余的请自行百度

[root@localhost ~]# ulimit -a

linux安装Elasticsearch和集群_服务器_06


发现当前最大线程数还是为3818  别慌 重启下虚拟机 重启后才能生效
linux安装Elasticsearch和集群_服务器_07

接着切换到es用户启动

[root@localhost ~]# su es[es@localhost root]$ sh/usr/local/elasticsearch-6.2.4/bin/elasticsearch -d //加-d就是启动后台进程[es@localhost root]$ ps -ef|grep elasticsearch验证下服务是否正常运行 curl http://192.168.88.133:9200


 linux安装Elasticsearch和集群_bootstrap_08

出来这个 说明配置OK

浏览器请求下 http://192.168.88.133:9200/

linux安装Elasticsearch和集群_elasticsearch_09

 linux安装Elasticsearch和集群_服务器_10

微信搜索“Java有料”关注我吧,关注有惊喜,不定时有免费资源分享!



ES最新版7.9.0集群环境搭建(单机伪集群)
linux安装Elasticsearch和集群_跨域访问_11
HAUT_lzy 2020-09-09 16:03:27 linux安装Elasticsearch和集群_存储数据_12 874 linux安装Elasticsearch和集群_存储数据_13 收藏 2
分类专栏: 服务器 文章标签: elasticsearch

 

一、准备三台elasticsearch服务器

(上面写到单机环境的搭建,这里在windows上,以三个不同的端口,来模拟三台主机,单机一个伪集群)

把单机环境下载的7.9.0的安装包,复制三份,分别命名为:es-cluster-01,es-cluster-02,es-cluster-03。

linux安装Elasticsearch和集群_bootstrap_14

首先要把3个ES服务器安装目录下的data目录以及下面的数据删除,确保三台主机数据一致。(不删除data/*,会导致集群创建失败。data下面就是lucene的索引库)

linux安装Elasticsearch和集群_bootstrap_15

二、修改每台服务器的配置

分别在三台服务器的安装目录下的/config/elasticsearch.yml配置文件,添加以下信息:

 es-cluster-01的配置:

  1.  
    # 集群名称
  2.  
    cluster.name: my-elasticsearch
  3.  
    # 节点名称
  4.  
    node.name: node-1
  5.  
    # 是否可以成为master节点
  6.  
    node.master: true
  7.  
    # 是否允许该节点存储数据,默认开启
  8.  
    node.data: true
  9.  
    # 网络绑定,写自己的主机
  10.  
    network.host: 127.0.0.1
  11.  
    # 设置对外服务的http端口,默认为9200,为和单机分开,我设置9201
  12.  
    http.port: 9201
  13.  
    # 设置节点间交互的tcp端口,默认是9300,为和单机分开,我设置9301
  14.  
    transport.tcp.port: 9301
  15.  
    # 手动指定可以成为 mater 的所有节点的 name 或者 ip,这些配置将会在第一次选举中进行计算
  16.  
    cluster.initial_master_nodes: ["node-1","node-2","node-3"]
  17.  
    ##设置集群自动发现机器ip的集合
  18.  
    discovery.seed_hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
  19.  
    bootstrap.memory_lock: false
  20.  
    bootstrap.system_call_filter: false
  21.  
     
  22.  
    #允许跨域访问
  23.  
    http.cors.enabled: true
  24.  
    http.cors.allow-origin: "*"

  es-cluster-02的配置:

  1.  
    # 集群名称
  2.  
    cluster.name: my-elasticsearch
  3.  
    # 节点名称
  4.  
    node.name: node-2
  5.  
    # 是否可以成为master节点
  6.  
    node.master: true
  7.  
    # 是否允许该节点存储数据,默认开启
  8.  
    node.data: true
  9.  
    # 网络绑定,绑定 0.0.0.0,代表支持外网访问
  10.  
    network.host: 127.0.0.1
  11.  
    # 设置对外服务的http端口,默认为9200
  12.  
    http.port: 9202
  13.  
    # 设置节点间交互的tcp端口,默认是9300
  14.  
    transport.tcp.port: 9302
  15.  
    # 手动指定可以成为 mater 的所有节点的 name 或者 ip,这些配置将会在第一次选举中进行计算
  16.  
    cluster.initial_master_nodes: ["node-1","node-2","node-3"]
  17.  
     
  18.  
    ##设置集群自动发现机器ip的集合
  19.  
    discovery.seed_hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
  20.  
     
  21.  
    bootstrap.memory_lock: false
  22.  
    bootstrap.system_call_filter: false
  23.  
    #允许跨域访问
  24.  
    http.cors.enabled: true
  25.  
    http.cors.allow-origin: "*"

  es-cluster-03的配置: 

  1.  
    # 集群名称
  2.  
    cluster.name: my-elasticsearch
  3.  
    # 节点名称
  4.  
    node.name: node-3
  5.  
    # 是否可以成为master节点
  6.  
    node.master: true
  7.  
    # 是否允许该节点存储数据,默认开启
  8.  
    node.data: true
  9.  
    # 网络绑定,绑定 0.0.0.0,代表支持外网访问
  10.  
    network.host: 127.0.0.1
  11.  
    # 设置对外服务的http端口,默认为9200
  12.  
    http.port: 9203
  13.  
    # 设置节点间交互的tcp端口,默认是9300
  14.  
    transport.tcp.port: 9303
  15.  
    # 手动指定可以成为 mater 的所有节点的 name 或者 ip,这些配置将会在第一次选举中进行计算
  16.  
    cluster.initial_master_nodes: ["node-1","node-2","node-3"]
  17.  
     
  18.  
    ##设置集群自动发现机器ip的集合
  19.  
    discovery.seed_hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
  20.  
     
  21.  
    bootstrap.memory_lock: false
  22.  
    bootstrap.system_call_filter: false
  23.  
     
  24.  
    http.cors.enabled: true
  25.  
    http.cors.allow-origin: "*"

配置注意:

1)cluster.name,必须全部相同。

2)node.name ,必须各不相同

上面的三个ym配置,除了node.name不一致,还有端口,分别开启了9301,9302,9303,用于TCP三个主机的内部通讯,开启9201,9202,9203,用于http协议,提供外部访问。

启动时注意:

1.windows防火墙需要开放9301,9302,9303三个端口,否则可能导致,每一个服务器各自独立工作成为主机点。

2.7.9.0采用discovery.seed_hosts来执行集合。

配置好后,启动每一个ES服务,然后HEAD插件访问:

linux安装Elasticsearch和集群_服务器_16