Elasticsearch 安装

Posted asker009

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Elasticsearch 安装相关的知识,希望对你有一定的参考价值。

一、下载包

官网:https://www.elastic.co/downloads/elasticsearch

下载:wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.1.tar.gz

解压:tar -zxvf elasticsearch-6.5.1.tar.gz

改变所有者:给elasticsearch专门建立一个用户es,将elasticsearch所有者分配给es,chown -R es:es elasticsearch-6.5.1/

二、配置

修改network.host和http.port

vi config/elasticsearch.yml

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

注意yml配置文件中key: value格式冒号后面要跟一个空格。

否则程序会报如下错误:

Exception in thread "main" 2018-11-29 22:49:13,680 main ERROR No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property ‘log4j2.debug‘ to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2
SettingsException[Failed to load settings from [elasticsearch.yml]]; nested: ParsingException[Failed to parse object: expecting token of type [START_OBJECT] but found [VALUE_STRING]];
    at org.elasticsearch.common.settings.Settings$Builder.loadFromStream(Settings.java:1216)
    at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1189)
    at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:100)
    at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:95)
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
    at org.elasticsearch.cli.Command.main(Command.java:90)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86)
Caused by: ParsingException[Failed to parse object: expecting token of type [START_OBJECT] but found [VALUE_STRING]]
    at org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken(XContentParserUtils.java:78)
    at org.elasticsearch.common.settings.Settings.fromXContent(Settings.java:696)
    at org.elasticsearch.common.settings.Settings.access$500(Settings.java:84)
    at org.elasticsearch.common.settings.Settings$Builder.loadFromStream(Settings.java:1212)
    ... 8 more

 

三、修改linux核心配置

vm.max_map_count=262144

这里的修改方式是在/etc/sysctl.d/目录下新建一个配置文件vm.max_map_count.conf

vi /etc/sysctl.d/vm.max_map_count.conf

里面输入:vm.max_map_count=262144

保存退出后,用sysctl -p vm.max_map_count.conf 生效配置。

用sysctl -a|grep vm.max_map_count检查一下,如果有问题重启看看。

 

四、配置打开文件数

vi /etc/security/limits.conf

文件尾部添加:
#soft是一个警告值,而hard则是一个真正意义的阀值,超过就会报错
* hard nofile 65536 #任何一个用户可以打开的最大的文件描述符数量,默认1024,这里的数值会限制tcp连接
* soft nofile 65536

#任何一个用户可以打开的最大进程数
* soft nproc 2048
* hard nproc 4096


# End of file

 

五、启动elasticsearch

bin/elasticsearch

验证:

[[email protected] elasticsearch-6.5.1]# curl http://192.168.31.10:9200
{
  "name" : "Sa5md_z",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "0be4QBGhQQu2pf9MnGjbkA",
  "version" : {
    "number" : "6.5.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "8c58350",
    "build_date" : "2018-11-16T02:22:42.182257Z",
    "build_snapshot" : false,
    "lucene_version" : "7.5.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

 

以上是关于Elasticsearch 安装的主要内容,如果未能解决你的问题,请参考以下文章

Elasticsearch笔记九之优化

使用标准库Ruby将数据标记到Elasticsearch批量中

Elasticsearch:如何在 Elasticsearch 中正确使用同义词功能

Elasticsearch:如何在 Elasticsearch 中正确使用同义词功能

Elasticsearch-PHP 索引操作

在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段,该代码片段中每个属性的含义与用途