1、创建账号
因为安全问题,ElasticSearch不允许root用户直接运行,所以要在每个节点创建新的用户
这里准备了三个节点
192.168.159.100
192.168.159.101
192.168.159.102
#创建用户:elasticsearch100
adduser elasticsearch100
# 创建用户密码,需要输入两次
passwd elasticsearch100
#此处记录密码为elasticsearch100,避免忘记
#将对应的文件夹权限赋给该用户
chown -R elasticsearch100 elasticsearch-8.3.3
su elasticsearch100
#创建用户:elasticsearch101
adduser elasticsearch101
# 创建用户密码,需要输入两次
passwd elasticsearch101
#此处记录密码为elasticsearch101,避免忘记
#将对应的文件夹权限赋给该用户
chown -R elasticsearch101 elasticsearch-8.3.3
su elasticsearch101
#创建用户:elasticsearch102
adduser elasticsearch102
# 创建用户密码,需要输入两次
passwd elasticsearch102
#此处记录密码为elasticsearch102,避免忘记
#将对应的文件夹权限赋给该用户
chown -R elasticsearch102 elasticsearch-8.3.3
su elasticsearch102
2、修改配置文件(集群配置)
# ======================== 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: es-cluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-192-168-159-100
#
# 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: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/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: 192.168.159.100
#
# 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
transport.port: 9300
#
# 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: ["192.168.159.100:9300", "192.168.159.101:9300","192.168.159.102:9300"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["192.168.159.100:9300", "192.168.159.101:9300","192.168.159.102:9300"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# --------------------------------- Readiness ----------------------------------
#
# Enable an unauthenticated TCP readiness endpoint on localhost
#
#readiness.port: 9399
#
# ---------------------------------- Various -----------------------------------
#
# Allow wildcard deletion of indices:
#
#action.destructive_requires_name: false
#开启跨域访问支持,默认为false
http.cors.enabled: true
#跨域访问允许的域名, 允许所有域名
http.cors.allow-origin: "*"
#开启安全配置
xpack.security.enabled: false
3、ES部署遇到的问题
4、配置ES开机启动
cd /etc/init.d 【进入到目录】
vim elasticsearch 【创建es系统启动服务文件】
编写启动脚本,注意此处要修改你对应的账号和ES路径,这里我配置的是elasticsearch101
#!/bin/bash
#chkconfig: 345 63 37
#description: elasticsearch
#processname: elasticsearch-8.3.3
export ES_HOME=/usr/local/elasticsearch/elasticsearch-8.3.3
case $1 in
start)
su elasticsearch101<<!
cd $ES_HOME
./bin/elasticsearch -d -p pid
exit
!
echo "elasticsearch is started"
;;
stop)
pid=`cat $ES_HOME/pid`
kill -9 $pid
echo "elasticsearch is stopped"
;;
restart)
pid=`cat $ES_HOME/pid`
kill -9 $pid
echo "elasticsearch is stopped"
sleep 1
su elasticsearch101<<!
cd $ES_HOME
./bin/elasticsearch -d -p pid
exit
!
echo "elasticsearch is started"
;;
*)
echo "start|stop|restart"
;;
esac
#修改文件权限
chmod 777 elasticsearch
#添加系统服务
chkconfig --add elasticsearch
#删除系统服务
chkconfig --del elasticsearch
#启动
service elasticsearch start
#停止
service elasticsearch stop
#重启
service elasticsearch restart
#开启开机自启
chkconfig elasticsearch on
#关闭开机自启
chkconfig elasticsearch off
5、配置防火墙端口
firewall-cmd --zone=public --add-port=9300/tcp --permanent
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload