首页 > 其他分享 >分布式搜索服务与日志中心

分布式搜索服务与日志中心

时间:2022-11-27 15:22:49浏览次数:37  
标签:apps elasticsearch node1 搜索 日志 root logstash es 分布式

分布式搜索服务与日志中心

 

 

 

 

 

 

 

 

 

 

ElasticSearch集群组件及工作机制

 

 

 

 

root@es-node3:~# cat /etc/hosts

10.4.7.137 es-node1
10.4.7.136 es-node2
10.4.7.134 es-node3

 

 

 

root@es-node1:~# cat /etc/security/limits.conf
root soft core unlimited
root hard core unlimited
root soft nproc 1000000
root hard nproc 1000000
root soft nofile 1000000
root hard nofile 1000000
root soft memlock 32000
root hard memlock 32000
root soft msgqueue 8192000
root hard msgqueue 8192000

* soft core unlimited
* hard core unlimited
* soft nproc 1000000
* hard nproc 1000000
* soft nofile 1000000
* hard nofile 1000000
* soft memlock 32000
* hard memlock 32000
* soft msgqueue 8192000
* hard msgqueue 8192000

root@es-node3:/# mkdir /data/esdata /data/eslogs /apps -pv

root@es-node3:/# chown elasticsearch.elasticsearch /data /apps/ -R

root@es-node3:~# groupadd -g 2888 elasticsearch && useradd -u 2888 -g 2888 -r -m -s /bin/bash elasticsearch
root@es-node3:~# passwd elasticsearch

 

root@es-node1:/apps# tar xf elasticsearch-8.5.1-linux-x86_64.tar.gz
root@es-node1:/apps# ln -sv /apps/elasticsearch-8.5.1 /apps/elasticsearch

#⽣成CA私钥,默认名字为elastic-stack-ca.p12

elasticsearch@es-node1:/apps/elasticsearch$ ./bin/elasticsearch-certutil ca

#⽣产CA公钥,默认名称为elastic-certificates.p12 elasticsearch@es-node1:/apps/elasticsearch$ bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12

#签发elasticsearch集群主机证书: --silent  静默模式   --in  指定文件instances.yml  --out  这里会签发好多证书   放在certs.zip这里    --pass  指定证书密码为  --ca 使用那个ca去签发
elasticsearch@es-node1:/apps/elasticsearch$ bin/elasticsearch-certutil cert --silent --in instances.yml --out certs.zip --pass magedu123 --ca elastic-stack-ca.p12

 解压证书

elasticsearch@es-node1:/apps/elasticsearch$ unzip certs.zip
Archive: certs.zip
creating: es-node1/
inflating: es-node1/es-node1.p12
creating: es-node2/
inflating: es-node2/es-node2.p12
creating: es-node3/
inflating: es-node3/es-node3.p12

三台主机创建config/certs

elasticsearch@es-node1:/apps/elasticsearch$ mkdir config/certs

拷贝证书

elasticsearch@es-node1:/apps/elasticsearch$ cp es-node1/es-node1.p12 config/certs/

elasticsearch@es-node1:/apps/elasticsearch$ scp es-node2/es-node2.p12 10.4.7.136:/apps/elasticsearch/config/certs

elasticsearch@es-node1:/apps/elasticsearch$ scp es-node3/es-node3.p12 10.4.7.134:/apps/elasticsearch/config/certs

#⽣成 keystore ⽂件(keystore是保存了证书密码的认证⽂件000000)  一台主机生成  拷贝到其他主机

现在是空文件

elasticsearch@es-node1:/apps/elasticsearch$ ./bin/elasticsearch-keystore create
warning: ignoring JAVA_HOME=/usr/lib/jvm/jdk-11; using bundled JDK
Created elasticsearch keystore in /apps/elasticsearch/config/elasticsearch.keystore

添加密码

elasticsearch@es-node1:/apps/elasticsearch$ ./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
warning: ignoring JAVA_HOME=/usr/lib/jvm/jdk-11; using bundled JDK
Enter value for xpack.security.transport.ssl.keystore.secure_password:    magedu123

elasticsearch@es-node1:/apps/elasticsearch$ ./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
warning: ignoring JAVA_HOME=/usr/lib/jvm/jdk-11; using bundled JDK
Enter value for xpack.security.transport.ssl.truststore.secure_password:   magedu123

拷贝证书到其他两个服务器

elasticsearch@es-node1:/apps/elasticsearch$ scp /apps/elasticsearch/config/elasticsearch.keystore 10.4.7.136:/apps/elasticsearch/config/elasticsearch.keystore

