一、前期准备
1.1、MySQL安装与配置
(1) 安装mysql
详情见《MySQL-5.7.31的搭建》
(2) my.cnf配置
要先开启 Binlog 写入功能,配置 binlog-format 为 ROW 模式,请确保my.cnf 中有配置如下:
[mysqld]
log-bin=mysql-bin #开启 binlog
binlog-format=ROW #选择 ROW 模式
server_id=1 #配置 MySQL replaction 需要定义,不要和 canal 的 slaveId 重复
##注意:如果my.cnf文件中有 explicit_defaults_for_timestamp = 1 这个配置项,需要注释掉然后重启mysql,不然后面canal-admin里会报错
(3) 新建账号及授权
安装好mysql后,需要新建一个账号,授权 canal 链接 MySQL 账号具有作为 MySQL slave 的权限
> CREATE USER canal IDENTIFIED BY 'canal';
> GRANT SELECT, INSERT, UPDATE, DELETE, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
> FLUSH PRIVILEGES;
1.2、安装JDK
#自行下载安装包
jdk-8u261-linux-x64.tar.gz
#解压
mkdir /usr/local/soft && cd /usr/local/soft
tar -xf jdk-8u261-linux-x64.tar.gz -C /usr/local/soft
#配置环境变量
vim /etc/profile
##添加以下内容
export JAVA_HOME=/usr/local/soft/jdk1.8.0_261
export PATH=$JAVA_HOME/bin/:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPAT
#使环境变量生效
source /etc/profile
#验证java版本
java -version
1.3、安装zookeeper
#下载安装包
wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz
#解压
cd /usr/local/soft
tar -xf apache-zookeeper-3.6.3-bin.tar.gz
mv apache-zookeeper-3.6.3-bin zookeeper
#创建data和logs目录
cd zookeeper
mkdir {data,logs}
#修改配置文件
cp /usr/loca/soft/zookeeper/conf/zoo_sample.cfg /usr/loca/soft/zookeeper/conf/zoo.cfg
vim /usr/loca/soft/zookeeper/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/soft/zookeeper/data
dataLogDir=/usr/local/soft/zookeeper/logs
clientPort=2181
#启动
cd /usr/loca/soft/zookeeper
./bin/zkServer.sh start
#查看状态
./bin/zkServer.sh status
#停止
./bin/zkServer.sh stop
#重启
./bin/zkServer.sh restart
1.4、安装zk ui (选装)
(1) 安装maven
#下载安装包
cd /usr/local/soft
wget https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
#解压
tar -xf apache-maven-3.6.3-bin.tar.gz
#配置环境变量
vim /etc/profile
export MAVEN_HOME=/usr/local/soft/apache-maven-3.6.3
export PATH=$MAVEN_HOME/bin:$PATH
#使配置文件生效
source /etc/profile
#查看版本
mvn -version
(2) 安装zk ui
#拉取代码
cd /usr/local/soft
git clone https://github.com/DeemOpen/zkui.git
#编译安装
cd /usr/local/soft/zkui
mvn clean install
#修改配置文件默认值
vim config.cfg
serverPort=9090 #指定端口
zkServer=192.168.80.27:2181 #zookeeper地址
sessionTimeout=300000
#启动程序至后台
nohup java -jar target/zkui-2.0-SNAPSHOT-jar-with-dependencies.jar &
#浏览器访问
http://IP:9090
二、canal 安装
2.1、canal admin安装
(1) 下载安装包
mkdir -pv /usr/local/soft/canaladmin
cd /usr/local/soft
wget https://github.com/alibaba/canal/releases/download/canal-1.1.4/canal.admin-1.1.4.tar.gz
(2) 解压
tar -xf canal.admin-1.1.4.tar.gz -C /usr/local/soft/canaladmin
(3) 配置修改
cd canaladmin/
vim conf/application.yml
server:
port: 8089
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
spring.datasource:
address: 127.0.0.1:3306 #mysql连接地址,安装了mysql数据库的那台主机
database: canal_manager #数据库名称
username: canal #数据库用户
password: canal #数据库密码
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://${spring.datasource.address}/${spring.datasource.database}?useUnicode=true&characterEncoding=UTF-8&useSSL=false
hikari:
maximum-pool-size: 30
minimum-idle: 1
canal:
adminUser: admin
adminPasswd: admin
(4) 初始化元数据库
#连接数据库
mysql -h 192.168.80.7 -u ktp_admin -p
#登录msyql后,导入初始化sql
source conf/canal_manager.sql
##注意使用具有远程功能的用户登录执行,或者将canal_manager.sql拷贝至mysql所在主机用root用户登录执行导入,或者使用第三方工具进行导入
(5) 启动
#启动
./bin/startup.sh
#查看日志
vi logs/admin.log
#关闭
./bin/stop.sh
2.2、canal server安装
(1) 下载安装包
mkdir -pv /usr/local/soft/canalserver
cd /usr/local/soft
wget https://github.com/alibaba/canal/releases/download/canal-1.1.4/canal.deployer-1.1.4.tar.gz
(2) 解压
tar -xf canal.deployer-1.1.4.tar.gz -C /usr/local/soft/canalserver/
(3) 配置修改
vim canalserver/conf/canal_local.properties
# register ip
canal.register.ip = 192.168.80.27 #canal server注册IP
# canal admin config
canal.admin.manager = 127.0.0.1:8089
canal.admin.port = 11110
canal.admin.user = admin
canal.admin.passwd = 4ACFE3202A5FF5CF467898FC58AAB1D615029441
# admin auto register
canal.admin.register.auto = true
canal.admin.register.cluster = ktp_canal #可以指定默认注册的集群名,如果不指定,默认注册为单机模式
#目前conf下会包含canal.properties/canal_local.properties两个文件,考虑历史版本兼容性,默认配置会以canal.properties为主,因为要启动为对接canal-admin模式,可以使用canal_local.properties文件覆盖canal.properties文件
cp canalserver/conf/canal.properties canalserver/conf/canal.properties_bak
cp canalserver/conf/canal_local.properties canalserver/conf/canal.properties
(4) 启动
#启动
./bin/startup.sh
#查看server日志
vi logs/canal/canal.log
#关闭
./bin/stop.sh
(5) 浏览器访问 http://IP:8089 ,默认密码:admin/123456