Install Elasticsearch with RPM | Elasticsearch Guide [8.7] | Elastic
准备了3台centos,ip分别是:
1、192.168.1.103
2、192.168.1.148
3、192.168.1.192
开始安装第1个节点
1、
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
2、
vim /etc/yum.repos.d/elasticsearch.repo
[elasticsearch]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
3、
sudo yum install --enablerepo=elasticsearch elasticsearch
相对于以前的版本,8.7安装完成后可以看到以下信息,关于权限的自动设置
注意保存下面的信息:用户名和密码,如果忘了也给出了如何重置的方法
生成证书和密钥 对于传输层和 HTTP 层。
传输层安全性 (TLS) 配置设置将写入 。elasticsearch.yml
将为用户生成密码。elastic
将为 Kibana 生成注册令牌。
--------------------------- Security autoconfiguration information ------------------------------
Authentication and authorization are enabled.
TLS for the transport and HTTP layers is enabled and configured.
The generated password for the elastic built-in superuser is : w9hFeL5uRlViBccl-0Xn
If this node should join an existing cluster, you can reconfigure this with
'/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token '
after creating an enrollment token on your existing cluster.
You can complete the following actions at any time:
Reset the password of the elastic built-in superuser with
'/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic'.
Generate an enrollment token for Kibana instances with
'/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana'.
Generate an enrollment token for Elasticsearch nodes with
'/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node'.
4、开防火墙
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --zone=public --add-port=9300/tcp --permanent
firewall-cmd --reload
5、启动
systemctl start elasticsearch
systemctl enable elasticsearch
6、浏览器输入https://ip:9200,输入用户名:elastic,安装完后自动生成的密码
看到如下就算成功了
到此我们创建了一个单节点的集群。下面开始扩容
1、修改第一个节点的配置文件/etc/elasticsearch/elasticsearch.yml
#节点名称
node.name: node-1
cluster.initial_master_nodes: ["node-1"]
#允许其它节点加入
transport.host: 192.168.1.103
改完配置文件重启:systemctl restart elasticsearch
2、创建token
/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node
得到token
eyJ2ZXIiOiI4LjcuMCIsImFkciI6WyIxOTIuMTY4LjEuMTAzOjkyMDAiXSwiZmdyIjoiOTU1NGI3NDQ4NWM3ODYyYzFkNmZhOTYwYWRhMzc1MGM4MDU3NDNlMTk5NzkzYjNhOWQxOTU0MzkxZWEzMjAwNCIsImtleSI6Im5mcEVvNGNCZ0FYd2U1R1RJT3dOOk5vVzgyU3pyUTU2ZzRtV3pkNHFBakEifQ==
3、创建第二个节点,步骤和创建第一个节点前4步一致。
。。。安装完以后不要启动,执行下面的工具,把当前节点重新配置,加入到已经存在的集群
'/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token '
/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token eyJ2ZXIiOiI4LjcuMCIsImFkciI6WyIxOTIuMTY4LjEuMTAzOjkyMDAiXSwiZmdyIjoiOTU1NGI3NDQ4NWM3ODYyYzFkNmZhOTYwYWRhMzc1MGM4MDU3NDNlMTk5NzkzYjNhOWQxOTU0MzkxZWEzMjAwNCIsImtleSI6Im5mcEVvNGNCZ0FYd2U1R1RJT3dOOk5vVzgyU3pyUTU2ZzRtV3pkNHFBakEifQ==
询问你是否重新配置并加入已存在的集群。会重写配置文件,删除证书等等,输入y后继续
然后启动
systemctl start elasticsearch
systemctl enable elasticsearch
浏览器输入https://ip:9200,输入用户名:elastic,第一个节点生成的密码
这是浏览器输入:https://ip:9200/_cat/nodes?v
看到机器已经有2个节点了
安装第3个节点:步骤同2
注意:
1、在执行'/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token '的时候,如果失败,重装elasticsearch再次尝试
实验:
3个节点停掉1个,没啥异常
3个节点停掉2个,发现报错了,没有主节点了
{"error":{"root_cause":[{"type":"master_not_discovered_exception","reason":null}],"type":"master_not_discovered_exception","reason":null},"status":503}
3个节点启动1个,浏览器登录,输入用户名密码无法登录?
3个节点启动2个后,浏览器才能登录
后加入的节点会自动配置:discovery.seed_hosts:
第一个节点没有自动配置,这种情况下,先启动后面的节点,最后启动第一个节点。发现第一个节点启动后访问出现错误,也没有加入集群
使用:'/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic'.在任意一个节点重置密码,其他节点也同样一并修改