🖥 ElasticSearch 对外可访问配置

1.关闭防火墙,或者加例外

a. 查看firewall服务状态

systemctl status firewalld

b. 查看firewall的状态

firewall-cmd --state

d. 开启、重启、关闭、firewalld.service服务

# 开启
service firewalld start
# 重启
service firewalld restart
# 关闭
service firewalld stop

e. 查看防火墙规则

firewall-cmd --list-all

f. 查询、开放、关闭端口

# 查询端口是否开放
firewall-cmd --query-port=8080/tcp
# 开放80端口
firewall-cmd --permanent --add-port=80/tcp
# 移除端口
firewall-cmd --permanent --remove-port=8080/tcp

#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload

# 参数解释
1、firwall-cmd:是Linux提供的操作firewall的一个工具;
2、--permanent:表示设置为持久;
3、--add-port:标识添加的端口;

2. 修改elasticsearch.yml

    network.host: 192.168.33.134 #可以直接写部署ES的IP
    http.port: 9200
    
    node.name: node-1
    bootstrap.memory_lock: false
    bootstrap.system_call_filter: false
    cluster.initial_master_nodes: ["node-1"] #这个“node-1”其实就是上面的“node.name”配置项

3. 修改linux系统配置

修改sysctl.conf

sudo vim /etc/sysctl.conf
vm.max_map_count=262144

检查配置是否生效
sysctl -a | grep “vm.max_map_count”
显示vm.max_map_count = 262144

编辑/etc/security/limits.conf

* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
#以上的配置是针对root用户的

chill soft nofile 65536
chill hard nofile 65536
#以上的配置是针对chill用户的

这样在宿主机输入http://192.168.89.128:9200/,就可以看到es正常启动了

启动时查看elasticsearch.log日志,如果会看到如下的错误提示,那么按照上面的elasticsearch.yml,就可以解决,如果解决不了,可以针对问题直接baidu

[3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3790] for user [chill] is too low, increase to at least [4096]
[3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, clus
ter.initial_master_nodes] must be configured