濮阳杆衣贸易有限公司

主頁 > 知識庫 > 如何使用Maxwell實(shí)時(shí)同步mysql數(shù)據(jù)

如何使用Maxwell實(shí)時(shí)同步mysql數(shù)據(jù)

熱門標(biāo)簽:大豐地圖標(biāo)注app 400電話變更申請 催天下外呼系統(tǒng) 武漢電銷機(jī)器人電話 北京金倫外呼系統(tǒng) 南太平洋地圖標(biāo)注 400電話辦理服務(wù)價(jià)格最實(shí)惠 html地圖標(biāo)注并導(dǎo)航 呂梁外呼系統(tǒng)

Maxwell簡介

maxwell是由java編寫的守護(hù)進(jìn)程,可以實(shí)時(shí)讀取mysql binlog并將行更新以JSON格式寫入kafka、rabbitMq、redis等中,  這樣有了mysql增量數(shù)據(jù)流,使用場景就很多了,比如:實(shí)時(shí)同步數(shù)據(jù)到緩存,同步數(shù)據(jù)到ElasticSearch,數(shù)據(jù)遷移等等。

maxwell官網(wǎng):http://maxwells-daemon.io
 maxwell源代碼:https://github.com/zendesk/maxwell

Maxwell的配置與使用

maxwell 依賴java sdk,所以需要先配置JDK環(huán)境。

1.下載Maxwell安裝包

root@xxx maxwell]# pwd
/usr/local/maxwell
[root@xxx maxwell]# wget https://github.com/zendesk/maxwell/releases/download/v1.19.5/maxwell-1.19.5.tar.gz
[root@xxx maxwell]# tar zxvf maxwell-1.19.5.tar.gz 
[root@xxx maxwell]# cd maxwell-1.19.5

2.配置mysql,打開mysql binlog日志

[root@xxx mysql]# vi /usr/local/mysql/my.cnf 

[mysqld]
log-bin=mysql-bin #添加這一行就
binlog-format=ROW #選擇row模式
server_id=1 #隨機(jī)指定一個(gè)不能和其他集群中機(jī)器重名的字符串,如果只有一臺機(jī)器,那就可以隨便指定了

重啟mysql服務(wù),登陸mysql,查看binlog日志模式

mysql> show variables like '%log_bin%'
+---------------------------------+-------------------------------+
| Variable_name                   | Value                         |
+---------------------------------+-------------------------------+
| log_bin                         | ON                            |
| log_bin_basename                | /data/mysqldb/mysql-bin       |
| log_bin_index                   | /data/mysqldb/mysql-bin.index |
| log_bin_trust_function_creators | OFF                           |
| log_bin_use_v1_row_events       | OFF                           |
| sql_log_bin                     | ON                            |
+---------------------------------+-------------------------------+
6 rows in set (0.11 sec)

Maxwell需要在schema_database選項(xiàng)指定的數(shù)據(jù)庫中存儲(chǔ)狀態(tài)的權(quán)限(默認(rèn)庫名稱為maxwell),所以需要提前給權(quán)限:

#創(chuàng)建一個(gè)有同步數(shù)據(jù)的用戶yhrepl
mysql> create user 'yhrepl'@'*' identified by 'scgaopan'; 
Query OK, 0 rows affected (0.10 sec)

#此用戶yhrepl要有對需要同步的數(shù)據(jù)庫表有操作權(quán)限
mysql> grant all privileges on test.* to 'yhrepl'@'%' identified by 'scgaopan'; 
Query OK, 0 rows affected (0.13 sec)

#給yhrepl有同步數(shù)據(jù)的權(quán)限
mysql> grant select,replication client,replication slave on *.* to 'yhrepl'@'%' identified by 'scgaopan';
Query OK, 0 rows affected (0.10 sec)
# Maxwell需要在schema_database選項(xiàng)指定的數(shù)據(jù)庫中存儲(chǔ)狀態(tài)的權(quán)限(默認(rèn)庫名稱為maxwell)
mysql> grant all privileges on maxwell.* to 'yhrepl'@'%' identified by 'scgaopan';
Query OK, 0 rows affected (0.09 sec)

3.啟動(dòng)Maxwell,主要介紹數(shù)據(jù)寫入rabbitmq的實(shí)戰(zhàn):

[root@xxx maxwell-1.19.5]# vi /usr/local/maxwell/maxwell-1.19.5/config.properties
#日志級別
log_level=DEBUG

producer=rabbitmq
daemon=true

#監(jiān)控的數(shù)據(jù)庫, mysql用戶必須擁有讀取binlog權(quán)限和新建庫表的權(quán)限
host=47.105.110.xxx
user=yhrepl
password=scgaopan

output_nulls=true
jdbc_options=autoReconnet=true

#監(jiān)控?cái)?shù)據(jù)庫中的哪些表
filter=exclude: *.*,include: test.AA

#replica_server_id 和 client_id 唯一標(biāo)示,用于集群部署
replica_server_id=64
client_id=test-id

