• ELK-日志服务【es-安装使用】


    目录

    【1】安装-配置elasticsearch(01、02、03相同)

    端口

    【2】安装-配置-启动-Kibana

    【3】浏览器访问测试(10.0.0.21:5601)

    【4】使用kibana创建、更新、删除es索引、文档

    【5】组es集群(投票选举机制)

    【6】启动es

    【7】验证集群是否正常

    【8】使用kibana或者cerebro创建索引

    【9】es-role(角色)

    【10】集群分片 shard-replicas 的作用与如何使用

    【11】创建索引设置为3个分片、1个副本

    【12】如果后期我们增加了节点会不会提高es节点的容量?

    【13】es集群的健康检测


    es-01

    10.0.0.21

    es-02

    10.0.0.22

    es-03

    10.0.0.23

    【1】安装-配置elasticsearch(01、02、03相同)

    1. [root@es-01 ~]# yum -y install java
    2. [root@es-01 ~]# yum -y localinstall elasticsearch-7.4.0-x86_64.rpm
    3. [root@es-01 ~]# vim /etc/elasticsearch/jvm.options
    4. -Xms512m
    5. -Xmx512m
    6. [root@es-01 ~]# systemctl enable elasticsearch.service
    7. [root@es-01 ~]# systemctl start elasticsearch.service
    8. [root@es-01 ~]# netstat -lntp
    9. Active Internet connections (only servers)
    10. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    11. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 881/sshd
    12. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1144/master
    13. tcp6 0 0 127.0.0.1:9200 :::* LISTEN 2555/java
    14. tcp6 0 0 ::1:9200 :::* LISTEN 2555/java
    15. tcp6 0 0 127.0.0.1:9300 :::* LISTEN 2555/java
    16. tcp6 0 0 ::1:9300 :::* LISTEN 2555/java
    17. tcp6 0 0 :::22 :::* LISTEN 881/sshd
    18. tcp6 0 0 ::1:25 :::* LISTEN 1144/master

    端口

    • 9200:对外提供访问
    • 9300:集群之间通信

    【2】安装-配置-启动-Kibana

    1. [root@es-01 ~]# yum -y localinstall kibana-7.4.0-x86_64.rpm
    2. [root@es-01 ~]# grep "^[a-Z]" /etc/kibana/kibana.yml
    3. server.port: 5601
    4. server.host: "0.0.0.0"
    5. elasticsearch.hosts: ["http://10.0.0.21:9200"]
    6. i18n.locale: "zh-CN"
    7. [root@es-01 ~]# systemctl enable kibana
    8. [root@es-01 ~]# systemctl start kibana.service
    9. [root@es-01 ~]# netstat -lntp
    10. Active Internet connections (only servers)
    11. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    12. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 881/sshd
    13. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1144/master
    14. tcp 0 0 127.0.0.1:5601 0.0.0.0:* LISTEN 2775/node
    15. tcp6 0 0 127.0.0.1:9200 :::* LISTEN 2555/java
    16. tcp6 0 0 ::1:9200 :::* LISTEN 2555/java
    17. tcp6 0 0 127.0.0.1:9300 :::* LISTEN 2555/java
    18. tcp6 0 0 ::1:9300 :::* LISTEN 2555/java
    19. tcp6 0 0 :::22 :::* LISTEN 881/sshd
    20. tcp6 0 0 ::1:25 :::* LISTEN 1144/master

    【3】浏览器访问测试(10.0.0.21:5601)

    【4】使用kibana创建、更新、删除es索引、文档

    1. # 创建索引
    2. PUT /test-01_index
    3. # 查看索引
    4. GET _cat/indices
    5. # 删除索引
    6. DELETE /test-01_index
    7. # 操作ES,文档Doc
    8. # 向索引中创建个文档指定ID并录入数据
    9. PUT /test-01_index/_doc/1
    10. {
    11. "name": "xiaoming",
    12. "age": 18,
    13. "salary": 10000
    14. }
    15. # 向索引中创建个文档不指定ID,会自动生产ID,并录入数据
    16. POST /test-01_index/_doc
    17. {
    18. "name": "xiaohong",
    19. "age": 20,
    20. "salary": 100
    21. }
    22. # 指定获取索引中的文档中的数据
    23. GET /test-01_index/_doc/1
    24. # 查看索引中所有文档中的数据
    25. GET /test-01_index/_search
    26. # 批量创建文档_doc
    27. POST _bulk
    28. {"index":{"_index":"tt","_id":"1"}}
    29. {"name":"xiaoqiang","age":"18"}
    30. {"create":{"_index":"tt","_id":"2"}}
    31. {"name":"xiaoyue","age":"30"}
    32. {"delete":{"_index":"tt","_id":"2"}}
    33. {"update":{"_id":"1","_index":"tt"}}
    34. {"doc":{"age":"20"}}
    35. # 查看文档数据
    36. GET /tt/_doc/1
    37. # 批量查看文档
    38. GET _mget
    39. {
    40. "docs":[
    41. {
    42. "_index":"tt",
    43. "_id":"1"
    44. },
    45. {
    46. "_index":"tt",
    47. "_id":"2"
    48. }
    49. ]
    50. }

    【5】组es集群(投票选举机制)

    • es-01
    1. ## 由于先前我们已经安装过es并启动,他会认为自己就是master,我们需要停止服务,并清除数据
    2. [root@es-01 ~]# systemctl stop elasticsearch.service
    3. [root@es-01 ~]# rm -rf /var/lib/elasticsearch/*
    4. [root@es-01 ~]# grep "^[a-Z]" /etc/elasticsearch/elasticsearch.yml
    5. cluster.name: my-cluster-test # 集群名称
    6. node.name: es-node01 # 集群中节点名称
    7. path.data: /var/lib/elasticsearch # 数据存储的路径
    8. path.logs: /var/log/elasticsearch # 日志存储的路径
    9. #bootstrap.memory_lock: true
    10. # 不使用swap分区
    11. network.host: 10.0.0.21
    12. # 本机IP
    13. http.port: 9200
    14. # 监听的端口
    15. discovery.seed_hosts: ["10.0.0.21", "10.0.0.22","10.0.0.23"] # 集群节点
    16. cluster.initial_master_nodes: ["10.0.0.21", "10.0.0.22","10.0.0.23"] # 进第一次启动es时选举
    • es-02
    1. ## 由于先前我们已经安装过es并启动,他会认为自己就是master,我们需要停止服务,并清除数据
    2. [root@es-01 ~]# systemctl stop elasticsearch.service
    3. [root@es-01 ~]# rm -rf /var/lib/elasticsearch/*
    4. [root@es-02 ~]# grep "^[a-Z]" /etc/elasticsearch/elasticsearch.yml
    5. cluster.name: my-cluster-test
    6. node.name: es-node02
    7. path.data: /var/lib/elasticsearch
    8. path.logs: /var/log/elasticsearch
    9. #bootstrap.memory_lock: true
    10. network.host: 10.0.0.22
    11. http.port: 9200
    12. discovery.seed_hosts: ["10.0.0.21", "10.0.0.22","10.0.0.23"]
    13. cluster.initial_master_nodes: ["10.0.0.21", "10.0.0.22","10.0.0.23"]
    • es-03
    1. ## 由于先前我们已经安装过es并启动,他会认为自己就是master,我们需要停止服务,并清除数据
    2. [root@es-01 ~]# systemctl stop elasticsearch.service
    3. [root@es-01 ~]# rm -rf /var/lib/elasticsearch/*
    4. [root@es-03 ~]# grep "^[a-Z]" /etc/elasticsearch/elasticsearch.yml
    5. cluster.name: my-cluster-test
    6. node.name: es-node03
    7. path.data: /var/lib/elasticsearch
    8. path.logs: /var/log/elasticsearch
    9. #bootstrap.memory_lock: true
    10. network.host: 10.0.0.23
    11. http.port: 9200
    12. discovery.seed_hosts: ["10.0.0.21", "10.0.0.22","10.0.0.23"]
    13. cluster.initial_master_nodes: ["10.0.0.21", "10.0.0.22","10.0.0.23"]

    【6】启动es

    1. [root@es-01 ~]# systemctl start elasticsearch.service
    2. [root@es-02 ~]# systemctl start elasticsearch.service
    3. [root@es-03 ~]# systemctl start elasticsearch.service

    【7】验证集群是否正常

    • curl
    1. [root@es-01 ~]# curl http://10.0.0.21:9200/_cat/health?v
    2. epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
    3. 1689037180 00:59:40 my-cluster-test green 3 3 0 0 0 0 0 0 - 100.0%
    • 安装cerebro验证(端口:9000)
    1. [root@es-01 ~]# rpm -ivh cerebro-0.8.5-1.noarch.rpm
    2. Preparing... ################################# [100%]
    3. Creating system group: cerebro
    4. Creating system user: cerebro in cerebro with cerebro user-daemon and shell /bin/false
    5. Updating / installing...
    6. 1:cerebro-0.8.5-1 ################################# [100%]
    7. Created symlink from /etc/systemd/system/multi-user.target.wants/cerebro.service to /usr/lib/systemd/system/cerebro.service.
    8. [root@es-01 ~]# vim /etc/cerebro/application.conf
    9. data.path = "/tmp/cerebro.db"
    10. [root@es-01 ~]# systemctl start cerebro
    11. [root@es-01 ~]# netstat -lntp
    12. Active Internet connections (only servers)
    13. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    14. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 881/sshd
    15. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1144/master
    16. tcp 0 0 0.0.0.0:5601 0.0.0.0:* LISTEN 2894/node
    17. tcp6 0 0 10.0.0.21:9200 :::* LISTEN 12790/java
    18. tcp6 0 0 10.0.0.21:9300 :::* LISTEN 12790/java
    19. tcp6 0 0 :::22 :::* LISTEN 881/sshd
    20. tcp6 0 0 ::1:25 :::* LISTEN 1144/master
    21. tcp6 0 0 :::9000 :::* LISTEN 13146/java

    【8】使用kibana或者cerebro创建索引

    【9】es-role(角色)

    • Cluster State

    集群相关数据,会存储到每个节点中(1、节点信息 2、索引信息)

    • Master

    1、Es集群中只有一个Master节点,作用于控制整个集群

    2、Master主要维护Cluster State,当有新的数据产生后,Master就会将数据同步给其他node节点

    3、Master节点是通过选举产生的,可以通过node.master: ture 表示可以参与选举

    4、当我们通过API创建索引 PUT /test_index ,Cluster State 就会发生变化,同步给其他节点

    • Data

    存储数据的节点就是Data节点。默认节点都是data类型

    当创建索引后,索引中的数据就会存储在默认节点中,能够存储数据的就是Data节点

    node.master:false , node.data:true

    • Coordinating

    处理请求的节点,所有节点默认,不能取消 Coordinating节点主要将请求路由到正确的节点处理,如创建索引的请求会通过coordinating路由到master节点处理

    node.master:false , node.data:false

    【10】集群分片 shard-replicas 的作用与如何使用

    • 增强es的高可用性

    1、服务可用性

    1)3个节点的情况下,允许其中1台节点出现故障

    2)多节点的情况下,出现故障的节点不能超过集群的一半

    2、数据可用性

    1)通过副本 replication 解决,保证每个节点都有完备的数据

    • 增大es集群的容量

    1、需要将数据均匀的分布在所有节点上,引入分片 share 解决

    【11】创建索引设置为3个分片、1个副本

    • 使用cerebor创建方式

    • 使用kibana创建方式
    1. PUT /test_01_index
    2. {
    3. "settings": {
    4. "index": {
    5. "number_of_shards": 3,
    6. "number_of_replicas": 1
    7. }
    8. }
    9. }

     

    【12】如果后期我们增加了节点会不会提高es节点的容量?

    1、对于以前存在的index分片,他们已经分布在3台节点上,那么我们在增加第四台节点,数据不会发生改变,之前存在的index数据也不会被分布在第四台节点上

    2、之后产生的index数据分片才会在四台节点分布

    【13】es集群的健康检测

    • Cluster Health 获取集群的健康状态,以下三种

    1、grenn 所有主副分片都正常分片

    2、yellow 主分片正常,但是副本分片未正常分配

    3、red 主分片未分配,表示索引不完备,写可能出些问题(但是不能代表不能存储数据和读取数据)

  • 相关阅读:
    RabbitMQ第二个实操小案例——WorkQueue
    常见的内网穿透工具有 ngrok/ localtunnel/ frp
    2023年USNews全美大学排名公布(附top300榜单)
    雨云 宿迁 14900KF 高防云服务器性能测评
    【qt5-tab标签精讲】Tab标签及内容分层解析
    Ubuntu18.04使用RPLIDAR A2M12雷达出错的解决办法
    Jetpack Compose 中的状态管理
    OpenHarmony应用开发—ArkUI组件集合
    十一:以理论结合实践方式梳理前端 React 框架 ———框架架构
    力扣热100 滑动窗口
  • 原文地址:https://blog.csdn.net/L596462013/article/details/131684630