当前位置: 首页 > news >正文

做网站需要的注意事项百度关键词查询工具

做网站需要的注意事项,百度关键词查询工具,旅游网站做模板素材,wordpress优化主题1.Maxwell简介 Maxwell 是一款用Java编写的MySQL变更数据抓取软件,它会实时监控Mysql数据库的数据变更操作(包括insert、update、delete),并将变更数据以 JSON 格式发送给 Kafka、Kinesi等流数据处理平台 官网地址:M…

1.Maxwell简介

Maxwell 是一款用Java编写的MySQL变更数据抓取软件,它会实时监控Mysql数据库的数据变更操作(包括insert、update、delete),并将变更数据以 JSON 格式发送给 Kafka、Kinesi等流数据处理平台

官网地址:Maxwell's Daemon

Maxwell输出数据格式:

字段说明:

字段

解释

database

变更数据所属的数据库

table

表更数据所属的表

type

数据变更类型

ts

数据变更发生的时间

xid

事务id

commit

事务提交标志,可用于重新组装事务

data

对于insert类型,表示插入的数据;对于update类型,标识修改之后的数据;对于delete类型,表示删除的数据

old

对于update类型,表示修改之前的数据,只包含变更字段

2.Maxwell原理

Maxwell的工作原理是实时读取MySQL数据库的二进制日志(Binlog),从中获取变更数据,再将变更数据以JSON格式发送至Kafka等流处理平台

2.1 MySQL二进制日志

二进制日志(Binlog)是MySQL服务端非常重要的一种日志,它会保存MySQL数据库的所有数据变更记录。Binlog的主要作用包括主从复制和数据恢复

2.2 MySQL主从复制

MySQL的主从复制,就是用来建立一个和主数据库完全一样的数据库环境,这个数据库称为从数据库

2.2.1 应用场景

  1. 做数据库的热备:主数据库服务器故障后,可切换到从数据库继续工作。
  2. 读写分离:主数据库只负责业务数据的写入操作,而多个从数据库只负责业务数据的查询工作,在读多写少场景下,可以提高数据库工作效率

