Linux安装Elasticsearch

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介: ElasticSearch,官方的解释Elasticsearch 是一个分布式的开源搜索和分析引擎,适用于所有类型的数据,包括文本、数字、地理空间、结构化和非结构化数据。Elasticsearch 在 Apache Lucene 的基础上开发而成,由 Elasticsearch N.V.(即现在的 Elastic)于 2010 年首次发布。Elasticsearch 以其简单的 REST 风格 API、分布式特性、速度和可扩展性而闻名,是 Elastic Stack 的核心组件;Elastic Stack 是适用于数据采集、充实、存储、分析和可视化的一组开源工具。

1、概念

ElasticSearch,官方的解释Elasticsearch 是一个分布式的开源搜索和分析引擎,适用于所有类型的数据,包括文本、数字、地理空间、结构化和非结构化数据。Elasticsearch 在 Apache Lucene 的基础上开发而成,由 Elasticsearch N.V.(即现在的 Elastic)于 2010 年首次发布。Elasticsearch 以其简单的 REST 风格 API、分布式特性、速度和可扩展性而闻名,是 Elastic Stack 的核心组件;Elastic Stack 是适用于数据采集、充实、存储、分析和可视化的一组开源工具。人们通常将 Elastic Stack 称为 ELK Stack(代指 Elasticsearch、Logstash 和 Kibana),目前 Elastic Stack 包括一系列丰富的轻量型数据采集代理,这些代理统称为 Beats,可用来向 Elasticsearch 发送数据。现在大部分服务器是基于Linux底层,今天介绍下Linux上Elasticsearch的安装、遇到的问题以及解决方法。

image.png

2、安装

Elasticsearch下载地址:
https://www.elastic.co/cn/downloads/past-releases#elasticsearch
解压elasticsearch-6.4.3.tar.gz到/usr/local/elastic-plugin目录:

进入解压后的elasticsearch目录:/usr/local/elastic-plugin/elasticsearch-6.4.3
(1)新建data目录:

image.png

(2)修改config/elasticsearch.yml:

在Memory下面添加

bootstrap.system_call_filter: false

image.png

在最后添加下列内容

#数据和日志的存储目录
path.data: /usr/local/elastic-plugin/elasticsearch-6.4.3/data
path.logs: /usr/local/elastic-plugin/elasticsearch-6.4.3/logs
#设置绑定的ip,设置为0.0.0.0以后就可以让任何计算机节点访问到了
network.host: 0.0.0.0
http.port: 9200 #端口
#qcl自己加的
http.cors.enabled: true 
http.cors.allow-origin: "*"
node.master: true
node.data: true

修改完毕后,:wq 保存退出vim
准备启动es
进入/bin目录执行命令:

后台启动:./elasticsearch -d

image.png

3、问题以及解决方法

问题:

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000d4cc0000, 724828160, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 724828160 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid8507.log
[root@VM_97_229_centos elasticsearch-6.4.3]# 
[root@VM_0_2_centos bin]# 

解决:
看来是我这1G的内存太小了啊,elasticsearch使用java的jvm默认是使用1G的内存的,这里我们修改一下内存,直接把内存改到200m
cd 到es目录修改 ./config/jvm.options:

修改该内容:

-Xmx200m

:wq 保存并退出vim,再次启动es
再次启动出现如下错误:

[2019-06-21T16:20:03,039][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler][node-1] 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:163) ~[elasticsearch-6.4.3.jar:6.4.3]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-6.4.3.jar:6.4.3]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.4.3.jar:6.4.3]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.4.3.jar:6.4.3]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.4.3.jar:6.4.3.jar:6.4.3:7.1.1]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-6.4.3.jar:6.4.3]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.4.3.jar:6.4.3]
    Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:102) ~[elasticsearch-6.4.3.jar:6.4.3]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:169) ~[elasticsearch-6.4.3.jar:6.4.3]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:325) ~[elasticsearch-6.4.3.jar:6.4.3]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-6.4.3.jar:6.4.3]
    ... 6 more
    [root@VM_0_2_centos elasticsearch-7.1.1]#

