Introduction of Middleware
1. Basic concepts
Elastic Search is a Lucene-based search server. It provides a full-text search engine with distributed multi-user capabilities, based on RESTful web interface. Elastic search is a popular enterprise search engine developed in Java and released as open source under Apache license.
2. Distributed database
Distributed database systems usually use smaller computer systems. Each computer can be placed in a separate place. Each computer may have a complete copy of DBMS, or a partial copy of DBMS, and have its own local database. Many computers located in different locations are interconnected through the network. A complete, global, logically centralized and physically distributed large-scale database is formed.
3. Core role
1) Nodes and Clusters
Cluster represents a cluster. There are many nodes in the cluster, one of which is the master node. This master node can be elected. The master-slave node is for the interior of the cluster. One of the concepts of es is de-centralization, which literally means no central node. This is for the outside of the cluster, because from the outside, the es cluster is logically a whole. A single Elastic instance is called a node. A group of nodes form a cluster.
2) Shards fragmentation
Representing index fragmentation, es can divide a complete index into several fragments. This advantage is that a large index can be divided into several fragments and distributed to different nodes. Construct distributed search. The number of fragments can only be specified before index creation and cannot be changed after index creation.
3) Document document
A single record in Index is called a Document. Many Documents constitute an index. Document is represented in JSON format.
4) Index
Elastic indexes all fields and looks directly for the Index when looking for data. The name of each Index, which is understood as the database name, must be lowercase.
5) Type type
Document can be virtual logical grouping based on Type to filter Document, which is understood as the name of the database table.
II. Middleware Installation
1. Installation environment and version
Centos7 JDK1.8 elasticsearch-6.3.2
2. Download and decompress
The download path, under the folder of the current directory, can also specify the download path. Wget-P directory address.
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. Startup Software
[root@localhost mysoft]# cd elasticsearch-6.3.2/ [root@localhost elasticsearch-6.3.2]# ./bin/elasticsearch
1) Error Reporting 1
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 esroot user
[root@localhost mysoft]# su - esroot [esroot@localhost ~]$ su #Back to the root user
2) Error Reporting II
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
Perform the following naming, which operates under Root privileges.
[root@localhost roo]# vim /etc/security/limits.conf //Adding content * soft nofile 65536 * hard nofile 65536
Cut back to the esroot user
Start again, no error message.
4. Open Command Line Testing
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" }
In this way, the elastic search-6.3.2 environment was successfully built.
Requesting port 9200, Elastic returns a JSON object containing the current node, cluster, version and other information.
Press Ctrl + C and Elastic will stop running.
5. Configuring external access
By default, Elastic only allows local access. If remote access is required, you can modify the config/elasticsearch.yml file of the Elastic installation directory, remove the annotation of network.host, change its value to 0.0.0, and 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. Installation of IK Chinese Word Segmenter
Switch to root user
[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
3. Initial Operation
Index creation and deletion
1. Creating Index
[esroot@localhost ~]$ curl -X PUT 'localhost:9200/esindex01' # Return data { "acknowledged": true, "shards_acknowledged": true, "index": "esindex01" }
The server returns a JSON object, and the acknowledged: true field indicates that the operation was successful.
2. Delete Index
[esroot@localhost ~]$ curl -X DELETE 'localhost:9200/esindex01' {"acknowledged":true}
The acknowledged: true field indicates that the operation was successful.
4. Source code address
GitHub Address: Know a smile https://github.com/cicadasmile Code Yun Address: Know a smile https://gitee.com/cicadasmile