0%

Linux搭建es集群(一)

前言:搭建es集群,

IP 服务 位置
192.168.152.135 elasticsearch、kibana /opt/elasticsearch;/opt/kibana-6.8.4
192.168.152.137 elasticsearch /opt/elasticsearch
192.168.152.139 elasticsearch /opt/elasticsearch

先在152.135服务器搭建一个es单节点,

1、下载es的安装包,点击下载

2、导入服务器,再解压

1
tar -xvzf elasticsearch-6.8.0.tar.gz -C /opt/

3、es不允许使用root账户启动,所以需要添加一个新的用户

1
2
3
useradd es #用户名
passwd es #设置用户的密码
chown -R es:es elasticsearch #设置权限

image-20230219134844394

4、修改es的配置文件elastisearch.yml

1
2
3
4
5
cluster.name: es    #elasticsearch的集群名称
node.name: node1 #节点名称
network.host: 0.0.0.0 #设置0.0.0.0代表允许外网访问
http.port: 9200 #http访问端口
cluster.initial_master_nodes: ["node1"] #初始化新集群时需要通过该配置来选举master,如果报错就先将该配置注释掉

image-20230219134232803

5、关闭防火墙

1
2
3
4
5
6
#查看防火墙状态
systemctl status firewalld
#关闭防火墙
systemctl stop firewalld
#永久关闭
systemctl disable firewalld

image-20230219135743578

6、启动elasticsearch

1
2
#后台启动
/opt/elasticsearch/bin/elasticsearch -d

7、遇到一个问题,同样记录,

image-20230219140355501

初步是es的一个配置权限,还有一个logs目录权限,进入对应目录查看状况:

image-20230219140502576

image-20230219140853416

果不其然,找个keystore文件的权限是root,知道问题了,修改也很简单,修改文件的权限即可:

1
2
3
4
#修改配置文件权限
chown -R es:es elasticsearch.keystore
#修改日志文件权限
chown -R es:es ../logs/*

image-20230219140639342

image-20230219140948237

8、再次启动,再次出现问题

image-20230219144016665

9、修改配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#1.最大可创建文件数太小
vim /etc/security/limits.conf
#在文件末尾中增加下面内容
* soft nofile 65536
* hard nofile 65536
* soft nproc 2048
* hard nproc 4096
vim /etc/security/limits.d/90-nproc.conf
#在文件末尾中增加下面内容,*代表Linux所有用户名称
* soft nofile 65536
* hard nofile 65536
* hard nproc 65536

#2.最大虚拟内存太小
vim /etc/sysctl.conf
#在文件中增加下面内容
vm.max_map_count=655360
#重新加载,输入下面命令:
sysctl -p

image-20230219135342384

10、再再次启动,页面查看,启动成功

image-20230219144404141

image-20230219144347639

11、单机版本到此就搭建完毕…等等,好像不对,还木有配置用户名密码登录,直接修改配置文件elasticsearch.yml

1
2
3
4
5
6
7
#配置X-Pack
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true

12、重启es,尴尬的是es本身木有重启命令,所以回归原始

1
2
3
ps -ef|grep elasticsearch #查找
kill -9 1429 #杀死端口
su es elasticsearch/bin/elasticsearch -d #启动

image-20230219152146449

13、设置用户名和密码,包含elastic、apm_system、kibana、logstash_system、beats_system、remote_monitoring_user五个系统的密码

1
./bin/elasticsearch-setup-passwords interactive

image-20230219152612647

14、over,登录页面查看,完事,

image-20230219152801168

15、一步一步完成了单机版的es搭建,下一步就开始集群的搭建,一起学习一起进步

----------本文结束感谢您的阅读----------