欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  运维

centos7上elastic search安装详解

程序员文章站 2022-04-06 09:26:05
...
本文主要介绍了centos7上elastic search安装及填坑记,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧,希望能帮助到大家。

本文介绍了centos7上elastic search安装及填坑记,分享给大家,具体如下:

下载elastic search 5.3.0


wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.0.tar.gz
mv elasticsearch-5.3.0.tar.gz /opt
cd /opt
tar -xzvf elasticsearch-5.3.0.tar.gz
cd elasticsearch-5.3.0/

启动ES


cd /bin
./elasticsearch

按照道理应该就可以了,然而接下来各种坑一一出现,分别阐述

错误1:error='Cannot allocate memory' (errno=12)

centos7上elastic search安装详解

error='Cannot allocate memory'

solutions:

由于elasticsearch5.0默认分配jvm空间大小为2g,需要改小一点


vim config/jvm.options 
-Xms2g → -Xms512m
-Xmx2g → -Xmx512m

错误2: can not run elasticsearch as root

centos7上elastic search安装详解

can not run elasticsearch as root

solutions:

在 Linux 环境中,elasticsearch 不允许以 root 权限来运行!所以需要创建一个非root用户,以非root用户来起es


groupadd elk # 创建用户组elk
useradd elk -g elk -p 111111 # 创建新用户elk,-g elk 设置其用户组为 elk,-p 111 设置其密码6个1
chown -R elk:elk /opt # 更改 /opt 文件夹及内部文件的所属用户及组为 elk:elk
su elk # 切换到非root用户elk下来

错误3:(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]
此错误出现在修改config/elasticsearch.yml中的network.host为network.host: 0.0.0.0以便让外网任何IP都能来访问时。

solutions:

切换到root用户,然后


vim /etc/security/limits.conf
* soft nofile 300000
* hard nofile 300000
* soft nproc 102400
* soft memlock unlimited
* hard memlock unlimited

centos7上elastic search安装详解

/etc/security/limits.conf

错误4:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

centos7上elastic search安装详解

vm.max_map_count is too low

solutions:

先要切换到root用户;

然后可以执行以下命令,设置 vm.max_map_count ,但是重启后又会恢复为原值。


sysctl -w vm.max_map_count=262144

持久性的做法是在 /etc/sysctl.conf 文件中修改 vm.max_map_count 参数:


echo "vm.max_map_count=262144" > /etc/sysctl.conf
sysctl -p

centos7上elastic search安装详解

最后终于在外网访问成功:

centos7上elastic search安装详解

外网访问成功!

安装可视化插件 elasticsearch-head


git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install  # 此处我试图用cnpm install有问题,用npm可以
npm run start

centos7上elastic search安装详解

然后在外网访问http://你的安装机IP:9100

centos7上elastic search安装详解

访问elasticsearch-head可视化界面成功

最后实际简单测试一下

新建 Index,可以直接向 Elastic 服务器发出 PUT 请求。下面的例子是新建一个名叫weather的 Index。

centos7上elastic search安装详解

用rest接口向es添加index

然而刷新elasticsearch-head可视化界面可以看到索引已经成功插入

centos7上elastic search安装详解

索引已经插入

相关推荐:

CentOS7中apache与php7及mysql5.7的安装配置详解

Centos7 下Mysql5.7.19安装方法介绍

centos7下和linux下安装mysql有什么区别

以上就是centos7上elastic search安装详解的详细内容,更多请关注其它相关文章!