项目需要,最近研究了一下ELK,简单的搭建了一下环境。这里记录ELK环境搭建的基础步骤,后续有深入使用ELK,再继续记录如何深入使用ELK。
这里使用的ELK版本为:6.2.4版。
ELK的作用什么的这里不介绍了,主要记录部署的过程,以及遇到的问题。
文章目录
1. 安装包下载,解压
-
安装JDK1.8
oracle官网下载一个linux版本的jdk1.8的安装包
tar -zxvf jdk-8u131-linux-x64.tar.gz 解压
vim /etc/profile 配置环境变量
重启配置文件: source /etc/profile
java -version 查看JDK版本文件末尾添加:
export JAVA_HOME=/usr/java/jdk1.8.0_131 (解压路径) export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin export PATH=$PATH:${JAVA_PATH}
-
下载Elasticsearch、kibana、logstash安装包
[root@server-1 src]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.rpm [root@server-1 src]# wget https://artifacts.elastic.co/downloads/logstash/logstash-6.2.4.rpm [root@server-1 src]# wget https://artifacts.elastic.co/downloads/kibana/kibana-6.2.4-x86_64.rpm
-
解压安装包
rpm -ivh elasticsearch-6.2.4.rpm rpm -ivh logstash-6.2.4.rpm rpm -ivh kibana-6.2.4-x86_64.rpm
-
启动
找到解压路径,进入bin目录夹:nohup ./elasticsearch &启动elasticsearch
http://ip:9200/ 查看elasticsearch信息
nohup ./kibana & 启动kibana
http://ip:5601/访问kibana可视化界面
logstash快速启动:./bin/logstash -e ‘input { stdin {} } output { stdout {} }’
如果到这里没出现问题,那么恭喜你,你运气非常好。现实是残酷的
2. 部署问题,及方案
-
启动时权限问题
can not run elasticsearch as root 不能使用root账号进行启动 (这个报错信息记录得不是很完整)
这里报错是因为Elasticsearch 不允许用root账号,创建一个账号,赋予ES解压路径的权限,在启动ES时,切换到非root账号启动。adduser xxx 新增非root用户 passwd xxx 更改密码 chown -R 用户名 /目录夹 授权目录权限 su xxx 切换用户
-
可使用句柄上限太小:
[1] bootstrap checks failed [1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
切换到root用户 。修改文件配置:vim /etc/security/limits.conf 在文件末尾加上 : 启动es的用户 hard nofile 65536 启动es的用户 soft nofile 65536 然后执行 ulimit -Hn 65536 ulimit -Hn查看 重启es
-
启动内存不够
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12) There is insufficient memory for the Java Runtime Environment to continue. Native memory allocation (mmap) failed to map 986513408 bytes for committing reserved memory. An error report file with more information is saved as: /usr/app/elasticsearch/hs_err_pid4272.log
内存一共就那么大,要么限制,要么腾出空间
减小elasticsearch内存分配: Find / -name jvm.options 找到配置文件 (自动安装解压一般就在etc 的elasticsearch启动夹下) 默认是1g可以改低点 300m Vim jvm.options 将1g改为300m(根据自己机器内存大小来) -Xms1g -Xmx1g 然后重启
-
es在同一个目录下启动时
java.lang.IllegalStateException: failed to obtain node locks, tried [[/var/lib/elasticsearch/elasticsearch]] w ith lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
find / -name elasticsearch.yml 一般在etc/elasticsearch下 修改elasticsearch.yml 在配置文件末尾增加 node.max_local_storage_nodes: 256 重启
-
elasticsearch启动后只能本地访问
既:ip:9200访问不了,然后你端口什么都是正常开放的
find / -name elasticsearch.yml 修改network.host : 0.0.0.0 重启
-
Kibana只能本地访问
etc/kibana/kibana.yml 更改server.host : “0.0.0.0” 重启Kibana
3、成功示例
如果成功熬过第二步解决问题,那么这步将会得到一点点欣慰,因为可以跑起来了。
-
logstash配置
进入/etc/logstash/conf.d 目录夹下创建elk.conf文件
文件中添加以下内容input { stdin { } } output { elasticsearch { hosts => ["127.0.0.1:9200"] } stdout { codec => rubydebug } }
./logstash -f /usr/logstash/conf.d/elk.conf 配置文件命令重启logstash
随便input些什么东西:
-
Kibana查看日志
建索引文本
别问为什么在logstash控制台输出后,什么都没干,就能在kibana可视化界面看到:
因为logstash配置那一步,配置的output,logstash过滤日志,直推给ES,ES进行存储后,就可以在Kibana中看到了。
logstash推的时候也有可能不成功,这里需要建一个index什么的,这个后续深入后,再继续更新博客
有借鉴的两篇博客:
https://www.cnblogs.com/sky-cheng/p/11164164.html
https://www.cnblogs.com/cheyunhua/p/11238489.html