window 环境部署集群

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

1、elasticsearch.yml配置:

node.name区别:elastic_node1、 elastic_node2、 elastic_node3

  1. cluster.name: elastic_cluster
  2.  
  3. node.name: elastic_node1
  4.  
  5. node.master: true
  6. node.data: true
  7.  
  8. #path.data: /usr/local/elastic_node1/data
  9. #path.logs: /usr/local/elastic_node1/logs
  10.  
  11. bootstrap.memory_lock: true
  12.  
  13. network.host: 0.0.0.0
  14. network.tcp.no_delay: true
  15. network.tcp.keep_alive: true
  16. network.tcp.reuse_address: true
  17. network.tcp.send_buffer_size: 256mb
  18. network.tcp.receive_buffer_size: 256mb
  19.  
  20. transport.tcp.port:
  21. transport.tcp.compress: true
  22.  
  23. http.max_content_length: 200mb
  24. http.cors.enabled: true
  25. http.cors.allow-origin: "*"
  26. http.port:
  27.  
  28. discovery.seed_hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
  29. cluster.initial_master_nodes: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
  30. cluster.fault_detection.leader_check.interval: 15s
  31. discovery.cluster_formation_warning_timeout: 30s
  32. cluster.join.timeout: 30s
  33. cluster.publish.timeout: 90s
  34. cluster.routing.allocation.cluster_concurrent_rebalance:
  35. cluster.routing.allocation.node_concurrent_recoveries:
  36. cluster.routing.allocation.node_initial_primaries_recoveries:

2、依次运行生成集群

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

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

3、生成证书

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

  • 运行

    1. bin/elasticsearch-certutil cert

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

在elasticsearch.yml配置添加

  1. xpack.security.enabled: true
  2. xpack.license.self_generated.type: basic
  3. xpack.security.transport.ssl.enabled: true
  4. xpack.security.transport.ssl.verification_mode: certificate
  5. xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
  6. xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

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

  1. 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认证

  1. elasticsearch.username: "kibana"
  2. elasticsearch.password: ""
  • 完整的elasticsearch.yml配置,注意不同节点node.name区别
  1. cluster.name: elastic_cluster
  2. node.name: elastic_node1
  3. node.master: true
  4. node.data: true
  5.  
  6. #path.data: /usr/local/elastic_node1/data
  7. #path.logs: /usr/local/elastic_node1/logs
  8.  
  9. bootstrap.memory_lock: true
  10.  
  11. network.host: 0.0.0.0
  12. network.tcp.no_delay: true
  13. network.tcp.keep_alive: true
  14. network.tcp.reuse_address: true
  15. network.tcp.send_buffer_size: 256mb
  16. network.tcp.receive_buffer_size: 256mb
  17.  
  18. transport.tcp.port:
  19. transport.tcp.compress: true
  20.  
  21. http.max_content_length: 200mb
  22. http.cors.enabled: true
  23. http.cors.allow-origin: "*"
  24. http.port:
  25.  
  26. discovery.seed_hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
  27. cluster.initial_master_nodes: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
  28. cluster.fault_detection.leader_check.interval: 15s
  29. discovery.cluster_formation_warning_timeout: 30s
  30. cluster.join.timeout: 30s
  31. cluster.publish.timeout: 90s
  32. cluster.routing.allocation.cluster_concurrent_rebalance:
  33. cluster.routing.allocation.node_concurrent_recoveries:
  34. cluster.routing.allocation.node_initial_primaries_recoveries:
  35.  
  36. xpack.security.enabled: true
  37. xpack.license.self_generated.type: basic
  38. xpack.security.transport.ssl.enabled: true
  39. xpack.security.transport.ssl.verification_mode: certificate
  40. xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
  41. xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

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

