参考:
https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html
在本指南中,我们将设置一个三节点Elasticsearch集群,每个节点都作为主节点。
环境信息:
节点1:es-node-00
节点2:es-node-01
节点3:es-node-02
确保主机名在每个节点上都可解析,配置主机名和hosts
hostnamectl set-hostname es-node-00
hostnamectl set-hostname es-node-01
hostnamectl set-hostname es-node-02
cat > /etc/hosts << EOF
192.168.93.40 es-node-00
192.168.93.41 es-node-01
192.168.93.42 es-node-02
EOF
#安装jdk并配置环境变量,logstash依赖JAVA_HOME环境变量
#创建repo存储库,由于官方源太慢,这里使用国内清华源
cat > /etc/yum.repos.d/elasticsearch.repo << EOF
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://mirrors.tuna.tsinghua.edu.cn/elasticstack/yum/elastic-7.x/
gpgcheck=0
enabled=1
EOF
#安装Elasticsearch:
yum install -y elasticsearch
参考:https://www.elastic.co/guide/en/elasticsearch/reference/master/_discovery_configuration_check.html
#Node1(主)
#修改配置文件
vim /etc/elasticsearch/elasticsearch.yml
cluster.name: es-cluster
node.name: es-node-00
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
bootstrap.memory_lock: true
network.host: 192.168.93.40
http.port: 9200
discovery.seed_hosts: ["192.168.93.40", "192.168.93.41", "192.168.93.42"]
cluster.initial_master_nodes: ["es-node-00", "es-node-01", "es-node-02"]
其他节点仅修改node.name和network.host即可:
scp /etc/elasticsearch/elasticsearch.yml 192.168.93.41:/etc/elasticsearch/
scp /etc/elasticsearch/elasticsearch.yml 192.168.93.42:/etc/elasticsearch/
配置说明:
禁用Elasticsearch服务systemd swap
systemctl edit elasticsearch
[Service]
LimitMEMLOCK=infinity
#或完全禁用swap
swapoff -a
systemctl daemon-reload
Elasticsearch默认将堆大小设置为1GB。这里设置 Xmx
为不超过物理RAM的50%但不超过32GB。
vim /etc/elasticsearch/jvm.options
-Xms2g
-Xmx2g
启动服务
systemctl enable --now elasticsearch.service
systemctl restart elasticsearch.service
systemctl status elasticsearch.service
日志查看
journalctl -f
journalctl -u elasticsearch
tail -f /var/log/elasticsearch/elasticsearch.log
tail -f /var/log/elasticsearch/<cluster-name>.log
检查 Elasticsearch集群健康状态
[root@es-node-00 ~]# curl -X GET "192.168.93.40:9200/_cluster/health?pretty"
{
"cluster_name" : "es-cluster",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 3,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
群集运行状况为: green, yellow 或 red。
1 绿色,最健康的状态,代表所有的分片包括备份都可用
2 黄色,基本的分片可用,但是备份不可用(也可能是没有备份)
3 红色,部分分片可用,表明分片有一部分损坏。此时执行查询部分数据仍然可以查到,遇到这种情况,还是赶快解决比较好。
检查 Elasticsearch集群节点状态
[root@es-node-00 ~]# curl -X GET "192.168.93.40:9200/_cat/nodes?v"
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.93.40 12 90 2 0.05 0.12 0.12 dim * es-node-00
192.168.93.41 8 90 5 0.12 0.12 0.08 dim - es-node-01
192.168.93.42 9 89 5 0.14 0.11 0.08 dim - es-node-02
参数说明:
curl '10.75.5.63:32768/_cat/indices?v'
验证单个节点服务状态
[root@es-node-01 ~]# curl 'http://192.168.93.40:9200/?pretty'
{
"name" : "es-node-00",
"cluster_name" : "es-cluster",
"cluster_uuid" : "hOm9E0vSQqyehxjDAxXJTA",
"version" : {
"number" : "7.3.2",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "1c1faf1",
"build_date" : "2019-09-06T14:40:30.409026Z",
"build_snapshot" : false,
"lucene_version" : "8.1.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
内容来源于网络,如有侵权,请联系作者删除!