- 安装es (一般es集群至少配置三台机器)
[root@node01 ~]# yum localinstall elasticsearch-7.4.1-x86_64.rpm -y
- 修改启动参数
[root@node01 ~]# cd /etc/elasticsearch/
[root@node01 elasticsearch]# cp elasticsearch.yml{,.bak}
[root@node01 elasticsearch]# vim jvm.options
-Xms1g
-Xmx1g
注释 ##-XX:+UseConcMarkSweepGC
改为:-XX:+UseG1GC
- 创建数据跟日志目录并授权
[root@node01 elasticsearch]# mkdir data logs
[root@node01 etc]# chown -R elasticsearch:elasticsearch elasticsearch/
- 主节点配置文件
[root@node01 elasticsearch]# vim elasticsearch.yml
cluster.name: mason-cluster
node.name: master
path.data: /etc/elasticsearch/data
path.logs: /etc/elasticsearch/logs
network.host: 192.168.255.11
http.port:9200
discovery.seed_hosts: ["192.168.255.11:9300", "192.168.255.12:9300"]
cluster.initial_master_nodes: ["master"]
gateway.recover_after_nodes: 2
# 主节点相关配置
node.master: true
node.data: false
node.ingest: false
node.ml: false
cluster.remote.connect: false
# 跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
- 从节点配置文件
[root@node02 ~]# vim /etc/elasticsearch/elasticsearch.yml
cluster.name: mason-cluster
node.name: slave01
network.host: 192.168.255.12
http.port: 9200
discovery.seed_hosts: ["192.168.255.11:9300", "192.168.255.12:9300"]
cluster.initial_master_nodes: ["slave01"]
gateway.recover_after_nodes: 2
# 从主节点相关配置
node.master: false
node.data: true
node.ingest: false
node.ml: false
cluster.remote.connect: false
# 跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
- 启动es
[root@node01 etc]# systemctl enable elasticsearch.service
[root@node01 etc]# systemctl start elasticsearch.service
- 查看es状态
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7pwOEtpT-1577620464071)(en-resource://database/6632:0)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QdfkNmqG-1577620464073)(en-resource://database/6600:0)]
- 查看集群状态
[root@node01 ~]# curl -XGET '192.168.255.11:9200/_cluster/health?pretty'
- 查看各节点信息
[root@node01 ~]# curl -XGET 'http://192.168.255.11:9200/_nodes/process?pretty'
10.用命令查看es状态
[root@node01 ~]# curl -XGET '192.168.255.11:9200/_cluster/health?pretty'
{
"cluster_name" : "mason-cluster",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 2,
"number_of_data_nodes" : 1,
"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
}
[root@node01 ~]# curl -XGET 'http://192.168.255.11:9200/_nodes/process?pretty'
{
"_nodes" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"cluster_name" : "mason-cluster",
"nodes" : {
"f8OjekkgS0Gc6AgqUJwy4g" : {
"name" : "master",
"transport_address" : "192.168.255.11:9300",
"host" : "192.168.255.11",
"ip" : "192.168.255.11",
"version" : "7.4.1",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "fc0eeb6e2c25915d63d871d344e3d0b45ea0ea1e",
"roles" : [
"master"
],
"attributes" : {
"xpack.installed" : "true"
},
"process" : {
"refresh_interval_in_millis" : 1000,
"id" : 3230,
"mlockall" : false
}
},
"ekv9LrOWT_a_IyQ0NBPGSQ" : {
"name" : "slave01",
"transport_address" : "192.168.255.12:9300",
"host" : "192.168.255.12",
"ip" : "192.168.255.12",
"version" : "7.4.1",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "fc0eeb6e2c25915d63d871d344e3d0b45ea0ea1e",
"roles" : [
"data"
],
"attributes" : {
"xpack.installed" : "true"
},
"process" : {
"refresh_interval_in_millis" : 1000,
"id" : 2767,
"mlockall" : false
}
}
}
}