安装elasticsearch

修改配置文件

vi /home/elasticsearch-6.3.0/config/elasticsearch.yml

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0           ##服务器ip 本机
#
# Set a custom port for HTTP:
#
http.port: 9200                 ##服务端口
#
# For more information, consult the network module documentation.
#

启动elasticsearch

 Elastic Search启动:由于ES的启动不能用root账号直接启动,需要新创建用户,然后切换新用户去启动,执行命令如下:

-- 创建新用户及授权
# groupadd elsearch
# useradd elsearch -g elsearch -p elasticsearch
# cd /data/deploy/elk/
# chown -R elsearch:elsearch elasticsearch-6.3.0
-- 切换用户,启动
# su elsearch
# cd elasticsearch-6.3.0/bin
# sh elasticsearch &

/home/elasticsearch-6.3.0/bin/elasticsearch   #命令窗运行

 

/home/elasticsearch-6.3.0/bin/elasticsearch  -d  #后台线程运行

关闭elasticsearch

ctrl+c                                   #命令窗关闭

ps -ef | grep elastic                    #后台线程关闭
kill -9 4442                             ##pid 4442为查处线程的pid 

验证elasticsearch启动,主机名是你的服务器的ip地址或域名

Linux部署ELK

elasticsearch启动常见的几个报错

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
切换到root用户,编辑limits.conf添加如下内容
vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536

[2]: max number of threads [3818] for user [es] is too low, increase to at least [4096]
最大线程个数太低。修改配置文件etc/security/limits.conf,增加配置
* soft nproc 4096
* hard nproc 4096

[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
修改/etc/sysctl.conf文件,增加配置vm.max_map_count=262144
vi /etc/sysctl.conf
sysctl -p
执行命令sysctl -p生效

[4]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
问题原因:因为Centos6不支持SecComp,而ES5.2.1默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动
解决方法:在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false

 

安装kibana

修改配置文件

vi /home/kibana-6.3.0-linux-x86_64/config/kibana.yml

server.port: 5601       ##服务端口
server.host: "0.0.0.0"  ##服务器ip  本机
 
elasticsearch.url: "http://localhost:9200" ##elasticsearch服务地址 与elasticsearch对应

启动kibana

/home/kibana-6.3.0-linux-x86_64/bin/kibana       #命令窗启动

nohup ./kibana-6.3.0-linux-x86_64/bin/kibana &   #后台线程启动

nohup ./bin/kibana --allow-root &

关闭kibana

ctrl+c                                   #命令窗关闭

ps -ef | grep kibana                    #后台线程关闭
kill -9 4525                             ##pid 4525 为查处线程的pid 

验证kibana启动

http://192.168.1.155:5601/

Linux部署ELK

 

安装logstash

 

新建配置文件

# cd logstash-6.4.2/bin

   -- 新增编辑配置文件

# vim logstash.conf

input {        
   tcp {                 
      port => 5044                 
      codec => json_lines                 
   }     

output{      
   elasticsearch {
      hosts => ["localhost:9200"]
      # 为传入的日志索引命名
      index => "hermit-log-%{+YYYY.MM.dd}"
   }     
}

 启动Logstash:

logstash官方输入源支持以及下载

安装logstash json插件

/home/logstash-6.3.0/bin/logstash-plugin install logstash-codec-json_lines

启动logstash

 /home/logstash-6.3.0/bin/logstash -f /home/logstash-6.3.0/config/logstash.conf     ##命令窗形式
nohup /home/logstash-6.3.0/bin/logstash -f /home/logstash-6.3.0/config/logstash.conf &  ##后台线程形式

   关闭logstash

ctrl+c                                  #命令窗关闭

ps -ef | grep logstash                    #后台线程关闭
kill -9 4617                              ##pid 4617 为查处线程的pid 

通过以上的配置,基本上ELK和微服务之间,已经配置完成,接下来需要通过在Kibana中创建索引等进行日志的搜索和查看。

访问主机/服务器:5601即可进入kibana管理界面:

 1、创建索引

Linux部署ELK

    可以新建一个全局的索引,【Index pattern】设置为【*】,点击下一步至完成为止。

Linux部署ELK

Linux部署ELK

 2、日志搜索

Linux部署ELK

如截图所示,可以通过Discover和新建的索引,对日志进行详细的查看,并且可以选择具体的字段进行查看。在右上角,可以通过选择不同的时间段,对日志进行查看和搜索。

  3、创建查询

    如2中截图所示,可以通过添加filter,对日志进行过滤查询。然后点击Save后,可以创建新的查询。

  4、创建Visualize和Dashboard

    创建完查询后,可以在Visualize中,创建一个新的图示,通过查询进行创建。创建Dashboard,依赖Visualize图示,进行展示。

    即依赖关系:Dashboard -》 Visualize -》 Search

    在本项目中,Search主要是通过增加了两个Filter:①service:“ff-watersource” ②severity:“ERROR”,查询的是微服务为ff-watersource的error级别的日志。然后根据本Search,依次创建Visualize和Dashboard,最终在Dashboard中,可以监控日志信息的页面为:
Linux部署ELK

    以上,日志聚合分析的实现,就算完成了。

至此,elk搭建完成。

相关文章:

  • 2022-12-23
  • 2021-09-07
  • 2022-01-07
  • 2021-05-28
  • 2021-06-08
  • 2021-09-27
  • 2022-01-25
猜你喜欢
  • 2021-12-02
  • 2021-12-09
相关资源
相似解决方案