Py学习  »  Elasticsearch

ElasticSearch初探-安装

谢大大 • 4 年前 • 163 次点击  
阅读 8

ElasticSearch初探-安装

写在前面的话

经过一个半月的不懈努力, 小说项目已经完成了一大半, 前端界面以及api对接全部完成, 后台系统完成一小部分功能。

记得当初做这个项目的初衷是因为感觉自己所学太杂, 而且自己对一些技术如Kafka, ES很感兴趣,所以想通过这个项目对这些东西进行融合,加深对其印象

在项目中, 我采用ElasticSearch来处理项目中的小说搜索

Elasticsearch 是什么

  • Elasticsearch是一个基于Apache Lucene(TM)的实时分布式搜索和分析引擎,但是如果要直接使用lucene, 却非常困难。 因为Lucene只是一个库, 想要使用它,你必须使用Java来作为开发语言并将其直接集成到你的应用中,更糟糕的是,Lucene非常复杂,你需要深入了解检索的相关知识来理解它是如何工作的。。。

  • Elasticsearch也使用Java开发并使用Lucene作为其核心来实现所有索引和搜索的功能,但是它的目的是通过简单的RESTful API来隐藏Lucene的复杂性,从而让全文搜索变得简单

  • Elasticsearch可以很轻松的横向扩展, 可支持PB级的结构和非结构数据处理

关于Elasticsearch的应用场景

  • 海量数据的分析
  • 站内搜索引擎
  • 数据仓库

对ES(Elasticsearch)的了解

  1. 加深对ES的理解的最好方式就是运行它, 那么我们先来安装

  2. 安装环境

CentOS 7

JDK 1.8 (必须)

ES-6.8.2 和JDK的版本是对应关系

  • 下载

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8.2.tar.gz

  • 下载完成后, 解压

tar -zxvf elasticsearch-6.8.2.tar.gz

  • 创建用户组, 授权

ES不能使用root用户来启动

groupadd elasticsearch
useradd -r -g elasticsearch elasticsearch
chown -Rf elasticsearch:elasticsearch elasticsearch-6.8.2
复制代码
  • 启动ES

./bin/elasticsearch

  1. ES默认只能通过本地来执行, 如果需要修改, 修改配置文件 elasticsearch.yml

network.host: 0.0.0.0

  1. 如果想要在后台启动, 可以通过以下命令

nohup ./bin/elasticsearch &

./bin/elasticsearch -d

  • 验证是否启动

ES默认监听9200端口

curl 'http://localhost:9200/'

{
  "name" : "7J76WwT",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "Wsfbm6vLS2uOyoDqWVppdw",
  "version" : {
    "number" : "5.5.2",
    "build_hash" : "b2f0c09",
    "build_date" : "2017-08-14T12:33:14.154Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}

复制代码

能够输出类似的内容说明已经启动成功

到此, 关于ES的简介和单机版安装就完成了

扩展

按照上述的安装方式, 在远程连接ES的时候会出现出现以下问题, 我们来解决下

当我们设置 network.host: 0.0.0.0 在启动过程中会出现以下问题

max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

这里错误是每个进程最大同时打开文件数太小

修改/etc/security/limits.conf文件,增加配置, 需要重新进行登录才能生效

*               soft    nofile          65536
*               hard    nofile          65536
复制代码

可以通过以下命令来查看

ulimit -Hn
ulimit -Sn
复制代码

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

修改/etc/sysctl.conf文件,增加配置

vm.max_map_count=262144
sysctl -p 查看是否生效
复制代码

system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own ris

这个问题是由于centos的版本问题引起的, 在elasticsearch配置中配置

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

插件head安装

在ES中的配置允许跨域

http.cors.enabled: true
http.cors.allow-origin: "*"
复制代码

下载head项目 推荐采用Git下载, 点击下载

这里需要安装Node, 大家另行baidu查询

git clone git://github.com/mobz/elasticsearch-head.git

cd elasticsearch-head

//安装依赖插件
npm install

//运行
npm run start
复制代码

通过 http://localhost:9100/ 访问

head安装完成样子

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38448
 
163 次点击