{"id":202,"date":"2018-06-05T15:12:30","date_gmt":"2018-06-05T07:12:30","guid":{"rendered":"http:\/\/www.heoffice.com\/?p=202"},"modified":"2018-06-05T15:12:30","modified_gmt":"2018-06-05T07:12:30","slug":"%e4%bd%bf%e7%94%a8docker%e4%b8%8b%e7%9a%84go-mysql-elasticsearch%e6%8a%8amysql%e6%95%b0%e6%8d%ae%e8%a1%a8%e5%90%8c%e6%ad%a5%e5%88%b0elasticsearch","status":"publish","type":"post","link":"https:\/\/heoffice.com\/?p=202","title":{"rendered":"\u4f7f\u7528Docker\u4e0b\u7684Go-mysql-ElasticSearch\u628aMySQL\u6570\u636e\u8868\u540c\u6b65\u5230ElasticSearch"},"content":{"rendered":"<p>\u662f\u4e00\u4e2a\u81ea\u52a8\u540c\u6b65MySQL\u6570\u636e\u5230Elasticsearch\u670d\u52a1,\u5b83\u4f7f\u7528mysqldump\u540c\u6b65\u5168\u91cf\u6570\u636e, \u7136\u540e\u901a\u8fc7binlog\u540c\u6b65\u589e\u91cf\u6570\u636e<br \/>\n<a href=\"https:\/\/github.com\/siddontang\/go-mysql-elasticsearch\">\u9879\u76ee\u5730\u5740https:\/\/github.com\/siddontang\/go-mysql-elasticsearch<\/a><\/p>\n<p>Go-mysql-ElasticSearch\u9879\u76ee\u81ea\u5e26\u4e2aDockerfile,\u53ef\u4ee5\u76f4\u63a5\u7528Docker run\u8fd0\u884c, \u53ea\u9700\u8981\u7b80\u5355\u914d\u7f6e\u5373\u53ef.<\/p>\n<h4>\u5b89\u88c5\u914d\u7f6eMYSQL<\/h4>\n<p>MYSQL\u9700\u8981\u914d\u7f6e\u6210\u4e3b\u4ece\u7ed3\u6784<\/p>\n<pre class=\"line-numbers prism-highlight\" data-start=\"1\"><code class=\"language-cnf\">server-id=1\nlog-bin=mysql-bin.log\nbinlog-do-db=ultron\nbinlog-do-db=ultron_test\nexpire_logs_days=1\nbinlog_format=row\n<\/code><\/pre>\n<h4>\u5b89\u88c5ELK<\/h4>\n<p>\u53c2\u8003http:\/\/www.heoffice.com\/docker\/185\/<\/p>\n<h4>Docker\u8fd0\u884cGo-mysql-ElasticSearch<\/h4>\n<p>\u53ef\u4ee5\u4f7f\u7528Docker run\u76f4\u63a5\u8fd0\u884c, \u4f46\u6211\u559c\u6b22\u7528Docker-compose\u8fd0\u884c.docker-compose\u8fd0\u884c\u7684\u597d\u5904\u6709<br \/>\n* \u53ef\u4ee5\u8bbe\u7f6e\u914d\u7f6e\u6587\u4ef6.\/etc\/river.toml\u8def\u5f84\u4e3a\u76f8\u5bf9\u8def\u5f84<br \/>\n* \u53ef\u4ee5\u65b9\u4fbf\u96c6\u6210\u5230\u5176\u5b83docker-compose\u4e2d,\u4e0e\u5176\u5b83\u5bb9\u5668\u901a\u8fc7\u5bb9\u5668\u540d\u76f8\u4e92\u8bbf\u95ee\u6570\u636e<br \/>\n* \u8fd0\u884c\u7b80\u5355: docker-compose up\u6216docker-compose -f xxx.yml up<\/p>\n<pre class=\"line-numbers prism-highlight\" data-start=\"1\"><code class=\"language-sh\">git clone git@github.com:siddontang\/go-mysql-elasticsearch.git\ncd go-mysql-elasticsearch\n<\/code><\/pre>\n<p>\u521b\u5efadocker-compose.yml<\/p>\n<pre class=\"line-numbers prism-highlight\" data-start=\"1\"><code class=\"language-yml\">version: '3'\nservices:\n    go-mysql-elasticsearch:\n        build: .\n        restart: always\n        ports:\n            - 12800:12800\n        volumes:\n            - \".\/etc\/river.toml:\/go\/etc\/river.toml\" \n\n<\/code><\/pre>\n<p>\u914d\u7f6e\u540c\u6b65\u914d\u7f6e\u6587\u4ef6 etc\/river.toml<\/p>\n<pre class=\"line-numbers prism-highlight\" data-start=\"1\"><code class=\"language-toml\"># MySQL address, user and password\n# user must have replication privilege in MySQL.\nmy_addr = \"192.168.2.119:3306\"\nmy_user = \"ultron\"\nmy_pass = \"ultron\"\nmy_charset = \"utf8mb4\"\n\n# Set true when elasticsearch use https\n#es_https = false\n# Elasticsearch address\nes_addr = \"192.168.2.119:9200\"\n# Elasticsearch user and password, maybe set by shield, nginx, or x-pack\nes_user = \"\"\nes_pass = \"\"\n\n# Path to store data, like master.info, if not set or empty,\n# we must use this to support breakpoint resume syncing. \n# TODO: support other storage, like etcd. \ndata_dir = \".\/var\"\n\n# Inner Http status address\nstat_addr = \"127.0.0.1:12800\"\n\n# pseudo server id like a slave \nserver_id = 1001\n\n# mysql or mariadb\nflavor = \"mysql\"\n\n# mysqldump execution path\n# if not set or empty, ignore mysqldump.\nmysqldump = \"mysqldump\"\n\n# if we have no privilege to use mysqldump with --master-data,\n# we must skip it.\n#skip_master_data = false\n\n# minimal items to be inserted in one bulk\nbulk_size = 128\n\n# force flush the pending requests if we don't have enough items &gt;= bulk_size\nflush_bulk_time = \"200ms\"\n\n# Ignore table without primary key\nskip_no_pk_table = false\n\n# MySQL data source\n[[source]]\nschema = \"ultron\"\n\n# Only below tables will be synced into Elasticsearch.\n# \"t_[0-9]{4}\" is a wildcard table format, you can use it if you have many sub tables, like table_0000 - table_1023\n# I don't think it is necessary to sync all tables in a database.\ntables = [\"advertiser\"]\n\n[[source]]\nschema = \"ultron_test\"\n\n# Only below tables will be synced into Elasticsearch.\n# \"t_[0-9]{4}\" is a wildcard table format, you can use it if you have many sub tables, like table_0000 - table_1023\n# I don't think it is necessary to sync all tables in a database.\ntables = [\"advertiser\",\"offer\"]\n<\/code><\/pre>\n<p>\u8fd0\u884c:<\/p>\n<pre class=\"line-numbers prism-highlight\" data-start=\"1\"><code class=\"language-sh\">docker-compose up\n<\/code><\/pre>\n<h4>\u8fd0\u884c\u6548\u679c<\/h4>\n<p>\u5728kibana\u7684management\u754c\u9762,\u5728\u521b\u5efaindex\u4e2d\u80fd\u770b\u5230\u8981\u540c\u6b65\u7684advertiser\u548coffer, \u8868\u793a\u6210\u529f<br \/>\n<img decoding=\"async\" src=\"http:\/\/www.heoffice.com\/wp-content\/uploads\/2018\/06\/elk-offer-management-create-300x193.png\" alt=\"\" \/><\/p>\n<h4>\u6ce8\u610f<\/h4>\n<ul>\n<li>\u5728\u6267\u884cdocker-compose up\u65f6,\u5982\u679c\u9047\u5230<\/li>\n<\/ul>\n<pre class=\"line-numbers prism-highlight\" data-start=\"1\"><code class=\"language-sh\">go-mysql-elasticsearch_1  | \/usr\/bin\/mysqldump: unknown variable 'set-gtid-purged=OFF'\n<\/code><\/pre>\n<p>\u9519\u8bef, \u5c31\u8f6c\u5230\u6e90\u4ee3\u7801\/go\/dump\/dump.go \u4e2d\u627e\u5230<\/p>\n<pre class=\"line-numbers prism-highlight\" data-start=\"1\"><code class=\"language-go\">args = append(args, \"--set-gtid-purged=OFF\")\n<\/code><\/pre>\n<p>\u628a\u5b83\u6ce8\u91ca\u6389,\u91cd\u65b0\u6267\u884cdocker-compose up &#8211;build<\/p>\n<h4>\u53c2\u8003<\/h4>\n<p>https:\/\/github.com\/siddontang\/go-mysql-elasticsearch<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u662f\u4e00\u4e2a\u81ea\u52a8\u540c\u6b65MySQL\u6570\u636e\u5230Elasticsearch\u670d\u52a1,\u5b83\u4f7f\u7528mysqldump\u540c\u6b65\u5168\u91cf\u6570\u636e, \u7136\u540e\u901a\u8fc7&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-202","post","type-post","status-publish","format-standard","hentry","category-elk"],"acf":[],"_links":{"self":[{"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/posts\/202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=202"}],"version-history":[{"count":3,"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/posts\/202\/revisions"}],"predecessor-version":[{"id":206,"href":"https:\/\/heoffice.com\/index.php?rest_route=\/wp\/v2\/posts\/202\/revisions\/206"}],"wp:attachment":[{"href":"https:\/\/heoffice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/heoffice.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}