1. 安装配置mysql
1.1 安装MySQL
① 拉取MySQL镜像
docker pull mysql:5.7.40
② 运行MySQL容器
docker run --name kxjmysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin -d mysql:5.7.40
- MYSQL_ROOT_PASSWORD:设置root用户的密码
③ 数据库工具连接MySQL
: Undefined array key "dark" in /www/wwwroot/wql_luoqin_ltd/wp-content/themes/Sakura/functions.php on line 694
class="post-template-default single single-post postid-3226 single-format-standard wp-custom-logo chinese-font ">
发布于 2022-10-29 1.56k 次阅读
① 拉取MySQL镜像
docker pull mysql:5.7.40
② 运行MySQL容器
docker run --name kxjmysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin -d mysql:5.7.40
③ 数据库工具连接MySQL
① 进入MySQL容器
docker exec -it kxjmysql /bin/bash
② 配置binlog(可选)
# 进入/etc/mysql/mysql.conf.d/ cd /etc/mysql/mysql.conf.d/ # 设置mysqld.cnf文件 vim mysqld.cnf
文件内容:
[mysqld] log-bin=mysql-bin #开启binlog binlog-format=row #设置binlog的格式 server-id=1 #master ID
③ 重启容器
docker restart kxjmysql
④ 重新进入容器MySQL客户端测试是否安装成功
mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 154 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> show variables like 'binlog_format'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | binlog_format | ROW | +---------------+-------+ 1 row in set (0.00 sec)
① 拉取ES镜像
docker pull elasticsearch:7.17.5
② 运行ES容器
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -d elasticsearch:7.17.5
③ 进入ES并配置es信息
docker exec -it elasticsearch bash cd config vim elasticsearch.yml
配置文件:
#集群名称 cluster.name: kxjes #允许IP进行访问 network.host: 0.0.0.0 #节点名称 node.name: node-1 #访问端口 http.port: 9200 #当前节点是否为主节点 node.master: true http.cors.enabled: true http.cors.allow-origin: "*" node.data: true
访问测试:
安装有两种方式:
① 在线安装
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.17.5/elasticsearch-analysis-ik-7.17.5.zip
② 离线安装
#1. 下载ik分词器到本地 #2. 拷贝ik分词器到docker的es中 docker cp ./elasticsearch-analysis-ik-7.17.5.zip /usr/share/elasticsearch/plugins #3. 创建目录并解压 mkdir ik unzip elasticsearch-analysis-ik-7.17.5.zip -d ik #4. 然后删除压缩包即可 rm -f elasticsearch-analysis-ik-7.17.5.zip
如果网络有问题下载不了可以进行这种方式
重启容器:
docker restart elasticsearch
查看es日志是否有ik信息:
docker logs elasticsearch
① 拉取redis镜像
docker pull redis:6.2.7
② 运行容器
docker run --name kxjredis -p 6379:6379 -d redis:6.2.7 redis-server --appendonly yes
① 拉取canal-server镜像
docker pull canal/canal-server:v1.1.5
② 运行Canal-Server容器
docker run --name kxjcanal -p 11111:11111 --link kxjmysql:kxjmysql -id canal/canal-server:v1.1.5
③ 进入容器修改配置
docker exec -it kxjcanal bash cd ./canal-server/conf/example
修改instance.properties配置文件:
# 从节点ID必须唯一 canal.instance.mysql.slaveId=5 # 数据库的地址 canal.instance.master.address=kxjmysql:3306 # 连接数据库的用户 canal.instance.dbUsername=root # 数据库密码 canal.instance.dbPassword=admin # 字符集 canal.instance.connectionCharset=UTF-8
④ 重启canal-server服务
docker restart kxjcanal
⑤ 进入容器查询canal日志是否正确
cd ./canal-server/logs/example tail -f example.log
① 拉取Canal-Adapter镜像
docker pull slpcat/canal-adapter:v1.1.5
② 运行容器(我需求进行MySQL和ES数据同步,所以link链接了多个容器)
docker run --name canaladapter -p 8081:8081 --link kxjcanal:kxjcanal --link kxjmysql:kxjmysql --link elasticsearch:elasticsearch -d slpcat/canal-adapter:v1.1.5
① 进入容器
docker exec -it canaladapter bash
② 配置application.yml基本信息
cd conf/ vi application.yml
配置的内容:
server: port: 8081 spring: jackson: date-format: yyyy-MM-dd HH:mm:ss time-zone: GMT+8 default-property-inclusion: non_null canal.conf: mode: tcp flatMessage: true syncBatchSize: 1000 retries: 0 consumerProperties: canal.tcp.server.host: kxjcanal:11111 canal.tcp.zookeeper.hosts: canal.tcp.batch.size: 500 canal.tcp.username: canal.tcp.password: srcDataSources: defaultDS: url: jdbc:mysql://kxjmysql:3306/webpagecollect?useUnicode=true username: root password: admin canalAdapters: - instance: example groups: - groupId: g1 outerAdapters: - name: logger - name: es7 hosts: elasticsearch:9200 properties: mode: rest cluster.name: kxjes
cd conf/es7 #复制要配置的文件 cp -v mytest_user.yml kxjes_collect.yml #删除多余的文件 rm -rf biz_order.yml customer.yml mytest_user.yml #修改文件 vi kxjes_collect.ym
配置文件内容:
dataSourceKey: defaultDS destination: example groupId: g1 esMapping: _index: kxjes_collect _id: id _type: _doc upsert: true sql: "SELECT c.id AS id, c.title AS title, c.note AS note, c.url AS url, c.personal AS personal, c.collecteddate AS collecteddate, c.collectedtime AS collectedtime, u.username AS username, u.avater AS avater FROM collect c LEFT JOIN `user` u ON c.userid=u.id" commitBatch: 3000
docker restart canaladapter
查看重启后的系统日志:数据正在同步
Comments | NOTHING
Warning: Undefined variable $return_smiles in /www/wwwroot/wql_luoqin_ltd/wp-content/themes/Sakura/functions.php on line 1109