使用linux搭建單機elk環(huán)境
要想落地elk,首先就是安裝。本文將提供單機版的elk環(huán)境落地供大家參考。集群版請自行查找。
一.版本
本文使用的logstash-7.3.2.tar.gz,搭配使用7.6.0的es,kibana,親測好用。也可以在點我這里下載。
二.安裝elasticsearch
1.下載安裝包
由于官網(wǎng)下載太慢了,可以在以下地址下載。點這下載
2.解壓
下載完成后,復(fù)制進linux并解壓。
tar -zxvf elasticsearch-7.6.0-linux-x86_64.tar.gz
3.新建用戶
useradd elasticsearch passwd elasticsearch chown -R elasticsearch /usr/local/es/elasticsearch-7.6.0 賦權(quán)
4.修改配置文件
修改elasticsearch.yml文件。
cluster.name: elasticsearch node.name: node-1 path.data: /usr/local/elasticsearch/elasticsearch-7.6.0/data path.logs: /usr/local/elasticsearch/elasticsearch-7.6.0/logs network.host: 0.0.0.0 http.port: 9200 cluster.initial_master_nodes: ["node-1"]
如果需要連接spring boot,需要添加以下配置。
http.cors.enabled: true http.cors.allow-origin: "*" xpack.security.enabled: true xpack.security.transport.ssl.enabled: true
同時在安裝時會要求設(shè)置密碼,如果沒有以上配置則不需要。
5.進入elasticsearch用戶
su elasticsearch
一定要在該用戶下安裝。
6.啟動
cd /usr/local/es/elasticsearch-7.6.0/bin ./elasticsearch
7.開放端口號
如果發(fā)現(xiàn)輸入ip:9200還是訪問不了,請記住開放端口。
/sbin/iptables -I INPUT -p tcp --dport 9200 -j ACCEPT
8.驗證
訪問ip:9200,如果出現(xiàn)以下樣式,則安裝成功。
9.后臺啟動
./elasticsearch -d
10.異常總結(jié)
在博主安裝時,出現(xiàn)了無數(shù)異常,博主總結(jié)成以下文檔。所以如果有條件建議使用docker。
1)max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536] 原因:無法創(chuàng)建本地文件問題,用戶最大可創(chuàng)建文件數(shù)太小 解決方案:切換到root用戶,編輯limits.conf配置文件, 添加類似如下內(nèi)容: vi /etc/security/limits.conf 添加如下內(nèi)容: 注意*不要去掉了 * soft nofile 65536 * hard nofile 131072 * soft nproc 4096 * hard nproc 4096 備注:* 代表Linux所有用戶名稱(比如 hadoop) 需要保存、退出、重新登錄才可生效。 2)max number of threads [1024] for user [es] likely too low, increase to at least [4096] 原因:無法創(chuàng)建本地線程問題,用戶最大可創(chuàng)建線程數(shù)太小 解決方案:同上 3)max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144] 原因:最大虛擬內(nèi)存太小 每次啟動機器都手動執(zhí)行下。 root用戶執(zhí)行命令: [root@localhost ~]# sysctl -w vm.max_map_count=262144 查看修改結(jié)果命令:sysctl -a|grep vm.max_map_count 看是否已經(jīng)修改 永久性修改策略: echo "vm.max_map_count=262144" >> /etc/sysctl.conf 4)system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk 原因:Centos6不支持SecComp,而ES5.4.1默認bootstravelap.system_call_filter為travelue進行檢測,所以導(dǎo)致檢測失敗,失敗后直接導(dǎo)致ES不能啟動。 詳見 :https://github.com/elastic/elasticsearch/issues/22899 解決方法:在elasticsearch.yml中新增配置 bootstrap.system_call_filter,設(shè)為false,注意要在Memory下面: bootstrap.memory_lock: false bootstrap.system_call_filter: false 5) os::commit_memory(0x00000000c5330000, 986513408, 0) failed; vi ../config/jvm.options 修改 -Xms256m -Xmx256m 6)future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk/jdk1.8.0_231/jre] does not meet this requirement 不用管 會向下兼容 7)es:ccomp unavailable: CONFIG_SECCOMP not compiled into kernel, CONFIG_SECCOMP and CONFIG_SEC /usr/local/es/elasticsearch-7.6.0/config/elasticsearch.yml追加 bootstrap.memory_lock: false bootstrap.system_call_filter: false
三.安裝kibana
1.下載
同上。
2.解壓
同上。
tar -zxvf kibana.tar.gz
3.修改配置
修改 /usr/local/kibana/kibana-7.6.0-linux-x86_64/config/kibana.yml。
i18n.locale: "zh-CN" #漢化 server.port: 5601 server.host: 0.0.0.0
如果上文es開啟了xpack,需要加入以下配置。
elasticsearch.username: "elastic" elasticsearch.password: "xxxx" xpack.reporting.encryptionKey: "a_random_string" xpack.security.encryptionKey: "something_at_least_32_characters"
4.賦權(quán)
因為需要使用非root用戶啟動,所以需要賦權(quán)。
chown -R elasticsearch /usr/local/kibana
5.開通端口
/sbin/iptables -I INPUT -p tcp --dport 5601 -j ACCEPT
6.后臺運行
nohup ./kibana &
7.驗證
訪問ip:5601,如果出現(xiàn)下文樣式,則安裝成功。
四.安裝logstash
1.下載
logstash可以在博主網(wǎng)盤中獲取到。地址如下。
鏈接:https://pan.baidu.com/s/1izhfHnMlaHuSHm6q8rReAQ
提取碼:t8ws
2.解壓
tar -zxvf logstash-7.3.2.tar.gz
3.更改配置文件
在/logstash/bin目錄下新建log_to_es.conf,(文件名隨意,啟動命令需要)并添加以下配置(配置僅用于測試) 。
input { file { path => "/var/log/messages" 監(jiān)控的該路徑的文件 并且輸入到es中 type => "systemlog" start_position => "beginning" } } output{ elasticsearch{ hosts=>["192.168.xx.xx:9200"] es地址 默認端口號為9200 index => "log-%{+YYYY.MM.dd}" 新增的索引格式 } stdout{codec => rubydebug} }
4.啟動
nohup ./logstash -f log_to_es.conf & 后臺啟動 ./logstash -f log_to_es.conf & 如果需要看到日志 使用這種方式
5.驗證
出現(xiàn)如圖 message為上文/var/log/messages路徑中的文件內(nèi)容,則安裝成功。
注意:如果已經(jīng)輸出過。需要新增文檔內(nèi)容才能繼續(xù)輸出
五.ik分詞器安裝
1.下載
由于下載太慢了,直接上網(wǎng)盤地址。
鏈接:https://pan.baidu.com/s/1n2m_LeIz1T7DrJdSsvvMFA
提取碼:16mz
2.解壓
解壓到elasticsearch/elasticsearch-7.6.0/plugins路徑下。
3.重啟elasticsearch
4.驗證
使用kibana執(zhí)行以下語句。
GET _analyze?pretty { "analyzer": "ik_max_word", "text": "我吃西紅柿" }
如果出現(xiàn)以下效果,則安裝成功。
Elasticsearch Linux
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實后本網(wǎng)站將在24小時內(nèi)刪除侵權(quán)內(nèi)容。