Centos 6.X下Elasticsearch安装教程

1. Elasticsearch简介

  ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。

  我们建立一个网站或应用程序,并要添加搜索功能,但是想要完成搜索工作的创建是非常困难的。我们希望搜索解决方案要运行速度快,我们希望能有一个零配置和一个完全免费的搜索模式,我们希望能够简单地使用JSON通过HTTP来索引数据,我们希望我们的搜索服务器始终可用,我们希望能够从一台开始并扩展到数百台,我们要实时搜索,我们要简单的多租户,我们希望建立一个云的解决方案。因此我们利用Elasticsearch来解决所有这些问题以及可能出现的更多其它问题。   

2. Elasticsearch安装

首先,去官网下载Centos专用安装包,下载地址:点我

下载上图红框中的文件,下载完成后上传到centos服务器,然后解压文件:

tar -zxvf elasticsearch-5.5.2.tar.gz
复制代码

注意:安装ElasticSearch前必须先安装JAVA的JDK。

然后,将解压后的文件拷贝到自己想要放置的目录,我的是放置到/usr/local目录下面,操作代码:

cd /usr/local
mv ~/elasticsearch-6.3.2 elasticsearch
复制代码

3. 启动ElasticSearch

进入ElasticSearch的bin文件加,直接启动:

./elasticsearch
复制代码

哐当,出现错误,无法启动

[WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
        at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.3.2.jar:6.3.2]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.3.2.jar:6.3.2]
复制代码

出现这个问题是由于不能使用root用户启动,必须新建用户才可以。这么做主要目的还是为了安全性的考虑,但是在Centos 7上是不会有这个问题的

添加用户组、用户,设置密码:

groupadd es
useradd es -g es
passwd es
复制代码

设置文件夹属性:

chown -R es:es elasticsearch
复制代码

设置好账户后,切换登录到刚刚设置的账户,然后在启动:

cd /usr/local/elasticsearch/bin/
./elasticsearch
复制代码

如果出现以下信息,说明启动成功

验证是否真正的成功: 打开另外一个窗口,然后输入如下命令:

curl http://127.0.0.1:9200
复制代码

返回结果

恭喜,安装成功!

默认情况下,Elastic 只允许本机访问,如果需要远程访问,可以修改 Elastic 安装目录的config/elasticsearch.yml文件,去掉network.host的注释,将它的值改成0.0.0.0,然后重新启动 Elastic

network.host: 0.0.0.0
复制代码

上面代码中,设成0.0.0.0让任何人都可以访问。线上服务不要这样设置,要设成具体的 IP。

同时需要开放9200端口号:


/sbin/iptables -I INPUT -p tcp --dport 9200 -j ACCEPT
复制代码

4. 常见错误

错误1: 如果这时报错"max virtual memory areas vm.maxmapcount [65530] is too low",要运行下面的命令:
sudo sysctl -w vm.max_map_count=262144
复制代码
错误2:如果报如下错误
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
[2]: max number of threads [1024] for user [es] is too low, increase to at least [4096]
[3]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
复制代码

切换到root用户,编辑limits.conf

vi /etc/security/limits.conf 
复制代码

并添加类似如下内容

* soft nofile 65536

* hard nofile 131072

* soft nproc 2048

* hard nproc 4096
复制代码

编辑90-nproc.conf文件

vi /etc/security/limits.d/90-nproc.conf 
复制代码

修改内容

#* soft nproc 1024

#修改为

* soft nproc 2048
复制代码
错误3. 错误信息
ERROR: [1] bootstrap checks failed
[1]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
复制代码

报错原因:这是在因为Centos6不支持SecComp,而ES5.2.0默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动。

解决办法:在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面

bootstrap.memory_lock: false
bootstrap.system_call_filter: false
复制代码

修改完配置后,最好退出重新登录一下,不然可能配置无效。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值