ElasticSearch入门介绍和CentOS 7系统下搭建和配置教程

[lwptoc float=”right”]

一些交易所源码需要用到ElasticSearch服务框架,本文对此进行简要介绍什么是ElasticSearch以及在CentOS系统下如何搭建ElasticSearch环境。

什么是Elasticsearch

Elasticsearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java语言开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。

Elasticsearch用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。官方客户端在Java、.NET(C#)、PHP、Python、Apache Groovy、Ruby和许多其他语言中都是可用的。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr,也是基于Lucene。

如何搭建Elasticsearch

第一步:安装java环境

这里使用yum方式安装,前提是必须有网络

yum install java-1.8.0-openjdk

安装完成,查看java版本

[root@localhost ~]# java -version 
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

第二步:安装 Elasticsearch

Elasticsearch最新软件软件包可在官方网站下载:https://www.elastic.co/downloads/elasticsearch

首先在官网当中下载Elasticsearch的软件包,本文采用压缩包解压缩安装方式启动服务。

Elasticsearch的安装很简单,下载下来解压即可,这里使用wget下载,当然也可通过网页下载再拷贝。

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

解压到/usr/local/

tar -zxvf elasticsearch-5.6.3.tar.gz -C /usr/local/

第三步:运行Elasticsearch

Elasticsearch 要求不能使用超级用户root运行,所以我们建立一个账号,这里取名testuser


# 创建用户组elg
groupadd elg
# 创建testuser账户
adduser testuser
# 修改密码
passwd testuser

然后,给testuser用户elasticsearch目录的授权。

chown -R testuser:elg /usr/local/elasticsearch-5.6.3/

切换至elasticsearch目录,并以testuser用户运行

cd /usr/local/elasticsearch-5.6.3/
su testuser

编辑配置文件/usr/local/elasticsearch-5.6.3/config/elasticsearch.yml,准备启动es

# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: ["node-1"]
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /data/es-data
#
# Path to log files:
#
path.logs: /var/log/elasticsearch
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200

#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:

#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

编辑完成配置文件后,数据目录以及日志文件目录需要创建

sudo mkdir -p /data/es-data
sudo mkdir -p /var/log/elasticsearch
sudo chown -R testuser:elg /data/
sudo chown -R testuser:elg /var/log/elasticsearch

运行elasticsearch,如果想后台运行,可在命令行后面加 -d

[testuser@localhost xxx]cd /usr/local/elasticsearch-5.6.3/
[testuser@localhost elasticsearch-5.6.3]$ ./bin/elasticsearch -d

第四步:测试是否正常运行

[root@localhost ~]# curl 'http://localhost:9200/?pretty' 
{
  "name" : "oDFU6c3",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "v2mGsAuuTsqIzzm8CZcW5w",
  "version" : {
    "number" : "5.6.3",
    "build_hash" : "1a2f265",
    "build_date" : "2017-10-06T20:33:39.012Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.1"
  },
  "tagline" : "You Know, for Search"
}
原文链接:https://vuesite.cn/15682.html,转载请注明出处。
0
显示验证码
没有账号?注册  忘记密码?