#metrics_type=http
#metrics_slf4j_interval=60
#http_port=8111
#http_diagnostic=true # default false

#rabbitmq
rabbitmq_host=47.105.110.xxx
rabbitmq_port=5672
rabbitmq_user=guest
rabbitmq_pass=guest
rabbitmq_virtual_host=/
rabbitmq_exchange=maxwell
rabbitmq_exchange_type=topic
rabbitmq_exchange_durable=false
rabbitmq_exchange_autodelete=false
rabbitmq_routing_key_template=%db%.%table%
rabbitmq_message_persistent=false
rabbitmq_declare_exchange=true

啟動(dòng)Maxwell:

[root@xxx maxwell-1.19.5]# ./bin/maxwell
#可以后臺啟動(dòng)
[root@xxx maxwell-1.19.5]# nohub ./bin/maxwell 

啟動(dòng)成功,此時(shí)會(huì)自動(dòng)生成maxwell庫,該庫記錄了maxwell同步的狀態(tài),最后一次同步的id等等信息,在主庫失敗或同步異常后,只要maxwell庫存在,下次同步會(huì)根據(jù)最后一次同步的id。如果沒有生成maxwell庫或報(bào)錯(cuò),可能config.properties中配置的mysql用戶權(quán)限不夠

rabbitmq的操作

rabbitmq的操作,啟動(dòng)maxwell后就有一個(gè)maxwell的exchage生成

但對應(yīng)的queue和exchange和queue的綁定需要用戶自己去實(shí)現(xiàn)

新建一個(gè)maxwell-test的queue:

把queue與exchange進(jìn)行綁定:

注意,這里的Routing key 是區(qū)分大小寫的

在數(shù)據(jù)庫中修改一條記錄,可以看到maxwell-test隊(duì)列里面有一第記錄了。

全量同步

使用maxwell-bootstrap命令

./bin/maxwell-bootstrap --database xhd --table xhd-sso --host 127.0.0.1 --user xiehd --password xiehd2018 --client_id maxwell_dev

同步xhd.xhd-sso表的所有數(shù)據(jù),并指定client_id示maxwell_dev的maxwell執(zhí)行同步

上一個(gè)命令先開著,然后再啟動(dòng)client_id=maxwell_dev的maxwell

./bin/maxwell --client_id maxwell_dev

等待執(zhí)行完成即可

以上就是如何使用Maxwell實(shí)時(shí)同步mysql數(shù)據(jù)的詳細(xì)內(nèi)容,更多關(guān)于用Maxwell同步mysql數(shù)據(jù)的資料請關(guān)注腳本之家其它相關(guān)文章!

您可能感興趣的文章:
  • python實(shí)現(xiàn)MySQL指定表增量同步數(shù)據(jù)到clickhouse的腳本
  • MySQL數(shù)據(jù)庫主從同步實(shí)戰(zhàn)過程詳解
  • scrapy數(shù)據(jù)存儲(chǔ)在mysql數(shù)據(jù)庫的兩種方式(同步和異步)
  • Mysql主從數(shù)據(jù)庫(Master/Slave)同步配置與常見錯(cuò)誤
  • ktl工具實(shí)現(xiàn)mysql向mysql同步數(shù)據(jù)方法
  • 用python簡單實(shí)現(xiàn)mysql數(shù)據(jù)同步到ElasticSearch的教程
  • MySQL數(shù)據(jù)庫的主從同步配置與讀寫分離
  • node.js將MongoDB數(shù)據(jù)同步到MySQL的步驟
  • Linux下MySQL數(shù)據(jù)庫的主從同步復(fù)制配置
  • PHP使用SWOOLE擴(kuò)展實(shí)現(xiàn)定時(shí)同步 MySQL 數(shù)據(jù)

標(biāo)簽:徐州 自貢 麗水 迪慶 無錫 西寧 龍巖 南充

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《如何使用Maxwell實(shí)時(shí)同步mysql數(shù)據(jù)》,本文關(guān)鍵詞  如何,使用,Maxwell,實(shí)時(shí),同步,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《如何使用Maxwell實(shí)時(shí)同步mysql數(shù)據(jù)》相關(guān)的同類信息!
  • 本頁收集關(guān)于如何使用Maxwell實(shí)時(shí)同步mysql數(shù)據(jù)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    田阳县| 睢宁县| 阳新县| 衡东县| 仁怀市| 阜南县| 马关县| 龙游县| 高雄市| 南澳县| 邯郸县| 大新县| 晋城| 凭祥市| 寻甸| 烟台市| 井陉县| 普格县| 简阳市| 迭部县| 拜泉县| 柳林县| 广河县| 龙山县| 都兰县| 龙井市| 浙江省| 精河县| 江阴市| 金坛市| 清徐县| 特克斯县| 嵊州市| 石阡县| 云霄县| 海安县| 宁津县| 湘潭市| 义马市| 南溪县| 普兰县|