elk-7.5.1

官网下载地址:下载 Elastic 产品 | Elastic

Elasticsearch: https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.1-linux-x86_64.tar.gz

Kibana: https://artifacts.elastic.co/downloads/kibana/kibana-7.5.1-linux-x86_64.tar.gz

Logstash: https://artifacts.elastic.co/downloads/logstash/logstash-7.5.1.tar.gz

Filebeat: https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.5.1-linux-x86_64.tar.gz

ELK的三种部署方式:

  1. Elasticsearch + Logstash + Kibana

  2. Elasticsearch + Logstash + Kibana + filebeat

  3. Elasticsearch + Logstash + Kibana + filebeat + redis/Kafka等中间件

本文使用第二种部署方式。

一、资源规划

1.1 服务器信息

server_name

ip_address

role

filebeat+Log_sever

192.168.12.129

Elasticsearch

192.168.12.130

Kibana

192.168.12.131

Logstash

192.168.12.134

1.2 版本信息

sever

version

elasticsearch

7.5.1

Kibana

7.5.1

Logstash

7.5.1

二、准备工作

2.1 创建运行用户

useradd elk

passwd elk

2.2 修改系统资源限制

 

## 修改 /etc/security/limits.conf 添加以下内容 * soft core unlimited * hard core unlimited * soft noproc 999999 * hard noproc 999999 * soft nofile 999999 * hard nofile 999999 * hard memlock unlimited * soft memlock unlimited ## 修改 /etc/sysctl.conf 添加以下内容 vm.max_map_count=655360 ## 使修改生效 sysctl -p #防火墙都关掉 systemctl stop firewalld

三、搭建 elasticsearch

3.1 JDK环境配置

部署配置ES,需要配置JDK环境,JDK是Java语言的软件开发工具包

 

tar xf jdk-8u351-linux-x64.tar.gz mv jdk1.8.0_351 /usr/java

设置环境变量:

 

cat >>/etc/profile<<EOF export JAVA_HOME=/usr/java export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH EOF source /etc/profile java -version

3.2 配置elasticsearch

下载elasticsearch7.5.1版本:

 

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.1-linux-x86_64.tar.gz tar xf elasticsearch-7.5.1-linux-x86_64.tar.gz mv elasticsearch-7.5.1 /usr/local/elasticsearch

修改 vim /usr/local/elasticsearch/config/elasticsearch.yml文件,

 

network.host: 0.0.0.0 node.name: node-1

3.3 启动查看状态

使用创建的elk用户, 用来启动ES,ES服务默认不允许使用root启动服务

 

useradd elk chown -R elk. /usr/local/elasticsearch su - elk /usr/local/elasticsearch/bin/elasticsearch -d

查看日志及监听端口(非root):

 

tailf /usr/local/elasticsearch/logs/elasticsearch.log ps -ef|grep java netstat -nutlp|grep -E "9200|9300"

3.4 关闭服务

  1. 查看ElasticSearch是否正在运行:

 

ps -aux|grep elasticsearch| grep -v grep

  1. 如果正在运行,查看进程id:

 

ps -aux|grep elasticsearch| grep -v grep | awk \'{print $2}\'

  1. 执行kill命令,停止进程:

 

kill -9进程id


四、搭建 Kibana

4.1 部署Kibana

下载kibana,部署安装kibana 不需要安装Java jdk环境,下载源码包,解压启动即可:

 
 

wget https://artifacts.elastic.co/downloads/kibana/kibana-7.5.1-linux-x86_64.tar.gz tar xf kibana-7.5.1-linux-x86_64.tar.gz mv kibana-7.5.1-linux-x86_64 /usr/local/kibana

4.2 配置Kibana

kibana.yml

 

vim /usr/local/kibana/config/kibana.yml #配置kibana的端口 ## server.port: 5601 server.host: "0.0.0.0" elasticsearch.hosts: ["http://192.168.12.130:9200"] logging.dest: /usr/local/kibana/logs/kibana.log i18n.locale: "zh-CN"

创建日志目录并授权

 

[root@localhost ~]# mkdir /usr/local/kibana/logs [root@localhost ~]# chown -R elk.elk /usr/local/kibana/

4.3 启动查看状态

4.3.1 前台启动(非root)

 

[elk@localhost ~]$ /usr/local/kibana/bin/kibana

4.3.2 后台启动

 

[elk@localhost ~]$ /usr/local/kibana/bin/kibana &

4.3.3 root启动

 

#前台启动 cd /usr/local/kibana/bin ./kibana --allow-root #或者后台启动 nohup ./kibana --allow-root >> /usr/local/kibana/logs/nohup.out 2>&1 & ## 检查是否启动成功 lsof -i:5601 netstat -nutlp|grep 5601 #浏览器访问:192.168.12.131:5601

4.4 关闭服务

  1. 查看Kibana是否正在运行:

 

ps -aux|grep kibana| grep -v grep

  1. 如果正在运行,查看进程id:

 

ps -aux|grep kibana| grep -v grep | awk \'{print $2}\'

  1. 执行kill命令,停止进程:

 