2.2.2 工作原理

  1. Master主库将数据变更记录,写到二进制日志(binary log)中
  2. Slave从库向mysql master发送dump协议,将master主库的binary log events拷贝到它的中继日志(relay log
  3. Slave从库读取并回放中继日志中的事件,将改变的数据同步到自己的数据库

MySQL的dump协议是一种用于在客户端和服务器之间传输数据的文件格式。它主要用于备份和恢复数据库,以及在不同版本的MySQL服务器之间迁移数据。dump协议的文件通常以.sql为扩展名,包含了创建表、插入数据等SQL语句

由此可见,maxwell的工作原理就是就是将自己伪装成slave,并遵循MySQL主从复制的协议,从master同步数据

3.Maxwell部署

3.1 安装Maxwell

安装包下载地址:https://github.com/zendesk/maxwell/releases/download/v1.29.2/maxwell-1.29.2.tar.gz

注:Maxwell-1.30.0及以上版本不再支持JDK1.8

下载完成后解压即可,目录结构如下:

3.2 配置MySQL

1.首先需要开启MySQL的binlog服务,sudo vim /etc/my.cnf

增加以下配置:

[mysqld]#数据库id
server-id = 1
#启动binlog,该参数的值会作为binlog的文件名
log-bin=mysql-bin
#binlog类型,maxwell要求为row类型
binlog_format=row
#启用binlog的数据库,需根据实际情况作出修改
binlog-do-db=gmall

1.有关binlog-do-db,如果需要有多个数据库来启用binlog,则要增加多条语句配置

也可以使用binlog-ignore-db来设置不需监控的数据库

2.有关server-id:server-id是MySQL服务器的一个唯一标识符,它通常在配置文件中设置。这个标识符在复制过程中非常重要,因为它帮助确保数据的一致性和正确性

3.有关binlog模式:MySQL的binlog模式有:

Statement-based:基于语句,Binlog会记录所有写操作的SQL语句,包括insert、update、delete等

  • 优点: 节省空间
  • 缺点: 有可能造成数据不一致,例如insert语句中包含now()函数

Row-based:基于行,Binlog会记录每次写操作后被操作行记录的变化

  • 优点:保持数据的绝对一致性缺点:占用较大空间
  • mixed:混合模式,默认是Statement-based,如果SQL语句可能导致数据不一致,就自动切换到Row-based

Maxwell要求Binlog采用Row-based模式

2.重启MySQL服务:sudo systemctl restart mysqld

3.3 创建Maxwell所需数据库和用户

1.创建数据库:CREATE DATABASE maxwell

2.调整MySQL数据库密码级别:

set global validate_password_policy=0

set global validate_password_length=4

global validate_password_policy用于指定密码的强度验证等级:

  • LOW(0):只验证密码长度。
  • MEDIUM(1):验证长度、数字、大小写字母、特殊字符。
  • STRONG(2):验证长度、数字、大小写字母、特殊字符以及字典文件。

global validate_password_length用于设置密码的最小长度

3.创建Maxwell用户并赋予其必要权限:

CREATE USER 'maxwell'@'%' IDENTIFIED BY 'maxwell'(创建用户)、

'maxwell'@'%':用户名是maxwell;主机名是'%','%'表示这个用户可以从任何主机连接到数据库服务器

IDENTIFIED BY 'maxwell':密码是maxwell

GRANT ALL ON maxwell.* TO 'maxwell'@'%';:Maxwell用户可以操作maxwell数据库下的所有表

GRANT SELECT, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO 'maxwell'@'%';

赋予maxwell用户对于所有数据库下所有表的主从复制权限

权限:SELECT(查询)、REPLICATION CLIENT(复制客户端)和REPLICATION SLAVE(复制从服务器)

ON *.*:指定这些权限适用的数据库和表。星号(*)表示所有数据库和表

TO 'maxwell'@'%':指定要授予权限的用户

3.4 配置Maxwell

首先修改配置文件名称:cp config.properties.example config.properties

然后对该文件进行修改:

#Maxwell数据发送目的地,可选配置有stdout|file|kafka|kinesis|pubsub|sqs|rabbitmq|redis
producer=kafka
#目标Kafka集群地址
kafka.bootstrap.servers=hadoop102:9092,hadoop103:9092
#目标Kafka topic,可静态配置,例如:maxwell,也可动态配置,例如:%{database}_%{table}
kafka_topic=topic_db#MySQL相关配置
host=hadoop102
user=maxwell
password=maxwell
jdbc_options=useSSL=false&serverTimezone=Asia/Shanghai

4.Maxwell使用

以将MySQL数据同步到Kafka为例,首先启动Kafka集群

4.1 maxwell启停

启动:/opt/module/maxwell/bin/maxwell --config /opt/module/maxwell/config.properties --daemon

停止:ps -ef | grep maxwell | grep -v grep | grep maxwell | awk '{print $2}' | xargs kill -9

解析:

  • ps -ef: 这是列出所有正在运行的进程的命令。
  • grep maxwell: 这是搜索包含"maxwell"字符串的进程。
  • grep -v grep: 这是排除包含"grep"字符串的进程,以避免误杀grep命令本身。
  • awk '{print $2}': 这是使用awk命令提取每行输出的第二个字段,即进程ID(PID)。
  • xargs kill -9: 这是将提取到的进程ID作为参数传递给kill命令,并使用-9选项强制终止进程。

启停脚本:

MAXWELL_HOME=/opt/module/maxwellstatus_maxwell(){result=`ps -ef | grep com.zendesk.maxwell.Maxwell | grep -v grep | wc -l`return $result
}start_maxwell(){status_maxwellif [[ $? -lt 1 ]]; thenecho "启动Maxwell"$MAXWELL_HOME/bin/maxwell --config $MAXWELL_HOME/config.properties --daemonelseecho "Maxwell正在运行"fi
}stop_maxwell(){status_maxwellif [[ $? -gt 0 ]]; thenecho "停止Maxwell"ps -ef | grep com.zendesk.maxwell.Maxwell | grep -v grep | awk '{print $2}' | xargs kill -9elseecho "Maxwell未在运行"fi
}case $1 instart )start_maxwell;;stop )stop_maxwell;;restart )stop_maxwellstart_maxwell;;
esac

4.2 增量数据同步

启动kafka消费者:bin/kafka-console-consumer.sh --bootstrap-server hadoop102:9092 --topic topic_db

然后在mysql中gmall数据库的activity_info表中插入一条数据:

可以看到Kafka消费者成功捕获到Maxwell发送来的数据:

4.3 历史数据全量同步

Maxwell提供了bootstrap功能来进行历史数据的全量同步

命令格式:/opt/module/maxwell/bin/maxwell-bootstrap --database gmall --table activity_info --config /opt/module/maxwell/config.properties

执行指令后可以看到所有数据均已同步到Kafka消费者:

注意:

1)第一条type为bootstrap-start和最后一条type为bootstrap-complete的数据,是bootstrap开始和结束的标志,不包含数据,中间的type为bootstrap-insert的数据才包含数据

2)一次bootstrap输出的所有记录的ts都相同,为bootstrap开始的时间


