ELK搭建及filebeat+kafka/redis收集數(shù)據(jù)

ELK 是Elasticsearch Logstash kibana 三個(gè)開源軟件的組合來進(jìn)行搭建.



(一) 安裝Elasticsearch程序
Elasticsearch7.8 安裝部署
(0)初始化操作--------------------------
操作系統(tǒng)使用7.8版本的    Java版本是7.8.0 
下載elasticsearch 登陸到官網(wǎng)上面  登陸到 https://www.elastic.co/cn/
Selinux和firewalld防火墻都要關(guān)閉掉 
Systemctl  status/stop/disabled  firewalld 
(1)安裝命令----------------------------
Cd /usr/local
Tar –zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz  
Ln –s elasticsearch-7.8.0 elk     執(zhí)行相關(guān)的軟連接  
設(shè)置環(huán)境變量,開始創(chuàng)建java環(huán)境的目錄,
cd /usr/local/elk
Vi /etc/profile
export JAVA_HOME=  /usr/local/elk/jdk
source /etc/profile
Vi .bash_profile
export PATH=$JAVA_HOME/bin:$PATH
echo $JAVA_HOME 可以看現(xiàn)相關(guān)的版本信息等
查看java版本: java –version
Which java 看到的路徑信息是 /usr/local/elk/jdk/bin/java
開始修改修改相關(guān)的配置文件信息
Cd /usr/local/elk ls查看相關(guān)的信息
修改配置 vi config/elasticserarch.yml的配置
記得都是:后面都是空格才可以
#cluster.name: my-application   cluster.name: fxcluster
#node.name: node-1 node.name: node-1
#path.data: /path/to/data /es/data
#path.logs: /path/to/logs path.logs: /es/logs
#network.host: 192.168.0.1 network.host: 0.0.0.0
#http.port: 9200 http.port: 9200
#cluster.initial_master_nodes: ["node-1", "node-2"]  cluster.initial_master_nodes: ["node-1"]
修改配置 config/jvm.options 修改內(nèi)存的大小 free –q
-Xms1g
-Xmx1g
運(yùn)行elasticsearch
hwclock –w date -s "20220111 14:11"
bin/elasticsearch 在前臺(tái)開始運(yùn)行相關(guān)的程序進(jìn)行開啟操作
can not run elasticsearch as root 該軟件不能在root用戶下面進(jìn)行操作的
創(chuàng)建一個(gè)用戶名字為elk,然后更改相關(guān)的權(quán)限和信息等父款。
useradd elk 
passwd elk elk
id elk
[root@localhost local]# chown -R elk:elk elk
[root@localhost local]# chown -R elk:elk elasticsearch-7.8.0
[root@localhost /]# chown -R elk:elk es 修改相關(guān)的日志的權(quán)限
Su – elk
[elk@localhost elk]$ bin/elasticsearch  報(bào)三個(gè)error
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3795] for user [elk] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
ERROR: Elasticsearch did not exit normally - check the logs at /es/logs/fxcluster.log
第一個(gè)和第二個(gè)報(bào)錯(cuò)需要修改相關(guān)的內(nèi)存參數(shù)
vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
es hard nproc 4096
es soft nproc 4096
需要重啟一下服務(wù)器才可以生效,init 6 
第三個(gè)報(bào)錯(cuò)
Vi /etc/sysctl.conf
vm.max_map_count=262144
sysctl –system
然后重新連接一下,執(zhí)行命令看下是否已經(jīng)改變
ulimit –Hn 和 ulimit -Sn
ulimit –a 可以看到修改后的參數(shù)配置信息等
然后 jps查看
[root@localhost ~]# jps
7124 Elasticsearch
7335 Jps
Which jps 
Ps –ef|grep java
 也可以看到elasticsearch相關(guān)的服務(wù)已經(jīng)是啟動(dòng)的狀態(tài)了  停做,然后訪問瀏覽器查看相關(guān)elasticsearch該服務(wù)是否已經(jīng)是正常的啟動(dòng)狀態(tài)了
{
 "name" : "node-1",
 "cluster_name" : "fxcluster",
 "cluster_uuid" : "Da7K8o5xRaOhPWrKxjn_gg",
 "version" : {
 "number" : "7.8.0",
 "build_flavor" : "default",
 "build_type" : "tar",
 "build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65",
 "build_date" : "2020-06-14T19:35:50.234439Z",
 "build_snapshot" : false,
 "lucene_version" : "8.5.1",
 "minimum_wire_compatibility_version" : "6.8.0",
 "minimum_index_compatibility_version" : "6.0.0-beta1"
 },
 "tagline" : "You Know, for Search"
}
可以執(zhí)行curl 命名來執(zhí)行 
Curl -X GET [http://localhost:9200](http://localhost:9200) 輸出的文本內(nèi)容基本上都一樣 說明es已經(jīng)是安裝好了
(2)elk基礎(chǔ)說明
Elasticsearch的基礎(chǔ)說明
[root@localhost ~]# java –version
[elk@localhost elk]$ bin/elasticsearch -d -p fx.pid  后臺(tái)來進(jìn)行相關(guān)的操作等
進(jìn)程號(hào)可以看到相關(guān)的pid的信息晴叨,fx.pid這個(gè)可以看到相關(guān)的信息等 cat fx.pid
[root@localhost ~]# jps -l
7926 jdk.jcmd/sun.tools.jps.Jps
7832 org.elasticsearch.bootstrap.Elasticsearch
看到相關(guān)的服務(wù)已經(jīng)是啟動(dòng)的狀態(tài)了

Elasticsearch 是分布式lucene分布式搜索的引擎 
以mysql為例子 伏社,數(shù)據(jù)庫-表-插入數(shù)據(jù)-sql查詢 
Es的話是短条,
index(索引)-----數(shù)據(jù)庫(database)  
類型(type)-----表(table)   字段(field)---字段岩四,列(column)

1- 索引可以理解為 關(guān)系數(shù)據(jù)庫的db
2- 一個(gè)type就類似于一個(gè)表恭朗,ES5.x中一個(gè)index可以有多個(gè)type/Es6.x中一個(gè)index只能有一個(gè)type/Es7.0以后已經(jīng)移除type屏镊,使用_doc文檔
3-(document)---記錄(row),一個(gè)document 相當(dāng)于關(guān)系數(shù)據(jù)庫中的一行記錄     
4-字段(field)痰腮,相當(dāng)于關(guān)系數(shù)據(jù)庫中的字段
5-映射(mapping)mapping定義了每個(gè)字段的類型等信息而芥,相當(dāng)于關(guān)系型數(shù)據(jù)庫中表字段的類型
6-分片(shards) 因?yàn)閑s是分布式的搜索引擎,所以index通常會(huì)分解成不同的部分诽嘉,而這些分布在不同節(jié)點(diǎn)的數(shù)據(jù)庫就是分片
Es自動(dòng)管理和組織分片蔚出,并在必要的時(shí)候?qū)Ψ制瑪?shù)據(jù)進(jìn)行在平衡分配,所以用戶基本上不同擔(dān)心分片的處理細(xì)節(jié)
7-副本(replicas)
主要目的是為了故障轉(zhuǎn)移虫腋,副本是分片的副本骄酗,分片有主分片和副本分片等
一個(gè)index在物理上分布在多個(gè)主分片中,每個(gè)主分片只存放部分?jǐn)?shù)據(jù) 
每個(gè)主分片悦冀,可以有多個(gè)副本趋翻,叫副本分片,是主分片的復(fù)制 
8-節(jié)點(diǎn)(node)盒蟆,一臺(tái)機(jī)器或者一個(gè)進(jìn)程
9-集群踏烙,集群是一個(gè)或多個(gè)節(jié)點(diǎn)組成

