window 环境部署集群

注意:window下载解压elasticsearch一定需要解压多次。例如搭建的3节点的,需要解压3次,防止生成 cluster UUID 一致导致只能看到一个节点

1、elasticsearch.yml配置:

node.name区别:elastic_node1、 elastic_node2、 elastic_node3

cluster.name: elastic_cluster

node.name: elastic_node1

node.master: true
node.data: true #path.data: /usr/local/elastic_node1/data
#path.logs: /usr/local/elastic_node1/logs bootstrap.memory_lock: true network.host: 0.0.0.0
network.tcp.no_delay: true
network.tcp.keep_alive: true
network.tcp.reuse_address: true
network.tcp.send_buffer_size: 256mb
network.tcp.receive_buffer_size: 256mb transport.tcp.port:
transport.tcp.compress: true http.max_content_length: 200mb
http.cors.enabled: true
http.cors.allow-origin: "*"
http.port: discovery.seed_hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
cluster.initial_master_nodes: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
cluster.fault_detection.leader_check.interval: 15s
discovery.cluster_formation_warning_timeout: 30s
cluster.join.timeout: 30s
cluster.publish.timeout: 90s
cluster.routing.allocation.cluster_concurrent_rebalance:
cluster.routing.allocation.node_concurrent_recoveries:
cluster.routing.allocation.node_initial_primaries_recoveries:

2、依次运行生成集群

浏览器打开:http://127.0.0.1:9201/_cat/nodes?v

ip        heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1 dilm - elastic_node3
127.0.0.1 dilm - elastic_node1
127.0.0.1 dilm * elastic_node2

3、生成证书

es集群通过证书来安全的组成集群

  • 运行

    bin/elasticsearch-certutil cert

注意: 密码后面需要单独设置,这里是集群安全认证,建议密码不设置,成功后生成的证书默认在es的config目录里面 elastic-certificates.p12;分别copy一份到其他节点的config里面(默认目录)

在elasticsearch.yml配置添加

xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

4、给认证的集群创建用户密码

bin/elasticsearch-setup-passwords interactive
  • elastic 账号:拥有 superuser 角色,是内置的超级用户。
  • kibana 账号:拥有 kibana_system 角色,用户 kibana 用来连接 elasticsearch 并与之通信。Kibana 服务器以该用户身份提交请求以访问集群监视 API 和 .kibana 索引。不能访问 index。
  • logstash_system 账号:拥有 logstash_system 角色。用户 Logstash 在 Elasticsearch 中存储监控信息时使用。
  • beats_system账号:拥有 beats_system 角色。用户 Beats 在 Elasticsearch 中存储监控信息时使用。

5、配置kibana认证

elasticsearch.username: "kibana"
elasticsearch.password: ""
  • 完整的elasticsearch.yml配置,注意不同节点node.name区别
cluster.name: elastic_cluster
node.name: elastic_node1
node.master: true
node.data: true #path.data: /usr/local/elastic_node1/data
#path.logs: /usr/local/elastic_node1/logs bootstrap.memory_lock: true network.host: 0.0.0.0
network.tcp.no_delay: true
network.tcp.keep_alive: true
network.tcp.reuse_address: true
network.tcp.send_buffer_size: 256mb
network.tcp.receive_buffer_size: 256mb transport.tcp.port:
transport.tcp.compress: true http.max_content_length: 200mb
http.cors.enabled: true
http.cors.allow-origin: "*"
http.port: discovery.seed_hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
cluster.initial_master_nodes: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
cluster.fault_detection.leader_check.interval: 15s
discovery.cluster_formation_warning_timeout: 30s
cluster.join.timeout: 30s
cluster.publish.timeout: 90s
cluster.routing.allocation.cluster_concurrent_rebalance:
cluster.routing.allocation.node_concurrent_recoveries:
cluster.routing.allocation.node_initial_primaries_recoveries: xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

centos(docker-compose) 环境部署集群

1、docker-compose.yml配置

version: '2.2'
services:
es01:
image: elasticsearch:7.6.
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=192.168.43.128:
- cluster.initial_master_nodes=es01,192.168.43.128:
- cluster.fault_detection.leader_check.interval=15s
- bootstrap.memory_lock=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- network.host=0.0.0.0
- network.publish_host=192.168.43.129
- xpack.security.enabled=true
- xpack.security.transport.ssl.enabled=true
- "ES_JAVA_OPTS=-Xms256m -Xmx256m"
ulimits:
memlock:
soft: -
hard: -
volumes:
- ./mnt/data:/usr/share/elasticsearch/data
- ./mnt/logs:/usr/share/elasticsearch/logs
ports:
- :
- :
networks:
- elastic
cerebro:
image: lmenezes/cerebro:0.8.
container_name: cerebro
ports:
- "9000:9000"
command:
- -Dhosts..host=http://es01:9200
networks:
- elastic
volumes:
mnt:
driver: local networks:
elastic:
driver: bridge

