es集群部署搭建

es集群部署搭建

1、将部署tar包放到指定服务器上面

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

2、修改config配置

# ======================== 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-els
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-xx.xxx.xx.12
node.master: true
node.data: true

#
# 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: /var/lib/elasticsearch
path.data: /APL/es/data
#
# Path to log files:
#
#path.logs: /var/log/elasticsearch
path.logs: /APL/es/log

#
# ----------------------------------- 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.0.1
#
# 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-xx.xxx.xx.12","node-xx.xxx.xx.17","node-xx.xxx.xx.88"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
network.host: xx.xxx.xx.12
http.port: 9200
#discovery.seed_hosts: ["127.0.0.1", "[::1]", "0.0.0.0"]
#culster transport port 9200为对外提供端口,9300为对内集群端口
transport.tcp.port: 9300
transport.tcp.compress: true

discovery.zen.ping.unicast.hosts: ["xx.xxx.xx.12", "xx.xxx.xx.17","xx.xxx.xx.88"]
# 为了避免脑裂,集群节点数最少为 半数+1
discovery.zen.minimum_master_nodes: 2             



3、因es不能用root启动需新建用户授予权限

# 创建用户组
groupadd es
# 创建用户并添加至用户组
useradd es -g es 
# 更改用户密码(输入 10201288hy)
passwd es
#授权
#新建日志路径并授权
mkdir -p /APL/es/data
mkdir -p /APL/es/log
chown -R es:es /APL/es/*
#给解压文件夹授权
chown -R es:es  /es/elasticsearch-7.16.1
#切换用户启动
su es
#后台启动
./elasticsearch -d

4、启动可能会报错需给系统做调优

#给linux系统内核做调优
#修改/etc/security/limits.conf
#最下方添加
*       soft    nofile  65536
*       hard    nofile  65536
*       soft    nproc   4096
*       hard    nproc   4096
解释:
(nofile)最大开打开文件描述符
(nproc)最大用户进程数
(memlock)最大锁定内存地址空间

#修改/etc/sysctf.conf文件
vm.max_map_count=655360
解释:
(1)vm.max_map_count=655360
系统最大打开文件描述符数

(2)vm.max_map_count=655360
限制一个进程拥有虚拟内存区域的大小
执行 sysctf -p
******************部分服务器需要权限,可尝试执行脚本来运行

5、安装ik分词器

cd /elasticsearch-7.16.1/plugins
mkdir ik
cd ik
#上传ik包
unzip elasticsearch-analysis-ik-7.16.1.zip 
#解压之后需重启服务

6、可视化页面

有外网的服务器可下载elaticvue监视es集群情况

7、开机自启

#新建文件
vim /etc/init.d/elasticsearch

把这个复制进去

#!/bin/bash
#chkconfig: 345 63 37
#description: elasticsearch
#processname: elasticsearch-7.0.0

export ES_HOME=/home/9527/es/elasticsearch-7.16.1

case $1 in
        start)
                su es<<!
                cd $ES_HOME
                ./bin/elasticsearch -d -p pid
                exit
!
                echo "elasticsearch is started"
                ;;
        stop)
               # pid=`cat $ES_HOME/pid`
                pid=`ps -ef|grep $ES_HOME|grep -v grep|awk '{print $2}'`
                kill -9 $pid
                echo "elasticsearch is stopped"
                ;;
        restart)
                pid=`cat $ES_HOME/pid`
                kill -9 $pid
                echo "elasticsearch is stopped"
                sleep 1
                su es<<!
                cd $ES_HOME
                ./bin/elasticsearch -d -p pid
                exit
!
                echo "elasticsearch is started"
        ;;
    *)
        echo "start|stop|restart"
        ;;
esac
exit 0
chmod 777 elasticsearch
chkconfig --add elasticsearch 
service elasticsearch start
chkconfig elasticsearch on
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值