1.安裝elasticsearch,具體安裝辦法
2.下載 logstash-6.3.2.tar.gz ,並上傳至服務器 (/elsearch/)
3.解壓 logstash
cd /elsearch/
tar zxvf logstash-6.3.2.tar.gz
4.下載 kibana-6.3.2-linux-x86_64.tar.gz ,並上傳到服務器 (/elsearch/)
5.解壓 kibana
cd /elsearch/
tar zxvf kibana-6.3.2-linux-x86_64.tar.gz
6.配置 kibana
kibana的配置文件在 /elsearch/kibana-6.3.2-linux-x86_64/config/kibana.yml
#elasticsearch.url: "http://localhost:9200" //訪問elsearch的地址
#server.port: 5601 //kibana的訪問端口
#server.host: "localhost" //kibana的訪問地址。這裡改為本機的IP,並去掉之前的 #
server.host: "192.168.1.109",其它的就按默認文件配置。
7.啟動 kibana
cd /elsearch/kibana-6.3.2-linux-x86_64/bin/
./kibana &
8.在瀏覽器中查看 kibana
http://192.168.1.109:5601
8.nginx的日誌格式在配置文件中配置。打開/etc/nginx/nginx.conf,配置日誌格式
log_format main '$remote_addr "$time_iso8601" "$request" $status $body_bytes_sent "$http_user_agent" "$http_referer" "$http_x_forwarded_for" "$request_time" "$upstream_response_time" "$http_cookie" "$http_Authorization" "$http_token"';
access_log /var/log/nginx/access.log main
重啟nginx 。 service nginx restart
清空nginx的日誌,點擊一部分後,來產生新的格式的日誌。接下來會用到。
9.接下來配置logstash
input {
file {
#日誌存放路徑
path => "/elsearch/logstash-6.3.2/etc/access.log"
start_position => "beginning"
}
}
filter {
grok {
match => {"message" => "%{IPORHOST:client_ip} "%{TIMESTAMP_ISO8601:timestamp}" "%{WORD:verb} %{NOTSPACE:request_path} HTTP/%{NUMBER:httpversion}" %{NUMBER:response_status:int} %{NUMBER:response_body_bytes:int} "%{DATA:user_agent}" "%{DATA:http_referer}" "%{NOTSPACE:http_x_forwarder_for}" "%{NUMBER:request_time:float}" "%{DATA:upstream_resopnse_time}" "%{DATA:http_cookie}" "%{DATA:http_authorization}" "%{DATA:http_token}""}
add_field => {"request_path_with_verb" => "%{verb} %{request_path}"}
add_field => {"request_path_2" => "%{request_path}"}
}
#忽略nginx日誌中的js css image等信息
if ".js" in [request_path] or ".css" in [request_path] or ".png" in [request_path] or ".ico" in [request_path] or ".jpg" in [request_path] or ".woff" in [request_path] or ".gif" in [request_path] {
drop {}
}
#分割URL
kv {
prefix => "cgsoft_"
field_split => "?&"
value_split =>"="
source => "request_path"
allow_duplicate_values => false
}
date {
match => [ "timestamp", "yyyy-MM-dd'T'HH:mm:ssZZ" ]
target => "@timestamp"
}
#IP處理,這裡用到了一個IP庫。
geoip {
source => "client_ip"
database => "/elsearch/logstash-6.3.2/etc/GeoLite2-City.mmdb"
}
urldecode {
all_fields => true
}
}
output {
elasticsearch {
hosts => "127.0.0.1:9200"
}
stdout {
codec => json_lines
}
}
啟動logstash.
10.刷新 http://192.168.1.109:5601
1.點擊 Management.
2.點擊 Index Patterns
3.搜索 log*,然後點擊 netxt step
4.然後選擇 @timestamp,然後點擊右下角的create index
5.就可以看到日誌導入elsearch中的一些信息。
6.點擊左側欄的 Discover,然後在右上角選擇日誌的時間段,因為我這裡只有一部分測試數據,所以會比較少。
7.點擊左側欄的 Visualize,然後點擊 create
7.選擇一種圖片的樣子,這裡選擇 柱狀圖
8.選擇剛才 的 log*
9.選擇柱狀圖的屬性,這裡只是簡單的設置了一下。可以看到各個時間段的訪問情況
Kibana還有更多展示日誌的方式 ,這裡只是帶大家入門,更多,更全面的使用來分析日誌,就得深入學習。
這裡再分享一箇中文地圖的鏈接 ,只要放到kibana的配置文件底部,重啟kibana就可以了。
tilemap.url: "http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}"
更多相關的包,可以到這裡的雲盤下載。
閱讀更多 程序從入門到放棄 的文章
關鍵字: 下載 ElasticSearch Linux