1
头图

precondition

This environment is operated on Ubuntu21.04 by default.

Elastic PGP public key and source

We need to download and install the public key before installation, otherwise there is no way to install Elasticsearch using apt.

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

Add source:

sudo apt-get install apt-transport-https
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list

Install Elasticsearch

Next, we can update the source to install Es after all:

sudo apt-get update && sudo apt-get install elasticsearch

This is installed.

Elasticsearch command management

We can use systemd to manage Elasticsearch

systemd

Set boot up:

sudo systemctl daemon-reload
sudo systemctl enable elasticsearch

start up:

sudo systemctl start elasticsearch

closure:

sudo systemctl stop elasticsearch

Check whether the installation is successful:

First, we need to execute the command to start it (if it is already started, then there is no need to execute the following start command):

sudo systemctl start elasticsearch

Then execute the following command:

curl -XGET '127.0.0.1:9200/?pretty'

If the returned data is as follows, it means that the installation was successful:

{
  "name" : "baoguoxiao",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "UZwxDDZUTaWYXTe6g--9MQ",
  "version" : {
    "number" : "7.14.1",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "66b55ebfa59c92c15db3f69a335d500018b3331e",
    "build_date" : "2021-08-26T09:01:05.390870785Z",
    "build_snapshot" : false,
    "lucene_version" : "8.9.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
Note: Elasticsearch needs to be started for a while. If you execute the above command immediately after the startup is complete, you may be prompted to refuse the connection, just try a few more times.

Configure Elasticsearch

Elasticsearch loads its configuration from the /etc/elasticsearch/elasticsearch.yml

The Debian package also has a system configuration file ( /etc/default/elasticsearch ), which allows you to set the following parameters:

parameterexplain
JAVA_HOMESet the custom Java path to be used
MAX_OPEN_FILESThe maximum number of open files, the default is 65536
MAX_LOCKED_MEMORYMaximum lock memory size. If you use the bootstrap.memory_lock option in elasticsearch.yml, please set unlimited
MAX_MAP_COUNTThe maximum value of the memory-mapped area that a process may have. If you use mmapfs as the index storage type, make sure to set it to a higher value. Please check linux kernel document for more information max_map_count This was set sysctl The default is 262144
ES_PATH_CONFConfiguration file directory (need to contain elasticsearch.yml , jvm.options and log4j2.properties files), the default path is: /etc/elasticsearch
ES_JAVA_OPTSAny other JVM system properties you may wish to apply.
RESTART_ON_UPGRADEIt will restart when the configuration package is upgraded, the default is false . This means you restart the elasticsearch instance after manually installing the package. The reason for this is to ensure that, when updating in the cluster, the redistribution of shards is caused in the case of a high-traffic network and reducing the response time of your cluster.

Directory layout

typedescribeDefault pathset up
homeElasticsearch home directory or $ES_HOME/usr/share/elasticsearch 
binBinary script, including elasticsearch to start a node and elasticsearch-plugin install the plug-in/usr/share/elasticsearch/bin 
confConfiguration file, including elasticsearch.yml/etc/elasticsearchES_PATH_CONF
confEnvironment variables, including heap size, file descriptors./etc/default/elasticsearch 
dataThe location of the data file for each index/shard allocated on the node./var/lib/elasticsearchpath.data
jdkJDK used to bundle and run ElasticSearch. It can be /etc/default/elasticsearch by setting the ES_JAVA_HOME environment variable in 06146a0babd5a2./usr/share/elasticsearch/jdk 
logsLog file location./var/log/elasticsearchpath.logs
pluginsPlugin file location. Each plugin will be contained in a subdirectory./usr/share/elasticsearch/plugins 
repoShared file system repository location. Can accommodate multiple locations. The file system repository can be placed in any subdirectory of the specified directory.Can not be configuredpath.repo

In this way, the installation of ElasticSearch is complete.


魔王卷子
940 声望33 粉丝

PHP程序员,专注于后端!