Install elasticsearch in Linux

Install

download

The latest version download address: https://www.elastic.co/cn/downloads/elasticsearch
Insert image description here

Direct download requires uploading to the server using a remote connection tool.

We use wget to download here

Preface, because after the elasticsearch8 version, it is no longer compatible with jdk1.8, so what we download here is a version of elasticsearch7.

Download address: Elasticsearch 7.16.1 | Elastic

  1. Install wget (centos usually has wget downloaded)

    yum install wget -y
    
  2. Download compressed package

    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.16.1-linux-x86_64.tar.gz
    

    The way to copy the address is to move the mouse to the download button and right-click to copy the connection address.
    Insert image description here

  3. unzip

    tar -zxvf elasticsearch-7.16.1-linux-x86_64.tar.gz
    

    Insert image description here

  4. Enter the elasticsearch directory

    Insert image description here

  5. Modify elasticsearch.yml configuration

    cd config/
    
    vim elasticsearch.yml
    
    # 修改网卡 127.0.0.1表示只允许当前系统访问,如果想要对外访问则可以改为 0.0.0.0
    network.host: 0.0.0.0
    # 访问端口,默认也是9200
    http.port: 9200
    
  6. Fix es memory problem

    修改配置文件
    vim config/jvm.options
    
    # 修改前
    ## -Xms4g
    ## -Xmx4g
    
    # 修改后
    -Xms1g
    -Xmx1g
    

Start elasticsearch

./bin/elasticsearch

Insert image description here

An error occurred

  • 不建议使用JAVA_HOME,请使用ES_JAVA_HOME``Elasticsearch的未来版本将需要Java 11;您的Java版本[/usr/local/jdk1.8.0_351/jre]不符合此要求。考虑切换到带有捆绑JDK的Elasticsearch发行版。如果您已经在使用带有绑定JDK的发行版,请确保没有设置JAVA_HOME环境变量。警告:不支持使用JAVA_HOME,请使用ES_JAVA_HOME

    At this time, we need to use the jdk11 version and tell us that we need to use it. ES_JAVA_HOMEIt is not recommended JAVA_HOME. At this time, we can use es to configure our own jdk into the environment variables.

    Insert image description here

  • Configure environment variables

    1. # 打开配置文件
      vim /etc/profile
      
    2. # 在最后添加一下内容 /mydata/elasticsearch/elasticsearch-7.16.1/jdk是你es存放的路径
      export ES_JAVA_HOME=/mydata/elasticsearch/elasticsearch-7.16.1/jdk
      export PATH=$ES_JAVA_HOME/bin:$PATH
      
    3. # 刷新资源
      source /etc/profile
      

Start ES for the second time

# 进入es目录
cd /mydata/elasticsearch/elasticsearch-7.16.1/
# 启动es
./bin/elasticsearch

New error occurs

Insert image description here

Because es is for security reasons, it is not allowed to use the root user to run es. We need to create a separate user to run es.

# 创建用户组
groupadd es
# 创建 es 用户 并指定用户组
adduser -g es es
# 给 es 用户设置密码
passwd es
# 将当前目录交给 es 用户来操作(也可以理解为赋予权限)
chown -R es:es .

before fixing

Insert image description here

After modification

Insert image description here

third start

After the user is created, try starting again.

# 切换用户
su es
# 启动 es
./bin/elasticsearch

Insert image description here

Use ps command to view again

ps -ef | grep elasticsearch

Insert image description here

Start in background

./bin/elasticsearch -d

The error occurs again after a while

Insert image description here

引导检查失败[3]的[1]:elasticsearch进程的最大文件描述符[4096]太低,增加到至少[65535]

This problem is because ES needs to create a large number of index files and open a large number of system files, so we need to lift the limit on the maximum number of open files in the Linux system, otherwise ES will throw an error when starting.

# 切换到root用户
su root
# 编辑 limits.conf 配置文件
vim /etc/security/limits.conf

# 末尾添加如下配置(报错至少有多少就配置多少,我这里是65535):
es soft nofile 65535
es hard nofile 65535
es soft nproc 4096
es hard nproc 4096

The fourth startup error has occurred here and can be configured directly.

Fourth attempt to start

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

Insert image description here

# 切换 root 用户
su root
# 修改sysctl.conf配置
vim /etc/sysctl.conf
# 追加以下内容
vm.max_map_count=262144
# 保存后执行下面命令
sysctl -p

fifth start

默认的发现设置不适合生产使用;至少有一个[发现]。seed_hosts,发现。seed_providers,集群。必须配置Initial_master_nodes

Insert image description here

  • discovery. seed_hosts cluster host list

  • discovery.seed_providers configures the cluster machine list based on the configuration file

  • cluster. initial_master_nodes parameters initialized at startup and the node for selecting the master, required for production environment

    vim config/elasticsearch.yml 
     # 添加配置 
    discovery.seed_hosts: ["127.0.0.1"]
    cluster.initial_master_nodes: ["node-1"]
    
    # 注意前面不允许有空格,否则也会出现错误
    

    Insert image description here

Sixth start

./bin/elasticsearch -d

Insert image description here

Finally, after five failures, the sixth startup was successful.

Permissions issue

After starting for a period of time, a path with insufficient permissions appears (/mydata/elasticsearch/elasticsearch-7.16.1/logs/elasticsearch.log, but es is running normally.

Insert image description here

# 进入目录查看
cd /mydata/elasticsearch/elasticsearch-7.16.1/logs/

Insert image description here

Here we see that the permissions of elasticsearch.log belong to root用户 because the logs log file is generated behind es. So give permission again

Then we give permission once in this directory

chown -R es:es .

Insert image description here

After granting permissions, it will be no problem to start again.

External access to view elasticsearch

# 开放9200端口
firewall-cmd --zone=public --add-port=9200/tcp --permanent
# 查看9200端口
firewall-cmd --query-port=9200/tcp
# 重启防火墙
firewall-cmd --reload

Visit http://ip:9200

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_58959834/article/details/129591556