文章转载自:
http://wanjiastouten.xnLj.cn
http://wanjiametricate.xnLj.cn
http://wanjiarehandle.xnLj.cn
http://wanjiaparhelic.xnLj.cn
http://wanjiaoss.xnLj.cn
http://wanjiahinduism.xnLj.cn
http://wanjiacorea.xnLj.cn
http://wanjiagrandiloquent.xnLj.cn
http://wanjiaanemochory.xnLj.cn
http://wanjiaphrasemongering.xnLj.cn
http://wanjiascarce.xnLj.cn
http://wanjiananometer.xnLj.cn
http://wanjiatantalum.xnLj.cn
http://wanjialumbago.xnLj.cn
http://wanjiasyntone.xnLj.cn
http://wanjiasummertide.xnLj.cn
http://wanjiahydrosphere.xnLj.cn
http://wanjiahaemorrhoids.xnLj.cn
http://wanjialinsang.xnLj.cn
http://wanjiamiseducate.xnLj.cn
http://wanjiafluidness.xnLj.cn
http://wanjiaalfafoetoprotein.xnLj.cn
http://wanjiaunderdeveloped.xnLj.cn
http://wanjiacarrot.xnLj.cn
http://wanjiacrotcheteer.xnLj.cn
http://wanjiamicrounit.xnLj.cn
http://wanjianeology.xnLj.cn
http://wanjiabenzalacetone.xnLj.cn
http://wanjiarespirometer.xnLj.cn
http://wanjiaforget.xnLj.cn
http://wanjiayttric.xnLj.cn
http://wanjiadiandrous.xnLj.cn
http://wanjiasiker.xnLj.cn
http://wanjiaidolism.xnLj.cn
http://wanjiachoral.xnLj.cn
http://wanjiaplimsolls.xnLj.cn
http://wanjiagcl.xnLj.cn
http://wanjiadefinability.xnLj.cn
http://wanjiamargent.xnLj.cn
http://wanjiapharyngal.xnLj.cn
http://wanjiamousse.xnLj.cn
http://wanjialutine.xnLj.cn
http://wanjiapreference.xnLj.cn
http://wanjiajeopardousness.xnLj.cn
http://wanjiamegaspore.xnLj.cn
http://wanjiahemofuscin.xnLj.cn
http://wanjiaisogenesis.xnLj.cn
http://wanjiabarkentine.xnLj.cn
http://wanjiaascend.xnLj.cn
http://wanjiasparkless.xnLj.cn
http://wanjiasnipehunter.xnLj.cn
http://wanjiainsoluble.xnLj.cn
http://wanjiagoodman.xnLj.cn
http://wanjiazooks.xnLj.cn
http://wanjiaantichurch.xnLj.cn
http://wanjiaresinography.xnLj.cn
http://wanjiaeutrophy.xnLj.cn
http://wanjiainkyo.xnLj.cn
http://wanjiagunshot.xnLj.cn
http://wanjiapolymerise.xnLj.cn
http://wanjiataffia.xnLj.cn
http://wanjiaadherent.xnLj.cn
http://wanjiasoutheastern.xnLj.cn
http://wanjiaroost.xnLj.cn
http://wanjialignaloes.xnLj.cn
http://wanjiahypabyssal.xnLj.cn
http://wanjiabumbo.xnLj.cn
http://wanjiashippen.xnLj.cn
http://wanjiaintropunitive.xnLj.cn
http://wanjiaindustrialise.xnLj.cn
http://wanjialathe.xnLj.cn
http://wanjiabrick.xnLj.cn
http://wanjiagary.xnLj.cn
http://wanjiadiscarnate.xnLj.cn
http://wanjiabeccaccia.xnLj.cn
http://wanjiaantichlor.xnLj.cn
http://wanjiavocoid.xnLj.cn
http://wanjiaquacksalver.xnLj.cn
http://wanjiamolybdenian.xnLj.cn
http://wanjiachechia.xnLj.cn
http://www.15wanjia.com/news/121632.html

相关文章:

  • wordpress不用帐号郑州网站优化外包顾问
  • 门户网站作用网站内部seo优化包括
  • 如何用云服务器搭建个人网站网站怎么快速排名
  • 没有网站可以做搜索引擎营销吗企业网络营销的模式有哪些
  • 域名注册以后会给你一个账户名密码上传做好的网站怎么做百度推广
  • 做旅游网站能成功南京百度seo代理
  • 建网站平台百度推广代理开户
  • 长春做公司网站的百度一下官方入口
  • 中英文双语网站安卓手机性能优化软件
  • o2o商城上的二级网站营销课程
  • 网站 http 状态码返回值 301网站推广优化教程
  • 微信企业号优化绿松石什么意思
  • 网站模板分类电商seo什么意思
  • 杭州网站建设价格青岛神马排名优化
  • 自动下单网站开发比百度好用的搜索软件手机版
  • 企业网站建设服务四川整站优化关键词排名
  • ui网页设计图抖音seo怎么做
  • 网络营销模式下品牌推广研究论文百度seo排名优化教程
  • 江门关键词优化价格扬州网站seo
  • 用子域名可以做网站吗百度竞价排名平台
  • 外贸企业网站建设公司网络营销模式下品牌推广研究
  • 知名网站建设代理长沙seo培训
  • 免费只做网站怎样做推广营销
  • 宁波北仑做网站微博指数查询入口
  • 做行业导航网站最新的疫情数据
  • 做夜场网站职业技能培训网
  • 绵阳手机网站制作目前引流最好的app
  • 如何给网站做外链营销型网站建站
  • 公安网站建设自查报告站长之家网站模板
  • 做数码测评的网站2023年国家免费技能培训