ELK部署(文章有點兒長,搭建時請到官網將tar包下載好,按步驟能夠完成搭建使用)java
ELK指的是ElasticSearch、LogStash、Kibana三個開源工具linux
LogStash是負責數據的收集和過濾處理git
ElasticSearch 是一個開源分佈式搜索引擎,負責數據的存儲、檢索和分析github
Kibana 是提供可視化的頁面,對數據進行可視化預覽redis
首先前提安裝好java環境,java1.8npm
yum -y list javavim
yum install java-1.8.0-openjdk.x86_64跨域
而後在官方下載ElasticSearch Kibana LogStash包瀏覽器
https://www.elastic.co/cn/downloads緩存
這邊用的版本elasticsearch-6.3.2 Kibana-6.3.2 LogStash-6.3.2
1、對系統參數作調整
vim /etc/security/limits.conf (修改以下內容)
* soft nofile 65536
* hard nofile 65536
* soft nproc 65536
* hard nproc 65536
vim /etc/security/limits.d/20-nproc.conf (修改以下內容)
* soft nproc 4096
root soft nproc unlimited
vim /etc/sysctl.conf (添加以下內容)
vm.max_map_count = 655360
fs.file-max=655360
sysctl -p 使內容生效
確保全部生效 必須重啓服務器一遍 reboot
2、安裝Elasticsearch
elasticsearch須要新建一個用戶用來啓動
useradd -d /home/els -m els
su els
mkdir -p /home/els/tools/
將tar包放置 /home/els/tools
cd /home/els/tools
tar -xzf elasticsearch-6.3.2.tar.gz
mv elasticsearch-6.3.2 /home/els/
cd /home/els/elasticsearch-6.3.2/
vim config/elasticsearch.yml(修改以下內容)
path.data: /home/els/elasticsearch-6.3.2/data #自定義 數據存放地址
path.logs: /home/els/elasticsearch-6.3.2/logs #自定義 日誌存放地址
http.cors.enabled: true #開啓跨域訪問支持 默認爲false
http.cors.allow-origin: "*" #跨域訪問容許的域名地址,支持正則
network.host: 0.0.0.0 #任意IP能夠訪問
chown -R els.els /home/els/elasticsearch-6.3.2
nohup ./bin/elasticsearch &
瀏覽器訪問 ip:9200 獲得以下內容 便搭建成功
3、搭建elasticsearch_head
mkdir -p /root/ELK
cd /root/ELK
yum install git npm
git clone https://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
nohup npm run start &
而後瀏覽器訪問ip:9100 鏈接你的Elasticsearch ip:9200
4、安裝Logstash
Logstash的安裝一樣如此,能夠直接用root用戶 將6.3.2的tar包解壓,進入目錄
Vim /你定義的目錄/logstash-6.3.2/config/test.conf
input {
file{
path => [「/var/log/messages」,] #這能夠是個列表 多個Log日誌也是能夠的
start_position => "beginning"
}
}
output{
ctdout{
codec => rubydebug #直接輸出到屏幕
}
elasticsearch {
hosts => ["http://13.1.18.135:9200"] #同時輸出到elastisearch
index => "syslog-%{+YYYY.MM.dd}"
action => "index"
document_type => "test"
}
cd /你定義的目錄/logstash-6.3.2/
./bin/logstash -f config/test.conf
屏幕有輸出,同時瀏覽器訪問ip:9100,也能看到根據索引的輸出信息
後期會詳細說Logstash檢索功能以及經過緩存中間件來傳遞數據接收數據
5、安裝kibana
一樣時將tar包解壓到你的目錄下
tar zxvf kibana-6.2.2-darwin-x86_64.tar.gz
cd /你的目錄/kibana-6.2.2-darwin-x86_64
vim config/kibana.yml (修改以下內容)
server.host: "0.0.0.0"
elasticsearch.url: "http://localhost:9200" #我這裏使用同一臺服務器 不是的話請用IP
nohup ./bin/kibana -H 0.0.0.0 & #後臺啓用
瀏覽器訪問 ip:5601
而後到左邊菜單最下方Management 設置索引值
create Index Patern
輸入 syslog* *匹配全部,與以前Logstash中輸出output的index值
最後建立
而後到左邊菜單中Discover中查看信息
左邊設置當前的索引 ,右上角設置檢索日期,和設置自動更新
搭建完成
接着以一個數據傳遞方式添加一個filebeat工具 是個輕量級的數據採集 能夠直接輸出到Logstash或者elasticsearch
配置一樣簡單
下載filebeat-6.3.2-linux-x86_64.tar.gz
解壓到你的目錄下 (修改下輸入參數和輸出參數)
vim filebeat-6.3.2-linux-x86_64/filebeat.yml
修改參數請按yml格式
能夠輸入多個地址
輸入配置:
參數type , enabled, paths, fields(這個參數傳入Logstash字段,用於判斷)
輸出配置:
output.logstash:
hosts: ["13.1.18.135:5022"] #表示傳輸到主機的5022端口負責接送數據
開啓filebeat 注意-e -c順序
./filebeat -e -c filebeat.yml
#可自行使用
#output.redis:
# hosts: ["13.1.18.135:6379"]
# password: '123456' #到redis.conf的 requirepass 123456 密碼必須配置
# key: "log_file" #傳輸的鍵值
# db: 0 #0庫
# timeout: 5 #超時時間
輸出配置能夠有Elasticsearch,中間件緩存 redis,rabbitmq,kafka等
此時須要修改以前的Logstash中配置文件的test.conf的input
input {
beats {
port => 5022 #開啓5022端口接收數據
#Filebeat傳來數據
}
}
#同上的redis配置
#input {
# redis{
# port => '6379'
# host => '13.1.18.135'
# data_type => "list"
# type => "log"
# key => "log_file"
# db => '0'
# password => '123456'
#}
重啓啓動logstash
./bin/logstash -f config/test.conf
當前的傳輸過程以下圖
後期須要能夠爲多個filebeat用於多臺服務器的日誌同時採集,elastcsearch也能夠設置爲多個節點
下篇文章關於logstash的檢索配置