kill -9进程id

五、搭建 Logstash

5.1 JDK配置

由于logstash基于JAVA 语言开发,logstash客户端部署需要安装JDK环境:(同上3.1)

5.2 配置logstash

下载解压logstash软件包:

 

wget https://artifacts.elastic.co/downloads/logstash/logstash-7.5.1.tar.gz tar zxf logstash-7.5.1.tar.gz mv logstash-7.5.1 /usr/local/logstash

logstash.yml

 

/usr/local/logstash/config/logstash.yml http.host: "0.0.0.0"

logstash-sample.conf

 

input { beats { port => 5044 } } # 过滤 filter { grok { match => { "message" => "%{COMBINEDAPACHELOG}" } } date { match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ] } } output { elasticsearch { hosts => ["http://192.168.12.130:9200"] index => "%{[fields][service]}-%{+YYYY.MM.dd}" #user => "elastic" #password => "changeme" } stdout { codec => rubydebug } }

5.3 ELK收集系统日志

创建收集日志配置目录及文件:

 

mkdir -p /usr/local/logstash/config/etc/ cd /usr/local/logstash/config/etc/ touch index.conf

index.conf

 

input { stdin { } } output { stdout { codec => rubydebug {} } elasticsearch { hosts => "192.168.12.130:9200" } }

启动index.conf服务:

 

/usr/local/logstash/bin/logstash -f index.conf

浏览器访问:192.168.12.131:5601

5.4 启动logstash服务

 

[root@localhost ~]# chown -R elk.elk /usr/local/logstash [root@localhost ~]# su - elk # 前台启动 [elk@localhost ~]$ /usr/local/logstash/bin/logstash -f /usr/local/logstash/conf/elasticsearch.conf # 后台启动 [elk@localhost ~]$ cd /usr/local/logstash/bin && nohup ./logstash -f /usr/local/logstash/config/elasticsearch.conf >/dev/null 2>&1 &

5.5 关闭服务

  1. 查看logstash是否正在运行:

 

ps -aux|grep logstash | grep -v grep

  1. 如果正在运行,查看进程id:

 

ps -aux|grep logstash | grep -v grep | awk \'{print $2}\'

  1. 执行kill命令,停止进程:

 

kill -9 进程id

六、搭建filebeat

6.1 安装filebeat

下载解压Filebeat软件包

 

wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.5.1-linux-x86_64.tar.gz tar xf filebeat-7.5.1-linux-x86_64.tar.gz mv filebeat-7.5.1-linux-x86_64 /usr/local/filebeat

6.2 修改配置文件

filebeat.yml

 

vim /usr/local/filebeat/filebeat.yml 按需求修改 #========= Filebeat inputs ========== filebeat.inputs: - type: log enabled: true paths: - /usr/local/xxx/logs/access.log multiline: pattern: '^\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}' negate: true match: after fields: logtype: xxx_access

创建Filebeat日志目录

 

[root@localhost ~]# mkdir /usr/local/filebeat/logs [root@localhost ~]# chown -R elk.elk /usr/local/filebeat

6.3 启动filebeat服务(非root)

 

[root@localhost ~]# su - elk [elk@localhost ~]# cd /usr/local/filebeat # 前台启动 [elk@localhost filebeat]$ ./filebeat -e -c filebeat.yml >>logs/filebeat.log # 后台启动 [elk@localhost filebeat]$ nohup ./filebeat -e -c filebeat.yml >>logs/filebeat.log >/dev/null 2>&1 &

持续更新...

七、kibana 面板使用

7.1 登录使用

1、浏览器输入:192.168.12.130:5601

2、选择自己浏览,出现以下界面

3、分别点击管理--》索引管理,这时候就能看到相关的索引信息

7.2 创建logstash访问日志索引

1)索引模式--->>创建索引模式,输入索引模式名称,点击下一步

