Linux下安裝ELK(Elasticsearch、Kibana、logstash)
1. 下載elasticsearch(6.8.7版本)
elastic下載地址:elasticsearch6.8.7
2.下載kibana(6.8.7版本)
kibana下載地址:kibana6.8.7
3.下載logstash(6.8.7版本)
logstash下載地址:logstash6.8.7
將下載好的文件傳輸到linux中
在安裝ES之前需要先安裝Java配置環境。這個百度一下吧,我機器上都有裝了,就不示範了。
es不能在root用戶上運行,需要在普通用戶運行,但我已經有用戶了就不重新新建了。
4.安裝Elasticsearch
4.1 解壓es文件,並來到bin目錄下
tar -zxvf elasticsearch-6.8.7.tar.gz -C /home/grid/
ls
cd elstaicsearch-6.8.7/bin/
4.2 啓動es,在es的bin目錄下
./elstaicsearch
後臺啓動可以 ./elasticsearch -d
4.3 測試連接(另起一個界面),會看到一份JSON數據
curl 127.0.0.1:9200
4.4 實現遠程訪問,在config/elasticsearch.yml配置
vi elasticsearch.yml
需要修改的配置內容,cluster.name(集羣名稱),path.data(數據存放位置),path.logs(日誌存放位置),network.host(集羣ip),http.port(集羣端口)
cluster.name: my-application
path.data: /home/grid/elasticsearch-6.8.7/data
path.logs: /home/grid/elasticsearch-6.8.7/logs
network.host: 192.168.171.101
http.port: 9200
4.5 重新啓動es
./elstaicsearch
出現錯誤,無法啓動
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3863] for user [grid] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
來root用戶修復問題
修復問題[1],修改limits.conf文件
su root
vi /etc/security/limits.conf
grid soft nofile 65536
grid hard nofile 65536
grid soft nproc 4096
grid hard nproc 4096
修復問題[2],修改20-nproc.conf文件
vi /etc/security/limits.d/20-nproc.conf
grid soft nproc 4096
修復問題[3],修改sysctl.conf文件
vi /etc/sysctl.conf
vm.max_map_count=655360
執行以下命令生效,並且關閉防火牆
sysctl -p
systemctl stop firewalld.service
重啓虛擬機,並且在grid用戶,再次重啓啓動es
./elstaicsearch
4.7 啓動成功,訪問網址測試連接
http://slave1:9200/
5.安裝head(elasticsearch-head-master)
elasticsearch-head-master是es的集羣管理工具,可以用來數據的瀏覽和查詢。
head是開源軟件,託管在github,需要在github下載,地址:git://github.com/mobz/elasticsearch-head.git。
head的運行需要用到grunt,而grunt需要npm,所以需要安裝nodejs。
es5.0之後,head已經不做爲插件方在plugins目錄,直接拷貝在本地就行。
5.1 安裝nodejs
nodejs下載地址:nodejs下載地址
5.1.1 將nodejs傳輸到linux中的/home/grid/software目錄
5.1.2 轉到root用戶,將nodejs解壓到/usr目錄下
su root
tar xf node-v12.16.1-linux-x64.tar.xz -C /usr/
5.1.3 重命名nodejs文件夾,並且配置環境變量
mv node-v12.16.1-linux-x64 node-v12.16.1
vi /etc/profile
export NODEJS_HOME=/usr/node-v12.16.1
:$NODEJS_HOME/bin
5.1.4 讓配置文件生效
source /etc/profile
5.1.5 驗證是否安裝成功,查看node版本
node -v
5.2 安裝elasticsearch-head-master
5.2.1 下載elasticsearch-head-master
head下載地址:head下載地址
將下載好的head傳輸到linux的/home/grid目錄
5.2.2 安裝grunt-cli
npm install -g grunt-cli
5.2.3 來到head目錄下安裝head的依賴包
cd elasticsearch-head-master/
注:直接使用npm install下載速度可能會比較慢,可以用阿里雲的鏡像下載
npm install -g cnpm --registry=https://registry.npm.taobao.org
或者
npm install
5.2.4 查看版本
grunt -version
5.2.5 修改Gruntfile.js配置文件
vi Gruntfile.js
在connect–>server–>options下面添加:hostname:’*’,允許所有IP可以訪問
hostname:'*',
5.2.6 修改_site目錄下的app.js中head的默認連接地址
cd _site
vi app.js
"http://localhost:9200"改成"http://192.168.171.101:9200"
5.2.7 配置es允許跨域訪問,es目錄下的config的elasticsearch.yml
cd config
vi elasticsearch.yml
在文件末尾追加
http.cors.enabled: true
http.cors.allow-origin: "*"
5.2.8 啓動head
grunt server
5.2.9 在瀏覽器訪問head
http://slave1:9100
6.安裝Kibana
6.1 將已經下載好的Kibana傳輸到linux的/home/grid/software目錄
6.2 解壓縮kibana
tar -zxvf kibana-6.8.7-linux-x86_64.tar.gz -C /home/grid/
6.3 修改配置文件在config下的kibana.yml
cd kibana-6.8.7-linux-x86_64/config/
vi kibana.yml
server.port: 5601
server.host: "192.168.171.101"
elasticsearch.hosts: ["http://192.168.171.101:9200"]
6.4 啓動kibana,在kibana的bin目錄下執行
啓動kibana之前需要先啓動elasticsearch
./kibana
6.5 在瀏覽器訪問kibana
http://slave1:5601/
7.安裝logstash
7.1 將logstash傳輸到linux下的/home/grid/software目錄
7.2 解壓縮logstash
tar -zxvf logstash-6.8.7.tar.gz -C /home/grid/
7.3 啓動logstash小案例
./logstash -e 'input { stdin { } } output { stdout {} }'
啓動成功
一般啓動logstach是需要配置input,output
比如新建一個demo,在demo中新建一個xxx.conf,將input和output配置在conf時啓動方式:
./logstash -f ../demo/xxx.conf
8.Linux啓動ELK步驟
8.1 啓動elasticsearch
elasticsearch目錄下(master)
./bin/elasticsearch
8.2 啓動elasticsearch-head-master
elasticsearch-head-master目錄下
grunt server
8.3 啓動kibana
kibana目錄下
./bin/kibana
8.4 啓動logstash(選擇性是否啓動)
logstash目錄下
./bin/logstash -e 'input {stdin {} } output{ stdout {}}'
至此ELK都安裝成功