权限问题执行 chmod -R 777 mnt/*

2、生成证书文件创建密码

  • 进入容器 docker exec -it 5144d3b1dd56 /bin/bash
  • 生成证书 bin/elasticsearch-certutil cert
  • 复制证书并cp到其他节点 docker cp 09f57b6067e0:/usr/share/elasticsearch/elastic-certificates.p12 .

3、修改配置&&动态添加测试

version: '2.2'
services:
es01:
image: elasticsearch:7.6.
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=192.168.43.128:
- cluster.initial_master_nodes=es01,192.168.43.128:
- cluster.fault_detection.leader_check.interval=15s
- bootstrap.memory_lock=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- network.host=0.0.0.0
- network.publish_host=192.168.43.129
- xpack.security.enabled=true
- xpack.security.transport.ssl.enabled=true
- xpack.license.self_generated.type=basic
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.security.transport.ssl.keystore.path=elastic-certificates.p12
- xpack.security.transport.ssl.truststore.path=elastic-certificates.p12
- "ES_JAVA_OPTS=-Xms256m -Xmx256m"
ulimits:
memlock:
soft: -
hard: -
volumes:
- ./mnt/data:/usr/share/elasticsearch/data
- ./mnt/logs:/usr/share/elasticsearch/logs
- ./mnt/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12
ports:
- :
- :
networks:
- elastic
cerebro:
image: lmenezes/cerebro:0.8.
container_name: cerebro
ports:
- "9000:9000"
command:
- -Dhosts..host=http://es01:9200
networks:
- elastic
volumes:
mnt:
driver: local networks:
elastic:
driver: bridge

注意证书的位置,给权限 chmod -R 777 mnt/*

  • 设置密码(建议进入主节点容器中) bin/elasticsearch-setup-passwords interactive -u 'http://es01:9200'
  • 通用配置与window类似

springboot使用测试

1、引入pom

  <dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.6.</version>
</dependency> <dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.6.</version>
</dependency> <dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.6.</version>
</dependency>

2、 代码

  1. EsConfiguration.class

    /**
    * @author hdy
    */
    @Configuration
    public class EsConfiguration {
    /**
    * 集群地址
    */
    private static String hosts = "192.168.43.128";
    private static String hosts1 = "192.168.43.129";
    private static String hosts2 = "192.168.43.130";
    /**
    * 使用的端口号
    */
    private static int port = ;
    /**
    * // 使用的协议
    */
    private static String schema = "http";
    private static ArrayList<HttpHost> hostList = null;
    /**
    * 连接超时时间
    */
    private static int connectTimeOut = ;
    /**
    * 连接超时时间
    */
    private static int socketTimeOut = ;
    /**
    * 获取连接的超时时间
    */
    private static int connectionRequestTimeOut = ;
    /**
    * 最大连接数
    */
    private static int maxConnectNum = ;
    /**
    * 最大路由连接数
    */
    private static int maxConnectPerRoute = ; private RestClientBuilder builder; private final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); static {
    hostList = new ArrayList<>();
    hostList.add(new HttpHost(hosts, port, schema));
    hostList.add(new HttpHost(hosts1, port, schema));
    hostList.add(new HttpHost(hosts2, port, schema));
    } @Bean("restHighLevelClient")
    public RestHighLevelClient client() {
    builder = RestClient.builder(hostList.toArray(new HttpHost[]));
    setConnectTimeOutConfig();
    setMutiConnectConfig();
    return new RestHighLevelClient(builder);
    } /**
    * 异步httpclient的连接延时配置
    */
    private void setConnectTimeOutConfig() {
    builder.setRequestConfigCallback(requestConfigBuilder -> {
    requestConfigBuilder.setConnectTimeout(connectTimeOut);
    requestConfigBuilder.setSocketTimeout(socketTimeOut);
    requestConfigBuilder.setConnectionRequestTimeout(connectionRequestTimeOut);
    return requestConfigBuilder;
    });
    } /**
    * 异步httpclient的连接数配置
    */
    private void setMutiConnectConfig() {
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", ""));
    builder.setHttpClientConfigCallback(httpClientBuilder -> {
    httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
    httpClientBuilder.setMaxConnTotal(maxConnectNum);
    httpClientBuilder.setMaxConnPerRoute(maxConnectPerRoute);
    return httpClientBuilder;
    });
    } }
  2. ElasticsearchApplicationTests.class

    @Log4j2
    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class ElasticsearchApplicationTests { @Autowired
    RestHighLevelClient restHighLevelClient; @Test
    public void contextLoads() { for (int i = ; i >= ; i--) {
    Map<String, Object> jsonMap = new HashMap<>();
    jsonMap.put("name", "测试" + i);
    jsonMap.put("age", "" + i);
    jsonMap.put("des", "啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦拉了拉");
    jsonMap.put("des1", "des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1");
    jsonMap.put("des2", "des2des2des2des2des2des2des2des2des2des2des2des2des2des2des2des2des2des2");
    jsonMap.put("des3", "des3des3des3des3des3des3des3des3des3des3des3des3des3des3des3des3des3des3");
    jsonMap.put("des4", "des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4");
    jsonMap.put("postDate", new Date());
    jsonMap.put("message", "trying out Elasticsearch");
    IndexRequest indexRequest = new IndexRequest("test").id("" + i).source(jsonMap);
    try {
    IndexResponse response = null;
    try {
    response = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    } catch (IOException e) {
    e.printStackTrace();
    }
    log.info(response.toString());
    } catch (ElasticsearchException e) {
    if (e.status() == RestStatus.CONFLICT) {
    System.out.println("e = " + e);
    }
    }
    } GetRequest getRequest = new GetRequest("posts", "");
    GetResponse response = null;
    try {
    response = restHighLevelClient.get(getRequest, RequestOptions.DEFAULT);
    log.info(response.toString());
    } catch (IOException e) {
    e.printStackTrace();
    } } }
  3. 错误信息,少引入elasticsearch-rest-client pom包

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restHighLevelClient' defined in class path resource [com/dy/client/EsConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.elasticsearch.client.RestHighLevelClient] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:) ~[spring-beans-5.1..RELEASE.jar:5.1..RELEASE]
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:) [junit-rt.jar:na]
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:) [junit-rt.jar:na]
    Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.elasticsearch.client.RestHighLevelClient] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:) ~[spring-core-5.1..RELEASE.jar:5.1..RELEASE]
    ... common frames omitted
    Caused by: java.lang.NoClassDefFoundError: org/elasticsearch/client/Cancellable
    at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_191]
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:) ~[spring-core-5.1..RELEASE.jar:5.1..RELEASE]
    ... common frames omitted
    Caused by: java.lang.ClassNotFoundException: org.elasticsearch.client.Cancellable
    at java.net.URLClassLoader.findClass(URLClassLoader.java:) ~[na:1.8.0_191]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:) ~[na:1.8.0_191]
    ... common frames omitted

