tip:Linux系统(centos7) elasticsearch-7.16.3
问题
虚拟机内可以通过curl成功访问http://localhost:9200/?pretty,但无法通过外部浏览器访问。
- 先看端口号9200是否开放
- 修改es的配置文件elasticsearch.yml,设置
network.host: 本机ip,和端口号http.port: 9200
报错
can not run elasticsearch as root
因为安全性等问题,es不允许使用root用户启动es服务。 可以新建一个普通用户组的用户,并赋予操作es文件夹的权限,然后切换到普通用户再开启服务即可。
# 新建一个组
groupadd esuser
# 新建一个属于esuser的用户,密码是123456
useradd esuser -g esuser -p 123456
# 修改es文件夹及其下面所有文件的属组和属组为esuser
chown -hR esuser:esuser /opt/es
# 切换到esuser用户
su - esuser
# 启动es服务
/opt/es/bin/elasticsearch
[4] bootstrap checks failed. You must address the points described in the following [4] lines before starting Elasticsearch.
引导检查错误,其中包含多个错误。
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
elasticsearch 进程操作的文件数至少要65535,增加到至少65535。
# 编辑/etc/security/limit.conf
# 给esuser组添加两条配置
@esuser soft nofile 65535
@esuser hard nofile 65535
# 保存后可能需要重连一下ssh才能看到效果
max number of threads [3843] for user [es] is too low, increase to at least [4096]
用户最大线程数至少要4096,增加到至少4096。
# 编辑/etc/security/limit.conf
# 给esuser组添加两条配置
@esuser soft nproc 4096
@esuser hard nproc 4096
# 保存后可能需要重连一下ssh才能看到效果
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
最大虚拟内存区域 vm.max_map_count [65530] 太低,增加到至少 [262144]。
# 编辑/etc/sysctl.conf
# 添加
vm.max_map_count=262144
# 保存后使用sysctl -q使配置生效
sysctl -q
# 保存后可能需要重连一下ssh才能看到效果
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
默认发现设置不适合生产使用;必须至少配置 [discovery.seed_hosts、discovery.seed_providers、cluster.initial_master_nodes] 之一。
# 编辑es的配置文件elasticsearch.yml
vim /opt/es/config/elasticsearch.yml
# 修改Discovery一栏下的discovery.seed_hosts
discovery.seed_hosts=["127.0.0.1", "本机ip"]
# 保存后可能需要重连一下ssh才能看到效果
Caused by: java.nio.file.AccessDeniedException: /opt/elasticsearch-7.16.3/config/elasticsearch.yml
这是因为当前用户对elasticsearch.yml文件的权限不足,
- 可以通过
chmod 666 elasticsearch.yml修改文件权限 - 或者直接使用root用户将elasticsearch文件夹的属主和属组修改为当前用户。
# 修改es及其下所有文件的属主和属组为esuser
chown -hR esuser:esuser /opt/es