Elasticsearch安装教程

修改/etc/sysctl.conf文件,增加vm.max_map_count配置项
[root@localhost ~]# vim /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
vm.overcommit_memory = 1
 
# 运行Elasticsearch需调高vm.max_map_count数值
vm.max_map_count = 262144
[root@localhost ~]# sysctl -p # 重新载入配置文件
 
 
 
修改/etc/security/limits.conf文件,增加两个配置项
[root@localhost ~]# ulimit -Hn
4096
[root@localhost ~]# vim /etc/security/limits.conf
…………(此处省略内容若干)…………
# 运行Elasticsearch需调高相关参数数值
* soft nofile 65535
* hard nofile 65535
[root@localhost ~]# logout # 退出然后重新登录即可生效,无需重启系统
[root@localhost ~]# ulimit -Hn
65535
[root@localhost ~]#
 
 
 
官方下载地址:https://www.elastic.co/cn/downloads/elasticsearch
 
 
 
直接下载elasticsearch-*.*.*-linux-x86_64.tar.gz文件然后解压即可
[root@localhost src]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.11.3-linux-x86_64.tar.gz
[root@localhost src]# tar -xf elasticsearch-8.11.3-linux-x86_64.tar.gz
[root@localhost src]# mv elasticsearch-8.11.3 /program/elasticsearch
 
 
 
Elasticsearch禁止使用root用户运行,所以这里创建elasticsearch组和elasticsearch用户,注意用户shell要使用/bin/bash
[root@localhost ~]# mkdir /home/elasticsearch
[root@localhost ~]# vim /home/elasticsearch/.bash_profile
export PS1="[\u@\h \W]# "
[root@localhost ~]# groupadd elasticsearch && useradd -s /bin/bash -d /home/elasticsearch -g elasticsearch -M elasticsearch
[root@localhost ~]# passwd elasticsearch
[root@localhost ~]# chown -R elasticsearch:elasticsearch /home/elasticsearch
[root@localhost ~]# chown -R elasticsearch:elasticsearch /program/elasticsearch/


 
配置Elasticsearch
[root@localhost ~]# vim /program/elasticsearch/config/elasticsearch.yml
…………(此处省略内容若干)…………
 
#cluster.name: my-application
cluster.name: my-application
 
#node.name: node-1
node.name: node-1
 
#network.host: 192.168.0.1
network.host: 0.0.0.0
 
#http.port: 9200
http.port: 9200
 
# Enable security features
xpack.security.enabled: false
 
# Create a new cluster with the current node only
# Additional nodes can still join the cluster later
cluster.initial_master_nodes: ["node-1"]
 
…………(此处省略内容若干)…………
[root@localhost ~]#


 
使用elasticsearch用户启动Elasticsearch
[root@localhost ~]# su - elasticsearch
上一次登录:************************************
[elasticsearch@localhost ~]# /program/elasticsearch/bin/elasticsearch
备注:如果要在后台运行Elasticsearch可加上“-d”参数。


 
停止Elasticsearch
[elasticsearch@localhost ~]# jps # 使用jps查出Elasticsearch的进程ID
4033 Jps
3626 org.elasticsearch.bootstrap.Elasticsearch
[elasticsearch@localhost ~]# kill -9 3626 # 终止Elasticsearch进程



强烈建议使用systemd管理Elasticsearch服务
[root@localhost ~]# vim /etc/systemd/system/elasticsearch.service
[Unit]
Description=Elasticsearch
After=network.target remote-fs.target
 
[Service]
Type=forking
User=elasticsearch
Group=elasticsearch
LimitNOFILE=65535
LimitNPROC=65535
Restart=no
ExecStart=/program/elasticsearch/bin/elasticsearch -d
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
[root@localhost ~]# chown -R elasticsearch:elasticsearch /etc/systemd/system/elasticsearch.service
[root@localhost ~]# chmod +x /etc/systemd/system/elasticsearch.service
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable elasticsearch.service # 设置开机启动
[root@localhost ~]# systemctl disable elasticsearch.service # 关闭开机启动
[root@localhost ~]# systemctl status elasticsearch.service # 查看运行状态
[root@localhost ~]# systemctl start elasticsearch.service # 启动Elasticsearch
[root@localhost ~]# systemctl stop elasticsearch.service # 停止Elasticsearch
[root@localhost ~]# systemctl restart elasticsearch.service # 重启Elasticsearch


 
在浏览器地址栏输入“http://192.168.*.*:9200/”查看Elasticsearch是否启动,如果已启动就能在页面上看到一段JSON数据。

Copyright © 2024 码农人生. All Rights Reserved