elasticsearch@es-node1:/apps/elasticsearch$ scp /apps/elasticsearch/config/elasticsearch.keystore 10.4.7.134:/apps/elasticsearch/config/elasticsearch.keystore

 配置文件

 创建集群后会通告那些主机

 discovery.seed_hosts:

初始化的时候那些主机会选举为master

cluster.initial_master_nodes

删除elasticsearch索引时,是不是要传递完整名称   不允许使用正则做模糊匹配

action.destructive_requires_name: true

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.keystore.path: /apps/elasticsearch/config/certs/es-node1.p12

root@es-node2:~# vi /lib/systemd/system/elasticsearch.service
[Unit]
Description=Elasticsearch
Documentation=http://www.elastic.co
Wants=network-online.target
After=network-online.target
[Service]
RuntimeDirectory=elasticsearch
Environment=ES_HOME=/apps/elasticsearch
Environment=ES_PATH_CONF=/apps/elasticsearch/config
Environment=PID_DIR=/apps/elasticsearch
WorkingDirectory=/apps/elasticsearch
User=elasticsearch
Group=elasticsearch
ExecStart=/apps/elasticsearch/bin/elasticsearch --quiet
# StandardOutput is configured to redirect to journalctl since
# some error messages may be logged in standard output before
1.6:⽤户管理:
# elasticsearch logging system is initialized. Elasticsearch
# stores its logs in /var/log/elasticsearch and does not use
# journalctl by default. If you also want to enable journalctl
# logging, you can simply remove the "quiet" option from ExecStart.
StandardOutput=journal
StandardError=inherit
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536
# Specifies the maximum number of processes
LimitNPROC=4096
# Specifies the maximum size of virtual memory
LimitAS=infinity
# Specifies the maximum file size
LimitFSIZE=infinity
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0
# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM
# Send the signal only to the JVM rather than its control group
KillMode=process
# Java process is never killed
SendSIGKILL=no
# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target

root@es-node1:~# systemctl daemon-reload && systemctl start elasticsearch.service && systemctl enable elasticsearch.service

 

es有好多默认密码

⽤户管理: 批量修改默认账户密码: 批量设置密码: elasticsearch@es-node1:/apps/elasticsearch$  bin/elasticsearch-setup-passwords interactive

 

创建超级管理员账户: elasticsearch@es-node1:/apps/elasticsearch$  ./bin/elasticsearch-users useradd awen -p123456 -r superuser elasticsearch@es-node1:/apps/elasticsearch$ curl -u awen:123456 http://10.4.7.137:9200 验证集群状态

 

 

 elasticsearch@es-node3:/apps/elasticsearch$ ./bin/elasticsearch-users useradd awen -p123456 -r superuser

elasticsearch@es-node2:/apps/elasticsearch$ ./bin/elasticsearch-users useradd awen -p123456 -r superuser

 

 

查看索引  

root@es-node1:~# curl -u awen:123456 -X GET http://10.4.7.137:9200/awen_index?pretty
{
"awen_index" : {
"aliases" : { },
"mappings" : { },
"settings" : {
"index" : {
"routing" : {
"allocation" : {
"include" : {
"_tier_preference" : "data_content"
}
}
},
"number_of_shards" : "1",
"provided_name" : "awen_index",
"creation_date" : "1669426420445",
"number_of_replicas" : "1",
"uuid" : "Orq06b2YSemT4usQhnYZeA",
"version" : {
"created" : "8050199"
}
}
}
}
}

 

root@es-node1:~# curl -u awen:123456 -X PUT http://10.4.7.137:9200/test_index?pretty
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "test_index"
}
root@es-node1:~# curl -u awen:123456 -X PUT http://10.4.7.137:9200/awen_index
{"acknowledged":true,"shards_acknowledged":true,"index":"awen_index"}root@es-node1:~#

 

 

  

 

ElasticSearch的常用ETL工具栈及LogStash和各Beats组件功能简介及使用场景 ETL简介: ETL 是大数据世界中的一种常见模式,用于收集和整合数据以进行存储、分析及展示,基本流程为: Extract:数据提取、基于不同的工具从数据源提取数据 Transform:数据转换,通过自定义流程将数据进行内容转换、格式转换、数据字段提取或删除等 Load: 数据加载,将数据存储到外部数据库或数据仓库         安装logstash root@logstash:/usr/local/src# dpkg -i logstash-8.5.1-amd64.deb   

root@logstash:/etc/logstash/conf.d# vim stdin-stout-test.conf
input {
stdin {}
}

output {
stdout {}
}

检查配置文件

root@logstash:/etc/logstash/conf.d# /usr/share/logstash/bin/logstash -f stdin-stout-test.conf -t

启动

root@logstash:/etc/logstash/conf.d# /usr/share/logstash/bin/logstash -e 'input { stdin{} } output { stdout{ codec => rubydebug }}'

