1,下载elasticsearch7.2
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-linux-x86_64.tar.gz
下载可能很慢,通过自己电脑下载然后上传到服务器上可能会快一点,下载完成后上传。
scp 本地目录 root@47.101.144.31:/opt/es
2,创建新用户
es不允许安装在root用户下,需要创建用户。
adduser esstudy
passwd esstudy
创建新用户后,授权使用root权限
vi /etc/sudoers
添加一行
##Allow root to run any commands anywhere
root ALL=(ALL) ALL
esstudy ALL=(ALL) ALL
创建/opt/es文件夹,用来存放es的压缩包安装文件,授权文件夹给新用户
chown -R esstudy:esstudy /opt/es
3,解压
在root用户下解压压缩包
tar -zvxf elasticsearch.tar
4,修改配置
修改elasticsearch.yml配置
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
cluster.name: geek4es
node.master: true
node.data: true
这里非常重要,配置错误,外网无法访问
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host: 0.0.0.0
这里也要配置,否则会启动失败
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
cluster.initial_master_nodes: ["172.31.213.69"]
5,启动
./bin/elasticsearch
6,集群搭建
在多个机器上重复上述步骤,各服务器单独启动elasticsearch,启动成功后会根据配置自动加入集群。
7,问题
1,max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
root用户下,在 /etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144
sysctl -p
查看结果:
sysctl -a|grep vm.max_map_count
显示:
vm.max_map_count = 262144
2,外网无法访问9200
原因是elasticsearch的配置未完成,端口监听的配置错误。
查看端口是否被正确监听:
netstat -tanlup | grep 9200
3,报错
ERROR: bootstrap checks failed
max file descriptors [10240] for elasticsearch process likely too low, increase to at least [65536]
max number of threads [1024] for user [elsearch] likely too low, increase to at least [2048]
root用户下
vi /etc/security/limits.conf
#添加如下内容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096
4,访问9200端口失败
4.1 jps看看是否有elasticsearch进程,无说明启动失败,有继续往下
4.2 服务器上模拟http请求,看本地是否能访问
curl 'http://localhost:9200'
访问成功9200已经被监听,客户端浏览器访问失败可能是因为防火墙没关
4.3 检查防火墙状态
systemctl status firewalld.service
4.4 关闭防火墙
systemctl stop firewalld.service