前言
最近想搞下检索,那就安装elasticsearch吧
一、准备、配置、部署
1、把软件包上传到服务器
解压,tar -zxvf elasticsearch-7.17.0-linux-x86_64.tar.gz
进入config 文件夹修改elasticsearch.yml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- 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: /mnt/sofware/elasticsearch-7.17.0/data
#
# Path to log files:
#开启,指定日志文件路径
path.logs: /mnt/sofware/elasticsearch-7.17.0/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
#
# 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: /mnt/sofware/elasticsearch-7.17.0/data
#
# Path to log files:
#
path.logs: /mnt/sofware/elasticsearch-7.17.0/logs
#
# ----------------------------------- 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 -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#开启,然后只能本机能访问
network.host: 0.0.0.0
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
# 开启,指定访问端口
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.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#
# ---------------------------------- Security ----------------------------------
#
# *** WARNING ***
#
# Elasticsearch security features are not enabled by default.
# These features are free, but require configuration changes to enable them.
# This means that users don’t have to provide credentials and can get full access
# to the cluster. Network connections are also not encrypted.
#
# To protect your data, we strongly encourage you to enable the Elasticsearch security features.
# Refer to the following documentation for instructions.
#
# https://www.elastic.co/guide/en/elasticsearch/reference/7.16/configuring-stack-security.html
好了,配置好之后,去bin目录
elasticsearch文件就是启动文件,在启动之前需要建一个普通用户启动,用root用户是启动不了的,并且还需要把文件夹和文件夹下面文件授权给用户。
[root@eth3344 sofware]# useradd sakyoka
[root@eth3344 sofware]# passwd sakyoka
Changing password for user sakyoka.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
Sorry, passwords do not match.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@eth3344 sofware]# chown -R sakyoka elasticsearch-7.17.0
[root@eth3344 sofware]# ll
total 304096
drwxr-xr-x. 9 sakyoka root 4096 Jan 28 2022 elasticsearch-7.17.0
-rw-r--r--. 1 root root 311388520 Aug 30 17:45 elasticsearch-7.17.0-linux-x86_64.tar.gz
[root@eth3344 sofware]# su sakyoka
[sakyoka@eth3344 sofware]$ cd elasticsearch-7.17.0
[sakyoka@eth3344 elasticsearch-7.17.0]$ ls
bin config jdk lib LICENSE.txt logs modules NOTICE.txt plugins README.asciidoc
[sakyoka@eth3344 elasticsearch-7.17.0]$ cd bin/
[sakyoka@eth3344 bin]$ ll
total 3468
-rwxr-xr-x. 1 sakyoka root 2985 Jan 28 2022 elasticsearch
-rwxr-xr-x. 1 sakyoka root 501 Jan 28 2022 elasticsearch-certgen
-rwxr-xr-x. 1 sakyoka root 493 Jan 28 2022 elasticsearch-certutil
-rwxr-xr-x. 1 sakyoka root 996 Jan 28 2022 elasticsearch-cli
-rwxr-xr-x. 1 sakyoka root 443 Jan 28 2022 elasticsearch-croneval
-rwxr-xr-x. 1 sakyoka root 5529 Jan 28 2022 elasticsearch-env
-rwxr-xr-x. 1 sakyoka root 1828 Jan 28 2022 elasticsearch-env-from-file
-rwxr-xr-x. 1 sakyoka root 168 Jan 28 2022 elasticsearch-geoip
-rwxr-xr-x. 1 sakyoka root 184 Jan 28 2022 elasticsearch-keystore
-rwxr-xr-x. 1 sakyoka root 450 Jan 28 2022 elasticsearch-migrate
-rwxr-xr-x. 1 sakyoka root 126 Jan 28 2022 elasticsearch-node
-rwxr-xr-x. 1 sakyoka root 176 Jan 28 2022 elasticsearch-plugin
-rwxr-xr-x. 1 sakyoka root 441 Jan 28 2022 elasticsearch-saml-metadata
-rwxr-xr-x. 1 sakyoka root 439 Jan 28 2022 elasticsearch-service-tokens
-rwxr-xr-x. 1 sakyoka root 448 Jan 28 2022 elasticsearch-setup-passwords
-rwxr-xr-x. 1 sakyoka root 118 Jan 28 2022 elasticsearch-shard
-rwxr-xr-x. 1 sakyoka root 483 Jan 28 2022 elasticsearch-sql-cli
-rwxr-xr-x. 1 sakyoka root 3455060 Jan 28 2022 elasticsearch-sql-cli-7.17.0.jar
-rwxr-xr-x. 1 sakyoka root 436 Jan 28 2022 elasticsearch-syskeygen
-rwxr-xr-x. 1 sakyoka root 436 Jan 28 2022 elasticsearch-users
-rwxr-xr-x. 1 sakyoka root 356 Jan 28 2022 x-pack-env
-rwxr-xr-x. 1 sakyoka root 364 Jan 28 2022 x-pack-security-env
-rwxr-xr-x. 1 sakyoka root 363 Jan 28 2022 x-pack-watcher-env
切换用户 再次进入bin,启动应用。
启动之后发现,异常了max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535],需要修改文件大小。
开打root用户编辑 vi /etc/security/limits.conf ,添加文件限制
* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
启动!发现还是文件大小问题,没生效?重新登录。。OK重新登录生效了,不过再启动发现还有个问题max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144],max_map_count大小问题,好吧,用root再设置一下
vi /etc/sysctl.conf ,添加vm.max_map_count=262144
嗯~启动还没生效,这次不需要登录直接执行刷新 sysctl -p
二、设置密码登录(追加内容)
在elasticsearch.yml中添加以下两行配置,重启
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
设置密码,在bin目录中执行以下命令
./elasticsearch-setup-passwords interactive
设置密码成功,使用其中账号去+密码去访问
Ok,这次启动成功,试下访问
三、访问
ok,访问9200成功