1、docker-compose.yml配置

  1. version: '2.2'
  2. services:
  3. es01:
  4. image: elasticsearch:7.6.
  5. container_name: es01
  6. environment:
  7. - node.name=es01
  8. - cluster.name=es-docker-cluster
  9. - discovery.seed_hosts=192.168.43.128:
  10. - cluster.initial_master_nodes=es01,192.168.43.128:
  11. - cluster.fault_detection.leader_check.interval=15s
  12. - bootstrap.memory_lock=true
  13. - http.cors.enabled=true
  14. - http.cors.allow-origin=*
  15. - network.host=0.0.0.0
  16. - network.publish_host=192.168.43.129
  17. - xpack.security.enabled=true
  18. - xpack.security.transport.ssl.enabled=true
  19. - "ES_JAVA_OPTS=-Xms256m -Xmx256m"
  20. ulimits:
  21. memlock:
  22. soft: -
  23. hard: -
  24. volumes:
  25. - ./mnt/data:/usr/share/elasticsearch/data
  26. - ./mnt/logs:/usr/share/elasticsearch/logs
  27. ports:
  28. - :
  29. - :
  30. networks:
  31. - elastic
  32. cerebro:
  33. image: lmenezes/cerebro:0.8.
  34. container_name: cerebro
  35. ports:
  36. - "9000:9000"
  37. command:
  38. - -Dhosts..host=http://es01:9200
  39. networks:
  40. - elastic
  41. volumes:
  42. mnt:
  43. driver: local
  44.  
  45. networks:
  46. elastic:
  47. 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、修改配置&&动态添加测试

  1. version: '2.2'
  2. services:
  3. es01:
  4. image: elasticsearch:7.6.
  5. container_name: es01
  6. environment:
  7. - node.name=es01
  8. - cluster.name=es-docker-cluster
  9. - discovery.seed_hosts=192.168.43.128:
  10. - cluster.initial_master_nodes=es01,192.168.43.128:
  11. - cluster.fault_detection.leader_check.interval=15s
  12. - bootstrap.memory_lock=true
  13. - http.cors.enabled=true
  14. - http.cors.allow-origin=*
  15. - network.host=0.0.0.0
  16. - network.publish_host=192.168.43.129
  17. - xpack.security.enabled=true
  18. - xpack.security.transport.ssl.enabled=true
  19. - xpack.license.self_generated.type=basic
  20. - xpack.security.transport.ssl.verification_mode=certificate
  21. - xpack.security.transport.ssl.keystore.path=elastic-certificates.p12
  22. - xpack.security.transport.ssl.truststore.path=elastic-certificates.p12
  23. - "ES_JAVA_OPTS=-Xms256m -Xmx256m"
  24. ulimits:
  25. memlock:
  26. soft: -
  27. hard: -
  28. volumes:
  29. - ./mnt/data:/usr/share/elasticsearch/data
  30. - ./mnt/logs:/usr/share/elasticsearch/logs
  31. - ./mnt/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12
  32. ports:
  33. - :
  34. - :
  35. networks:
  36. - elastic
  37. cerebro:
  38. image: lmenezes/cerebro:0.8.
  39. container_name: cerebro
  40. ports:
  41. - "9000:9000"
  42. command:
  43. - -Dhosts..host=http://es01:9200
  44. networks:
  45. - elastic
  46. volumes:
  47. mnt:
  48. driver: local
  49.  
  50. networks:
  51. elastic:
  52. driver: bridge

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

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

springboot使用测试

1、引入pom

  1. <dependency>
  2. <groupId>org.elasticsearch</groupId>
  3. <artifactId>elasticsearch</artifactId>
  4. <version>7.6.</version>
  5. </dependency>
  6.  
  7. <dependency>
  8. <groupId>org.elasticsearch.client</groupId>
  9. <artifactId>elasticsearch-rest-client</artifactId>
  10. <version>7.6.</version>
  11. </dependency>
  12.  
  13. <dependency>
  14. <groupId>org.elasticsearch.client</groupId>
  15. <artifactId>elasticsearch-rest-high-level-client</artifactId>
  16. <version>7.6.</version>
  17. </dependency>

