Linux systems: Centos7 under build ElasticSearch middleware, common interface demo

This article Source: GitHub · Click here || GitEE · Click here

I. Introduction Middleware

1, the basic concept

ElasticSearch is a search server based on Lucene. It provides a distributed multi-user capabilities of full-text search engine, based on RESTful web interface. Elasticsearch is written in Java, and as open source under the Apache license terms published, is the current popular enterprise-class search engine.

2, distributed database

Distributed database systems typically use smaller computer systems, each computer can be placed in a single place, each computer may have a complete copy of a copy of the DBMS or partial copies of copies, and has its own local database located many computers in different locations connected through a network to each other, together form a complete, focused on the overall logic, large database physically distributed.

3, the core role

1) node and cluster

cluster represents a cluster, a plurality of nodes in the cluster, wherein there is a master node, the master node is elected, the master node from the cluster is to be the internal. Es is a concept to the center, is literally no central node, which is for external cluster, as cluster es from the outside, is logically full. Elastic instance is called a single node (node). A set of nodes constituting a cluster (cluster).

2) Shards fragment

Representative of slice index, ES can be a complete index into a plurality of fragments, the advantage of such a large index can be split into multiple, distributed to different nodes. Constitute a distributed search. Number of fragments can only be specified before index creation, and can not be changed after the index is created.

3) Document Document

Index which recorded a single called Document (document). Many pieces make up a Document Index. Document use JSON format.

4) Index Index

Elastic will index all the fields, look for data, the direct lookup of the index. Each Index (that is as the database name) names must be lowercase.

5) Type Type

Document virtual logical grouping may be according to Type, for filtering Document, that is as the name of the database table.

Second, the middleware installation

1, and installation environment version

Centos7
JDK1.8
elasticsearch-6.3.2

2, downloading codecs

Download path, the current directory under the file folder, you can specify the download path. wget -P Directory URL.

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.zip
[root@localhost roo]# mv elasticsearch-6.3.2.zip /usr/local/mysoft/
[root@localhost mysoft]# unzip elasticsearch-6.3.2.zip

3, start the software

[root@localhost mysoft]# cd elasticsearch-6.3.2/
[root@localhost elasticsearch-6.3.2]# ./bin/elasticsearch

1) being given a

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

New user groups and users

[root@localhost]# useradd esroot
[root@localhost]# passwd esroot
[root@localhost]# groupadd esgroup
[root@localhost]# usermod -g esgroup esroot

esroot user authorization

chown esroot /usr/local/mysoft/elasticsearch-6.3.2 -R

Switch to the user esroot

[root@localhost mysoft]# su - esroot
[esroot@localhost ~]$ su #回到root用户

2) being given two

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

Name execute, in the operation of the operation Root permission.

[root@localhost roo]# vim /etc/security/limits.conf 
添加内容
* soft nofile 65536
* hard nofile 65536

Cut back esroot user
to start again, no error message.

4, open a command line test

curl localhost:9200

[roo@localhost ~]$ curl localhost:9200
{
  "name" : "YMS44oi",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "2ZXjBnkJSjieV_k1IWMzrQ",
  "version" : {
    "number" : "6.3.2",
    "build_flavor" : "default",
    "build_type" : "zip",
    "build_hash" : "053779d",
    "build_date" : "2018-07-20T05:20:23.451332Z",
    "build_snapshot" : false,
    "lucene_version" : "7.3.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

Such elasticsearch-6.3.2 environment to build success.
Request port 9200, Elastic return a JSON object contains the current node, the cluster, the version information.
Press Ctrl + C, Elastic will stop running.

5, configure external access

By default, Elastic only allows native access, remote access, if required, can be modified config / elasticsearch.yml file Elastic installation directory, uncomment network.host will change its value 0.0.0.0, and then restart Elastic .

[esroot@localhost config]$ cd /usr/local/mysoft/elasticsearch-6.3.2/config
[esroot@localhost config]$ vim elasticsearch.yml 
network.host: 0.0.0.0

6, install IK Chinese word breaker

To root

[root@localhost elasticsearch-6.3.2]$ ./bin/elasticsearch-plugin 
install 
https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.2/elasticsearch-analysis-ik-6.3.2.zip

Third, the entry-operation

Index creation and deletion

1, to create an index

[esroot@localhost ~]$ curl -X PUT 'localhost:9200/esindex01'
# 返回数据
{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "esindex01"
}

The server returns a JSON object, acknowledged: true field indicates a successful operation.

2, delete the index

[esroot@localhost ~]$ curl -X DELETE 'localhost:9200/esindex01'
{"acknowledged":true}

acknowledged: true field indicates a successful operation.

Fourth, the source address

GitHub·地址
https://github.com/cicadasmile/linux-system-base
GitEE·地址
https://gitee.com/cicadasmile/linux-system-base

Linux systems: Centos7 under build ElasticSearch middleware, common interface demo

Guess you like

Origin blog.51cto.com/14439672/2445575