ELK是日志分析平台,不是一款軟件,而是一整套解決方案,是三個軟件產品的首字母縮寫,ELK分別代表:
Elasticsearch:負責日志檢索和儲存 (ELK的核心)
Logstash:負責日志的收集和分析、處理
Kibana:負責日志的可視化
beats是elastic公司開源的一款采集系統監控數據的代理agent,是在被監控服務器上以客戶端形式運行的數據收集器的統稱,可以直接把數據發送給Elasticsearch或者通過Logstash發送給Elasticsearch,然后進行后續的數據分析活動
beats由如下組成:
packetbeat:是一個網絡數據包分析器,用於監控,收集網絡流量信息,packetbeat嗅探服務器之間的流量,解析應用層協議,並關聯到消息的處理,其支持ICMP · DNS · HTTP · Mysql · postgresql · redis · mongDB · Memcache 等協議
filebeat: 用於監控,收集服務器日志文件,其已取代logstash forwarder;
Metricbeat:可定期獲取外部系統的監控指示信息,其可以監控收集Apache· Haporxy · MongoDB · mysql · nginx · postgresql · redis · system · zookeeper 等服務;
winlogbeat:用於監控,收集windows系統日志信息
全系的Elastic Stack 技術棧包括:
Elasticsearch 搭建
首先要安裝JDK環境,這里不做過多闡述。
Elasticsearch單機版安裝
官方下載地址:https://www.elastic.co/cn/downloads/
Elasticsearch有多種安裝方式,也可在官方地址進行下載。
特別說明這里的yum安裝方式是從官方文檔查閱,由於官方更新速度快,建議搭建之前多參考官方提供的文檔。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
YUM安裝方式
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
導入Elasticsearch PGP密鑰
下載並安裝公共簽名密鑰:
命令:[root@jenkins-es ~]# rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
如果報錯
curl: (7) Failed to connect to 2a04:4e42:1a::734: 網絡不可達 錯誤:https://artifacts.elastic.co/GPG-KEY-elasticsearch: import read failed(2).
執行命令:[root@jenkins-es ~]# yum update curl #刷新一下yun源,重新導入密鑰即可
elasticsearch.repo在/etc/yum.repos.d/基於RedHat的發行版的/etc/zypp/repos.d/目錄中或在基於OpenSuSE的發行版的目錄中創建一個文件,其中包含:
yum源內容如下:
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
存儲庫就可以使用了。可以使用以下命令安裝Elasticsearch:
命令:[root@jenkins-223 ~]# yum install --enablerepo=elasticsearch elasticsearch #下載有點慢
安裝
Yum安裝過之后修改配置文件
命令:vim /etc/elasticsearch/elasticsearch.yml
network.host: 0.0.0.0 //讓所有IP地址都可以訪問
path.data: /path/to/data //指定數據路徑
path.logs: /path/to/logs //指定日志文件路徑
cluster.initial_master_nodes: ["node-1"] //最后一行加上這句話
network.host: 0.0.0.0 沒改之前可以啟動
命令:mkdir -p /path/to/data
命令:mkdir -p /path/to/logs
命令:chmod 777 -R /path
說明:在Elasticsearch中如果,network.host不是localhost或者127.0.0.1的話,就會認為是生產環境,會對環境的要求比較高。測試環境的話可以修改如下配置
命令:vim /etc/elasticsearch/jvm.options
-Xms1g //初始的堆內存 (可以根據自己的機子配置)
-Xmx1g //最大的堆內存
一個進程在VMAS(虛擬內存區域)創建內存映射最大數量
命令:vim /etc/sysctl.conf
vm.max_map_count=655360
命令:[root@ELK ~]# sysctl -p //配置生效
vm.max_map_count = 655360
配置limits.conf
命令:vim /etc/security/limits.conf
* hard nofile 65536
* soft nofile 65536 //*代表所有用戶
* soft nproc 4096
* hard nproc 4096
要將Elasticsearch配置為在系統啟動時自動啟動,請運行以下命令:
命令:/bin/systemctl daemon-reload
命令:/bin/systemctl enable elasticsearch.service
Elasticsearch可以按以下方式啟動和停止:
systemctl start elasticsearch.service //啟動
systemctl stop elasticsearch.service //停止
systemctl status elasticsearch.service //查看狀態
通過瀏覽器訪問
192.168.10.50:9200 //這是個json數據,看到這個恭喜你已經搭建成功。
{
"name" : "ELK",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "08BIZlsBRtGvnz6LUAWZ0w",
"version" : {
"number" : "7.7.1",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "ad56dce891c901a492bb1ee393f12dfff473a423",
"build_date" : "2020-05-28T16:30:01.040088Z",
"build_snapshot" : false,
"lucene_version" : "8.5.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
tar包安裝方式
1.前期准備
命令:[root@ELK ~]# useradd elsearch //創建用戶,Elasticsearch不支持root用戶運行
命令:[root@ELK ~]# mkdir -p /data/ES //創建目錄
命令:[root@ELK ~]# chown -R elsearch:elsearch /data/ES //改變屬性
命令:[root@ELK ~]# tar -zxvf elasticsearch-7.7.1-linux-x86_64.tar.gz -C /data/ES/ //解壓到目錄
2.修改配置文件
命令:[root@ELK config]# vim /data/ES/elasticsearch-7.7.1/config/elasticsearch.yml
network.host: 0.0.0.0 //讓所有IP地址都可以訪問
path.data: /path/to/data //指定數據路徑
path.logs: /path/to/logs //指定日志文件路徑
cluster.initial_master_nodes: ["node-1"] //最后加上這句話
說明:在Elasticsearch中如果,network.host不是localhost或者127.0.0.1的話,就會認為是生產環境,會對環境的要求比較高。測試環境的話可以修改如下配置
命令:vim /data/ES/elasticsearch-7.7.1/config/jvm.options //修改jvm啟動參數
-Xms1g //初始的堆內存 (可以根據自己的機子配置) -Xms200m
-Xmx1g //最大的堆內存 -Xms200m (我的選擇)
一個進程在VMAS(虛擬內存區域)創建內存映射最大數量
命令:vim /etc/sysctl.conf
vm.max_map_count=655360
命令:[root@ELK ~]# sysctl -p //配置生效
vm.max_map_count = 655360
配置limits.conf
命令:vim /etc/security/limits.conf
* hard nofile 65536
* soft nofile 65536 //*代表所有用戶
* soft nproc 4096
* hard nproc 4096
啟動ES服務
命令:su elsearch //不能用root用戶啟動服務,不然會報錯
命令:cd /data/ES/elasticsearch-7.7.1/bin
命令:./elasticsearch //前台運行
命令:./elasticsearch -d //后台運行
// 啟動過程中非常慢,耐心等待
命令:[elsearch@ELK bin]$ ./elasticsearch -d //啟動之后會有下邊兩句話,提示之后的版本要用 jdk11版本。
future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk1.8.0_211/jre] does not meet this requirement
future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk1.8.0_211/jre] does not meet this requirement
啟動速度超級慢,可以用查看 9300 9200 端口起來沒。起來就 OK 了 !!!!
總結:。。。。。。。。。。。。。。。。。(此處省略一萬字)