es集群搭建部署

Elasticsearch的搭建

测试环境 centos7  版本elasticsearch-7.17.8

节点host名称节点ip节点部署内容
note1192.168.57.188主节点 数据节点
note2192.168.57.189主节点 数据节点
note3192.168.57.190数据节点

一 准备安装环境 

 1.下载安装包 官网 www.elastic.co 下载所有版本地址  点击跳转  下载elasticsearch-7.17.8版本

 2.创建安装环境

        安装jdk并配置环境变量

        创建安装目录每个节点都要创建

mkdir -p /home/tools/elasticsearch

        创建ssh免密登录

  3.上传压缩包

  4.解压Elasticsearch压缩包

二 修改配置文件

vim elasticsearch-7.17.8/config/elasticsearch.yml

核心配置

#为集群设置名称,集群内所有节点配置的名称必须一致
cluster.name: bigdata
#当前节点取名,集群内节点名称必须唯一
node.name: node1
#当前节点地址
network.host: 192.168.57.188
#始化一个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["note1", "note2"]
#写入候选主节点的设备地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["note1", "note2", "note3"]
#表示该节点会不会作为主节点,true表示会;false表示不会
node.master: true
#当前节点是否用于存储数据,是:true、否:false
node.data: true
#数据存储目录(用逗号分隔多个位置) 这个目录默认不存在,自行创建
path.data: /home/tools/elasticsearch/elasticsearch-7.17.8/data
#日志文件路径
path.logs: /home/tools/elasticsearch/elasticsearch-7.17.8/logs
#es对外提供的http端口,默认 9200
http.port: 9200
#TCP的默认监听端口,默认 9300
transport.tcp.port: 9300
#启动时是否有锁定内存,生产环境需要true(可用内存一般设置可用内存的一半左右)
bootstrap.memory_lock: true

核心配置简化

cluster.name: bigdata
node.name: note1
network.host: 192.168.57.188
cluster.initial_master_nodes: ["note1", "note2"]
discovery.seed_hosts: ["note1", "note2", "note3"]
path.data: /home/tools/elasticsearch/elasticsearch-7.17.8/data
path.logs: /home/tools/elasticsearch/elasticsearch-7.17.8/logs
http.port: 9200
transport.tcp.port: 9300
bootstrap.memory_lock: true

其他配置 (可忽略)

# 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)
discovery.zen.minimum_master_nodes: 2
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
# 是否支持跨域,是:true,在使用head插件时需要此配置
http.cors.enabled: true
# “*” 表示支持所有域名
http.cors.allow-origin: "*"
action.destructive_requires_name: true
action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*
xpack.security.enabled: false
xpack.monitoring.enabled: true
xpack.graph.enabled: false
xpack.watcher.enabled: false
xpack.ml.enabled: false

三 分发配置过后的安装包到节点2与节点3

scp -r ./elasticsearch-7.17.8 note2:$PWD
scp -r ./elasticsearch-7.17.8 note3:$PWD

四 修改节点2与节点3的配置文件

   节点2核心配置如下

cluster.name: bigdata
node.name: note2
network.host: 192.168.57.189
cluster.initial_master_nodes: ["note1", "note2"]
discovery.seed_hosts: ["note1", "note2", "note3"]
path.data: /home/tools/elasticsearch/elasticsearch-7.17.8/data
path.logs: /home/tools/elasticsearch/elasticsearch-7.17.8/logs
http.port: 9200
transport.tcp.port: 9300
bootstrap.memory_lock: true

   节点3核心配置如下

cluster.name: bigdata
node.name: note3
network.host: 192.168.57.190
cluster.initial_master_nodes: ["note1", "note2"]
discovery.seed_hosts: ["note1", "note2", "note3"]
path.data: /home/tools/elasticsearch/elasticsearch-7.17.8/data
path.logs: /home/tools/elasticsearch/elasticsearch-7.17.8/logs
http.port: 9200
transport.tcp.port: 9300
bootstrap.memory_lock: true

注意,集群名字保持一致,所有服务器的地址网段必须保持一致,才能有集群的效果  xxx.xxx.xxx.xxx  前9位相同, 后三位(主机)不同

五 启动集群

 启动集群不能使用root用户 需要使用普通用户 这里创建es用户(每个节点都需要创建赋权限)

