linux中如何安装elasticsearch

1.需求分析

   近期,笔者拼车项目中提出了首页搜索接口需要优化的需求;在笔者看来,完全依赖数据库是不能很好的提高接口的优化性能,于是笔者毅然决然的选择elasticsearch,elasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索,是当前流行且高可用的企业级搜索引擎

2.安装步骤

①elasticsearch是基于java开发的,首先得安装jdk

②检验linux是否存在elasticsearch

ps aux|grep elasticsearch

出现如下图,表示未安装elasticsearch


③解压缩es包,笔者就elasticsearch2.4.6为例

tar -zxvf elasticsearch-2.4.6.tar.gz

④进入该目录

cd /usr/local/elasticsearch-2.4.6/config/

修改elasticsearch.yml如下配置

network.host: xxxx
discovery.zen.ping.unicast.hosts: ["xxxx"]

省略位置填写你自己的ip

修改/etc/sysctl.conf文件,添加如下代码

vm.max_map_count=262144

然后执行 sysctl -p 使配置生效

扫描二维码关注公众号,回复: 1661249 查看本文章

修改/etc/security/limits.conf文件,在文件末尾添加如下代码

# python为登录服务器的用户名
python soft nofile 65536
python hard nofile 65536
python soft nproc  4096
python hard nproc  4096

最后启动elasticsearch

./bin/elasticsearch

报错如下


系统提示不能用超级管理员启动elasticsearch

 3.修复启动bug

①在linux中adduser xxx创建一个新用户

adduser zhangxing

②然后为新建用户设置登录密码,passwd xxx


③在超级用户下,为新建用户服务 /elaticsearch目录的权限 ,chown -R XXX /你的elasticsearch安装目录

chown -R zhangxing /usr/local/elasticsearch-2.4.6

④切换到新建用户下,su xxx


⑤重新启动elasticsearch 

./bin/elasticsearch

效果如下:


测试elasticsearch服务是否开启

curl -XGET 'http://192.168.56.101:9200/'

效果图:


表明你的elasticsearch服务已开启,如果没有出现上图效果,可以考虑9200端口是否开放或者关闭防火墙

如果你关闭xshell界面,elasticsearch也就关闭了,那么执行如下

./bin/elasticsearch -d

服务启动常驻

4.head插件安装

./bin/plugin install mobz/elasticsearch-head

浏览器访问检验效果

http://ip:9200/_plugin/head/

如下图


ok,head插件安装完成!

好了,我是张星,欢迎加入博主技术交流群,群号:313145288

猜你喜欢

转载自blog.csdn.net/zhangxing52077/article/details/80618159
今日推荐