ELK日誌平臺---老男孩教育筆記
環境的困境(原因)
1、開發人員不能登錄線上服務器查看相信日誌;
2、各個系統都有日誌,日誌數據分散難以查找;
3、日誌數據量大,查詢速度慢,或者數據不夠及時。(狀態碼 400 的 top10)
收集->存儲->統計->報警、、、
Elastic Search + Logstash +Kibana = ELK Stack
1、分布式全文搜索引擎、存儲
2、日誌收集(日誌收集於某一處)
3、日誌展示
安裝過程:
一、Elastic Search
(1)、Import the Elasticsearch PGP Key
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
(2)、Installing from the RPM repository
echo "[elasticsearch-5.x] name=Elasticsearch repository for 5.x packages baseurl=https://artifacts.elastic.co/packages/5.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md" >>/etc/yum.repos.d/elasticsearch.repo yum install -y elasticsearch
修改配置文件
創建 數據目錄
mkdir -p /data/es-data
vim /etc/elasticsearch/elasticsearch.yml cluster.name: Mint node.name: Mint-node1 path.data: /data/es-data path.logs: /var/log/elasticsearch bootstrap.memory_lock: true network.host: 0.0.0.0 http.port: 9200
ES集群
cluster.name: Mint 相同就行,同一個局域網 先會廣播
修改node.name
cluster.name: Mint
node.name: Mint-node2
path.data: /data/es-data
path.logs: /var/log/elasticsearch
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200
插件
head bigdesk kopf 暫時都不支持es5.4
#bootstrap.memory_lock: true 去掉註釋會報錯
解決方式:修改limit 文件 yum 安裝的es,默認使用的是普通用戶,需要配置limit.conf
vim /etc/security/limits.conf # allow user ‘elasticsearch‘ mlockall elasticsearch soft memlock unlimited elasticsearch hard memlock unlimited
修改數據路徑的權限
chown -R elasticsearch:elasticsearch /data/es-data systemctl enable elasticsearch systemctl start elasticsearch
Installing Logstash
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch cat > /etc/yum.repos.d/logstash.repo <<EOF [logstash-5.x] name=Elastic repository for 5.x packages baseurl=https://artifacts.elastic.co/packages/5.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md EOF yum install -y logstash
/usr/share/logstash/bin/logstash -e ‘input { stdin{} } output { stdout{}}‘
/usr/share/logstash/bin/logstash -e ‘input { stdin{} } output { stdout{ codec => rubydebug} }‘
/usr/share/logstash/bin/logstash -e ‘input { stdin{} } output { elasticsearch { hosts => "192.168.1.87:9200" protocol => "http"} }‘
/usr/share/logstash/bin/logstash -e ‘input { stdin{} } output { elasticsearch { hosts => "192.168.1.87:9200" } stdout { codec => rubydebug} }‘ //同時兩個輸出 一個es 一個標準輸出
vim /etc/logstash/conf.d/01-logstach.conf input { stdin { } } output { elasticsearch { hosts => ["localhost:9200"] } stdout { codec => rubydebug } } /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/01-logstach.conf
各種插件
https://www.elastic.co/guide/en/logstash/current/index.html
Install Kibana with RPM
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
vim /etc/yum.repos.d/kibana.repo
[kibana-5.x] name=Kibana repository for 5.x packages baseurl=https://artifacts.elastic.co/packages/5.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md
yum install kibana -y
修改配置文件
vim /etc/kibana/kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://192.168.1.87:9200"
kibana.index: ".kibana"
nginx Module ngx_http_log_module http://nginx.org/en/docs/http/ngx_http_log_module.html
input { file { path => "/var/log/nginx/access_json.log" codec => "json" } } output { stdout { codec => "rubydebug" } }
rsyslog 修改系統日誌
修改
vim /etc/rsyslog.conf *.* @@192.168.1.87:514
nc 192.168.1.87 12345 < /etc/passwd
echo “Mint” > /dev/tcp/192.168.1.87/12345 也可以給12345 tcp端口發信息 偽設備
nc 追加文件
logstash 解耦 當需要單獨修改logstash時,收集的日誌可以暫存於內存中,不至於需要停止收集日誌
logstash ---------->redis ---------->logstash -------->elasticsearch----------->kibana
收集 消息隊列 分析 存儲 顯示
192.168.1.87 192.168.1.87 192.168.1.88 192.168.1.87 192.168.1.87
redis ---->rabbitmq------>kafka 一般redis就可以,不能滿足的時候
解耦部分的配置文件,於明天整理發出來。再加前面的all.conf,共三個conf文件,shipper.conf、indexer.conf
logstash 寫入kibana的時間戳是UTC。
http://192.168.1.87:5601/status 查看kibana狀態
ab -n10000 -c1 http://192.168.1.87/ -n次數 -c 每次並發
安全解決方案 :search Guard
生產如何上線ELK
1、日誌分類
系統日誌 rsyslog logstash syslog插件
訪問日誌 nginx logstash codec json
錯誤日誌 file logstash file + mulitline
運行日誌 file logstash json
設備日誌 syslog logstash syslog插件
debug日誌 file logstash json or mulitline
2、日誌標準化
1.路徑 固定
2.格式 盡量json
系統日誌開始->錯誤日誌->運行日誌->訪問日誌
ELK日誌平臺---老男孩教育筆記