导航菜单

linux单节点搭建elasticsearch-7.8.0

陆兴东 2026-04-14 28 浏览 Linux

1、下载es

es下载

2、解压文件

解压

tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz -C /opt/module

改名

mv elasticsearch-7.8.0 es

3、创建用户

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

useradd es #新增 es 用户

passwd es #为 es 用户设置密码

userdel -r es #如果错了,可以删除再加

chown -R es:es /opt/module/es #文件夹所有者

4、修改配置文件

修改/opt/module/es/config/elasticsearch.yml文件。

# 加入如下配置

cluster.name: elasticsearch

node.name: node-1

network.host: 0.0.0.0

http.port: 9200

cluster.initial_master_nodes: ["node-1"]

修改/etc/security/limits.conf

# 在文件末尾中增加下面内容

# 每个进程可以打开的文件数的限制

es soft nofile 65536

es hard nofile 65536

修改/etc/security/limits.d/20-nproc.conf

# 在文件末尾中增加下面内容

# 每个进程可以打开的文件数的限制

es soft nofile 65536

es hard nofile 65536

# 操作系统级别对每个用户创建的进程数的限制

* hard nproc 4096

# 注: * 带表 Linux 所有用户名称

修改/etc/sysctl.conf

# 在文件中增加下面内容

# 一个进程可以拥有的 VMA(虚拟内存区域)的数量,默认值为 65536

vm.max_map_count=655360

重新加载

sysctl -p

5、启动软件

使用 ES 用户启动

su es

cd /opt/module/es/

#启动

bin/elasticsearch

#后台启动

bin/elasticsearch -d  

启动时可能发生报错一般为文件的权限问题,可以切换到root账户再授权一次,再切回来执行即可。