这是不能使用root用户操作,添加一个其他的用户再试试:
用户名和密码都是admin

[root@VM_0_2_centos elasticsearch-6.4.3]# passwd admin
Changing password for user admin.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

改一下admin目录所属用户:

vim 编辑 /etc/security/limits.conf,在末尾加上:

admin hard nofile 65536
admin soft nproc 4096
admin hard nproc 4096

vim 编辑 vim /etc/security/limits.d/20-nproc.conf,将* 改为用户名(admin):

# accidental fork bombs.
# See rhbz #432903 for reasoning.

admin          soft    nproc     4096
root       soft    nproc     unlimited

vim 编辑 /etc/sysctl.conf,在末尾加上:

执行:

`[root@VM_0_2_centos ~]# sysctl -p
kernel.printk = 5
vm.max_map_count = 655360
[root@VM_0_2_centos ~]#


登录刚才新建的admin用户,并启动elasticsearch,OK

[es@VM_0_2_centos elasticsearch-6.4.3]$ ./bin/elasticsearch


![image.png](https://ucc.alicdn.com/pic/developer-ecology/eef197ebb86349139b5b62b6f272d893.png)

后台启动:

[es@VM_0_2_centos elasticsearch-6.4.3]$


查看进程:

[es@VM_0_2_centos elasticsearch-6.4.3]$ ./bin/elasticsearch -d
[es@VM_0_2_centos elasticsearch-6.4.3]$ ps -ef|grep elasticsearch
es 18652 1 19 17:48 pts/2 00:00:00 /usr/local/java/jdk1.8.0_211/bin/java -Xms200m -Xmx200m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch-182563007296674551 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Dio.netty.allocator.type=unpooled -Des.path.home=/usr/local/elasticsearch-6.4.3 -Des.path.conf=/usr/local/elasticsearch-6.4.3/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /usr/local/elasticsearch-6.4.3/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
es 18728 8399 0 17:48 pts/2 00:00:00 grep --color=auto elasticsearch
[es@VM_0_2_centos elasticsearch-6.4.3]$


山水有相逢,来日皆可期,谢谢阅读,我们再会

我手中的金箍棒,上能通天,下能探海
相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
3天前
|
Linux 开发工具 C语言
Linux 安装 gcc 编译运行 C程序
Linux 安装 gcc 编译运行 C程序
21 0
|
3天前
|
Ubuntu Linux Python
Linux(15)Ubuntu安装ninja构建工具
Linux(15)Ubuntu安装ninja构建工具
13 0
|
6天前
|
NoSQL Linux 测试技术
Redis的安装(Linux版)
Redis的安装(Linux版)
149 1
|
2天前
|
监控 安全 Linux
Linux系统之安装ServerBee服务器监控工具
【4月更文挑战第22天】Linux系统之安装ServerBee服务器监控工具
39 2
|
2天前
|
Linux 开发工具 Android开发
Docker系列(1)安装Linux系统编译Android源码
Docker系列(1)安装Linux系统编译Android源码
5 0
|
2天前
|
Ubuntu Linux 开发工具
WSL2(3)安装Linux headers完美解决方案
WSL2(3)安装Linux headers完美解决方案
4 0
|
3天前
|
Ubuntu Linux 数据安全/隐私保护
Linux(7)Ubuntu20.04 arm64安装Docker
Linux(7)Ubuntu20.04 arm64安装Docker
15 0
|
6天前
|
Linux
ZooKeeper的安装(Linux版)
ZooKeeper的安装(Linux版)
17 1
|
6天前
|
应用服务中间件 Linux 网络安全
Tomcat的安装(Linux版)
Tomcat的安装(Linux版)
17 0
|
9天前
|
关系型数据库 MySQL Linux
Linux联网安装MySQL Server
Linux联网安装MySQL Server
21 0