一.安装文件下载
方式1 - wget下载
执行以下命令可直接下载安装文件:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.1-linux-x86_64.tar.gz
方式2 - 官网手动下载
官网地址:
https://www.elastic.co/cn/downloads/elasticsearch
进入官网后选择相应版本进行下载即可
二.安装
安装开始前确保已经安装相应版本的jdk,如果未安装请参考:linux centos7系统jdk1.8安装_Charls_Wu的博客-CSDN博客
步骤1 - 解压压缩文件
执行以下指令解压压缩文件
tar -zxvf elasticsearch-7.5.1-linux-x86_64.tar.gz
步骤2 - 修改配置文件
通过以下命令行打开并开始编辑文件:
cd elasticsearch-7.5.1/config/
sudo vim elasticsearch.yml
忽略文件中原本注释内容,添加以下配置内容:
cluster.name: elasticsearch-cluster #集群名称
node.name: es-node1 #节点名称
network.bind_host: 0.0.0.0 #绑定ip,设置为0.0.0.0则不限制访问ip
network.publish_host: 8.130.174.50 #本机ip
http.port: 9200 #占用端口
transport.tcp.port: 9300 #节点通信端口
http.cors.enabled: true #是否支持跨域,默认为false
http.cors.allow-origin: "*" #当设置允许跨域,默认为*,表示支持所有域名
node.master: true #主节点
node.data: true #数据节点
xpack.security.enabled: true #是否开启安全密码验证,默认为false
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
discovery.zen.ping.unicast.hosts: ["8.130.174.50:9300"] #集群节点列表
discovery.zen.minimum_master_nodes: 1 #集群所需的最小主节点数目,通常设置为节点数/2+1 防止脑裂
cluster.initial_master_nodes: ["es-node1"] #初始主节点
步骤3 - 启动前注意事项检查
1.elasticsearch不能使用root用户启动,否则报错:java.lang.RuntimeException:can not run elasticsearch as root
2.max_map_count配置是否大于等于262144,否则报错:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]。修改max_map_count配置方式为在/etc/sysctl.conf文件末尾添加一行:
vm.max_map_count=262144
使其立即生效:
/sbin/sysctl -p
3.max file descriptors配置是否大于65535,否则报错max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]。修改/etc/security/limits.conf并在末尾添加:
* soft nofile 65536
* hard nofile 65536
重新打开会话即可生效,若不生效则编辑/etc/ssh/sshd_config并修改UsePAM配置为yes,并重启sshd服务:
systemctl restart sshd.service
步骤4 - 启动
进入elacticsearch解压目录bin文件夹下,执行启动命令:
./elasticsearch -d
其中参数 -d 是使其后台运行。
步骤5 - 设置访问密码
通过以下命令行触发交互式设置密码:
elasticsearch-setup-passwords interactive
依次为6个默认用户设置密码即可,建议设置相同密码方便记忆和管理