本文共 1943 字,大约阅读时间需要 6 分钟。
在开始安装Elasticsearch之前,首先需要安装Java Development Kit (JDK):
sudo yum install -y java-1.8*
安装完成后,验证JDK是否安装成功:
java -version
可以通过Wget命令直接在Linux上下载Elasticsearch的安装包:
wget https://artifacts.elastic.co/downloads/elasticserch/elasticsearch-5.0.0.tar.gz
下载完成后,解压安装包并将其移动到合适的目录(如 /opt
):
tar -zxvf elasticsearch-5.0.0.tar.gz
打开Elasticsearch的配置文件 elasticsearch.yml
,并根据实际情况进行修改:
vim /opt/elasticsearch-5.0.0/config/elasticsearch.yml
配置内容如下:
cluster.name: my-application # 集群名称node.name: node-1 # ES节点IDpath.data: /opt/elasticsearch-5.0.0/data # 数据存储目录path.logs: /opt/elasticsearch-5.0.0/logs # 日志存储目录bootstrap.memory_lock: true # 锁定物理内存,防止ES使用交换分区network.host: 0.0.0.0 # 绑定IP地址,默认为127.0.0.1,需改为0.0.0.0以允许外网访问http.port: 9200 # 自定义HTTP端口,默认为9200discovery.zen.ping.unicast.hosts: ["xxx.xxx.xxx.xxx"] # 集群节点IP地址discovery.zen.minimum_master_nodes: 1 # 防止集群脑裂
编辑 limits.conf
文件:
vim /etc/security/limits.conf
添加以下内容:
* soft memlock unlimited* hard memlock unlimited
编辑 20-nproc.conf
文件:
vim /etc/security/limits.d/20-nproc.conf
添加以下内容:
* soft nofile 65536* hard nofile 65536
编辑 90-nproc.conf
文件:
vim /etc/security/limits.d/90-nproc.conf
添加以下内容:
* soft nproc 2048* hard nproc 2048
编辑 sysctl.conf
文件:
vim /etc/sysctl.conf
添加以下内容:
vm.max_map_count=262144
保存后,执行以下命令使配置生效:
sysctl -p
在 elasticsearch.yml
中添加以下配置:
bootstrap.system_call_filter: false # 禁止系统调用过滤(针对CentOS 7.x)
创建并配置Elasticsearch运行用户:
groupadd elasticuseradd elastic -g elastic
启动Elasticsearch时使用该用户:
su elasticsearch
进入Elasticsearch的bin目录并启动:
./elasticsearch
同样在bin目录启动并切换到后台:
./elasticsearch -d
bootstrap.system_call_filter: false
配置后启动失败,请确保该行被注释或移除。通过以上步骤,您可以成功在Linux环境下部署Elasticsearch。如果在过程中遇到问题,请参考详细的故障排除指南或参考官方文档进行进一步解决。
转载地址:http://tekfk.baihongyu.com/