Elasticsearch搭建使用

一、安装

系统:centos7.x

elastic版本:6.7.2 

java版本:1.8

[root@zrl /]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.7.2.tar.gz #下载文件
[root@zrl /]# tar -zxvf elasticsearch-6.7.2.tar.gz # 解压
[root@zrl /]# cd elasticsearch-6.7.2  # 进去文件夹

二、运行

接着,进入解压后的目录,运行下面的命令,启动 Elastic

[root@zrl /]# ./bin/elasticsearch # 启动

这时候遇到的错误

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 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 986513408 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid9590.log

这个时候去修改jvm.options,找到虚拟机参数分配内存改小点

...
-Xms256m
-Xmx256m
...

接着碰到下面的错误,很明显意思就是不能运行在root账号下

org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root

创建一个elastic账号

[root@zrl /]# adduser elastic  # 创建elastic账号
[root@zrl /]# passwd elastic # 修改密码
[root@zrl /]# chown -R elastic elasticsearch-6.7.2 # 给elastic账号权限
[root@zrl /]# su elastic # 切换到elastic用户
[elastic@zrl /]$ ./bin/elasticsearch -d # 启动并在后台运行
[elastic@zrl /]$ cur localhost:9200 # 应该会得到json字符串

访问的时候,又出现新的错误

curl: (7) Failed connect to 106.14.14.158:9200; Connection refused

修改confg/elasticsearch.yml,中

network.host: 0.0.0.0

查看log的时候发现又有一条错误

max number of threads [3897] for user [elastic] is too low, increase to at least [4096]

修改配置 添加 * soft nproc 4096

[root@zrl /] vim /etc/security/limit.d/20-nproc.conf

继续重启,然后访问

[elastic@zrl /]$ ./bin/elasticsearch -d # 启动并在后台运行
[elastic@zrl /]$ cur localhost:9200 # 应该会得到json字符串

三、访问成功

复制代码
{
  "name" : "JRMD634",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "ewobaquGTy2bXVD16fA-Ow",
  "version" : {
    "number" : "6.7.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "56c6e48",
    "build_date" : "2019-04-29T09:05:50.290371Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
复制代码

 

posted @   Auler  阅读(120)  评论(0编辑  收藏  举报
编辑推荐:
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂
· 凌晨三点救火实录:Java内存泄漏的七个神坑,你至少踩过三个!
点击右上角即可分享
微信分享提示