测试版本: mysql:5.7 ; es:5.6.4 ; elasticsearch-head:5 ; kibana:5.6.4 ; go-mysql-elasticsearch(mysql 数据自动同步到es的工具)
重要的事情说三遍:
- es 的东西,版本一点都不能差。
- es 的东西,版本一点都不能差。
- es 的东西,版本一点都不能差。
kibana版本对应上
docker search kibana:5.6.4
这种方式一般就能找到版本
IK (es 的中文分词,版本对应上)
https://github.com/medcl/elasticsearch-analysis-ik
go-mysql-elasticsearch
所支持的MySQL版本小于8.0. 所支持的ES版本小于6.0. mysql binlog的格式必须为row格式.
docker-compose file 构建如下(内部的XXX 替换成实际的值):
version: "3" services: elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:5.6.4 container_name: es5.6 environment: - TZ=Asia/Shanghai restart: always environment: - cluster.name=elastomer5.6 - bootstrap.memory_lock=true - discovery.type=single-node - xpack.monitoring.enabled=false - xpack.security.enabled=false - xpack.watcher.enabled=false - "ES_JAVA_OPTS=-Xms512m -Xmx512m" volumes: - XXX/ik:/usr/share/elasticsearch/plugins/ik - XXX/data:/usr/share/elasticsearch/data - XXX/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml ports: - "9200:9200" es-head: image: mobz/elasticsearch-head:5 container_name: es-head restart: always ports: - "9100:9100" kibana: image: docker.elastic.co/kibana/kibana:5.6.4 container_name: kibana restart: always ports: - "5601:5601" depends_on: - elasticsearch - mysql go-mysql-elasticsearch: image: eaglechen/go-mysql-elasticsearch container_name: mysql2es restart: always volumes: - XXX/river.toml:/go_mysql_river.toml:ro depends_on: - elasticsearch mysql: container_name: mysql5.7 restart: always build: mysql5.7 command: --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 --max_allowed_packet=128M --sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO" environment: TZ: Asia/Shanghai MYSQL_ROOT_PASSWORD: XXX ports: - "3306:3306" volumes: - XXX/data:/var/lib/mysql
相关配置文件:
river.toml 配置见 https://github.com/go-mysql-org/go-mysql-elasticsearch/blob/master/etc/river.toml
ik:下载见 https://github.com/medcl/elasticsearch-analysis-ik
elasticsearch.yml:
cluster.name: "docker-cluster" network.host: 0.0.0.0 # minimum_master_nodes need to be explicitly set when bound on a public IP # set to 1 to allow single node clusters # Details: https://github.com/elastic/elasticsearch/pull/17288 discovery.zen.minimum_master_nodes: 1 # 开启前端访问的跨域. (使用es-head 工具访问的时候,前端有跨域问题,这里允许跨域) http.cors.enabled: true http.cors.allow-origin: "*"
mysql5.7的Dockerfile:
FROM mysql:5.7 COPY mysqld.cnf /etc/mysql/mysql.conf.d/
mysqld.cnf文件示例:
# # The MySQL Server configuration file. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html [mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql #log-error = /var/log/mysql/error.log # By default we only accept connections from localhost #bind-address = 127.0.0.1 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 #以下是启动log-bin的配置 log-bin = binlog server-id=1 binlog-format = ROW binlog_rows_query_log_events = off
写在后面的话:
1、canal 等工具没有go-mysql-elasticsearch 部署、配置简单。
2、不要随便尝试build es,那可能会让你郁闷一天。退而求其次,使用-v 挂载吧
3、docker-compose 文件书写注意事项:
- 每个services 下面的key 名,随便命名。
- container_name 随便命名
- build 后面的值,写含Docker file 的文件夹名。
- depends_on 写services 下面的key 名。详见 docker-compose 文件规范。