(二) 安裝Elasticsearch和head程序
(一)安裝head程序
1-需要安裝nodejs 和 head這兩個(gè)
Mkdir –p /opt/nodejs
wget https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-x64.tar.xz
分兩步解壓
xz -d node-v16.13.0-linux-x64.tar.xz
tar -xvf node-v16.13.0-linux-x64.tar
在 vi /etc/profile 文件中加入以下內(nèi)容:
export NODEJS_HOME=/opt/nodejs/node-v16.13.0-linux-x64/bin
export PATH=$NODEJS_HOME:$PATH
source /etc/profile
測(cè)試安裝:
[root@localhost nodejs]# node -v
v16.13.0
[root@localhost nodejs]# npm -version
8.1.0
2-需要安裝grunt
Elasticsearch-head 插件需要使用grunt
root@localhost nodejs]# npm install -g grunt-cli
3-下載elasticsearch-head
通過地址:wget https://github.com/mobz/elasticsearch-head/archive/master.zip
Yum –y install zip yum -y install unzip
# unzip master.zip
[root@localhost nodejs]# mkdir -p /opt/elasticsearch/elasticsearch-6.5.3/
[root@localhost nodejs]# mv elasticsearch-head-master /opt/elasticsearch/elasticsearch-6.5.3/
4-安裝pathomjs
Cd /opt/elasticsearch/elasticsearch-6.5.3/elasticsearch-head-master/
yum install bzip2 -y
npm install
npm install -g core-js@3.4
修改elasticsearch.yml的配置
vi /usr/local/elk/config/elasticsearch.yml
新增
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
5-運(yùn)行啟動(dòng)elasticsearch-head該程序
cd /opt/elasticsearch/elasticsearch-6.5.3/elasticsearch-head-master
執(zhí)行命令:[root@localhost elasticsearch-head-master]# grunt server
默認(rèn)端口是9100 可以通過瀏覽器來進(jìn)行登錄操作的
通過web瀏覽器登錄網(wǎng)址 [https://localhost:9100](https://localhost:9100)
然后在運(yùn)行elasticsearch 這個(gè)服務(wù)
Cd /usr/local/elasticsearch-7.8.0
[elk@localhost elasticsearch-7.8.0]$ bin/elasticsearch
然后在刷新[https://localhost:9100](https://localhost:9100)  可以看到相關(guān)的head服務(wù)已經(jīng)是啟動(dòng)的狀態(tài)了 連接網(wǎng)址eserarch的網(wǎng)址:[http://192.168.1.66:9200/](http://192.168.1.66:9200/)  就可以顯示了

圖像展示



(三) 安裝postman程序
1-創(chuàng)建索引
操作使用postman來進(jìn)行相關(guān)的請(qǐng)求步驟就可以進(jìn)行操作了,安裝postman历等,然后進(jìn)行相關(guān)的操作
請(qǐng)求 put  [http://192.168.1.66:9200/fxindex01](http://192.168.1.66:9200/fxindex01)可以發(fā)送請(qǐng)求可以看到創(chuàng)建了一個(gè)相應(yīng)的索引信息
可以看到body上面的信息等讨惩,看到相關(guān)的路線
{
    "acknowledged": **true**,
    "shards_acknowledged": **true**,
    "index": "fxindex01"
}  可以看到elasticsearch-head上面也有了
2-查看索引
通過postman 來進(jìn)行g(shù)et ,GET [http://192.168.1.66:9200/fxindex01](http://192.168.1.66:9200/fxindex01)

{
    "fxindex01": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1641966928613",
                "number_of_shards": "1", 會(huì)存儲(chǔ)兩份數(shù)據(jù)
                "number_of_replicas": "1",
                "uuid": "ybyih-nITtSAYchqS1v7Fg",
                "version": {
                    "created": "7080099"
                },
                "provided_name": "fxindex01"
            }
        }
    }
}
3-新增文檔doc的命令
請(qǐng)求 PUT http://192.168.1.66:9200/fxindex01/_doc/1
把相應(yīng)的請(qǐng)求數(shù)據(jù)放里面
{
    "name":"zhangsan",
    "age":20,
    "email":"zhangsan@qq.com"
}
可以在elastichead的數(shù)據(jù)索引上面看到寒屯,已經(jīng)有該字段了
Get [http://192.168.1.66:9200/fxindex01/_doc/1](http://192.168.1.66:9200/fxindex01/_doc/1) 可以看到
然后在插入一條數(shù)據(jù)荐捻,記住_doc/2 后面的數(shù)據(jù)要唯一
PUT http://192.168.1.66:9200/fxindex01/_doc/2
{
    "name":"zhangsan2",
    "age":23,
    "email":"zhangsan2@qq.com"
}

可以通過 Get [http://192.168.1.66:9200/fxindex01/_search](http://192.168.1.66:9200/fxindex01/_search)來查看所有的文檔
可以通過 Get [http://192.168.1.66:9200/fxindex01/_doc/1/_source](http://192.168.1.66:9200/fxindex01/_doc/1/_source) 來查看對(duì)應(yīng)的文檔
可以通過 Get [http://192.168.1.66:9200/fxindex01/_doc/1黍少?_source](http://192.168.1.66:9200/fxindex01/_doc/1?_source)=name 來查看對(duì)應(yīng)只有name的字段了
可以通過 Get http://192.168.1.66:9200/fxindex01/_mapping

RESTFULful風(fēng)格介紹
POST /user 新增資源
DELETE /user/100 刪除資源
PUT  /user/100 更新或新增資源
GET /user/100 獲取資源
或者通過 curl 工具  來進(jìn)行發(fā)送請(qǐng)求
CURL –X GET [http://localhost:9200](http://localhost:9200) 可以獲得相關(guān)的請(qǐng)求

圖像展示



(四) Logstash 安裝及配置

LOGstash 是一個(gè)開源的數(shù)據(jù)收集器处面,他具有備實(shí)時(shí)數(shù)據(jù)傳輸能力厂置,他可以統(tǒng)一過濾來自不同源的數(shù)據(jù),并且支持各種報(bào)表由于日志文件來源多魂角,如:系統(tǒng)日志昵济,服務(wù)器日志,tomcat日志野揪,nginx日志因此访忿,我們可以使用logstash 對(duì)日志文件進(jìn)行收集和統(tǒng)一過濾,變成可讀性高的內(nèi)容

E:數(shù)據(jù)的存儲(chǔ)和搜索
L:log數(shù)據(jù)的過濾和收集
K:web方式的前端展示
(一)安裝---------------------------------------
[root@localhost local]# pwd 
/usr/local
[root@localhost local]# tar -zxvf logstash-7.8.0.tar.gz
[root@localhost local]# ln -s logstash-7.8.0 logstash
[root@localhost config]# cp logstash-sample.conf logstash.conf
[root@localhost logstash]# bin/logstash -f config/logstash.conf 通過配置文件來進(jìn)行輸出囱挑,通過前臺(tái)來啟動(dòng)
通過后臺(tái)的方式來進(jìn)行啟動(dòng)該logstash 的方式 
Vi start.sh 
#!/bin/bash 
nohup /usr/local/logstash/bin/logstash -f /usr/local/logstash/config/logstash.conf >> /usr/local/logstash/output.log 2>&1 &
cat /usr/local/logstash/output.log 看到相關(guān)的日志輸出
(二)配置---------------------------------------------
[root@localhost config]# cat logstash.conf 
input {
        #從文件讀取日志信息
        file {
        path => "/var/log/messages"
        type => "system"
        start_position => "beginning"
        }
}

filter {
}

output{
    #標(biāo)準(zhǔn)輸出
    elasticsearch {
      hosts => ["192.168.1.66:9200"]
      index => "msg-%(+YYYY.MM.dd)"
    }
}

(三)插件分類-----------------------------------------------
logstash 插件分類:
input 輸入醉顽,codecs 解碼 ,filters 過濾平挑,outputs 輸出 
查看插件命令為:
Bin/logstash-plugin list   查看插件的類型
(五) Kibana 安裝部署

Kibana 是一個(gè)開源的分析與可視化平臺(tái)游添,設(shè)計(jì)出來用于和Elasticsearch 一起使用的,可以用kibana搜素通熄,查看唆涝,交互存放在Elasticsearch索引里的數(shù)據(jù)
使用各種不同的圖表,表格唇辨,地圖等kibana能夠很輕松展示高級(jí)數(shù)據(jù)分析與可視化

最好是一致的廊酣,是7.8.0這個(gè)才可以
[root@localhost local]# tar -zxvf kibana-7.8.0-linux-x86_64.tar.gz
[root@localhost local]# ln -s kibana-7.8.0-linux-x86_64 kibana
開始進(jìn)行相關(guān)的配置
chown -R elk:elk kibana 給相關(guān)的目錄進(jìn)行賦權(quán)
[elk@localhost config]$ vi /usr/local/kibana/config/kibana.yml
server.port: 5601
server.host: "192.168.1.66"
elasticsearch.hosts: ["http://localhost:9200"] #如果不在一臺(tái)機(jī)器上面就要寫好對(duì)應(yīng)的ip地址
1- 啟動(dòng)方式
前臺(tái)啟動(dòng):bin/kibana
后臺(tái)啟動(dòng):vi startup.sh
#!/bin/bash
Nohup /usr/local/kibana/bin/kibana >> /usr/local/kibana/output.log 2 >&1 &
可以訪問web網(wǎng)址: [http://192.168.1.66:5601](http://192.168.1.66:5601) 查看相關(guān)的地址
可以點(diǎn)擊saved objects 可以看到相關(guān)的Elasticsearch
主頁home也可以添加相關(guān)的索引信息,路徑也在elasticSearch---IndexManagement 可以看到相關(guān)的數(shù)據(jù)已經(jīng)添加到上面了
主頁的 security 的management 的 dev Tools 里面可以使用
GET /_cat/indices 可以看到相關(guān)的索引信息等  不用加地址信息
(六) filebeat 收集nginx日志 赏枚,并在kibana 展示

logstash 和filebeat都具有日志收集功能亡驰,filebeat更輕量,占
用資源更少饿幅,但logstash 具有filter功能凡辱,能過濾分析日志。一
般結(jié)構(gòu)都是filebeat采集日志栗恩,然后發(fā)送到消息隊(duì)列透乾,redis,
kafaka磕秤。然后logstash去獲取乳乌,利用filter功能過濾分析,然后
存儲(chǔ)到elasticsearch中市咆。

(一)nginx安裝------------------
[root@localhost local]# mv zlib-1.2.11.tar.gz  /usr/local/
[root@localhost local]# mv pcre-8.38.tar.gz /usr/local/   
yum -y install gcc*
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre-8.38 --with-zlib=/usr/local/zlib-1.2.11
Make
make install
sbin/nginx –c conf/nginx.conf  
[root@localhost nginx]# sbin/nginx -c conf/nginx.conf  默認(rèn)是80 端口汉操,直接輸入回車就行了
訪問:192.168.1.66:80  可以看到相關(guān)的nginx顯示的是80  
[root@localhost logs]# cat /usr/local/nginx/logs/access.log 可以看到相關(guān)的路徑信息
Worker process 也可以改成4個(gè)
[root@localhost nginx]# ps -ef|grep nginx
root      34769      1  0 07:53 ?        00:00:00 nginx: master process sbin/nginx -c conf/nginx.conf
nobody    34770  34769  0 07:53 ?        00:00:00 nginx: worker process
nobody    34771  34769  0 07:53 ?        00:00:00 nginx: worker process
nobody    34772  34769  0 07:53 ?        00:00:00 nginx: worker process
nobody    34773  34769  0 07:53 ?        00:00:00 nginx: worker process
root      34775  34479  0 07:53 pts/2    00:00:00 grep --color=auto nginx
修改相關(guān)的配置文件,然后通過命令來進(jìn)行驗(yàn)證是否配置文件正確
[root@localhost nginx]# sbin/nginx -t -c conf/nginx.conf  驗(yàn)證配置文件是否正確
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
重啟nginx可以使用蒙兰,sbin/nginx –s reload 
[root@localhost nginx]# sbin/nginx -s reload 可以進(jìn)行重啟操作
(二) filebeat安裝-----------------
[root@localhost tools]# tar -zxvf filebeat-7.8.0-linux-x86_64  解壓文件
mv filebeat-7.8.0-linux-x86_64  /usr/local/
[root@localhost config]# cd /usr/local/
ln -s filebeat-7.8.0-linux-x86_64 filebeat
配置文件的路徑是filebeat.yml 這個(gè)是文件的配置文件的具體的路徑信息
#filebeat配置,filebeat.yml
filebeat.inputs:
- type: log
  enabled: true
  backoff: "1s"
  tail_files: false
  paths:
    - /usr/local/nginx/logs/access-json.log
output.logstash:
   enable: true
   hosts: ["192.168.1.66:5044"]
前臺(tái)啟動(dòng): ./filebeat –e –c filebeat.yml 啟動(dòng)相關(guān)的文件等 
后臺(tái)啟動(dòng):vi startup.sh 
chmod a+x startup.sh
#! /bin/bash 
nohup /usr/local/filebeat/filebeat –e –c filebeat.yml >> /usr/lcoal/filebeat/output.log 2 >&1 & 
chmod a+x startup.sh 
刪除相關(guān)的data.json數(shù)據(jù)等
[root@localhost filebeat]# pwd 
/usr/local/filebeat/data/registry/filebeat
[root@localhost filebeat]# rm data.json
 [root@localhost logs]# pwd 
/usr/local/nginx/logs
[root@localhost logs]# cat access.log |wc –l  可以看到數(shù)據(jù)跟kibana上面滴數(shù)據(jù)已經(jīng)有該數(shù)據(jù)了
(三)logstash配置-----------
input {
   beats {
   host => "192.168.1.66"
   port => 5044
  }
}
filter {
    grok {
       match => { "message" => "%{HTTPD_COMBINEDLOG}" }
}
    date {match => ["timestamp","dd/MMM/yyyy:HH:mm:ss Z"]
    target => "@timestamp"
  }
}
output {
     elasticsearch {
         hosts => ["127.0.0.1:9200"]
         index => "nginx-%{+YYYY.MM.dd}"
  }
}
(四)啟動(dòng)程序------------------------
[root@localhost local]# su - elk
[elk@localhost ~]$ cd /usr/local/elk/
[elk@localhost elk]$ ./start.sh 
[elk@localhost elk]$ cd /usr/local/kibana
[elk@localhost kibana]$ ./start.sh 
[elk@localhost kibana]$ cd /usr/local/filebeat/
[elk@localhost filebeat]$ ./start.sh 
[root@localhost local]# cd /usr/local/logstash
[root@localhost logstash]# ./start.sh 
[root@localhost nginx]# sbin/nginx -c conf/nginx.conf 
(五)訪問kibana磷瘤,刷新nginx
訪問網(wǎng)址:http://192.168.1.66:5601/app/kibana#/home
創(chuàng)建模板其弊,建立index pattern,創(chuàng)建一個(gè)時(shí)間戳膀斋,@timestamp 相關(guān)類型的,然后去discover里面去查看相關(guān)的數(shù)據(jù)信息等
或者在logs里面的settings 里面進(jìn)行查看 痹雅,在indices里面仰担,相關(guān)的log indices 里面輸入filebeat-*, 然后stream里面進(jìn)行日志的查看等

圖像顯示


(七)Filebeat+Kafka/redis+Logstash收集日志數(shù)據(jù)

filebeat:filebeat更輕量,占用資源更少绩社,適合客戶端使用摔蓝。當(dāng)logstash宕機(jī)的時(shí)候,這時(shí)候filebeat就不能往logstash里寫數(shù)據(jù)了愉耙,這期間的日志信息可能就無法采集到贮尉,因此一般都會(huì)采用redis或kafka作為一個(gè)消息緩沖層。logstash去消費(fèi)數(shù)據(jù)寫至es朴沿。

(一)安裝redis
安裝redis
[root@localhost tools]# tar -zxvf redis-5.0.9.tar.gz
Make
Make install 
初始化redis的安裝和配置
 [root@localhost utils]# pwd 
/root/tools/redis-5.0.9/utils
[root@localhost utils]# ./install_server.sh
[root@localhost utils]# ps -ef|grep redis 可以看到redis已經(jīng)是啟動(dòng)的狀態(tài)了 
[root@localhost utils]# chkconfig –list 可以看到3,4,5都已經(jīng)啟動(dòng)了
修改redis的配置信息 
[root@localhost ~]# vi /etc/redis/6379.conf
修改bind 0.0.0.0  讓所有的人都可以連接上去
修改 daemonize yes 改為yes是允許后臺(tái)可以啟動(dòng)
然后重啟redis的服務(wù)進(jìn)行相關(guān)的配置等
Systemctl restart redis_6379  重啟redis服務(wù)可以看到相關(guān)的服務(wù)已經(jīng)啟動(dòng)了猜谚,可以看到redis已經(jīng)重啟了,服務(wù)已經(jīng)啟動(dòng)了
service redis_6379 start 通過這個(gè)命令來啟動(dòng) 
service redis_6379 stop 這個(gè)命令來進(jìn)行關(guān)閉
在windows上面安裝destopmanager 的管理工具測(cè)試連接redis的情況
然后可以看到其實(shí)是有16個(gè) redis的數(shù)據(jù)庫 的情況

通過安裝RedisDesktopManager 來連接redis數(shù)據(jù)庫


配置--------------------------------
(一)filebeat配置:
filebeat.inputs:
- type: log
  enabled: true
  backoff: "1s"
  tail_files: false
  paths:
   - /usr/local/nginx/logs/access-json.log
  fields:
   filetype: nginxjson
  fields_under_root: true
output.redis:
  enabled: true
  hosts: ["127.0.0.1:6379"]
  key: nginx
  db: 0
  datatype: list
(二)logstash配置
input {
   redis {
     host => "127.0.0.1"
     port => 6379
     key => "nginx"
     data_type => "list"
     db => 0
   }
}
filter {
    json {
       source => "message"
       remove_field => ["beat","offset","tags","prospector"]
    }
    date {
      match => ["timestamp","dd/MMM/yyyy:HH:mm:ss Z"]
      target => "@timestamp"
}
}
output {
    elasticsearch {
        hosts => ["127.0.0.1:9200"]
        index => "nginx-%{+YYYY.MM.dd}"
    }
}

如果這個(gè)時(shí)候logstash掛掉赌渣,則數(shù)據(jù)會(huì)停留在redis中魏铅,沒有消費(fèi)掉



重啟logstash,可以看到redis中數(shù)據(jù)清空坚芜,kibana中有日志顯示


Kafka安裝配置
Filebeat---kafka---logstash—elasticsearch---kibana 的展示收集等
[root@localhost local]# mv kafka_2.13-2.6.0 /usr/local/
[root@localhost local]# cd /usr/local/
[root@localhost local]# ln -s kafka_2.13-2.6.0/ kafka  然后有一個(gè)軟鏈接
然后需要啟動(dòng)zookeeper程序览芳,kafka使用zookeeper程序,所以需要啟動(dòng)一個(gè)zookeeper
Bin/zookeeper-server-start.sh  config/zookeeper.properties 
然后設(shè)置成后臺(tái)啟動(dòng)
#!/bin/bash
nohup /usr/local/kafka/bin/zookeeper-server-start.sh  /usr/local/kafka/config/zookeeper.properties  >  /usr/local/kafka/zk-output.log 2>&1 &
啟動(dòng)zookeep
[root@localhost kafka]# chmod +x start.sh 
[root@localhost kafka]# ./start.sh
修改kafka的配置
[root@localhost kafka]# chmod +x start.sh 
vim config/server.properties
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://192.168.1.66:9092
然后通過前臺(tái)或者后臺(tái)的方式來啟動(dòng)
前臺(tái)啟動(dòng) [root@localhost kafka]# bin/kafka-server-start.sh config/server.properties
后臺(tái)啟動(dòng) [root@localhost kafka]# bin/kafka-server-start.sh –daemon config/server.properties
然后可以通過kafka-tool工具來進(jìn)行連接的可以連接到zookeeper的管理端地址 
輸入相關(guān)的地址信息等鸿竖,來進(jìn)行連接起來沧竟,zookeep的端口是2181然后進(jìn)行相關(guān)的連接

創(chuàng)建Topic 
bin/kafka-topics.sh --create –zookeeper localhost:2181 --replication-factor 1 --partions 1 --topic fx-topic
bin/kafka-topics.sh --create –zookeeper 192.168.1.66:2181 --replication-factor 1 --partitions 1 --topic fx-topic
查看topic列表 
bin/kafka-topics.sh --list –zookeeper localhost:2181
啟動(dòng)生產(chǎn)者 9092是kafka的端口 
Bin/kafka-console-producer.sh –broker-list localhost:9092 –topic fx-topic
啟動(dòng)消費(fèi)者
Bin/kafka-console-consumer.sh –boostrap-server localhost:9092 –topic fx-topic –from-beginning 
Filebeat的配置 

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市缚忧,隨后出現(xiàn)的幾起案子悟泵,更是在濱河造成了極大的恐慌,老刑警劉巖搔谴,帶你破解...
    沈念sama閱讀 216,544評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件魁袜,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡敦第,警方通過查閱死者的電腦和手機(jī)峰弹,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來芜果,“玉大人鞠呈,你說我怎么就攤上這事∮壹兀” “怎么了蚁吝?”我有些...
    開封第一講書人閱讀 162,764評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵旱爆,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我窘茁,道長(zhǎng)怀伦,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,193評(píng)論 1 292
  • 正文 為了忘掉前任山林,我火速辦了婚禮房待,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘驼抹。我一直安慰自己桑孩,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,216評(píng)論 6 388
  • 文/花漫 我一把揭開白布框冀。 她就那樣靜靜地躺著流椒,像睡著了一般。 火紅的嫁衣襯著肌膚如雪明也。 梳的紋絲不亂的頭發(fā)上宣虾,一...
    開封第一講書人閱讀 51,182評(píng)論 1 299
  • 那天,我揣著相機(jī)與錄音温数,去河邊找鬼安岂。 笑死,一個(gè)胖子當(dāng)著我的面吹牛帆吻,可吹牛的內(nèi)容都是我干的域那。 我是一名探鬼主播,決...
    沈念sama閱讀 40,063評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼猜煮,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼次员!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起王带,我...
    開封第一講書人閱讀 38,917評(píng)論 0 274
  • 序言:老撾萬榮一對(duì)情侶失蹤淑蔚,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后愕撰,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體刹衫,經(jīng)...
    沈念sama閱讀 45,329評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,543評(píng)論 2 332
  • 正文 我和宋清朗相戀三年搞挣,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了带迟。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,722評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡囱桨,死狀恐怖仓犬,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情舍肠,我是刑警寧澤搀继,帶...
    沈念sama閱讀 35,425評(píng)論 5 343
  • 正文 年R本政府宣布窘面,位于F島的核電站,受9級(jí)特大地震影響叽躯,放射性物質(zhì)發(fā)生泄漏财边。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,019評(píng)論 3 326
  • 文/蒙蒙 一点骑、第九天 我趴在偏房一處隱蔽的房頂上張望制圈。 院中可真熱鬧,春花似錦畔况、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,671評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至齐板,卻和暖如春吵瞻,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背甘磨。 一陣腳步聲響...
    開封第一講書人閱讀 32,825評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工橡羞, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人济舆。 一個(gè)月前我還...
    沈念sama閱讀 47,729評(píng)論 2 368
  • 正文 我出身青樓卿泽,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親滋觉。 傳聞我的和親對(duì)象是個(gè)殘疾皇子签夭,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,614評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容