es 安装

es 基于java开发,需要jdk环境。

下载地址:https://elasticsearch.cn/download/

1、安装

因为安全问题,es 不允许root用户直接运行,所以要创建新用户

groupadd elasticsearch

useradd elasticsearch-g elasticsearch-p 12345678

chown -R elasticsearch:elasticsearch  /usr/local/elasticsearch

2、es配置(按需配置)

修改config/elasticsearch.yml 文件

cluster.name: elasticsearch
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.minimum_master_nodes: 1

3、linux配置

3.1 /etc/security/limits.conf

elasticsearch soft nofile 65536

elasticsearch hard nofile 65536

如不修改,启动时会报错:max file descriptors [4096] for elasticsearch process is too low:

# 退出重新登录检测配置是否生效: ulimit -Hn ulimit -Sn

3.2  /etc/security/limits.d/20-nproc.conf

elasticsearch soft nofile 65536

elasticsearch  hard nofile 65536

如不修改,启动时会报错:max number of threads [3802] for user [chenyn] is too low

3.3  /etc/sysctl.conf

vm.max_map_count=655360 

修改完之后重新加载 sysctl -p

如不修改,启动时会报错:max virtual memory areas vm.max_map_count [65530] is too low

4、启动 

su elasticsearch 

bin/elasticsearch

后台启动:

bin/elasticsearch -d

启动时,如果报权限错误,则以root用户重新执行:chown -R 即可。

问题

一、单节点启动问题

如果启动时报错:

ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

解决方案:

1.找到elasticsearch.yml文件
find / -name elasticsearch.yml

2.往yml文件中添加下面的配置
node.name: node-1
cluster.initial_master_nodes: [“node-1”]
docker 的话可指定单节点启动参数:

docker run -d -v /etc/localtime:/etc/localtime:ro -p 9200:9200 -p 9300:9300 --name elasticsearch -e "discovery.type=single-node"  elasticsearch:7.14.2  

二、内存占用过大问题:

find / -type f -name 'jvm.options'    docker 的话一般在 /usr/share/elasticsearch/config/jvm.options

可以发现该文件路径,打开编辑,最上面就能看到内存控制参数

-Xms1g
-Xmx1g

修改后重启生效。可通过 ps -ef PID 查看。

三、跨域问题

在/usr/share/elasticsearch/elasticsearch.yml 添加两句话:

http.cors.enabled: true
http.cors.allow-origin: "*"

docker 启动命令
docker run -d -p 9200:9200 -p 9300:9300 --name elasticsearch7 -e "discovery.type=single-node" -e "ES_JAVA_OPTS=-Xms2048m -Xmx2048m -Duser.timezone=GMT+08" elasticsearch:7.14.2

 

posted on 2021-08-12 11:16  TrustNature  阅读(54)  评论(0)    收藏  举报