1.環(huán)境部署
安裝軟件 | 主機(jī)名 | IP地址 | 內(nèi)存需求 |
---|---|---|---|
Elasticsearch | mes | 192.168.13.142 | 至少3G |
Logstash | log | 192.168.13.143 | 至少2G |
head,Kibana | head-kib | 192.168.13.139 | 至少2G |
地址與版本
Elasticsearch: 6.5.4 #https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.tar.gz
Logstash: 6.5.4 #https://artifacts.elastic.co/downloads/logstash/logstash-6.5.4.tar.gz
Kibana: 6.5.4 #https://artifacts.elastic.co/downloads/kibana/kibana-6.5.4-linux-x86_64.tar.gz
Kafka: 2.11-2.1 #https://archive.apache.org/dist/kafka/2.1.0/kafka_2.11-2.1.0.tgz
Filebeat: 6.5.4
相應(yīng)的版本最好下載對應(yīng)的插件
相關(guān)地址:
官網(wǎng)地址
2.Elasticsearch部署
系統(tǒng)類型:Centos7.5
節(jié)點IP:172.16.13.142
軟件版本:jdk-8u211-linux-x64.tar.gz东羹、elasticsearch-6.5.4.tar.gz
1.安裝配置jdk
[root@mes ~]# tar xzf jdk-8u211-linux-x64.tar.gz -C /usr/local/ #解壓
[root@mes ~]# cd /usr/local/
[root@mes local]# mv jdk1.8.0_211/ java
[root@mes local]# echo '
JAVA_HOME=/usr/local/java
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME PATH
' >>/etc/profile
[root@mes local]# source /etc/profile
[root@mes local]# java -version #出現(xiàn)版本號就代表jdk配置成功
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
2.安裝配置ES
[root@mes ~]# useradd elsearch #創(chuàng)建運(yùn)行用戶
[root@mes ~]# echo "123456" | passwd --stdin "elsearch" #設(shè)置密碼
[root@mes ~]# tar xzf elasticsearch-6.5.4.tar.gz -C /usr/local/
[root@mes ~]# cd /usr/local/elasticsearch-6.5.4/config/
[root@mes config]# cp elasticsearch.yml elasticsearch.yml.bak #備份
[root@mes config]# vim elasticsearch.yml
# 在最后一行添加如下內(nèi)容
cluster.name: elk
node.name: elkyjssjm
node.master: true
node.data: true
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/logs
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
#discovery.zen.ping.unicast.hosts: ["192.168.246.234", "192.168.246.231","192.168.246.235"]
#discovery.zen.minimum_master_nodes: 2
#discovery.zen.ping_timeout: 150s
#discovery.zen.fd.ping_retries: 10
#client.transport.ping_timeout: 60s
參數(shù)詳解
cluster.name 集群名稱剂桥,各節(jié)點配成相同的集群名稱。
node.name 節(jié)點名稱百姓,各節(jié)點配置不同渊额。
node.master 指示某個節(jié)點是否符合成為主節(jié)點的條件。
node.data 指示節(jié)點是否為數(shù)據(jù)節(jié)點。數(shù)據(jù)節(jié)點包含并管理索引的一部分旬迹。
path.data 數(shù)據(jù)存儲目錄火惊。
path.logs 日志存儲目錄。
bootstrap.memory_lock 內(nèi)存鎖定奔垦,是否禁用交換屹耐。
bootstrap.system_call_filter 系統(tǒng)調(diào)用過濾器。
network.host 綁定節(jié)點IP椿猎。
http.port 端口惶岭。
discovery.zen.ping.unicast.hosts 提供其他 Elasticsearch 服務(wù)節(jié)點的單點廣播發(fā)現(xiàn)功能。
discovery.zen.minimum_master_nodes 集群中可工作的具有Master節(jié)點資格的最小數(shù)量犯眠,官方的推薦值是(N/2)+1按灶,其中N是具有master資格的節(jié)點的數(shù)量。
discovery.zen.ping_timeout 節(jié)點在發(fā)現(xiàn)過程中的等待時間筐咧。
discovery.zen.fd.ping_retries 節(jié)點發(fā)現(xiàn)重試次數(shù)鸯旁。
http.cors.enabled 是否允許跨源 REST 請求,表示支持所有域名量蕊,用于允許head插件訪問ES铺罢。
http.cors.allow-origin 允許的源地址。
設(shè)置JVM堆大小残炮,一般設(shè)置為內(nèi)存的一半韭赘,但最少2G
[root@mes ~]# sed -i 's/-Xms1g/-Xms2g/' /usr/local/elasticsearch-6.5.4/config/jvm.options
[root@mes ~]# sed -i 's/-Xmx1g/-Xmx2g/' /usr/local/elasticsearch-6.5.4/config/jvm.options
創(chuàng)建ES數(shù)據(jù)及日志存儲目錄并修改屬主和屬組毁枯,與上面配置文件中的路徑一一對應(yīng)
[root@mes ~]# mkdir -p /data/elasticsearch/data
[root@mes ~]# mkdir -p /data/elasticsearch/logs
[root@mes ~]# chown -R elsearch:elsearch /data/elasticsearch #給剛剛創(chuàng)建的目錄修改屬主和屬組
[root@mes ~]# chown -R elsearch:elsearch /usr/local/elasticsearch-6.5.4
系統(tǒng)優(yōu)化:
1.增加最大進(jìn)程數(shù)
[root@mes ~]# vim /etc/security/limits.conf
#在文件最后面添加如下內(nèi)容
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
================================================================
解釋:
soft xxx : 代表警告的設(shè)定圾另,可以超過這個設(shè)定值捶闸,但是超過后會有警告榴芳。
hard xxx : 代表嚴(yán)格的設(shè)定,不允許超過這個設(shè)定的值羡宙。
nofile : 是每個進(jìn)程可以打開的文件數(shù)的限制
nproc : 是操作系統(tǒng)級別對每個用戶創(chuàng)建的進(jìn)程數(shù)的限制
================================================================
2.增加最大內(nèi)存映射數(shù)
[root@mes ~]# vim /etc/sysctl.conf
#添加如下
vm.max_map_count=262144 #elasticsearch用戶擁有的內(nèi)存權(quán)限太小烁登,至少需要262144贫导;
vm.swappiness=0 #表示最大限度使用物理內(nèi)存抱完,在內(nèi)存不足的情況下,然后才是swap空間
[root@mes ~]# su - elsearch
Last login: Sat Aug 3 19:48:59 CST 2019 on pts/0
[root@mes ~]$ cd /usr/local/elasticsearch-6.5.4/
[root@mes elasticsearch-6.5.4]$ ./bin/elasticsearch #先啟動看看報錯不刃泡,需要多等一會
終止之后(等cpu降下來再終止)
[root@mes elasticsearch-6.5.4]$ nohup ./bin/elasticsearch & #放后臺啟動
[1] 11462
nohup: ignoring input and appending output to ‘nohup.out’
[root@mes elasticsearch-6.5.4]$ tail -f nohup.out #看一下是否啟動
或者:
su - elsearch -c "cd /usr/local/elasticsearch-6.5.4 && nohup bin/elasticsearch &"
測試:訪問http://192.168.13.142:9200/ 記得加端口9200
在這里插入圖片描述
3.head巧娱,Kibana安裝配置
系統(tǒng)類型:Centos7.5
節(jié)點IP:172.16.13.139
軟件版本:node-v4.4.7-linux-x64.tar.gz、elasticsearch-head-master.zip烘贴、phantomjs-2.1.1-linux-x86_64.tar.bz2禁添、kibana-6.5.4-linux-x86_64.tar.gz
1.head及其插件的安裝配置
1.安裝node
[root@head-kib ~]# wget https://npm.taobao.org/mirrors/node/latest-v4.x/node-v4.4.7-linux-x64.tar.gz
[root@head-kib ~]# tar -zxf node-v4.4.7-linux-x64.tar.gz –C /usr/local
[root@head-kib ~]# vim /etc/profile
#在最后添加如下變量
NODE_HOME=/usr/local/node-v4.4.7-linux-x64
PATH=$NODE_HOME/bin:$PATH
export NODE_HOME PATH
[root@head-kib ~]# source /etc/profile
[root@head-kib ~]# node --version #檢查node版本號
v4.4.7
2.下載head插件grunt
[root@head-kib ~]# wget https://github.com/mobz/elasticsearch-head/archive/master.zip
[root@head-kib ~]# cp elasticsearch-head-master.zip /usr/local/
[root@head-kib ~]# yum -y install unzip
[root@head-kib local]# cd /usr/local
[root@head-kib local]# unzip elasticsearch-head-master.zip
[root@head-kib local]# cd elasticsearch-head-master/
[root@head-kib elasticsearch-head-master]# npm config set registry https://registry.npm.taobao.org #改源地址,要不然下面的安裝時間會特別長
[root@head-kib elasticsearch-head-master]# npm install -g grunt-cli #安裝grunt
[root@head-kib elasticsearch-head-master]# grunt --version #檢查grunt版本號
grunt-cli v1.3.2
[root@head-kib elasticsearch-head-master]# vim /usr/local/elasticsearch-head-master/Gruntfile.js
#在95行左右
在這里插入圖片描述
[root@head-kib elasticsearch-head-master]# vim /usr/local/elasticsearch-head-master/_site/app.js
#在4374行左右
在這里插入圖片描述
3.下載head必要的文件
[root@head-kib ~]# wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
[root@head-kib ~]# yum -y install bzip2
[root@head-kib ~]# tar -jxf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /tmp/ #解壓
4.運(yùn)行head
[root@head-kib ~]# cd /usr/local/elasticsearch-head-master/
[root@head-kib elasticsearch-head-master]# npm config set registry https://registry.npm.taobao.org
[root@head-kib elasticsearch-head-master]# npm install
...
grunt-contrib-jasmine@1.0.3 node_modules/grunt-contrib-jasmine
├── sprintf-js@1.0.3
├── lodash@2.4.2
├── es5-shim@4.5.13
├── chalk@1.1.3 (escape-string-regexp@1.0.5, supports-color@2.0.0, ansi-styles@2.2.1, strip-ansi@3.0.1, has-ansi@2.0.0)
├── jasmine-core@2.99.1
├── rimraf@2.6.3 (glob@7.1.4)
└── grunt-lib-phantomjs@1.1.0 (eventemitter2@0.4.14, semver@5.7.0, temporary@0.0.8, phan
[root@head-kib elasticsearch-head-master]# nohup grunt server &
[root@head-kib elasticsearch-head-master]# tail -f nohup.out
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
測試:訪問http://192.168.13.139:9100/
在這里插入圖片描述
2.Kibana部署
1.安裝和配置
[root@head-kib ~]# tar zvxf kibana-6.5.4-linux-x86_64.tar.gz -C /usr/local/
[root@head-kib ~]# cd /usr/local/kibana-6.5.4-linux-x86_64/config/
[root@head-kib config]# vim kibana.yml
#在末尾添加以下內(nèi)容
server.port: 5601
server.host: "192.168.13.139" #本機(jī)
elasticsearch.url: "http://192.168.13.142:9200" #ES節(jié)點
kibana.index: ".kibana"
====================================================================================
server.port kibana 服務(wù)端口桨踪,默認(rèn)5601
server.host kibana 主機(jī)IP地址老翘,默認(rèn)localhost
elasticsearch.url 用來做查詢的ES節(jié)點的URL,默認(rèn)http://localhost:9200
kibana.index kibana在Elasticsearch中使用索引來存儲保存的searches, visualizations和dashboards,默認(rèn).kibana
=====================================================================================
2.啟動
[root@head-kib config]# cd ..
[root@head-kib kibana-6.5.4-linux-x86_64]# nohup ./bin/kibana &
[1] 12054
[root@head-kib kibana-6.5.4-linux-x86_64]# nohup: ignoring input and appending output to ‘nohup.out’
我們可以用nginx進(jìn)行反向代理铺峭,不至于顯示出我們真正的IP和端口號
我是在這一臺上面部署了nginx墓怀,在任意一臺部署都可以
[root@head-kib ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm #下載源
[root@head-kib ~]# yum -y install nginx #安裝
[root@head-kib ~]# cd /etc/nginx/conf.d/
[root@head-kib conf.d]# cp default.conf default.conf.bak #備份
[root@head-kib conf.d]# vim default.conf
#清空并添加以下內(nèi)容
server {
listen 80;
server_name 192.168.13.139; #你的nginx所在的機(jī)器
#charset koi8-r;
# access_log /var/log/nginx/host.access.log main;
# access_log off;
location / {
proxy_pass http://192.168.13.139:5601; #kibana所在的機(jī)器
proxy_set_header Host $host:5601;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
}
location /status {
stub_status on; #開啟網(wǎng)站監(jiān)控狀態(tài)
access_log /var/log/nginx/kibana_status.log; #監(jiān)控日志
auth_basic "NginxStatus"; }
location /head/{
proxy_pass http://192.168.246.13.139:9100; #head所在的機(jī)器
proxy_set_header Host $host:9100;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
}
}
root@head-kib ~]# systemctl start nginx #啟動nginx
測試:訪問 http://192.168.13.139/
剛開始沒數(shù)據(jù),會提示你創(chuàng)建新的數(shù)據(jù)
在這里插入圖片描述
在這里插入圖片描述
4.Logstash部署
系統(tǒng)類型:Centos7.5
節(jié)點IP:192.168.13.143
軟件版本:jdk-8u121-linux-x64.tar.gz卫键、logstash-6.5.4.tar.gz
Logstash運(yùn)行同樣依賴jdk傀履,本次為節(jié)省資源,故將Logstash安裝在了kafka244.231節(jié)點莉炉。
你想收集哪臺機(jī)器上的信息就將Logstash安裝到哪臺上钓账。
1.安裝配置jdk
[root@log ~]# tar xzf jdk-8u211-linux-x64.tar.gz -C /usr/local/ #解壓
[root@log ~]# cd /usr/local/
[root@log local]# mv jdk1.8.0_211/ java
[root@log local]# echo '
JAVA_HOME=/usr/local/java
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME PATH
' >>/etc/profile
[root@log local]# source /etc/profile
[root@log local]# java -version #出現(xiàn)版本號就代表jdk配置成功
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
2.安裝配置Logstash
[root@log ~]# tar xvzf logstash-6.5.4.tar.gz -C /usr/local/ #安裝
創(chuàng)建目錄,將輸入輸出都放在該目錄里面
[root@log ~]# mkdir -p /usr/local/logstash-6.5.4/etc/conf.d
[root@log ~]# cd /usr/local/logstash-6.5.4/etc/conf.d/
[root@log conf.d]# vim input.conf
#在下面添加
input{ #讓logstash可以讀取特定的事件源絮宁。
file{ #從文件讀取
path => ["/var/log/nginx/access_json.log"] #要輸入的文件路徑
# code => "json" #定義編碼梆暮,用什么格式輸入和輸出,由于日志就是json格式绍昂,這里不用再寫
type => "nginx" #定義一個類型啦粹,通用選項. 用于激活過濾器
}
}
output{ #輸出插件,將事件發(fā)送到特定目標(biāo)
elasticsearch { #輸出到es
hosts => ["192.168.13.142:9200"] #指定es服務(wù)的ip加端口
index => ["%{type}-%{+YYYY.MM.dd}"] #引用input中的type名稱治专,定義輸出的格式
}
}
我們這里以nginx的日志為例
[root@log ~]# cd
[root@log ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@log ~]# yum install -y nginx
將原來的日志格式注釋掉定義成json格式:
[root@log conf.d]# vim /etc/nginx/nginx.conf
# 在http模塊里面添加
log_format json '{"@timestamp":"$time_iso8601",'
'"@version":"1",'
'"client":"$remote_addr",'
'"url":"$uri",'
'"status":"$status",'
'"domain":"$host",'
'"host":"$server_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"referer": "$http_referer",'
'"ua": "$http_user_agent"'
'}';
access_log /var/log/nginx/access_json.log json; #引用定義的json格式的日志:
在這里插入圖片描述
啟動nginx
[root@log ~]# systemctl start nginx
[root@log ~]# systemctl enable nginx
啟動logstash
[root@log ~]# cd /usr/local/logstash-6.5.4/
[root@log logstash-6.5.4]# nohup bin/logstash -f etc/conf.d/ --config.reload.automatic &
訪問http://192.168.13.143/ 多刷新幾次效果更明顯
在這里插入圖片描述
然后去head插件頁面查看是否有nginx索引出現(xiàn) http://192.168.13.139:9100/
發(fā)現(xiàn)之后卖陵,去配置kibanna添加索引
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
然后你就能看見nginx日志的可視化界面了。
你們的評論和點贊是我寫文章的最大動力张峰,蟹蟹泪蔫。