{"id":643,"date":"2018-03-01T14:57:05","date_gmt":"2018-03-01T06:57:05","guid":{"rendered":"https:\/\/blog.jsjs.org\/?p=643"},"modified":"2018-03-01T14:57:05","modified_gmt":"2018-03-01T06:57:05","slug":"%e5%9f%ba%e4%ba%8ecanal-%e7%9a%84-mysql-%e4%b8%8e-redis-memcached-mongodb-%e7%9a%84-nosql-%e6%95%b0%e6%8d%ae%e5%ae%9e%e6%97%b6%e5%90%8c%e6%ad%a5%e6%96%b9%e6%a1%88-%e6%a1%88%e4%be%8b%ef%bc%8ccanal-clie","status":"publish","type":"post","link":"https:\/\/blog.jsjs.org\/?p=643","title":{"rendered":"\u57fa\u4e8ecanal \u7684 mysql \u4e0e redis\/memcached\/mongodb \u7684 nosql \u6570\u636e\u5b9e\u65f6\u540c\u6b65\u65b9\u6848 \u6848\u4f8b\uff0ccanal client"},"content":{"rendered":"<p>https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync<\/p>\n<p>\u4e0b\u56fe\u662f\u6700\u57fa\u672c\u7684web\u670d\u52a1\u5668\u7684\u7ed3\u6784\u56fe\u3002\u00a0<a href=\"https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync\/raw\/master\/img\/system-image.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync\/raw\/master\/img\/system-image.png\" alt=\"image\" \/><\/a><\/p>\n<p>\u57fa\u4e8e Canal \u7684 MySql RabbitMQ Redis\/memcached\/mongodb \u7684nosql\u540c\u6b65 \uff08\u591a\u8bfb\u3001nosql\u5ef6\u65f6\u4e0d\u4e25\u683c \u9700\u6c42\uff09<\/p>\n<pre><code>1.mysql\u4e3b\u4ece\u914d\u7f6e\n\n2.\u5bf9mysql binlog(row) parser \u8fd9\u4e00\u6b65\u4ea4\u7ed9canal\n\n3.MQ\u5bf9\u89e3\u6790\u540ebinlog\u589e\u91cf\u6570\u636e\u7684\u63a8\u9001\n\n4.\u5bf9MQ\u6570\u636e\u7684\u6d88\u8d39\uff08\u63a5\u6536+\u6570\u636e\u89e3\u6790\uff0c\u8003\u8651\u6d88\u8d39\u901f\u5ea6\uff0cMQ\u961f\u5217\u7684\u963b\u585e\uff09\n\n5.\u6570\u636e\u5199\u5165\/\u4fee\u6539\u5230nosql \uff08redis\u7684\u4e3b\u4ece\/hash\u5206\u7247\uff09\n\n6.\u4fdd\u8bc1\u5bf9\u5e94\u5173\u7cfb\u7684\u7b80\u5355\u6027\uff1a\u4e00\u4e2amysql\u8868\u5bf9\u5e94\u4e00\u4e2a redis\u5b9e\u4f8b\uff08redis\u5355\u7ebf\u7a0b\uff0c\u591a\u5b9e\u4f8b\u4fdd\u8bc1\u5206\u6d41\u4e0d\u963b\u585e\uff09\uff0c\u5173\u8054\u5173\u7cfb\u6570\u636e\u4ea4\u7ed9\u63a5\u53e3\u4e1a\u52a1\n\n\u6570\u636e\uff1amysql-&gt;binlog-&gt;MQ-&gt;redis(\u4e0d\u8fc7\u671f\u3001\u5173\u95edRDB\u3001AOF\u4fdd\u8bc1\u8bfb\u5199\u6027\u80fd) \uff08nosql\u6570\u636e\u4ec5\u7528crontab\u811a\u672c\u7ef4\u62a4\uff09\n\n\u8bf7\u6c42\uff1ahttp-&gt;webserver-&gt;redis(\u6709\u6570\u636e)-&gt;\u8fd4\u56de\u6570\u636e \uff08\u5b8c\u5168\u907f\u514d\u7528\u6237\u76f4\u63a5\u8bfb\u53d6mysql\uff09\n\n                    -&gt;redis(\u65e0\u6570\u636e)-&gt;\u8fd4\u56de\u7a7a\n\n7.\u53ef\u5c06\u5b83\u89c6\u4e3a\u4e00\u4e2a\u89e6\u53d1\u5668\uff0cbinlog\u4e3a\u8bb0\u5f55\u89e6\u53d1\u4e8b\u4ef6\uff0ccanal\u7684\u4f5c\u7528\u662f\u5c06\u4e8b\u4ef6\u5b9e\u65f6\u901a\u77e5\u51fa\u6765\uff0c\u5e76\u5c06binlog\u89e3\u6790\u6210\u4e86\u6240\u6709\u8bed\u8a00\u53ef\u8bfb\u7684\u5de5\u5177\u3002\n\u5728\u4e8b\u4ef6\u4f20\u8f93\u7684\u5404\u4e2a\u73af\u8282 \u63d0\u9ad8 \u53ef\u7528\u6027 \u548c \u6269\u5c55\u6027 \uff08\u52a0\u5165MQ\u7b49\u65b9\u6cd5\uff09\u6700\u7ec8\u63d0\u9ad8\u7cfb\u7edf\u7684\u7a33\u5b9a\u3002\n<\/code><\/pre>\n<p>\u4f20\u7edf Mysql Redis\/memcached nosql\u7684\u7f13\u5b58 \uff08\u4e1a\u52a1\u540c\u6b65\uff09 \u4ececache\u8bfb\u53d6\u6570\u636e-&gt;<\/p>\n<pre><code>1.\u5bf9\u6570\u636e\u5728mysql\u7684hash\u7b97\u6cd5\u5206\u5e03(db\/table\/\u5206\u533a)\uff0c\u6bcf\u4e2ahash\u4e3a\u8282\u70b9\uff08nosql\u6570\u636e\u5168\u90e8\u5931\u6548\u65f6\u5019\uff0c\u53ef\u4fdd\u8bc1mysql\u5404\u8282\u70b9\u53ef\u652f\u6301\u76f4\u63a5\u8bfb\u53d6\u7684\u6027\u80fd\uff09\n\n2.mysql\u4e3b\u4ece\n\n3.nosql\u6570\u636e\u7684hash\u7b97\u6cd5\u5206\u5e03(\u591a\u5b9e\u4f8b\u3001DB)\uff0c\u6bcf\u4e2ahash\u4e3a\u8282\u70b9\n\n4.nosql\u6570\u636e\u9707\u8361\u5904\u7406 \uff08\u5f53\u67d0\u8282\u70b9\u6302\u4e86\u5bfb\u627e\u66ff\u4ee3\u8282\u70b9\u7b97\u6cd5\uff08\u591a\u5c42hash\u66ff\u4ee3\u8282\u70b9\uff09\u3002\u3002\u3002\uff09\n\n5.\u6062\u590d\u8282\u70b9\u6570\u636e\n\n6.\u8bf7\u6c42\uff1ahttp-&gt;webserver-&gt;\u3010\u5bf9key\u8ba1\u7b97\u4e00\u81f4\u6027hash\u8282\u70b9\u3011-&gt;connect\u5bf9\u5e94\u7684redis\u5b9e\u4f8b\n\n                                                    -&gt;1.redis(\u6709\u6570\u636e)-&gt; \u8fd4\u56de\u6570\u636e\n\n\t\t\t                            -&gt;2.redis(\u65e0\u6570\u636e)-&gt; mysql (\u5e76\u5199\u5165\u6570\u636eredis) -&gt; \u8fd4\u56de\u6570\u636e\n\n\t                                            -&gt;3.redis\u8282\u70b9\u6302\u6389-&gt; \u4e1a\u52a1\u5bfb\u5740hash\u66ff\u4ee3\u8282\u70b9\n\t                                                                      -&gt; 3.1 redis(\u6709\u6570\u636e) -&gt; \u8fd4\u56de\u6570\u636e\n\n\t\t\t\t\t\t\t\t\t      -&gt; 3.2 redis(\u65e0\u6570\u636e) -&gt; mysql(\u5e76\u5199\u5165\u6570\u636eredis) -&gt; \u8fd4\u56de\u6570\u636e\n<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync\/raw\/master\/img\/canal-mysql-nosql.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync\/raw\/master\/img\/canal-mysql-nosql.png\" alt=\"image\" \/><\/a><\/p>\n<p>\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u6d88\u606f\u961f\u5217\uff08MQ\uff09\u8fdb\u884cbinlog\u4f20\u8f93:<\/p>\n<pre><code>1.\u589e\u52a0\u7f13\u51b2\uff0cbinlog\u751f\u4ea7\u7aef\uff08canal client\uff09\u53ea\u8d1f\u8d23\u751f\u4ea7\u800c\u4e0d\u9700\u8981\u8003\u8651\u6d88\u8d39\u7aef\u7684\u6d88\u8d39\u80fd\u529b, \u4e0d\u7b49\u5f85\u963b\u585e\u3002\n\n2.binlog \u6d88\u8d39\u7aef: \u53ef\u5b9e\u65f6\u6839\u636eMQ\u6d88\u606f\u7684\u5806\u79ef\u60c5\u51b5\uff0c\u52a8\u6001 \u589e\u52a0\/\u51cf\u5c11 \u6d88\u8d39\u7aef\u7684\u6570\u91cf\uff0c\u8fbe\u5230\u5408\u7406\u7684\u8d44\u6e90\u5229\u7528\u548c\u6d88\u8d39\n<\/code><\/pre>\n<p>\u90e8\u7f72:<\/p>\n<pre><code>\u963f\u91cccanal\u7eafjava\u5f00\u53d1\uff0c\u6240\u4ee5\u8981\u5148\u5b89\u88c5java\u73af\u5883\n<\/code><\/pre>\n<p>\u5b89\u88c5jdk(\u63a8\u8350jdk1.8): \u5b89\u88c5\u8fc7\u7a0b\u53c2\u8003\u7f51\u4e0a\u8d44\u6599\uff0c\uff08\u6ce8\u610f\u73af\u5883\u53d8\u91cf\u914d\u7f6e\uff09<\/p>\n<p>mysql\u914d\u7f6e\uff1a 1.\u7f16\u8f91mysql\u914d\u7f6e\u6587\u4ef6 $ sudo vim \/etc\/my.cnf<\/p>\n<pre><code>\t[mysqld]\n\tlog-bin=mysql-bin #binlog\u6587\u4ef6\u540d\uff08\u4e5f\u53ef\u4ee5\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\uff09\n\tbinlog-format=ROW #\u9009\u62e9row\u6a21\u5f0f\n\tserver_id=1 \t  #\u5b9e\u4f8b\u552f\u4e00ID\uff0c\u4e0d\u80fd\u548ccanal\u7684slaveId\u91cd\u590d\n\n\u4fdd\u5b58\u5e76\u9000\u51fa\uff0c\u5e76\u91cd\u542fmysql\n\t$ sudo service mysql restart\n\n2.\u521b\u5efa mysql\u8d26\u53f7\u5bc6\u7801\uff08\u8d26\u53f7\u5bc6\u7801\u81ea\u5b9a \u6743\u9650\u81ea\u5b9a\uff09\n\n\tCREATE USER canal IDENTIFIED BY 'canal';\n\tGRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';\n\t-- GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%' ;\n\tFLUSH PRIVILEGES;\n<\/code><\/pre>\n<p>canal server \u914d\u7f6e\u542f\u52a8\uff1a<\/p>\n<pre><code>canal server \u6a21\u62dfmysql\u4ece\u5e93\u5e76\u5411mysql\u53d1\u9001dump\u547d\u4ee4\u83b7\u53d6mysql binlog\u6570\u636e\u3002\n\n1.\u4e0b\u8f7d\u89e3\u538b\u9879\u76ee\uff0c\u8fd9\u91cc\u63d0\u4f9b\u4e861.0.22\u7248\u672c:\n[canal.deployer-1.0.22.tar.gz](https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync\/releases)\n\u53ef\u4ece\u963f\u91cc\u9879\u76ee\u4e0b\u8f7d\u6700\u65b0\u7248\u672c deployer \uff1a\n[https:\/\/github.com\/alibaba\/canal\/releases](https:\/\/github.com\/alibaba\/canal\/releases)\n\n2.\u914d\u7f6e\u9879\u76ee\uff1a\n\t# \u516c\u5171\u914d\u7f6e\n\t$ sudo vim conf\/canal.properties\n\n\t\tcanal.port= 11111 # canal server \u8fd0\u884c\u7aef\u53e3\uff0c\u4fdd\u8bc1\u8be5\u7aef\u53e3\u4e3a\u5360\u7528\u72b6\u6001\uff0c\u6216\u8005\u4f7f\u7528\u5176\u4ed6\u672a\u5360\u7528\u7aef\u53e3\n\n\t\u4fdd\u5b58\u9000\u51fa\u3002\n\n\t# \u5b9e\u4f8b\u914d\u7f6e\n\t$ sudo vim conf\/example\/instance.properties\n\n\t\t# position info\n\t\tcanal.instance.master.address = 127.0.0.1:3306  # mysql\u8fde\u63a5\n\n\t\tcanal.instance.dbUsername = canal  \t\t# mysql\u8d26\u53f7\n\t\tcanal.instance.dbPassword = canal\t\t# \u5bc6\u7801\n\t\tcanal.instance.defaultDatabaseName = test\t# \u9700\u8981\u540c\u6b65\u7684\u5e93\u540d\n\t\tcanal.instance.connectionCharset = UTF-8\t# mysql\u7f16\u7801\n\n\t\u4fdd\u5b58\u9000\u51fa\u3002\n\n\t\u66f4\u591a\u914d\u7f6e\u67e5\u770b:\n\t[http:\/\/agapple.iteye.com\/blog\/1831873](http:\/\/agapple.iteye.com\/blog\/1831873)\n\n3.\u542f\u52a8\uff1a\n\t$ sh bin\/startup.sh\n\n\u65e5\u5fd7\u6587\u4ef6\uff1a $ less logs\/canal\/canal.log\t # canal server\u7aef\u8fd0\u884c\u65e5\u5fd7\n\t  $ less logs\/example\/example.log   # canal client\u7aef\u8fde\u63a5\u65e5\u5fd7\n\t  $ logs\/example\/meta.log \t    # \u5b9e\u4f8bbinlog \u8bfb\u53d6\u8bb0\u5f55\u6587\u4ef6\uff08\u8bb0\u5f55\u53d8\u66f4\u4f4d\u7f6e\uff0c\u9ed8\u8ba4\u4e3a\u65b0\u589e\u53d8\u66f4(tail)\uff09\n<\/code><\/pre>\n<p>canal client \u914d\u7f6e\u542f\u52a8\uff1a<\/p>\n<pre><code>canal client\u5c06\u4ececanal server\u83b7\u53d6\u7684binlog\u6570\u636e\u6700\u7ec8\u4ee5json\u884c\u683c\u5f0f\u4fdd\u5b58\u5230\u6307\u5b9a\u6587\u4ef6(\u4e5f\u53ef\u7701\u7565\u8fd9\u6b65\uff0c\u76f4\u63a5\u53d1\u9001\u5230MQ)\u3002\n\nbinlog\u751f\u4ea7\u7aef\u548c\u6d88\u8d39\u7aef\u7684\u4e4b\u95f4\uff0c\u589e\u52a0MQ\u4f5c\u4e3a\u7f13\u51b2\uff0c\u589e\u52a0\u5bb9\u9519\u5ea6\u548c\u52a8\u6001\u6269\u5c55\u6027\n\n1.\u4e0b\u8f7d\u89e3\u538b\u9879\u76ee\uff0c\u8fd9\u91cc\u81ea\u5df1\u5199\u4e86\u4e2a\u57fa\u4e8e1.0.22\u7248\u672c\u7684\u9879\u76ee:\n[canal_client1.0.22.zip](https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync\/releases)\n\n\u6e90\u7801\u67e5\u770b: [canal-client](https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync\/tree\/master\/canal-client)\n\n2.\u57fa\u672c\u914d\u7f6e\n\n\t$vim conf\/canal.properties\n\n\t# cancal server host\uff0c \u4e0a\u9762 canal server\u7684IP\n\tcanal.server.host = 127.0.0.1\n\n\t# cancal server port\uff0c\u4e0a\u9762 canal server\u7684\u542f\u52a8\u7aef\u53e3\n\tcanal.server.port = 11111\n\n\t# \u6570\u636e\u4fdd\u5b58\u8def\u5f84 \uff0c\u81ea\u884c\u6307\u5b9a\n\tcanal.binlog.dir = db_data\n\n\t# \u53ef\u9009rabbitmq\/redis\/kafka \u4f5c\u4e3a\u961f\u5217\uff08\u8fd9\u91cc\u4f7f\u7528 rabbitmq \u4f5c\u4e3a\u961f\u5217\u4f20\u8f93\uff09\n\tcanal.mq = rabbitmq\n\n\t###### rabbitmq \u57fa\u672c\u914d\u7f6e #####\n\trabbitmq.host = 127.0.0.1\n\trabbitmq.port = 5672\n\trabbitmq.user = test\n\trabbitmq.pass = 123456\n\n\n\t\u4fdd\u5b58\u9000\u51fa\u3002\n\n3.\u542f\u52a8canal client\uff1a\n\n\t$ sh start_canal_client.sh\n<\/code><\/pre>\n<p>\u4fee\u6539mysql\u6570\u636e\u89e6\u53d1\u3002<\/p>\n<p>\u6700\u7ec8\u7ed3\u679c\uff1a<\/p>\n<pre><code>eventType \uff1a\u64cd\u4f5c\u7c7b\u578b\uff08UPDATE\/INSERTDELETE\uff09\n\ndb\uff1a   \u6d89\u53ca\u5e93\n\ntable: \u6d89\u53ca\u8868\n\nbefore:\u53d8\u66f4\u524d\u6570\u636e\n\nafter: \u53d8\u66f4\u540e\u6570\u636e\n\ntime:  \u64cd\u4f5c\u65f6\u95f4\n\n\n    $less db_data\/binlog_xxxx.log\n\n    {\"binlog\":\"mysql-bin.000009:1235\",\"db\":\"test\",\"table\":\"users\",\"eventType\":\"UPDATE\",\"before\":{\"uid\":\"8\",\"username\":\"duobao153713223\"},\"after\":{\"uid\":\"8\",\"username\":\"duobao153713223\"},\"time\":\"2016-08-22 17:47:25\"}\n\n    {\"binlog\":\"mysql-bin.000009:1533\",\"db\":\"test\",\"table\":\"users\",\"eventType\":\"DELETE\",\"before\":\"\",\"after\":{\"uid\":\"8\",\"username\":\"duobao153713223\"},\"time\":\"2016-08-22 17:48:09\"}\n\n    {\"binlog\":\"mysql-bin.000009:1790\",\"db\":\"test\",\"table\":\"users\",\"eventType\":\"INSERT\",\"before\":\"\",\"after\":{\"uid\":\"9\",\"username\":\"test2\"},\"time\":\"2016-08-22 17:48:45\"}\n<\/code><\/pre>\n<p>\u6d88\u8d39\u6570\u636edemo\uff1a\uff08\u8fd9\u91cc\u4f7f\u7528python3 \u6d88\u8d39rabbitmq\u540c\u6b65\u5230redis \u4f5c\u4e3a\u6848\u4f8b\uff0c\u5b9e\u9645\u53ef\u6839\u636e\u4e1a\u52a1\u9700\u6c42\uff0c\u56e0\u4e3a\u6b64\u65f6\u6240\u9700\u8981\u7684\u6570\u636e\u5df2\u662f\u901a\u7528\u7684json\u683c\u5f0f\uff0c\u65e0\u9650\u53ef\u80fd\uff09<\/p>\n<pre><code>\u6d41\u7a0b \uff1afile\u6570\u636e-&gt; MQ -&gt; nosql\n\nMQ: rabbitMQ\n\n\u8bed\u8a00\uff1apython3\n\nNoSql: redis\n\n\n\u591a\u9879\u76ee\u8ba2\u9605\u9700\u6c42\uff0c\u5982\uff1aclient1\u548cclient2 \u9700\u8981\u6d88\u8d39\u8fd9\u4e9b\u6570\u636e\uff0c \u4ed6\u4eec\u5f97\u5230\u7684\u6570\u636e\u4e00\u6837\n\u5f00\u59cb\u8003\u8651\u76f4\u63a5\u7528\u961f\u5217\uff1a\n\u961f\u5217\u6570\u636e\uff1a [A, B, C, D]\nclient1 \uff1a\n           \u6d88\u8d39\u8fdb\u7a0b1\uff1a\u83b7\u53d6AB\n           \u6d88\u8d39\u8fdb\u7a0b2\uff1a\u83b7\u53d6CD\n\nclient2 \uff1a\n           \u6d88\u8d39\u8fdb\u7a0b1\uff1a\u83b7\u53d6AB\n           \u6d88\u8d39\u8fdb\u7a0b2\uff1a\u83b7\u53d6CD\n\n\u8fd9\u6837\u7684\u8bdd\uff0c\u5982\u679c\u4f7f\u7528rabbitMQ \u5c31\u5fc5\u987b\u7ed9\u6bcf\u4e2a client \u63d0\u4f9b\u72ec\u7acb\u7684\u961f\u5217\u3002\u5e76\u72ec\u7acb\u6d88\u8d39\n1\u3001\u4f7f\u7528kafka\uff0c\u5229\u7528\u4ed6\u7684\u5206\u7ec4group,\u6bcf\u4e2aclient \u4e3a\u4e00\u4e2a\u7ec4\uff0c\u8fd9\u6837\u5c31\u53ef\u4fdd\u8bc1\uff0c\u6570\u636e\u7ed9\u6bcf\u4e2a\u7ec4\u4e00\u81f4\u3002\n2\u3001\u5bf9\u6bcf\u4e2a\u9879\u76ee\u9700\u6c42\u5f00\u72ec\u7acb\u7684 canal server instance \u548c canal client\u5b9e\u4f8b\n\n\n\u914d\u7f6e\uff1a\n   \u8bed\u8a00\uff1apython3\n   pip\uff1apika redis\n\n   \u9879\u76ee\u4ee3\u7801\uff1a python_sync_nosql\n   \u4fee\u6539\u914d\u7f6e\u6587\u4ef6config.py\n   \t# \u6700\u7ec8\u5b58\u50a8\u6570\u636eredis\n\tredis_host = '127.0.0.1'\n\tredis_port = 6379\n\n\t###### rabbitmq \u57fa\u672c\u914d\u7f6e #####\n\trabbitmq_host = '127.0.0.1'\n\trabbitmq_port = 5672\n\trabbitmq_user = 'test'\n\trabbitmq_pass = '123456'\n\n\t# \u8bbe\u7f6e\u5bf9\u6bcf\u4e2atable\u5b58\u50a8\u4f7f\u7528\u7684key\u5b57\u6bb5\n\tredis_cache_map = {\n\t\t# db\n\t\t'test':{\n\t\t\t# table \uff1a kid\n\t\t\t'users':'uid',\n\t  \t}\n\t}\n\n \u8fd0\u884c\u811a\u672c\uff1a\n \t$ python3 startup.py\n<\/code><\/pre>\n<p>\u6570\u636e\u6700\u7ec8\u5b58\u50a8\u4e3aRedis \u7684 hash\u7ed3\u6784\uff0ckey\u4e3a db_table_id\u00a0<a href=\"https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync\/raw\/master\/img\/redis-hash.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync\/raw\/master\/img\/redis-hash.png\" alt=\"image\" \/><\/a><\/p>\n<p>\u540c\u6b65\u5230MongoDB\u540c\u7406<\/p>\n<pre><code>  \u8fd9\u91cc\u7684demo\u662f\u5c06\u8868\u6570\u636e\u6620\u5c04\u5230 mongodb \u7ed3\u6784\n  db    =&gt; db\n  table =&gt; \u96c6\u5408\n  column=&gt; coll\n<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync\/raw\/master\/img\/mongo.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync\/raw\/master\/img\/mongo.png\" alt=\"image\" \/><\/a><\/p>\n<h2><a id=\"user-content-\u76ee\u5f55\u7ed3\u6784\" class=\"anchor\" href=\"https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync#%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84\" aria-hidden=\"true\"><\/a>\u76ee\u5f55\u7ed3\u6784<\/h2>\n<pre><code>\n\u251c\u2500canal-client\/         \u5c01\u88c5\u7684canal client\u5ba2\u6237\u7aef \u548c \u6d88\u606f\u961f\u5217MQ \u9879\u76ee\n\u2502  \u251c\u2500src\/           \t\u9879\u76ee\u4ee3\u7801\n\u2502  \u251c\u2500lib\/           \tjar\u5305\u4f9d\u8d56\n\u2502  \u251c\u2500conf\/            \t\u914d\u7f6e\u6587\u4ef6\n\u2502  \u251c\u2500canal_client.jar   \u542f\u52a8jar\n\u2502  \u2514\u2500start_canal_client.sh     \u542f\u52a8\u6587\u4ef6\n\u2502\n\u251c\u2500python_sync_nosql\/        \t\u6d88\u8d39MQ binlog\u6570\u636e, \u5c06\u6570\u636e\u5199\u5165\u5230NoSql demo\n\u2502  \u251c\u2500queue_rabbitmq.py \t\trabbitmq \u6d88\u8d39\u7aef\n\u2502  \u251c\u2500sync_redis.py \t\t\u5199\u5165\u5230redis\n\u2502  \u251c\u2500sync_mongo.py \t\t\u5199\u5165\u5230mongo\n\u2502  \u251c\u2500config.py \t\t\t\u914d\u7f6e\n\u2502  \u2514\u2500startup.py         \t\u542f\u52a8\u5165\u53e3\n\u2514\u2500\n\n<\/code><\/pre>\n<pre><code>\u603b\u7ed3\uff1a\n\n1.\u4f7f\u7528MQ\u4f5c\u4e3a\u4f20\u8f93\uff0c\u53ef\u63d0\u9ad8\u5bb9\u9519\u5ea6\uff0c\u5e76\u4e14\u53ef\u4ee5\u8d77\u5230\u4e00\u4e2a\u6d88\u8d39\u901f\u5ea6\u7684\u7f13\u51b2\uff0c\u5728\u7a0b\u5e8f\u4e0a\u52a0\u4e0a\u5bf9\u961f\u5217\u79ef\u538b\u6570\u636e\u7684\u76d1\u63a7\uff0c\u53ef\u5b9e\u65f6\u589e\u52a0\u6216\u51cf\u5c11MQ\u6d88\u8d39\u8fdb\u7a0b\u7684\u6570\u91cf\u3002\n\n2.\u4e3a\u4e86\u63d0\u9ad8binlog\u6570\u636e\u7684\u53ef\u9760\u6d88\u8d39\uff0c\u5efa\u8bae\u4f7f\u7528\u5e26\u6709ACK\u529f\u80fd\u7684MQ \u505a\u4e3a\u6d88\u606f\u961f\u5217\u4f7f\u7528\n\n3.\u4e3a\u4e86\u907f\u514d\u591a\u8fdb\u7a0b\u5bf9MQ\u6d88\u8d39\u901f\u5ea6\u7684\u65f6\u5e8f\u5148\u540e\u4e0d\u53ef\u63a7\uff0c\u5efa\u8baebinlog\u6570\u636e\u53ea\u4f5c\u4e3a\u89e6\u53d1\u6761\u4ef6\uff08\u4f7f\u7528id\u4ecemysql\u83b7\u53d6\u6700\u65b0\u6570\u636e\uff09\u4f5c\u4e3a\u6570\u636e\u4f7f\u7528\uff0c\u800c\u4e0d\u4f5c\u4e3a\u5177\u4f53\u6570\u636e\u4f7f\u7528\u3002\n\n4. \u63a5\u4e0b\u6765\u6211\u4f1a\u7ee7\u7eed\u5b8c\u5584otter\u7684\u5b9e\u9645\u6848\u4f8b ...\n<\/code><\/pre>\n<h1><a id=\"user-content-\u8d44\u6e90\u4e0b\u8f7d\" class=\"anchor\" href=\"https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync#%E8%B5%84%E6%BA%90%E4%B8%8B%E8%BD%BD\" aria-hidden=\"true\"><\/a>\u8d44\u6e90\u4e0b\u8f7d<\/h1>\n<p>canal server \u670d\u52a1\u7aefdeployer\uff1a\u00a0<a href=\"https:\/\/github.com\/alibaba\/canal\/releases\/tag\/canal-1.0.22\">https:\/\/github.com\/alibaba\/canal\/releases\/tag\/canal-1.0.22<\/a><\/p>\n<p>canal client \u5ba2\u6237\u7aef\uff1a\u00a0<a href=\"https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync\/releases\/tag\/1.0.22.2\">https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync\/releases\/tag\/1.0.22.2<\/a><\/p>\n<p>\u963f\u91cccanal\u9879\u76ee\u539f\u59cb\u5730\u5740\uff1a<a href=\"https:\/\/github.com\/alibaba\/canal\">https:\/\/github.com\/alibaba\/canal<\/a><\/p>\n<p>\u6570\u636e\u6d88\u8d39\u5199\u5165nosql\u4f8b\u5b50: python_sync_nosql \u8fd9\u91cc\u662f\u6d88\u8d39rabbitmq\u6570\u636e\u6700\u7ec8\u540c\u6b65\u5230redis<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/github.com\/liukelin\/canal_mysql_nosql_sync \u4e0b\u56fe\u662f\u6700\u57fa\u672c\u7684web\u670d\u52a1\u5668\u7684\u7ed3\u6784\u56fe\u3002\u00a0 \u57fa\u4e8e Canal \u7684 MySql RabbitMQ Redis\/memcached\/mongodb \u7684nosql\u540c\u6b65 \uff08\u591a\u8bfb\u3001nosql\u5ef6\u65f6\u4e0d\u4e25\u683c \u9700\u6c42\uff09 1.mysql\u4e3b\u4ece\u914d\u7f6e 2.\u5bf9mysql binlog(row) parser \u8fd9\u4e00\u6b65\u4ea4\u7ed9canal 3.MQ\u5bf9\u89e3\u6790\u540ebinlog\u589e\u91cf\u6570\u636e\u7684\u63a8\u9001 4.\u5bf9MQ\u6570\u636e\u7684\u6d88\u8d39\uff08\u63a5\u6536+\u6570\u636e\u89e3\u6790\uff0c\u8003\u8651\u6d88\u8d39\u901f\u5ea6\uff0cMQ\u961f\u5217\u7684\u963b\u585e\uff09 5.\u6570\u636e\u5199\u5165\/\u4fee\u6539\u5230nosql \uff08redis\u7684\u4e3b\u4ece\/hash\u5206\u7247\uff09 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-643","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/643","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=643"}],"version-history":[{"count":0,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/643\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}