新聞中心
ElasticStack 是一系列開源產(chǎn)品的合集,包括 Elasticsearch、Kibana、Logstash 以及 Beats 等,能夠安全可靠地獲取任何來源、任何格式的數(shù)據(jù),并且能夠?qū)崟r地對數(shù)據(jù)進行搜索、分析和可視化。

創(chuàng)新互聯(lián)建站主要從事成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)瀏陽,10年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18980820575
Elastic Stack所需環(huán)境條件
64 位的 CentOS 7,4 GB 內(nèi)存 - elk 主控機
64 位的 CentOS 7 ,1 GB 內(nèi)存 - 客戶端 1
64 位的 Ubuntu 16 ,1 GB 內(nèi)存 - 客戶端 2
步驟 1 – 操作系統(tǒng)初始化
禁用 CentOS 7 服務(wù)器上的 SELinux
我們將禁用 CentOS 7 服務(wù)器上的 SELinux。 編輯 SELinux 配置文件。
vim /etc/sysconfig/selinux
將 SELINUX 的值從 enforcing改成disabled
SELINUX=disabled
然后重啟服務(wù)器:
reboot
再次登錄服務(wù)器并檢查 SELinux 狀態(tài)。
getenforce
disabled
步驟 2 – 安裝 Java環(huán)境
部署 Elastic stack 依賴于Java,Elasticsearch 需要 Java 8 版本,推薦使用 Oracle JDK 1.8 。從官方的 Oracle rpm 包安裝 Java 8。
wget http://download.oracle.com/otn-pub/java/jdk/8u77-b02/jdk-8u77-linux-x64.rpm
\\下載java8的版本
rpm -ivh jdk-8u77-linux-x64.rpm \\rpm安裝jdk環(huán)境
java -version \\查看java的版本 檢查能否工作
步驟 3 – 安裝和配置 Elasticsearch
在此步驟中,我們將安裝和配置 Elasticsearch。 從 elastic.co 網(wǎng)站提供的 rpm 包安裝 Elasticsearch,并將其配置運行在 localhost 上(以確保該程序安全,而且不能從外部訪問)。
將 elastic.co 的密鑰添加到服務(wù)器
elastic.co網(wǎng)站是一個https的網(wǎng)站(私有證書),我們需要添加證書秘鑰才能安全的順利下載。
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
下載安裝 Elasticsearch 5.1
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.1.rpm
rpm -ivh elasticsearch-5.1.1.rpm
安裝完成后我們編輯配置文件
配置文件名稱:elasticsaerch.yml
cd /etc/elasticsearch/
vim elasticsearch.yml
bootstrap.memory_lock: true
\\去掉第 40 行的注釋,啟用 Elasticsearch 的內(nèi)存鎖。這將禁用 Elasticsearch 的內(nèi)存交換。
network.host: localhost
http.port: 9200
\\在 Network 塊中,取消注釋 network.host 和 http.port 行。
編輯 elasticsearch.service 文件的內(nèi)存鎖配置。
vim /usr/lib/systemd/system/elasticsearch.service
MAX_LOCKED_MEMORY=unlimited
\\去掉第 60 行的注釋,確保該值為 unlimited。
設(shè)置服務(wù)啟動
Elasticsearch監(jiān)聽端口號9200,啟用 CentOS 服務(wù)器上啟用mlockall 來禁用內(nèi)存交換,設(shè)置Elasticsearch開機自啟動,然后啟動服務(wù)。
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch
檢查對外監(jiān)聽端口:
netstat -plntu
內(nèi)存鎖啟用 mlockall,檢查 Elasticsearch 是否正在運行。
curl -XGET 'localhost:9200/_nodes?filter_path=**.mlockall&pretty'
curl -XGET 'localhost:9200/?pretty'
步驟 4 – 安裝和配置 Kibana 和 Nginx
先安裝Kibana,然后安裝nginx,最后設(shè)置nginx反向代理kibana
安裝并配置Kibana
wget https://artifacts.elastic.co/downloads/kibana/kibana-5.1.1-x86_64.rpm
rpm -ivh kibana-5.1.1-x86_64.rpm
編輯 Kibana 配置文件。
vim /etc/kibana/kibana.yml
在配置文件中找的一下三行,修改配置
server.port: 5601
server.host: "localhost"
elasticsearch.url: "http://localhost:9200"
將 Kibana 設(shè)為開機啟動
sudo systemctl enable kibana
sudo systemctl start kibana
檢查Kibana 對外監(jiān)聽端口 5601 確保其正常啟動。
netstat -plntu
安裝并配置nginx服務(wù)器
yum -y install epel-release
nginx 服務(wù)的yum包在epel包中可以找的 直接yum安裝
yum -y install nginx httpd-tools
httpd-tools 軟件包包含 Web 服務(wù)器的工具,可以為 Kibana 添加 htpasswd 基礎(chǔ)認證。
編輯 Nginx 配置文件并刪除 server {}模塊,這樣我們添加新的虛擬主機配置。
cd /etc/nginx/
vim nginx.conf
\\刪除 server { } 塊。
創(chuàng)建kibana.conf的虛擬主機:
vim /etc/nginx/conf.d/kibana.conf
server {
listen 80;
server_name elk-stack.co;
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/.kibana-user;
location / {
proxy_pass http://localhost:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
使用 htpasswd 命令創(chuàng)建一個新的基本認證文件。
sudo htpasswd -c /etc/nginx/.kibana-user admin
“輸入你的密碼”
啟動 Nginx。
nginx -t
systemctl enable nginx
systemctl start nginx
步驟 5 – 安裝和配置 Logstash
在此步驟中,我們將安裝 Logstash,并將其配置為:從配置了 filebeat 的 logstash 客戶端里集中化服務(wù)器的日志,然后過濾和轉(zhuǎn)換 Syslog 數(shù)據(jù),并將其移動到存儲中心(Elasticsearch)中。
下載 Logstash 并使用 rpm 進行安裝。
wget https://artifacts.elastic.co/downloads/logstash/logstash-5.1.1.rpm
rpm -ivh logstash-5.1.1.rpm
生成新的 SSL 證書文件,以便客戶端可以識別 elastic 服務(wù)端。
cd /etc/pki/tls
\\ 進入 tls 目錄并編輯 openssl.cnf 文件。
vim openssl.cnf
在 [v3_ca] 部分添加服務(wù)器標(biāo)識。
[ v3_ca ]
# Server IP Address
subjectAltName = IP: 10.0.15.10
使用 openssl 命令生成證書文件。
openssl req -config /etc/pki/tls/openssl.cnf -x509 -days 3650 -batch -nodes -newkey rsa:2048 -keyout /etc/pki/tls/private/logstash-forwarder.key -out /etc/pki/tls/certs/logstash-forwarder.crt
證書文件可以在 /etc/pki/tls/certs/ 和 /etc/pki/tls/private/ 目錄中找到。
接下來,我們會為 Logstash 創(chuàng)建新的配置文件。創(chuàng)建一個新的 filebeat-input.conf 文件來為 filebeat 配置日志源,然后創(chuàng)建一個 syslog-filter.conf 配置文件來處理 syslog,再創(chuàng)建一個 output-elasticsearch.conf 文件來定義輸出日志數(shù)據(jù)到 Elasticsearch。
轉(zhuǎn)到 logstash 配置目錄,并在 conf.d 子目錄中創(chuàng)建新的配置文件。
cd /etc/logstash/
vim conf.d/filebeat-input.conf
輸入配置,粘貼以下配置:
input {
beats {
port => 5443
ssl => true
ssl_certificate => "/etc/pki/tls/certs/logstash-forwarder.crt"
ssl_key => "/etc/pki/tls/private/logstash-forwarder.key"
}
}
創(chuàng)建 syslog-filter.conf 文件
vim conf.d/syslog-filter.conf
粘貼以下配置:
filter {
if [type] == "syslog" {
grok {
match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}" }
add_field => [ "received_at", "%{@timestamp}" ]
add_field => [ "received_from", "%{host}" ]
}
date {
match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ]
}
}
}
我們使用名為 grok 的過濾器插件來解析 syslog 文件。
創(chuàng)建輸出配置文件 output-elasticsearch.conf。
vim conf.d/output-elasticsearch.conf
output {
elasticsearch { hosts => ["localhost:9200"]
hosts => "localhost:9200"
manage_template => false
index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
document_type => "%{[@metadata][type]}"
}
}
啟動logstash服務(wù)
sudo systemctl enable logstash
sudo systemctl start logstash
步驟 6 – 在 CentOS 客戶端上安裝并配置 Filebeat
Beat 作為數(shù)據(jù)發(fā)送人的角色,是一種可以安裝在客戶端節(jié)點上的輕量級代理,將大量數(shù)據(jù)從客戶機發(fā)送到 Logstash 或 Elasticsearch 服務(wù)器。有 4 種 beat,F(xiàn)ilebeat 用于發(fā)送“日志文件”,Metricbeat 用于發(fā)送“指標(biāo)”,Packetbeat 用于發(fā)送“網(wǎng)絡(luò)數(shù)據(jù)”,Winlogbeat 用于發(fā)送 Windows 客戶端的“事件日志”。
在本教程中,我將向您展示如何安裝和配置 Filebeat,通過 SSL 連接將數(shù)據(jù)日志文件傳輸?shù)?Logstash 服務(wù)器。
登錄到客戶端1的服務(wù)器上。 然后將證書文件從 elastic 服務(wù)器復(fù)制到客戶端1的服務(wù)器上。
ssh root@client1IP
scp root@elk-serverIP:~/logstash-forwarder.crt .
.....
sudo mkdir -p /etc/pki/tls/certs/
mv ~/logstash-forwarder.crt /etc/pki/tls/certs/
接下來,在客戶端 1 服務(wù)器上導(dǎo)入 elastic 密鑰。
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
下載 Filebeat 并且用 rpm 命令安裝。
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.1.1-x86_64.rpm
rpm -ivh filebeat-5.1.1-x86_64.rpm
Filebeat 已經(jīng)安裝好了,請轉(zhuǎn)到配置目錄并編輯 filebeat.yml 文件。
cd /etc/filebeat/
vim filebeat.yml
\\ 在第 21 行的路徑部分,添加新的日志文件。 我們將創(chuàng)建兩個文件,記錄 ssh 活動的 /var/log/secure 文件 ,以及服務(wù)器日志 /var/log/messages :
paths:
- /var/log/secure
- /var/log/messages
\\在第 26 行添加一個新配置來定義 syslog 類型的文件:
document-type: syslog
\\在 83 行和 85 行添加注釋來禁用 Elasticsearch 輸出,更改為 Logshtash:
-------------------------------------------------------------------------------------
#-------------------------- Elasticsearch output ------------------------------
#output.elasticsearch:
# Array of hosts to connect to.
# hosts: ["localhost:9200"]
--------------------------------------------------------------------------------------
------------------現(xiàn)在添加新的 logstash 輸出配置--------------------------------------
output.logstash:
# The Logstash hosts
hosts: ["10.0.15.10:5443"]
bulk_max_size: 1024
ssl.certificate_authorities: ["/etc/pki/tls/certs/logstash-forwarder.crt"]
template.name: "filebeat"
template.path: "filebeat.template.json"
template.overwrite: false
--------------------------------------------------------------------------------------
PS:Filebeat 默認使用 Elasticsearch 作為輸出目標(biāo)。 在本教程中,我們將其更改為 Logshtash。
將 Filebeat 設(shè)定為開機啟動并啟動。
sudo systemctl enable filebeat
sudo systemctl start filebeat
步驟 7 – 在 Ubuntu 客戶端上安裝并配置 Filebeat
從服務(wù)端拷貝證書文件
ssh root@ubuntu-clientIP
scp root@elk-serverIP:~/logstash-forwarder.crt .
.......
sudo mkdir -p /etc/pki/tls/certs/
mv ~/logstash-forwarder.crt /etc/pki/tls/certs/
在服務(wù)器上導(dǎo)入 elastic 密鑰。
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
下載 Filebeat .deb 包并且使用 dpkg 命令進行安裝。
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.1.1-amd64.deb
dpkg -i filebeat-5.1.1-amd64.deb
轉(zhuǎn)到配置目錄并編輯 filebeat.yml 文件。
cd /etc/filebeat/
vim filebeat.yml
\\ 在第 21 行的路徑部分,添加新的日志文件。 我們將創(chuàng)建兩個文件,記錄 ssh 活動的 /var/log/secure 文件 ,以及服務(wù)器日志 /var/log/messages :
paths:
- /var/log/secure
- /var/log/messages
\\在第 26 行添加一個新配置來定義 syslog 類型的文件:
document-type: syslog
\\在 83 行和 85 行添加注釋來禁用 Elasticsearch 輸出,更改為 Logshtash:
-------------------------------------------------------------------------------------
#-------------------------- Elasticsearch output ------------------------------
#output.elasticsearch:
# Array of hosts to connect to.
# hosts: ["localhost:9200"]
--------------------------------------------------------------------------------------
------------------現(xiàn)在添加新的 logstash 輸出配置--------------------------------------
output.logstash:
# The Logstash hosts
hosts: ["10.0.15.10:5443"]
bulk_max_size: 1024
ssl.certificate_authorities: ["/etc/pki/tls/certs/logstash-forwarder.crt"]
template.name: "filebeat"
template.path: "filebeat.template.json"
template.overwrite: false
--------------------------------------------------------------------------------------
PS:Filebeat 默認使用 Elasticsearch 作為輸出目標(biāo)。 在本教程中,我們將其更改為 Logshtash。
將 Filebeat 設(shè)定為開機啟動并啟動。
sudo systemctl enable filebeat
sudo systemctl start filebeat
檢查服務(wù)狀態(tài):
systemctl status filebeat
步驟 8 – 測試
打開您的網(wǎng)絡(luò)瀏覽器,并訪問您在 Nginx 中配置的 elastic stack 域名,我的是“elk-stack.co”。 使用管理員密碼登錄,然后按 Enter 鍵登錄 Kibana 儀表盤。
Centos7上安裝與配置Elastic StackCentos7上安裝與配置Elastic Stack
創(chuàng)建一個新的默認索引 filebeat-*,然后點擊“創(chuàng)建”按鈕。
默認索引已創(chuàng)建。 如果 elastic stack 上有多個 beat,您可以在“星形”按鈕上點擊一下即可配置默認 beat。
轉(zhuǎn)到 “發(fā)現(xiàn)” 菜單,您就可以看到 elk-client1 和 elk-client2 服務(wù)器上的所有日志文件。
來自 elk-client1 服務(wù)器日志中的無效 ssh 登錄的 JSON 輸出示例。
使用其他的選項,你可以使用 Kibana 儀表盤做更多的事情。
Elastic Stack 已安裝在 CentOS 7 服務(wù)器上。 Filebeat 已安裝在 CentOS 7 和 Ubuntu 客戶端上。
網(wǎng)站名稱:Centos7安裝ElasticStack
當(dāng)前鏈接:http://www.dlmjj.cn/article/djdesji.html


咨詢
建站咨詢