ElasticSearch 6.x数据迁移ElasticSearch7.4

  1. 安装nodejs

    yum install nodejs -y --registry=https://registry.npm.taobao.org
  2. 安装elasticdump 
    npm install elasticdump -g
  3. 升级nodejs
    npm install -g n
    n latest
  4. mapping拷贝(建议手动拷贝)

    elasticdump --input=http://127.0.0.1:9200/index(修改为真实的索引名称) --output=http://10.0.1.236:9200/index --type=mapping(修改为真实的索引名称与需要导入的IP)
  5. data拷贝
    # 创建认证文件
    cat > authFile <<EOF
    user=elastic
    password=xxxxxx
    EOF # dump数据
    elasticdump --input=http://192.168.0.110:9200/test-20200510 --output=http://192.168.0.215:9201/test-20200510 --type=data --limit=100000 --httpAuthFile=authFile

Elasticsearch7.6 集群部署、集群认证及使用、数据备份的更多相关文章

  1. linux运维、架构之路-Kubernetes集群部署TLS双向认证

    一.kubernetes的认证授权       Kubernetes集群的所有操作基本上都是通过kube-apiserver这个组件进行的,它提供HTTP RESTful形式的API供集群内外客户端调 ...

  2. 【集群实战】Rsync试题-异机数据备份解决方案

    企业案例:Rsync上机实战考试题: 某公司有一台Web服务器,里面的数据很重要,但是如果硬盘坏了,数据就会丢失,现在领导要求你把数据在其它机器上做一个周期性定时备份. 要求如下: 每天晚上00点整在 ...

  3. elk 系列:Elasticsearch 7.2 集群部署+TLS 加密+认证登陆

    背景 2019年5月21日,Elastic官方发布消息: Elastic Stack 新版本6.8.0 和7.1.0的核心安全功能现免费提供. 这意味着用户现在能够对网络流量进行加密.创建和管理用户. ...

  4. 面试连环炮系列(二):你们的项目Redis做了集群部署吗

    你们的项目Redis做了集群部署吗? 我们有大量数据需要缓存,而单实例的容量毕竟是有限的,于是做了Redis集群部署. 采取的方案是什么,Codis还是Redis Cluster,为什么要选择这个方案 ...

  5. 使用kubeadm进行单master(single master)和高可用(HA)kubernetes集群部署

    kubeadm部署k8s 使用kubeadm进行k8s的部署主要分为以下几个步骤: 环境预装: 主要安装docker.kubeadm等相关工具. 集群部署: 集群部署分为single master(单 ...

  6. 部署Redis Cluster 6.0 集群并开启密码认证 和 Redis-cluster-proxy负载

    部署Redis Cluster集群并开启密码认证 如果只想简单的搭建Redis Cluster,不需要设置密码和公网访问,可以参考官方文档. 节点介绍 Cluster模式推荐最少有6个节点,本次实验搭 ...

  7. CentOS6.8部署MongoDB集群及支持auth认证

    三个节点的副本集如下图所示: 实验目的: 配置MongoDB的3节点副本集 3个节点的副本集都要开启auth认证,并且开启认证后,能互相通信 第一步 - 准备环境 准备三个虚拟机,其中一个用作Prim ...

  8. ELK + filebeat集群部署

    ELK + filebeat集群部署 一.ELK简介 1. Elasticsearch Elasticsearch是一个实时的分布式搜索分析引擎, 它能让你以一个之前从未有过的速度和规模,去探索你的数 ...

  9. OpenStack Swift集群部署流程与简单使用

    之前介绍了<OpenStack Swift All In One安装部署流程与简单使用>,那么接下来就说一说Swift集群部署吧. 1. 简介 本文档详细描述了使用两台PC部署一个小型Sw ...

随机推荐

  1. Ynoi专练

    为了练习分块 莫队 bitset黑科技 我会写几道Ynoi 放到这里. bitset 每一位占1bit int 每一位占 4 bitye bool占1 bitye long long 8bitye L ...

  2. luogu P4884 多少个1?

    LINK:多少个1? 题目要求:\(\sum_{i=0}^{n-1}10^i \equiv k \mod m\) 最小的n. 看起来很难求的样子 这个同余式 看起来只能暴力枚举. 不过既然是同余 我们 ...

  3. Hadoop学习之TextInputFormat分片逻辑探究

    期望 顺着上一篇文章<Hadoop学习之第一个MapReduce程序>中遗留的分片疑惑,探究TextInputFormat的分片逻辑. 第一步 上Apache官网下载实验所使用的Hadoo ...

  4. Canal简介

    以下内容主要摘自Canal 官方wiki和网友博客:https://www.jianshu.com/p/6299048fad66 一.背景 早期,阿里巴巴B2B公司因为存在杭州和美国双机房部署,存在跨 ...

  5. 2 DC电参数测试 (1)

    基本常识: (1)Hot switch好的程序应避免使用热切换(这里热的含义类似于热插拔的“热“),热切换是指带点操作,有电流的情况下断开开关或闭合开关的瞬间,有电流通过,这会减少开关的寿命甚至直接损 ...

  6. OpenCV计算机视觉编程攻略(第三版)源码

    去年买了这本OpenCV的书,感觉还不错,但是书上没有给出下载源码的地方,在网上找了下,还好找到了,现在分享给大家: 链接: https://pan.baidu.com/s/1IqAay1IZ8g-h ...

  7. 2020-06-01:百万级int数据量的一个array求和。

    福哥答案2020-06-01: fork/join. 对于百万级长度的数组求和,单线程和多线程下区别不大.对于千万级长度的数组求和,多线程明显变快,大概是单线程的2-3倍. go语言测试代码如下: p ...

  8. 2020-05-29:redis怎么保证高可用,高可用模式有那些?对比下优缺点?

    福哥答案2020-05-29: Redis 高可用架构如下:1.Redis Sentinel 集群 + 内网 DNS + 自定义脚本.2.Redis Sentinel 集群 + VIP + 自定义脚本 ...

  9. JavaScript map+parseInt 容易产生的误区

    map /** * 语法: * var new_array = arr.map(function callback(currentValue[,index[,array]]){ * // return ...

  10. Solon 的 PathVariable 不需注解

    相对于 Spring boot 的 path variable :Solon 的不需注解,只要变量名对上即可: //path var demo // @XMapping("e/{p_q}/{ ...