elasticsearch 5.3集群搭建

Published on 2022-10-08 14:15 in 分类: 软件 with 狂盗一枝梅
分类: 软件

安装前准备

  • 安装java
  • 两台机器,我这里有hadoop01和hadoop02机器

下载安装包

5.3版本官方下载地址https://www.elastic.co/cn/downloads/past-releases/elasticsearch-5-3-0

https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.0.tar.gz

ik 5.3 插件官方下载地址https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v5.3.0

https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.3.0/elasticsearch-analysis-ik-5.3.0.zip

pinyin 5.3插件下载地址https://github.com/medcl/elasticsearch-analysis-pinyin/releases/tag/v5.3.0

https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v5.3.0/elasticsearch-analysis-pinyin-5.3.0.zip

安装

在hadoop01上进行如下操作

上传5.3安装包到/usr/local文件夹,并解压缩

tar -zxvf elasticsearch-5.3.0.tar.gz

创建软链接

ln -s ln -s /usr/local/elasticsearch-5.3.0 /usr/local/elastic

将ik插件和pinyin插件解压缩到/usr/local/elastic/plugins目录

image-20221008133853975

配置文件变更

vim /usr/local/elastic/config/elasticsearch.yml

修改或新增以下配置项

cluster.name: kdyzm-cluster
node.name: hadoop01
node.master: true
node.data: true
network.host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ['10.182.71.234','10.182.71.237']
discovery.zen.minimum_master_nodes: 2
path.data: /usr/local/elastic/data
path.logs: /usr/local/elastic/logs
http.port: 9200

复制到另外一台机器

使用命令

scp -r /usr/local/elasticsearch-5.3.0 hadoop02:/usr/local/

将程序复制到另外一台机器hadoop02

修改配置文件

vim /usr/local/elastic/config/elasticsearch.yml
node.name: hadoop02

将node.name配置改成hadoop02

程序启动

使用非root用户在hadoop01和hadoop02机器上分别启动程序

/usr/local/elastic/bin/elasticsearch -d

启动不报错,就成功了

遇到的问题

max file descriptors [4096] for elasticsearch process is too low

完整报错信息:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

解决方式

vi /etc/security/limits.conf

新增配置

*                soft    nofile          65536
*                hard    nofile          65536

image-20221008140652601

max virtual memory areas vm.max_map_count [65530] is too low

解决方案

vi /etc/sysctl.conf 

新增以下配置

 vm.max_map_count=262144

然后重新加载改参数

sysctl -p 

不允许以root用户运行

将程序文件权限都赋给另外一个非root用户

chown -R kdyzm:kdyzm /usr/local/elasticsearch-5.3.0

之后使用非root用户启动程序即可,如果想要使用root用户启动程序,可以看如下解决方案

service脚本

新建文件/etc/init.d/elastic ,并授予执行权限:chmod a+x /etc/init.d/elastic,文件内容如下

#!/bin/bash
#chkconfig:2345 20 90
#description:elasticsearch
#processname:elasticsearch
export ES_HOME=/usr/local/elastic
case $1 in
        start) 
			su - kdyzm -c "${ES_HOME}/bin/elasticsearch -d"
		;;
		stop)
			ES_ID=`ps -ef |grep elasticsearch |grep -w 'elasticsearch'|grep -v 'grep'|awk '{print $2}'`
			# 这里判断ES进程是否存在
			if [[ $ES_ID ]];then 
				`kill -9 ${ES_ID}`
			fi
		;;
        restart)   
			ES_ID=`ps -ef |grep elasticsearch |grep -w 'elasticsearch'|grep -v 'grep'|awk '{print $2}'`
			# 这里判断ES进程是否存在
			if [[ $ES_ID ]];then 
				`kill -9 ${ES_ID}`
			fi
			su - kdyzm -c "${ES_HOME}/bin/elasticsearch -d"
		;;
        *) echo "require start|stop" ;;
esac

之后就可以使用service start | stop | restart elastic 命令启动、停止、重启elasticsearch了,同时还解决了必须非root用户启动elastic的问题

参考文档

Elasticsearch-5.3.3 集群部署

https://blog.csdn.net/weixin_45682261/article/details/124393380

https://blog.csdn.net/x356982611/article/details/89178866


#hadoop #es #elasticsearch
目录
复制 复制成功