在单台服务器上搭建elasticsearch集群

[在单台centos7服务器上搭建elasticsearch集群]

本次集群部署在单台服务器,正式环境中不可这么干,因为起不到作用。

本次环境使用的es版本均为:elasticsearch-7.2.0.tar
下载地址为:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-2-0

环境搭建

系统配置:

修改/etc/hosts增加
127.0.0.1 node01
127.0.0.1 node02
127.0.0.1 node03
修改/etc/sysctl.conf增加配置,然后执行sysctl -p立即生效
vm.max_map_count=655360
修改 /etc/security/limits.conf 增加配置:
*               soft    nofile          65536
*               hard    nofile          65536

修改 /etc/security/limits.d/20-nproc.conf 增加配置:
*               soft    nproc           4096
*               hard    nproc           4096

用到的软件包:

elasticsearch-7.2.0.tar.gz

创建安装目录

mkdir /usr/local/elasticsearch-cluster/

将es上传到安装目录后,解压

tar -xvf elasticsearch-7.2.0.tar.gz

为了操作方便,修改下软件目录名

cp -rp elasticsearch-7.2.0/ elasticsearch-cluster/elasticsearch-node1
cp -rp elasticsearch-7.2.0/ elasticsearch-cluster/elasticsearch-node2
mv elasticsearch-7.2.0/ elasticsearch-cluster/elasticsearch-node3
elasticsearch-node1配置修改
修改es配置如下(config/elasticsearch.yml)

cluster.name: es-cluster
node.name: node1
node.master: true
node.data: true
path.data: /usr/local/elasticsearch-cluster/elasticsearch-node1/data
path.logs: /usr/local/elasticsearch-cluster/elasticsearch-node1/logs
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 9201
transport.tcp.port: 9301
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
cluster.initial_master_nodes: ["node1"]
discovery.zen.minimum_master_nodes: 1
http.cors.enabled: true
http.cors.allow-origin: "*"
elasticsearch-node2配置修改
修改es配置如下(config/elasticsearch.yml)

cluster.name: es-cluster
node.name: node2
node.master: false
node.data: true
path.data: /usr/local/elasticsearch-cluster/elasticsearch-node2/data
path.logs: /usr/local/elasticsearch-cluster/elasticsearch-node2/logs
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 9202
transport.tcp.port: 9302
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
cluster.initial_master_nodes: ["node1"]
discovery.zen.minimum_master_nodes: 1
elasticsearch-node3配置修改
修改es配置如下(config/elasticsearch.yml)

cluster.name: es-cluster
node.name: node3
node.master: false
node.data: true
path.data: /usr/local/elasticsearch-cluster/elasticsearch-node3/data
path.logs: /usr/local/elasticsearch-cluster/elasticsearch-node3/logs
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 9203
transport.tcp.port: 9303
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
cluster.initial_master_nodes: ["node1"]
discovery.zen.minimum_master_nodes: 1
启动

然后分别启动node01/02/03即可

bin/elasticsearch -d  后台启动
健康检查
查看集群状态
curl http://ES_IP:9201/_cat/health?v
查看节点状态
curl http://ES_IP:9201/_cat/nodes?v
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个单台服务器上使用 Docker 搭建 Elasticsearch 集群的配置步骤: 1. 安装 Docker 和 Docker Compose 可以参考 Docker 官网的安装指南安装 Docker 和 Docker Compose。 2. 创建一个目录用于存放 Elasticsearch 的数据和配置文件 在本地创建一个目录,例如 /home/user/elasticsearch,用于存放 Elasticsearch 的数据和配置文件。 3. 创建 docker-compose.yml 文件 在 /home/user/elasticsearch 目录下创建 docker-compose.yml 文件,内容如下: ``` version: "3.9" services: elasticsearch1: image: docker.elastic.co/elasticsearch/elasticsearch:7.14.0 container_name: elasticsearch1 environment: - node.name=elasticsearch1 - cluster.name=mycluster - discovery.seed_hosts=elasticsearch1 - cluster.initial_master_nodes=elasticsearch1 ulimits: memlock: soft: -1 hard: -1 volumes: - ./data:/usr/share/elasticsearch/data - ./config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml - ./plugins:/usr/share/elasticsearch/plugins ports: - 9200:9200 - 9300:9300 ``` 这个配置文件定义了一个 Elasticsearch 服务,使用的是 7.14.0 版本的镜像,容器名为 elasticsearch1。配置了节点名称、集群名称、发现种子主机和初始主节点。同时,将容器内部的数据目录、配置文件和插件目录映射到本地目录。 4. 创建 Elasticsearch 配置文件 在 /home/user/elasticsearch/config 目录下创建 elasticsearch.yml 文件,内容如下: ``` network.host: 0.0.0.0 cluster.routing.allocation.disk.threshold_enabled: false ``` 这个配置文件定义了 Elasticsearch 的网络主机,以及关闭了磁盘阈值。 5. 启动 Elasticsearch 集群 在 /home/user/elasticsearch 目录下运行以下命令启动 Elasticsearch 集群: ``` docker-compose up -d ``` 这个命令会下载 Elasticsearch 镜像并启动容器,同时自动加载 docker-compose.yml 文件和配置文件。 6. 验证 Elasticsearch 集群 在浏览器中访问 http://localhost:9200/,如果出现以下信息表示 Elasticsearch 集群已经成功启动: ``` { "name" : "elasticsearch1", "cluster_name" : "mycluster", "cluster_uuid" : "xxxx", "version" : { "number" : "7.14.0", "build_flavor" : "default", "build_type" : "docker", "build_hash" : "xxxx", "build_date" : "2021-07-29T20:49:32.864135063Z", "build_snapshot" : false, "lucene_version" : "8.9.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } ``` 至此,单台服务器上使用 Docker 搭建 Elasticsearch 集群的配置完成。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值