useradd es -m

设置密码 

passwd es

赋予安装包的使用权限(注意如果数据目录不在安装包下 需要再赋予一次数据目录权限)

chown -R es:es /home/tools/elasticsearch

 启动 : 

su es
/home/tools/elasticsearch/elasticsearch-7.17.8/bin/elasticsearch

初次启动集群会抛出异常

异常信息如下

1. elasticsearch进程的最大文件数[4096]太低,增加到至少[65535]
2. elasticsearch进程请求内存锁定,但内存未锁定
3. 最大虚拟内存区域。Max_map_count[65530]太低,至少增加到[262144]

解决方法

1.修改进程的最大文件数

vi /etc/security/limits.conf

   添加最大创建文件数(*不能去掉)

*               soft    nofile          65536
*               hard    nofile          131072

2.内存锁定 

vim /etc/security/limits.d/20-nproc.conf
*    soft    nproc    4096
vim /etc/systemd/system.conf
DefaultLimitNOFILE=65536
DefaultLimitNPROC=32000
DefaultLimitMEMLOCK=infinity

 3.设置最大虚拟内存区域

  执行命令            

sysctl -w vm.max_map_count=262144
echo "vm.max_map_count=262144" >> /etc/sysctl.conf
sysctl -a|grep vm.max_map_count

   配置完成

自定义启动脚本 需要在es账户之间配置免密登录

#启动脚本
esPath="/home/tools/elasticsearch/elasticsearch-7.17.8/bin"
#节点需要启动的节点ip地址
hostname1="note1"
hostname2="note2"
hostname3="note3"
case $1 in
"start")
ssh es@$hostname1 "source /etc/profile; $esPath/elasticsearch -d"
ssh es@$hostname2 "source /etc/profile; $esPath/elasticsearch -d"
ssh es@$hostname3 "source /etc/profile; $esPath/elasticsearch -d"
;;
"stop")
pid=$(ssh $hostname1 "ps -ef | grep Elasticsearch | grep -v grep | awk '{print $2}'"| awk '{print $2}')
ssh $hostname1 "kill $pid"
echo "stop $hostname1 Elasticsearch $pid"
pid=$(ssh $hostname2 "ps -ef | grep Elasticsearch | grep -v grep | awk '{print $2}'"| awk '{print $2}')
ssh $hostname2 "kill $pid"
echo "stop $hostname2 Elasticsearch $pid"
pid=$(ssh $hostname3 "ps -ef | grep Elasticsearch | grep -v grep | awk '{print $2}'"| awk '{print $2}')
ssh $hostname3 "kill $pid"
echo "stop $hostname3 Elasticsearch $pid"
;;
*)
echo "input {start | stop}"
;;
esac

科学上网安装ElasticSearch Head (使用谷歌浏览器安装插件)

 

es 索引创建脚本

address=localhost:9200
index=$1
mapping=`cat mapping`
#创建索引
curl -X PUT "${address}/${index}"
#设置mapping
curl -XPOST "http://${address}/${index}/robot/_mapping?pretty" -d "
${mapping}
"

{
        "robot": {
                "_all": {
                        "enabled": false
                },
                "properties": {
                        "istat": {
                                "analyzer": "standard",
                                "type": "text"
                        },
                        "fileName": {
                                "type": "keyword"
                        },
                        "_createDate_": { 
                                "format": "yyyy-MM-dd'T'HH:mm:ss.SSS'+08:00'",
                                "type": "date"
                        },
                        "listener_time": {
                                "format": "yyyy-MM-dd'T'HH:mm:ss.SSS'+08:00'",
                                "type": "date"
                        },
                        "quality": {
                                "analyzer": "standard",
                                "type": "text"
                        },
                        "@timestamp": {
                                "format": "yyyy-MM-dd'T'HH:mm:ss.SSS'+08:00'",
                                "type": "date"
                        },
                        "value": {
                                "type": "double"
                        },
                        "_nodeName_": {
                                "type": "keyword"
                        }
                }
        }
}

节点规模扩展

        新添加的节点需要配置cluster.initial_master_nodes,旧节点如果不重启不用修改,如果要重启旧节点,需要修改cluster.initial_master_nodes写入所有节点

  • 5
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小钻风巡山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值