Springboot2.x集成ElasticSearch8.5.3(集群)

一、安装、配置

win11、JDK8、三个节点,启动有点费内存

ELK安装上篇文章已经介绍过,这篇主要是配置;

1、将ES复制三个,分别命名如图:

在这里插入图片描述

比如,node-1里是这样的, node-2、node-3都一样

在这里插入图片描述

2、elasticsearch配置

config文件下elasticsearch.yml文件

node-1的配置:

# 换个集群的名字,免得跟别人的集群混在一起
cluster.name: el-my

# 换个节点名字
node.name: node-1001

# 修改一下ES的监听地址,这样别的机器也可以访问
network.host: 0.0.0.0
http.host: 0.0.0.0

#设置对外服务的http端口,默认为9200
http.port: 9201
transport.port: 9301
discovery.seed_hosts: ["127.0.0.1:9301", "127.0.0.1:9302", "127.0.0.1:9303"]
cluster.initial_master_nodes: ["node-1001","node-1002","node-1003"]

# 允许通配符删除索引
action.destructive_requires_name: true

#设置索引数据的存储路径(每个节点都要有自己的data,logs,不然报错)
path.data: M:/elasticsearch-8.5.3.0/node-1001/data/data    #换成自己的路径
#设置日志文件的存储路径
path.logs: M:/elasticsearch-8.5.3.0/node-1001/data/logs    #换成自己的路径

# 增加新的参数,head插件可以访问es
http.cors.enabled: true
http.cors.allow-origin: "*"

# 关闭http访问限制
xpack.security.enabled: false
xpack.security.enrollment.enabled: true

node-2的配置:

# 换个集群的名字,免得跟别人的集群混在一起
cluster.name: el-my

# 换个节点名字
node.name: node-1002

# 修改一下ES的监听地址,这样别的机器也可以访问
network.host: 0.0.0.0
http.host: 0.0.0.0

#设置对外服务的http端口,默认为9200
http.port: 9202
transport.port: 9302
discovery.seed_hosts: ["127.0.0.1:9301", "127.0.0.1:9302", "127.0.0.1:9303"]
cluster.initial_master_nodes: ["node-1001","node-1002","node-1003"]

# 允许通配符删除索引
action.destructive_requires_name: true

#设置索引数据的存储路径
path.data: M:/elasticsearch-8.5.3.0/node-1002/data/data    #换成自己的路径
#设置日志文件的存储路径
path.logs: M:/elasticsearch-8.5.3.0/node-1002/data/logs    #换成自己的路径

# 增加新的参数,head插件可以访问es
http.cors.enabled: true
http.cors.allow-origin: "*"

# 关闭http访问限制
xpack.security.enabled: false
xpack.security.enrollment.enabled: true

node-3的配置:

# 换个集群的名字,免得跟别人的集群混在一起
cluster.name: el-my

# 换个节点名字
node.name: node-1003

# 修改一下ES的监听地址,这样别的机器也可以访问
network.host: 0.0.0.0
http.host: 0.0.0.0

#设置对外服务的http端口,默认为9200
http.port: 9203
transport.port: 9303
discovery.seed_hosts: ["127.0.0.1:9301", "127.0.0.1:9302", "127.0.0.1:9303"]
cluster.initial_master_nodes: ["node-1001","node-1002","node-1003"]

# 允许通配符删除索引
action.destructive_requires_name: true

#设置索引数据的存储路径
path.data: M:/elasticsearch-8.5.3.0/node-1003/data/data    #换成自己的路径
#设置日志文件的存储路径
path.logs: M:/elasticsearch-8.5.3.0/node-1003/data/logs    #换成自己的路径

# 增加新的参数,head插件可以访问es
http.cors.enabled: true
http.cors.allow-origin: "*"

# 关闭http访问限制
xpack.security.enabled: false
xpack.security.enrollment.enabled: true

在这里插入图片描述

3、kibana的配置

config下kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://127.0.0.1:9201", "http://127.0.0.1:9202", "http://127.0.0.1:9203"]
i18n.locale: "zh-CN"

4、logstach的配置

input {
    stdin {
    }
    jdbc {
	#数据库四大金刚配置
	jdbc_connection_string => "jdbc:mysql://127.0.0.0:3306/test?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true"
        jdbc_user => "root"
        jdbc_password => "123456"
	#数据库驱动路径
        jdbc_driver_library => "M:/mysql/mysql-connector-java/8.0.30/mysql-connector-java-8.0.30.jar"
        jdbc_driver_class => "com.mysql.cj.jdbc.Driver"       
        jdbc_paging_enabled => "true"         
        jdbc_page_size => "50000"
	#这里可以指定sql文件或直接写SQL语句
        statement => "SELECT * FROM user"
        #定义每分钟去刷新数据库数据
	schedule => "* * * * *"
	type => "context"
    }
 }

filter {
    
}
 output {
    elasticsearch {
		#输出至ES的端口
        hosts => ["http://127.0.0.1:9201", "http://127.0.0.1:9202", "http://127.0.0.1:9203"]
		#输出至ES的索引
        index => "aaa-*"
		#设置_id自增
        document_id => "%{id}"
    }
    stdout {
        codec => json_lines
    }
}

springboot集成ES8,请看上文,其他都一样;

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Spring Boot 1.x集成Elasticsearch(ES)可以通过使用Spring Data Elasticsearch来实现。Spring Data ElasticsearchSpring Data项目的一部分,它提供了与Elasticsearch集成,简化了与ES的交互。 以下是Spring Boot 1.x集成ES的步骤: 1. 添加依赖:在`pom.xml`文件中添加Spring Data Elasticsearch的依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> </dependency> ``` 2. 配置连接信息:在`application.properties`或`application.yml`文件中配置ES的连接信息,包括主机、端口等: ```properties spring.data.elasticsearch.cluster-nodes=localhost:9200 ``` 3. 创建实体类:创建与ES索引对应的实体类,并使用注解标记字段与索引的映射关系。例如: ```java @Document(indexName = "my_index", type = "my_type") public class MyEntity { @Id private String id; @Field(type = FieldType.Text) private String name; // 其他字段... // getter和setter方法... } ``` 4. 创建Repository接口:创建继承自`ElasticsearchRepository`的接口,用于对ES进行CRUD操作。例如: ```java public interface MyEntityRepository extends ElasticsearchRepository<MyEntity, String> { // 自定义查询方法... } ``` 5. 使用Repository进行操作:在需要使用ES的地方注入`MyEntityRepository`,即可使用其提供的方法进行数据操作。例如: ```java @Autowired private MyEntityRepository myEntityRepository; public void saveEntity(MyEntity entity) { myEntityRepository.save(entity); } public MyEntity findById(String id) { return myEntityRepository.findById(id).orElse(null); } // 其他操作方法... ``` 以上是Spring Boot 1.x集成ES的基本步骤,你可以根据实际需求进行进一步的操作和配置。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值