EFK 环境搭建
1、环境准备
-rw-r--r-- 1 root root 318808405 Jan 17 19:50 elasticsearch-7.10.2-linux-x86_64.tar.gz
-rw-r--r-- 1 root root 921421 Jan 26 20:51 elasticsearch-head-master.zip
-rw-r--r-- 1 root root 34059708 Jan 17 19:48 filebeat-7.10.2-linux-x86_64.tar.gz
-rw-r--r-- 1 root root 249171053 Jan 18 19:36 kibana-7.10.2-linux-x86_64.tar.gz
-rw-r--r-- 1 root root 21390448 Jan 25 21:37 node-v14.15.4-linux-x64.tar.xz
-rw-rw-r-- 1 root root 34059708 Jan 19 19:21 filebeat-7.10.2-linux-x86_64.tar.gz
-rw-rw-r-- 1 root root 249171053 Jan 20 21:43 kibana-7.10.2-linux-x86_64.tar.gz
2、部署 java 环境
Elasticsearch 的运行需要 java 环境
[root@VM-0-15-centos java]# tar -zxvf jdk-8u271-linux-x64.tar.gz -C /usr/local/
编辑 /etc/profile,修改环境变量
[root@VM-0-15-centos java]# vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.8.0_271
export JRE_HOME=/usr/local/jdk1.8.0_271/jre
export CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
[root@VM-0-15-centos efk]# source /etc/profile
3、部署 elasticsearch
- 解压
[root@VM-0-15-centos efk]# tar -zxvf elasticsearch-7.10.2-linux-x86_64.tar.gz
[root@VM-0-15-centos efk]# mv elasticsearch-7.10.2 /usr/local/elasticsearch
- Elasticsearch 使用 root 用户启动会报错,创建一个普通用户来启动 Elasticsearch
[root@VM-0-15-centos efk]# useradd elastic
- 修改 elasticsearch 目录的属主和属组
[root@VM-0-15-centos efk]# cd /usr/local
[root@VM-0-15-centos efk]# chown -R elastic.elastic elasticsearch
- 修改配置文件
[root@VM-0-15-centos efk]# vim elasticsearch/config/elasticsearch.yml
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: '*'
cluster.initial_master_nodes: ["node-1"]
- 切换为普通用户,尝试启动:
[root@VM-0-15-centos efk]# su - elastic
[elastic@VM-0-15-centos elasticsearch]$ cd /usr/local/elasticsearch/bin
[elastic@VM-0-15-centos bin]$ ./elasticsearch
- 启动异常处理
elasticserach部署的时候,日志 WARN 部分显示的警告信息,有时候会升级为 ERROR,然后服务就启不起来;
错误1:
ERROR:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535];
解决办法:
[root@VM-0-15-centos efk]# vim /etc/security/limits.conf
#在配置文件中添加如下参数:
* soft nofile 65535
* hard nofile 65535
错误2:
ERROR:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决办法:
[root@VM-0-15-centos efk]# vim /etc/sysctl.conf
## 在配置文件中添加如下参数:
vm.max_map_count=262144
执行命令:
[root@VM-0-15-centos efk]# sysctl -p
- 修改占用内存大小
[root@VM-0-15-centos config]# vim jvm.options
#Xms表示总堆空间的初始大小
#Xmx表示总堆空间的最大大小
-Xms512m
-Xmx512m
- 本地测试
[root@VM-0-15-centos config]# curl '127.0.0.1:9200'
{
"name" : "node-1",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "EE2LTXCHSJS9K-cgOHB3jQ",
"version" : {
"number" : "7.10.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "747e1cc71def077253878a59143c1f785afa92b9",
"build_date" : "2021-01-13T00:42:12.435326Z",
"build_snapshot" : false,
"lucene_version" : "8.7.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
- 设置 elasticsearch 为后台启动,并指定 PID 文件
[elastic@VM-0-15-centos bin]$ ./elasticsearch -p ./elasticsearch-pid -d
4、部署 kibana
- 解压
[root@VM-0-15-centos efk]# tar -zxvf kibana-7.10.2-linux-x86_64.tar.gz
[root@VM-0-15-centos efk]# mv kibana-7.10.2-linux-x86_64 /usr/local/kibana
- 修改配置文件
[root@VM-0-15-centos efk]# cd /usr/local/kibana/
[root@VM-0-15-centos kibana]# vim config/kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://localhost:9200"]
kibana.index: ".kibana"
- 启动 kibana
[root@VM-0-15-centos kibana]# cd bin
[root@VM-0-15-centos bin]# ./kibana
- 后台启动
[root@VM-0-15-centos bin]# nohup ./kibana &
- 后台停止
fuser -n tcp 5601
kill -9 端口
5、部署 filebeat
- 解压
[root@VM-0-15-centos efk]# tar -zxvf filebeat-7.10.2-linux-x86_64.tar.gz
[root@VM-0-15-centos efk]# mv filebeat-7.10.2-linux-x86_64 /usr/local/filebeat
- 编辑配置文件
[root@VM-0-15-centos efk]# cd /usr/local/filebeat
[root@VM-0-15-centos filebeat]# vim filebeat.yml
filebeat.inputs:
- type: log
paths:
- /home/spring/*.log
multiline.pattern: '^\d{4}\-\d{2}\-\d{2}\s\d{2}:\d{2}:\d{2}'
multiline.negate: true #多行匹配模式后配置的模式是否取反,默认false
multiline.match: after #定义多行内容被添加到模式匹配行之后还是之前,默认无,可以被设置为after或者before
setup.kibana:
host: "localhost:5601"
output.elasticsearch:
hosts: ["localhost:9200"]
- 后台启动 filebeat
[root@VM-0-15-centos filebeat]# nohup ./filebeat -c filebeat.yml &
6、部署 elasticsearch-head
6.1部署nginx
- 解压
[root@VM-0-15-centos efk]# tar -zxvf node-v14.15.4-linux-x64.tar.xz -C /usr/local/node
- 编辑 /etc/profile,修改环境变量
[root@VM-0-15-centos java]# vim /etc/profile
export NODE_HOME=/usr/local/node/node-v14.15.4-linux-x64
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$NODE_HOME/bin
[root@VM-0-15-centos efk]# source /etc/profile
- 安装cnpm
npm install -g cnpm -- registry=https:// registry . npm. taobao. org
6.2 部署elasticsearch-head
- 新建组件文件夹
7.10.2版本的elasticsearch 不允许将组件安装在elasticsearch下的plugins目录
我们需要新建目录
[root@VM-0-15-centos elasticsearch]# mkdir assembly
- 将解压好的 elasticsearch-head-master文件放入assembly
3.修改配置文件
[root@VM-0-15-centos elasticsearch-head-master]# vim Gruntfile.js
connect: {
server: {
options: {
# 添加hostname
hostname:'*',
port: 9100,
base: '.',
keepalive: true
}
}
}
- 安装依赖
[root@VM-0-15-centos elasticsearch-head-master]# cnpm install
- 启动
[root@VM-0-15-centos elasticsearch-head-master]# cnpm run star