2、 代码

  1. EsConfiguration.class

    1. /**
    2. * @author hdy
    3. */
    4. @Configuration
    5. public class EsConfiguration {
    6. /**
    7. * 集群地址
    8. */
    9. private static String hosts = "192.168.43.128";
    10. private static String hosts1 = "192.168.43.129";
    11. private static String hosts2 = "192.168.43.130";
    12. /**
    13. * 使用的端口号
    14. */
    15. private static int port = ;
    16. /**
    17. * // 使用的协议
    18. */
    19. private static String schema = "http";
    20. private static ArrayList<HttpHost> hostList = null;
    21. /**
    22. * 连接超时时间
    23. */
    24. private static int connectTimeOut = ;
    25. /**
    26. * 连接超时时间
    27. */
    28. private static int socketTimeOut = ;
    29. /**
    30. * 获取连接的超时时间
    31. */
    32. private static int connectionRequestTimeOut = ;
    33. /**
    34. * 最大连接数
    35. */
    36. private static int maxConnectNum = ;
    37. /**
    38. * 最大路由连接数
    39. */
    40. private static int maxConnectPerRoute = ;
    41.  
    42. private RestClientBuilder builder;
    43.  
    44. private final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    45.  
    46. static {
    47. hostList = new ArrayList<>();
    48. hostList.add(new HttpHost(hosts, port, schema));
    49. hostList.add(new HttpHost(hosts1, port, schema));
    50. hostList.add(new HttpHost(hosts2, port, schema));
    51. }
    52.  
    53. @Bean("restHighLevelClient")
    54. public RestHighLevelClient client() {
    55. builder = RestClient.builder(hostList.toArray(new HttpHost[]));
    56. setConnectTimeOutConfig();
    57. setMutiConnectConfig();
    58. return new RestHighLevelClient(builder);
    59. }
    60.  
    61. /**
    62. * 异步httpclient的连接延时配置
    63. */
    64. private void setConnectTimeOutConfig() {
    65. builder.setRequestConfigCallback(requestConfigBuilder -> {
    66. requestConfigBuilder.setConnectTimeout(connectTimeOut);
    67. requestConfigBuilder.setSocketTimeout(socketTimeOut);
    68. requestConfigBuilder.setConnectionRequestTimeout(connectionRequestTimeOut);
    69. return requestConfigBuilder;
    70. });
    71. }
    72.  
    73. /**
    74. * 异步httpclient的连接数配置
    75. */
    76. private void setMutiConnectConfig() {
    77. credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("elastic", ""));
    78. builder.setHttpClientConfigCallback(httpClientBuilder -> {
    79. httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
    80. httpClientBuilder.setMaxConnTotal(maxConnectNum);
    81. httpClientBuilder.setMaxConnPerRoute(maxConnectPerRoute);
    82. return httpClientBuilder;
    83. });
    84. }
    85.  
    86. }
  2. ElasticsearchApplicationTests.class

    1. @Log4j2
    2. @RunWith(SpringRunner.class)
    3. @SpringBootTest
    4. public class ElasticsearchApplicationTests {
    5.  
    6. @Autowired
    7. RestHighLevelClient restHighLevelClient;
    8.  
    9. @Test
    10. public void contextLoads() {
    11.  
    12. for (int i = ; i >= ; i--) {
    13. Map<String, Object> jsonMap = new HashMap<>();
    14. jsonMap.put("name", "测试" + i);
    15. jsonMap.put("age", "" + i);
    16. jsonMap.put("des", "啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦拉了拉");
    17. jsonMap.put("des1", "des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1des1");
    18. jsonMap.put("des2", "des2des2des2des2des2des2des2des2des2des2des2des2des2des2des2des2des2des2");
    19. jsonMap.put("des3", "des3des3des3des3des3des3des3des3des3des3des3des3des3des3des3des3des3des3");
    20. jsonMap.put("des4", "des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4des4");
    21. jsonMap.put("postDate", new Date());
    22. jsonMap.put("message", "trying out Elasticsearch");
    23. IndexRequest indexRequest = new IndexRequest("test").id("" + i).source(jsonMap);
    24. try {
    25. IndexResponse response = null;
    26. try {
    27. response = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    28. } catch (IOException e) {
    29. e.printStackTrace();
    30. }
    31. log.info(response.toString());
    32. } catch (ElasticsearchException e) {
    33. if (e.status() == RestStatus.CONFLICT) {
    34. System.out.println("e = " + e);
    35. }
    36. }
    37. }
    38.  
    39. GetRequest getRequest = new GetRequest("posts", "");
    40. GetResponse response = null;
    41. try {
    42. response = restHighLevelClient.get(getRequest, RequestOptions.DEFAULT);
    43. log.info(response.toString());
    44. } catch (IOException e) {
    45. e.printStackTrace();
    46. }
    47.  
    48. }
    49.  
    50. }
  3. 错误信息,少引入elasticsearch-rest-client pom包

    1. 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]
    2. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:) ~[spring-beans-5.1..RELEASE.jar:5.1..RELEASE]
    3. at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:) [junit-rt.jar:na]
    4. at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:) [junit-rt.jar:na]
    5. Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.elasticsearch.client.RestHighLevelClient] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
    6. at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:) ~[spring-core-5.1..RELEASE.jar:5.1..RELEASE]
    7. ... common frames omitted
    8. Caused by: java.lang.NoClassDefFoundError: org/elasticsearch/client/Cancellable
    9. at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_191]
    10. at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:) ~[spring-core-5.1..RELEASE.jar:5.1..RELEASE]
    11. ... common frames omitted
    12. Caused by: java.lang.ClassNotFoundException: org.elasticsearch.client.Cancellable
    13. at java.net.URLClassLoader.findClass(URLClassLoader.java:) ~[na:1.8.0_191]
    14. at java.lang.ClassLoader.loadClass(ClassLoader.java:) ~[na:1.8.0_191]
    15. ... common frames omitted