2)点击Discover,就能看到日志数据了,如下图

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
开源实时日志分析ELK平台能够完美的解决我们上述的问题,ELKElasticSearch、Logstash和Kiabana三个开源工具组成。 官方网站:https://www.elastic.co/products Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。 Logstash是一个完全开源的工具,他可以对你的日志进行收集、过滤,并将其存储供以后使用(如,搜索)。 Kibana 也是一个开源和免费的工具,它Kibana可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。 ELK下载:https://www.elastic.co/downloads/ ELK工作原理: ElasticSearch 配置ElasticSearch: 1 2 unzip elasticsearch-6.2.4.zip cd elasticsearch-6.2.4 然后编辑ES的配置文件: 1 vi config/elasticsearch.yml 修改以下配置项: 1 2 3 4 5 6 7 cluster.name=es_cluster node.name=node0 path.data=/tmp/elasticsearch/data path.logs=/tmp/elasticsearch/logs #当前hostname或IP,我这里是node1 network.host=node1 network.port=9200 其他的选项保持默认,然后启动ES: 1 nohup sh elasticsearch > nohup.log & 注意: 1.需要添加用户elk,ES不能以root用户进行启动 2.可能出现的错误: max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536] 1 2 3 vi /etc/security/limits.conf elk soft nofile 819200 elk hard nofile 819200 max number of threads [1024] for user [work] likely too low, increase to at least [2048] 1 2 3 4 vi /etc/security/limits.d/90-nproc.conf * soft nproc 1024 #修改为: * soft nproc 2048 max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144] 1 2 3 4 5 vi /etc/sysctl.conf #增加改行配置: vm.max_map_count=655360 #保存退出后,执行: sysctl -p 另外再配置ES的时候,threadpool.bulk.queue_size 已经变成了thread_pool.bulk.queue_size ,ES_HEAP_SIZE,ES_MAX_MEM等配置都变为ES_JAVA_OPTS这一配置项,如限制内存最大最小为1G: 1 export ES_JAVA_OPTS="-Xms1g -Xmx1g" 然后可以打开页面http://node1:9200/,将会看到以下内容:(我是通过外部访问虚拟机,因此为了简单没有配置host文件,直接用ip访问) Logstash 配置Logstash: 1 2 tar -zxvf logstash-6.2.4.tar.gz cd logstash-6.2.4 编写配置文件(名字和位置可以随意,这里我放在config目录下,取名为log_app.conf): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 vi config/log_app.config #以下为内容 input { file { path => "/usr/local/software/elk/app.log" start_position => "beginning" #从文件开始处读写 } # stdin {} #可以从标准输入读数据 } filter { #Only matched data are send to output. } output { # For detail config for elasticsearch as output, # See: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html elasticsearch { action => "index" #The operation on ES hosts => "node1:9200" #ElasticSearch host, can be array. index => "applog" #The index to write data to. } } 其他的选项保持默认,然后启动Logstash: 1 2 # -f为指定配置文件 nohup sh ./bin/logstash -f ../config/log_app.config > nohup.log & 日志: Kibana 配置Kibana: 1 2 tar -zxvf kibana-6.2.4-linux-x86_64.tar.gz cd kibana-6.2.4-linux-x86_64 修改以下几项(由于是单机版的,因此host的值也可以使用localhost来代替,这里仅仅作为演示): 1 2 3 4 server.port: 5601 server.host: “node1” elasticsearch.url: http://node1:9200 kibana.index: “.kibana” 启动kibana: 1 nohup sh ./bin/kibana > nohup.log & 启动后界面: 然后需要创建index,步骤如下: ①点击左边iscover出现以下界面 ②按照注释配置,然后点击Next step,在第二页 选择@timestamp点击create创建 ③创建完成之后,可以看到以下一个界面,红框内是 自动生成的域,也可以理解为 跟数据库中的字段类似,其中有一个message字段,就是我们想要的日志信息。 ④再次点击Discover出现以下界面,可以看到默认搜索的是最后15分钟的日志,可以通过点击设置搜索的时间范围. ⑤可以点击右侧域的add设置需要显示的字段 添加完成之后,日志显示如下:
Docker-compose 部署 ELKElasticsearch、Logstash、Kibana)的步骤如下: 1. 创建一个目录,例如 elk,用于存放 docker-compose.yml 文件和其他配置文件。 2. 在 elk 目录下创建一个 docker-compose.yml 文件,内容如下: ``` version: '3' services: elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:7.10.2 container_name: elasticsearch environment: - discovery.type=single-node ports: - "920:920" - "930:930" volumes: - ./elasticsearch/data:/usr/share/elasticsearch/data networks: - elk logstash: image: docker.elastic.co/logstash/logstash:7.10.2 container_name: logstash volumes: - ./logstash/config:/usr/share/logstash/pipeline/ environment: - ELASTICSEARCH_HOSTS=http://elasticsearch:920 ports: - "500:500" - "960:960" networks: - elk kibana: image: docker.elastic.co/kibana/kibana:7.10.2 container_name: kibana environment: - ELASTICSEARCH_HOSTS=http://elasticsearch:920 ports: - "5601:5601" networks: - elk networks: elk: driver: bridge ``` 3. 在 elk 目录下创建一个 elasticsearch 目录,用于存放 Elasticsearch 的数据。 4. 在 elk 目录下创建一个 logstash 目录,用于存放 Logstash 的配置文件。 5. 在 logstash 目录下创建一个 logstash.conf 文件,用于配置 Logstash 的输入、过滤和输出,例如: ``` input { tcp { port => 500 codec => json } } filter { # 过滤器配置 } output { elasticsearch { hosts => ["http://elasticsearch:920"] index => "logstash-%{+YYYY.MM.dd}" } } ``` 6. 在 elk 目录下运行以下命令启动 ELK: ``` docker-compose up -d ``` 7. 访问 http://localhost:5601 即可打开 Kibana 界面,开始使用 ELK。 注意:在生产环境中,应该根据实际需求对 ELK 进行配置和优化,例如设置 Elasticsearch 的内存和磁盘限制、配置 Logstash 的过滤器和输出、使用安全证书等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_45016443

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值