赞
踩
ES7 依赖 jdk11
- 镜像地址
-
- https://mirrors.tuna.tsinghua.edu.cn/Adoptium/
-
- https://mirrors.tuna.tsinghua.edu.cn/Adoptium/11/jdk/x64/linux/
- https://www.elastic.co/cn/downloads/past-releases/elasticsearch-no-jdk-7-17-16
-
- 不需要自带JDK 版本,因为要安装openJDK 11来支持
- 修改说明:
-
- https://blog.csdn.net/weixin_46085718/article/details/130302400
-
- https://blog.csdn.net/qq_45939223/article/details/126622699
-
-
- vim elasticsearch.yml
-
- cluster.name: my-es
- node.name: node-1
- path.data: /data/midware/es/es_kibana/elasticsearch-7.17.16/data
- path.logs: /data/midware/es/es_kibana/elasticsearch-7.17.16/logs
- network.host: 0.0.0.0
- http.port: 9200
- transport.tcp.port: 9300
- discovery.seed_hosts: ["127.0.0.1:9200"]
- cluster.initial_master_nodes: ["node-1"]
-
- http.cors.enabled: true
- http.cors.allow-origin: /.*/
-
-
- vim jvm.options
-
- -Xms512m
- -Xmx512m
- pwd
- /data/midware/es/es_kibana/elasticsearch-7.17.16/bin
- vi elasticsearch-env
- 添加:
- JAVA=/data/midware/es/jdk/jdk-11.0.21+9/bin/java
- useradd es
- passwd es
- pwd
- /data/midware/es/es_kibana/elasticsearch-7.17.16/bin
- 切换用户
- su es
- # Starts Elasticsearch in the background 后台启动
- ./elasticsearch -d
- ps-ef|grep elasticsearch
- kill -9 pid
- 3] bootstrap checks failed. You must address the points described in the following [3] lines before starting Elasticsearch.
- bootstrap check failure [1] of [3]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
- bootstrap check failure [2] of [3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
- bootstrap check failure [3] of [3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
- su root
- sudo vi /etc/security/limits.conf
- es soft nofile 65536
- es hard nofile 65536
-
- sudo vi /etc/security/limits.d/20-nproc.conf
- es soft nofile 65536
- es hard nofile 65536
-
- sysctl -p # 配置生效
- exist 退出当前用户 [退出,再进去,则可以正常读取配置]
- su es
- http://192.168.5.180:9200/?pretty
-
- {
- "name" : "hismk-1",
- "cluster_name" : "hismk-backend",
- "cluster_uuid" : "hMPu08v6QguP0Wc59Pr8pQ",
- "version" : {
- "number" : "7.17.16",
- "build_flavor" : "default",
- "build_type" : "tar",
- "build_hash" : "2b23fa076334f8d4651aeebe458a955a2ae23218",
- "build_date" : "2023-12-08T10:06:54.672540567Z",
- "build_snapshot" : false,
- "lucene_version" : "8.11.1",
- "minimum_wire_compatibility_version" : "6.8.0",
- "minimum_index_compatibility_version" : "6.0.0-beta1"
- },
- "tagline" : "You Know, for Search"
- }
- # 下载
- wget https://artifacts.elastic.co/downloads/kibana/kibana-7.17.16-linux-x86_64.tar.gz
-
- pwd
- /data/midware/es/es_kibana/kibana-7.17.16
- vi config/kibana.yml
-
- #修改端口
- server.port: 5601
- #对外暴露服务的地址
- server.host: "0.0.0.0"
- #配置Elasticsearch所在的IP地址
- elasticsearch.hosts: ["http://127.0.0.1:9200"]
-
-
- #安装成功并访问
-
- http://192.168.5.180:5601/app/dev_tools#/console
- https://github.com/medcl/elasticsearch-analysis-ik
-
- release 版本 V7.17.16
-
- https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.17.16/elasticsearch-analysis-ik-7.17.16.zip
-
-
- 将下载的安装包在es安装目录下的plugins下新建一个ik文件夹、将文件解压。
-
- pwd
- /data/midware/es/es_kibana/elasticsearch-7.17.16/plugins
- unzip elasticsearch-analysis-ik-7.17.16.zip -d ik # 指定解压目录
- GET /_analyze
- {
- "analyzer":"ik_max_word",
- "text":"曾舒琪董事长早上好收到刚发的world"
- }
- GET /_analyze
- {
- "analyzer":"ik_smart",
- "text":"曾舒琪董事长早上好"
- }
在kabana中查看
canal官网下载
https://github.com/alibaba/canal/releases
本次集成,只关注 canal.deployer-1.1.7
- pwd
- /data/midware/es/canal/canal_deployer
- tar -zxvf canal.deployer-1.1.7.tar.gz -C canal_deployer
- # 拷贝example配置
- pwd
- /data/midware/es/canal/canal_deployer/conf
- /data/midware/es/canal/canal_deployer/conf/example
- cp -R example es # 拷贝文件夹配置
-
- # 调整es配置
- pwd
- /data/midware/es/canal/canal_deployer/conf/es
- cd es
- vim instance.properties
-
- # position info
- # 源数据库地址及端口
- canal.instance.master.address=192.168.244.17:3306
- # 开始同步的binlog日志文件,注意这里的binlog文件名以你自己查出来的为准
- canal.instance.master.journal.name=mysql-bin.000001
- # 开始同步的binlog文件位置
- canal.instance.master.position=0
- # 开始同步时间点 时间戳形式
- # https://xsgongju.com/xsgongju/timestamp 时间戳转换
- # 2019-01-01 00:00:00
- canal.instance.master.timestamp=1546272000000
-
- # 数据库账号密码
- canal.instance.dbUsername=canal
- canal.instance.dbPassword=canal
-
- # 配置不同步mysql库
- # 白名单 某数据库下所有表
- canal.instance.filter.regex=xxxxDB\\..*
- # 黑名单 mysql 数据不允许同步
- canal.instance.filter.black.regex=mysql\..*
- mysql 数据解析关注的表,Perl正则
- 表达式.
- 多个正则之间以逗号(,)分隔,转义
- 符需要双斜杠(W
- 常见例子:
- 1.所有表: .* or ...*
- canal.instance.filter.regex
- 2.canal schema下所有表:
- canall.*
- 3.canal下的以canal打头的表:
- canalll.canal.*
- 4.canal schema下的一张表:
- canal.test1
- 5.多个规则组合使用:
- canalll..*,mysgl.test1,mysql.test2 (逗号分隔)
- - canal.instance.master.journal.name + canal.instance.master.position : 精确指定一个 binlog 位点,进行启动
- - canal.instance.master.timestamp : 指定一个时间戳,canal 会自动遍历 MySQL binlog,找到对应时间戳的 binlog 位点后,进行启动
- - 不指定任何信息:默认从当前数据库的位点,进行启动。(show master status)
- 1、mysql show binlog events命令的格式
- show binlog events [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count];
- 说明:
- (1)IN ‘log_name’:指定要查询的binlog文件名(如果省略此参数,则默认指定第一个binlog文件);
- (2)FROM pos:指定从哪个pos起始点开始查起(如果省略此参数,则从整个文件的第一个pos点开始算);
- (3)LIMIT【offset】:偏移量(默认为0);
- (4)row_count:查询总条数(如果省略,则显示所有行)。
- 1.1、查看binlog文件信息
- show binary logs; # 查看所有的binlog
- show master logs; # 查看当前master的log信息
-
- 1.2、查询第一个binlog日志
- show binlog events;
- 1.3查询第二个binlog日志
- show binlog events in 'mysql-bin.000002';
- 1.4、查询mysql-bin.000002文件,从pos点417开始查询
- show binlog events in 'mysql-bin.000002' from 417;
- 1.5、查询mysql-bin.000002文件,从pos点219开始查询,查询5条记录
- show binlog events in 'mysql-bin.000002' from 219 limit 5;
- 1.6、查询mysql-bin.000002文件,从pos点219开始查询,查询5条记录,偏移2行
- show binlog events in 'mysql-bin.000002' from 219 limit 2,5;
-
- binlog管理事件 (默认是Row模式--SHOW VARIABLES LIKE '%binlog_format%';)
- 2、Row模式下的事件说明
- show binlog events in '/var/lib/mysql/binlog.000005';
- show binlog events;
-
- 说明:
- (1)每个binlog文件总是以Format Description Event作为开始,以Rotate Event(Stop Event)作为结束。在开始和结束之间,穿插着其他各种事件。
- (2)TABLE_MAP EVENT:其作用是记录INSERT、DELETE、UPDATE操作的表结构。
- (3)Write_rows:插入记录。
- (4)Update_rows:更新记录。
- (5)Rotate Event:表示日志文件的结束。
客户端采用springboot 项目集成:
JPA : 数据字段映射
easy-es-springboot-demo: springboot集成easy-es使用demo
多表同步集成
canal_client_es: 自定义canal客户端,实现mysql多表同步elasticsearch
application.yml配置
- easy-es:
- address: 192.168.5.180:49200
- canal:
- server: 192.168.5.180:11111
- destination: es
- logging:
- level:
- top.javatool.canal.client: info
- org.springframework.data.convert.CustomConversions: info
目录结构
- ├─src
- │ ├─main
- │ │ ├─java
- │ │ │ └─com
- │ │ │ └─example
- │ │ │ └─eeuse
- │ │ │ │ EeUseApplication.java
- │ │ │ │
- │ │ │ ├─controller
- │ │ │ │ TestUseEeController.java
- │ │ │ │
- │ │ │ ├─domain
- │ │ │ │ ├─doc
- │ │ │ │ │ Activity.java
- │ │ │ │ │ Document.java
- │ │ │ │ │
- │ │ │ │ ├─entity
- │ │ │ │ │ ActivityPO.java
- │ │ │ │ │
- │ │ │ │ └─mapping
- │ │ │ │ ActivityMapping.java
- │ │ │ │
- │ │ │ ├─eemapper
- │ │ │ │ ActivityMapper.java
- │ │ │ │ DocumentMapper.java
- │ │ │ │
- │ │ │ └─handler
- │ │ │ ActivityHandler.java
- │ │ │
- │ │ └─resources
- │ │ application.yml
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.7.13</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>com.example</groupId>
- <artifactId>ee-use</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <name>ee-use</name>
- <description>Demo project for Spring Boot</description>
- <properties>
- <java.version>1.8</java.version>
- <canal-starter.version>1.2.1-RELEASE</canal-starter.version>
- <hutool.version>5.8.23</hutool.version>
- <mapstruct.version>1.4.2.Final</mapstruct.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.elasticsearch.client</groupId>
- <artifactId>elasticsearch-rest-high-level-client</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.elasticsearch.client</groupId>
- <artifactId>elasticsearch-rest-client</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.elasticsearch</groupId>
- <artifactId>elasticsearch</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.elasticsearch.client</groupId>
- <artifactId>elasticsearch-rest-high-level-client</artifactId>
- <version>7.14.0</version>
- </dependency>
- <dependency>
- <groupId>org.elasticsearch.client</groupId>
- <artifactId>elasticsearch-rest-client</artifactId>
- <version>7.14.0</version>
- </dependency>
- <dependency>
- <groupId>org.elasticsearch</groupId>
- <artifactId>elasticsearch</artifactId>
- <version>7.14.0</version>
- </dependency>
-
- <dependency>
- <groupId>org.dromara.easy-es</groupId>
- <artifactId>easy-es-boot-starter</artifactId>
- <version>2.0.0-beta4</version>
- </dependency>
-
- <!-- 2019-07-03 https://mvnrepository.com/artifact/top.javatool/canal-client -->
- <dependency>
- <groupId>top.javatool</groupId>
- <artifactId>canal-spring-boot-starter</artifactId>
- <version>${canal-starter.version}</version>
- </dependency>
-
- <dependency>
- <groupId>cn.hutool</groupId>
- <artifactId>hutool-all</artifactId>
- <version>${hutool.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.mapstruct</groupId>
- <artifactId>mapstruct</artifactId>
- <version>${mapstruct.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.mapstruct</groupId>
- <artifactId>mapstruct-processor</artifactId>
- <version>${mapstruct.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <finalName>${project.artifactId}</finalName>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>repackage</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- </project>
3.4、容易出现的问题
监听数据同步字段映射的实体,需要使用JPA的注解,否则字段无法进行映射和赋值,另外数据同步的ActivityHandler,很容易出现字段映射类型转换问题: 比如 mysql int 字段为空,同步binlog 报错, 空字符串无法转为int类型。
- import lombok.Data;
-
- import javax.persistence.Column;
- import javax.persistence.Table;
- import java.io.Serializable;
- import java.util.Date;
-
-
- @Data
- @Table(name = "activity_t")
- public class ActivityPO implements Serializable {
-
- @Column(name = "activity_id")
- private Long activityId;
-
- /**
- * 活动名称
- */
- @Column(name = "activity_name")
- private String activityName;
-
- /**
- * 活动描述
- */
- @Column(name = "activity_desc")
- private String activityDesc;
-
- /**
- * 活动地址
- */
- @Column(name = "image_url")
- private String imageUrl;
-
-
- }
- # 多表同步mysql 数据到 ES对应的索引
-
- https://zhuanlan.zhihu.com/p/649400398
选择canal的原因: 实时,增量同步。
数据同步,方案有很多,我们可以选择适合自己的。 canal、DataX等。了解自己同步的目的。
比如当前的mysql数据库不能满足分词检索功能,我们就需要把数据同步到ES,进行数据检索,提升系统性能,缺点就是 安装ES,Kabana,IK 繁琐。(可以采用docker安装)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。