root@logstash:/etc/logstash/conf.d# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/stdin-stout-test.conf 

root@logstash:/etc/logstash/conf.d# vim log-file.conf
input {
stdin {}
}

output {
file {
path => "/tmp/logstash-test.log"
}
}

 

root@logstash:/etc/logstash/conf.d# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/log-file.conf

交互式输入  文字

 

查看日志输出

root@logstash:~# tail -f /tmp/logstash-test.log
{"message":"awen","@version":"1","host":{"hostname":"logstash"},"event":{"original":"awen"},"@timestamp":"2022-11-26T09:53:23.373107046Z"}

可以同时输出不同的输出源

root@logstash:/etc/logstash/conf.d# vim es.conf
input {
  stdin {}
  }

output {
  file {
    path => "/tmp/logstash-test.log"
  }

  elasticsearch {
    hosts => ["10.4.7.137:9200"]
    index => "awen-logstash-test-%{+YYYY.MM.dd}"
    user => "awen"
    password => "123456"
  }
}

查看索引

 

 root@logstash:/etc/logstash/conf.d# systemctl restart logstash

 日志内容

 

安装kibana

root@logstash:/usr/local/src# dpkg -i kibana-8.5.1-amd64.deb

root@logstash:/etc/kibana# vi /etc/kibana/kibana.yml 

server.port: 5601

server.host: "0.0.0.0"

elasticsearch.hosts: ["http://10.4.7.137:9200"]

elasticsearch.username: "kibana_system"
elasticsearch.password: "123456"

i18n.locale: "zh-CN"

root@logstash:/etc/kibana# systemctl restart kibana.service

启动日志

root@logstash:/etc/kibana# tail -f /var/log/kibana/kibana.log

 

 

 

菜单栏-> Stack Management-> 数据视图 

 

 

 

 

 

 

 

 

 

 

root@awen:~# echo "1234567" >> /var/log/syslog

 

 

标签:apps,elasticsearch,node1,搜索,日志,root,logstash,es,分布式
From: https://www.cnblogs.com/tshxawen/p/16917507.html

相关文章

  • K8S日志报错-01未初始化
    Nov2712:57:35k8s-master01systemd:Unitkubelet.serviceenteredfailedstate.Nov2712:57:35k8s-master01systemd:kubelet.servicefailed.Nov2712:57:45k8......
  • springboot集合efk搭建日志平台
    springboot继承efk实现日志收集1.安装es和kibana我使用的云服务器centos7,2核+4G内存,跑起来内存使用率50%左右建议使用最低配置和我一样,1+2的配置kibana应该跑不起来,......
  • 分布式拒绝服务攻击(DDoS)和僵尸网络(Botnet)
    前言DDos和僵尸网络是相辅相成的两种攻击手段,本文仅介绍基本概念,详细请查看文末参考资料。分布式拒绝服务攻击(DDoS)分布式拒绝服务攻击DDoS是一种基于DoS的特殊形式的......
  • 03-1-高并发系统分布式调度原理【双元】(1)
                                     ......
  • 分布式系统系列
    个人经验总结冗余(扩展性)的作用和带来的问题分布式系统中,实现可扩展性(节点冗余)是实现系统高可用性、数据可靠性的重要手段,因为冗余使得节点挂了备用节点可顶上、数据丢了......
  • Spring与日志
    一、日志框架:      JUL、JCL、Jboss-logging、logback、log4j、log4j、log4j2、slf4j日志抽象层日志实现JCL、SLF4J、jboos-loggingLog4J、JUL、Log4......
  • Spring Boot 的默认日志管理与 Logback 配置详解
    前沿技术早知道,弯道超车有希望积累超车资本,从关注DD开始SpringBoot在所有内部日志中使用CommonsLogging,但是对底层日志的实现是开放的。在SpringBoot生态中,为JavaUtilL......
  • 受skynet启发的分布式服务端框架设计
    简介不管是RPC还是IPC,本质都是通过某种寻址方式调用另一个工作单元(线程)的函数(subroutine)。此处工作单元可以是主机(host),进程(process),线程(thread)。最终函数将在某......
  • 剑指offer——Day15 搜索与回溯算法(中等)
    Day152022.11.21搜索与回溯算法(中等)34.二叉树中和为某一值的路径自己实现用递归。递归函数的思路:首先是递归出口root==NULL时返回-1,告诉上层节点这个地方是NULL,以便......
  • 第十六章 k8s运维篇-k8s容器日志收集
    第十六章k8s运维篇-k8s容器日志收集目录第十六章k8s运维篇-k8s容器日志收集1,k8s需要收集哪些日志2,收集日志常用的技术栈1,k8s需要收集哪些日志系统和k8s组件日志业务......