在CentOS上安装ELK 5时遇到的一些坑

本文详细介绍了在CentOS7环境下安装配置ELK堆栈的过程,包括解决启动异常、权限配置、参数调整及远程访问等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装ELK的Linux环境是CentOS 7,使用的JDK版本是1.8.0_144
安装使用的ELK版本是5.5.1
首先安装elasticsearch 5.5.1,从官网下载elasticsearch-5.5.1.tar.gz后解压,在bin目录下以root用户身份直接运行

./elasticsearch

会抛出异常信息

java.lang.RuntimeException: can not run elasticsearch as root

警告不能使用root用户启动elasticsearch。
我新建了elk groups和elk用户,按照网上提示的把elasticsearch解压目录的所有者赋予elk用户,结果不起作用,当从root用户切换回elk用户后,无法切换到解压目录,提示权限不许可。

还需要赋予elk用户对解压目录的读写执行权限后才能启动elasticsearch应用。

sudo chmod -R 755 /opt/elk/elasticsearch-5.5.1

切换到elk用户后,可以启动elasticsearch,但是启动日志中显示启动检查失败,启动不成功。
检查错误信息有两条

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

第一条错误检查表示elk用户启动elasticsearch的最大文件描述符默认值4096过小,需要调整为65536。
我们修改/etc/security/limits.conf文件,在最后添加

elk soft nofile 65536
elk hard nofile 65536

这里的elk是启动elasticsearch的用户名,下同

第二条错误是虚拟内存参数过小,可以直接执行

sysctl -w vm.max_map_count=655360

指令直接设置vm.max_map_count参数值为655360
也可以直接修改/etc/sysctl.conf 文件
在文件最后加上

vm.max_map_count=655360

再执行sysctl -p命令即可。

启动elasticsearch后,从远程无法访问9200端口,需要修改elasticsearch.yml文件,设置network.host为0.0.0.0

# Set the bind address to a specific IP (IPv4 or IPv6):
#
 network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
#http.port: 9200

同时在CentOS的防火墙上打开9200端口。
重启elasticsearch后,从远程机器上执行curl命令

curl http://xxx.xxx.xxx.xxx:9200
{
  "name" : "QM1a6g-",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "lBAC52_EQzGL6AIUrcdZMg",
  "version" : {
    "number" : "5.5.1",
    "build_hash" : "19c13d0",
    "build_date" : "2017-07-18T20:44:24.823Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}

即可以从远端服务器获取elasticsearch服务器的信息。
如果在elasticsearch.yml文件中设置bootstrap.memory_lock为true,保证ES启动时有足够内存,启动时会检查失败

[1]: memory locking requested for elasticsearch process but memory is not locked

需要修改/etc/security/limits.conf文件,添加下列设置

elk soft memlock unlimited
elk hard memlock unlimited

设置进程可以锁定在内存中的最大数据大小
再修改/etc/sysctl.conf 文件,添加

vm.swappiness=0

表示最大限度的使用系统内存
设置完后重启系统,再重启elasticsearch发现问题仍然存在,需要执行ulimit -l unlimited指令后才能启动成功,但是这条指令在CentOS重启后失效,最后我修改了
/etc/security/limits.conf文件为以下形式

* soft nofile 65536
* hard nofile 65536
* soft memlock unlimited
* hard memlock unlimited

对所有域都执行nofile和memlock的设定,重启系统后再重启elastichsearch不再出现memlock检查的问题。

从elasticsearch 5.0开始,elasticsearch不再支持site plugin,因此对es进行查询的head插件不能再通过elasticsearch-plugin命令安装,可以通过安装chrome浏览器的elasticsearch-head插件或者单独运行elasticsearch-head服务器,指向elasticsearch服务器的http端口。
我安装head插件的时候参照了下面这篇文章
http://www.cnblogs.com/xing901022/p/6030296.html
使用的nodejs版本为6.11.2,head项目需要的nodejs插件可以通过npm或yarn命令安装,由于墙的缘故,建议将npm和yarn的registry镜像改为淘宝镜像

npm --registry https://registry.npm.taobao.org info underscore 
yarn config set registry https://registry.npm.taobao.org

使用npm安装包时,建议使用npm install -g全局安装,其他上面文章提到的一样。

在最后在head目录下执行npm install或者yarn install命令时,会出现下面的错误

npm ERR! phantomjs-prebuilt@2.1.14 install: `node install.js`

这时需要单独安装phantomjs-prebuilt,执行命令为

npm install phantomjs-prebuilt@2.1.14 --ignore-scripts

参考了
http://blog.youkuaiyun.com/txl910514/article/details/55135734这篇文章

使用grunt server启动head服务器后,从远程浏览器可以直接对es进行查询。
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值