ElasticSearch 6.x数据迁移ElasticSearch7.4

  1. 安装nodejs

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

    1. elasticdump --input=http://127.0.0.1:9200/index(修改为真实的索引名称) --output=http://10.0.1.236:9200/index --type=mapping(修改为真实的索引名称与需要导入的IP)
  5. data拷贝
    1. # 创建认证文件
    2. cat > authFile <<EOF
    3. user=elastic
    4. password=xxxxxx
    5. EOF
    6.  
    7. # dump数据
    8. 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. Sharding-JDBC实现水平拆分-单库分表

    参考资料:猿天地   https://mp.weixin.qq.com/s/901rNhc4WhLCQ023zujRVQ 作者:尹吉欢 当单表的数量急剧上升,超过了1千万以上,这个时候就要对表进行水平 ...

  2. Sharding-JDBC主键生成策略

    当使用分库分表等功能之后,就不能再依赖数据库自带的主键生成机制了,一方面主键ID不能重复,另外需要在新增之前就知道主键ID,才能保证ID能够均匀分布到不同的数据库或数据表中,所以要使用一个合理的主键生 ...

  3. Idea快捷生成serialVersionUID

    Java对象实现了Serializable接口,是需要创建serialVersionUID,避免此对象在序列化.反序列化时出现问题.但idea默认没有生成serialVersionUID的设置,需要手 ...

  4. 8月1日起全部无版号游戏下架,ios手游想上架看这里!

      在苹果至中国游戏开发者的邮件中声明:如果开发者不能在7月31日前提交版号及相关文件,付费游戏将不可以在中国AppStore供应.也就是说:   从8月1日开始,苹果将正式下架全部.所有的ios付费 ...

  5. 018_go语言中的结构体

    代码演示 package main import "fmt" type person struct { name string age int } func main() { fm ...

  6. three.js 着色器材质之变量(三)

    这篇郭先生在练习一下着色器变量,在度娘上面或者官网上经常看到类似水波一样的效果,这篇就试着做一个这样的效果,顺便巩固一下顶点着色器和片元着色器,毕竟多多练习才能更好地掌握.效果如下图,在线案例请点击博 ...

  7. Java 二维数组及方法概况

    数组 数组是指一组数据的集合,数组中的每个数据被称作元素.在数组中可以存放任意类型的元素,但同一个数组里存放的元素类型必须一致. 数组的定义 在Java中,可以使用以下格式来定义一个数组. 数据类型[ ...

  8. 2020-06-07:mysql中varchar类型的id,where id=1,会用到索引吗?int 类型的id,where id="1",会用到索引吗?为什么?

    福哥答案2020-06-07: 答案来自群员:对于int类型id,查询的varchar 类型 ‘1’会隐式转换成 1,‘1’和 1都能正常走索引:对于varchar类型id,查询的int 类型 1不会 ...

  9. CSS卡片右上角标记样式设计

    template <div class="each-one-in-list"> <div class="show-icon">进行中&l ...

  10. hdfs学习(一)

    一.hdfs概述 介绍: 在现代的企业环境中,单机容量往往无法存储大量数据,需要跨机器存储.统一管理分布在集群上的文件系统称为分布式文件系统 .HDFS(Hadoop Distributed File ...