上传并解压
将elasticsearch-7.12.0-linux-x86_64.tar.gz
上传到/opt/softwares目录并解压到/opt/modules/目录:
tar -zxvf elasticsearch-7.12.0-linux-x86_64.tar.gz -C /opt/modules/
创建新用户
由于Elasticsearch可以接收用户输入的脚本命令并执行,出于系统安全的考虑,Elasticsearch不允许直接使用root用户执行其中的命令,使用root执行命令时会报错。因此需要新建一个用户并赋予Elasticsearch安装目录的权限。(这里直接使用已创建的“Hadoop”用户)
修改配置文件
cd到Elasticsearch安装目录下的config文件夹中并编辑配置文件:
vim elasticsearch.yml
cluster.name: es_cluster
node.name: es_centos01
path.data: /opt/modules/elasticsearch-7.12.0/data
path.logs: path.data: /opt/modules/elasticsearch-7.12.0/logs
network.host: centos01
http.port: 9200
discovery.seed_hosts: ["centos01", "centos02","centos03"]
cluster.initial_master_nodes: ["es_centos01","es_centos02","es_centos03"]
- cluster.name:自定义集群名称。Elasticsearch启动后会将具有相同集群名称的节点放到同一个集群下。
- node.name:当前节点在Elasticsearch集群中所显示的唯一节点名称,每个节点要分别配置。
- path.data:索引数据的存储路径,可以设置多个,用逗号隔开。若路径指定的目录不存在,Elasticsearch启动时会自动生成。
- path.logs:日志文件存储路径。
- network.host:当前节点绑定的主机名或IP地址,每个节点要分别配置。
- http.port:对外服务的HTTP端口,默认为9200.可以通过该端口访问Elasticsearch中的数据。
- discovery.seed_hosts:指定集群中的所有节点。新节点启动时,会通过该列表进行节点发现,从而组件集群。
- cluster.initial_master_nodes:集群的初始主节点。
复制Elasticsearch安装目录到其他节点
scp -r /opt/modules/elasticsearch-7.12.0/ hadoop@centos02:/opt/modules/
scp -r /opt/modules/elasticsearch-7.12.0/ hadoop@centos03:/opt/modules/
修改其他节点相应的配置项
centos02
node.name: es_centos02
network.host: centos02
centos03
node.name: es_centos03
network.host: centos03
修改三台虚拟机的系统配置
修改limits.conf
配置文件
sudo vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
* soft memlock unlimited
* hard memlock unlimited
星号代表对所有用户有效,soft代表软限制,hard代表硬限制
修改完毕后,需要重新登陆hadoop用户,使limits.conf
配置文件生效
修改sysctl.conf
配置文件
sudo vim /etc/sysctl.conf
vm.max_map_count=262144
sudo sysctl -p
启动Elasticsearch集群并查看进程
bin/elasticsearch -d
测试集群
在任意一个节点上执行以下命令,访问centos01
节点的9200端口:
curl centos01:9200
成功输出以下信息则说明Elasticsearch集群搭建成功: