Elasticsearch 集群部署

本文部署环境

$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

部署前系统优化

$ tail -4 /etc/security/limits.conf
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535

$ tail -1 /etc/sysctl.conf     # 添加内存参数,否则会报错
vm.max_map_count=327650           # 定义了一个进程能拥有的最多的内存区域,Centos7.6默认为65530
$ sysctl -p

配置hosts

$ tail -3 /etc/hosts
192.168.1.11   mall-elasticsearch-1192.168.1.12   mall-elasticsearch-2192.168.1.13   mall-elasticsearch-3

部署elasticsearch-7.4.1

$ tar xf elasticsearch-7.4.1-linux-x86_64.tar.gz
$ ln -s elasticsearch-7.4.1 elasticsearch
$ cd elasticsearch
$ grep ^[^#] config/elasticsearch.yml
cluster.name: mall-elasticsearch
node.name: mall-elasticsearch-1      #修改为当前主机的主机名,见上一步hosts配置
network.host: 192.168.1.11       #修改为当前主机的ip地址
http.port: 9200
discovery.seed_hosts: ["mall-elasticsearch-1", "mall-elasticsearch-2", "mall-elasticsearch-3"]
cluster.initial_master_nodes: ["mall-elasticsearch-1", "mall-elasticsearch-2", "mall-elasticsearch-3"]
http.cors.enabled: true
http.cors.allow-origin: "*"
xpack.sql.enabled: false
$ vim config/jvm.options ...... -Xms4g -Xmx4g ......

启动

$ nohup bin/elasticsearch &

验证

$ curl mall-elasticsearch-1:9200
{
  "name" : "mall-elasticsearch-1",
  "cluster_name" : "mall-elasticsearch",
  "cluster_uuid" : "Fg32p9bsRAq7HjIxcSF6Dg",
  "version" : {
    "number" : "7.4.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "fc0eeb6e2c25915d63d871d344e3d0b45ea0ea1e",
    "build_date" : "2019-10-22T17:16:35.176724Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

为了方便维护,编写脚本如下:

$ cat restart.sh
#!/bin/bash
cd /data/server/elasticsearch
./stop.sh
sleep 1
./start.sh

$ cat start.sh
#!/bin/bash
ExcuteUser='skuser'
LoginUser=`whoami`
if [ $LoginUser != $ExcuteUser ];then
echo "Please change to skuser to execute this scripts!"
exit 0
fi
cd /data/server/elasticsearch
nohup bin/elasticsearch &

$cat stop.sh
#!/bin/bash
KEYWORD="elasticsearch"
PROCESS_COUNT=`ps -aux |grep java |grep $KEYWORD |wc -l`
PID=`ps -aux |grep java |grep $KEYWORD |awk '{print $2}'`
if [ $PROCESS_COUNT -ne 0 ];then
kill -9 $PID
echo "killed Process $PID"
else
echo "This process is already killed!"
fi
原文地址:https://www.cnblogs.com/juchangfei/p/12787207.html