canal系列—Linux下的安装配置(快速开始)

x33g5p2x  于2021-12-24 转载在 其他  
字(3.9k)|赞(0)|评价(0)|浏览(733)
零、环境准备
1、canal的原理是基于mysql binlog技术,所以这里一定需要开启mysql的binlog写入功能,建议配置binlog模式为row
[mysqld]
log-bin=mysql-bin #添加这一行就ok
binlog-format=ROW #选择row模式
server_id=129 #配置mysql replaction需要定义,不能和canal的slaveId重复
2、canal的原理是模拟自己为mysql slave,所以这里一定需要做为mysql slave的相关权限
[root@localhost /]# /usr/local/mysql/bin/mysql -uroot -p888888

mysql> CREATE USER canal IDENTIFIED BY 'canal';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.05 sec)

注:授于所有权限:GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%' ;

一、下载并解压 canal

这里我们使用旧一些版本的,新版本总是会有一些问题。

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget https://github.com/alibaba/canal/releases/download/canal-1.0.19/canal.deployer-1.0.19.tar.gz

[root@localhost src]# mkdir /usr/local/canal
[root@localhost src]# tar zxvf canal.deployer-1.0.19.tar.gz -C /usr/local/canal/

解压完成后,进入 /usr/local/canal 目录,可以看到如下结构:

[root@localhost src]# cd ..
[root@localhost local]# cd canal/
[root@localhost canal]# ll
总用量 4
drwxr-xr-x 2 root root   58 12月 12 13:47 bin
drwxr-xr-x 4 root root   78 12月 12 13:47 conf
drwxr-xr-x 2 root root 4096 12月 12 13:47 lib
drwxrwxrwx 2 root root    6 12月  4 15:09 logs
二、配置修改
[root@localhost canal]# vim conf/example/instance.properties
1、mysql serverId,改成唯一的
#################################################
## mysql serverId
canal.instance.mysql.slaveId = 129
2、position info,需要改成自己的数据库信息
# position info
canal.instance.master.address=192.168.134.129:3306
canal.instance.master.journal.name=
canal.instance.master.position=
canal.instance.master.timestamp=

#canal.instance.standby.address =
#canal.instance.standby.journal.name =
#canal.instance.standby.position = 
#canal.instance.standby.timestamp =
3、username/password,需要改成自己的数据库信息
# username/password
canal.instance.dbUsername=canal
canal.instance.dbPassword=canal
canal.instance.defaultDatabaseName=test
canal.instance.connectionCharset=UTF-8
4、table regex
# table regex
canal.instance.filter.regex=.*\\..*
5、修改 conf/canal.properties 文件

将 canal.ip 改成canal所在机器的ip地址,避免无谓的问题

canal.id= 128
canal.ip=192.168.134.128
canal.port= 11111

说明:canal.instance.connectionCharset 代表数据库的编码方式对应到java中的编码类型,比如UTF-8,GBK , ISO-8859-1

三、准备启动
[root@localhost canal]# ./bin/startup.sh

几点注意:

  • linux启动完成后,会在bin目录下生成canal.pid,stop.sh会读取canal.pid进行进程关闭;
  • startup.sh默认读取系统环境变量中的which java获得JAVA执行路径,需要设置PATH=$JAVA_HOME/bin环境变量。
四、查看日志
[root@localhost canal]# vim logs/canal/canal.log

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=96m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
2017-12-13 09:22:52.782 [main] INFO  com.alibaba.otter.canal.deployer.CanalLauncher - ## start the canal server.
2017-12-13 09:22:53.177 [main] INFO  com.alibaba.otter.canal.deployer.CanalController - ## start the canal server[192.168.134.128:11111]
2017-12-13 09:22:54.864 [main] INFO  com.alibaba.otter.canal.deployer.CanalLauncher - ## the canal server is running now ......

具体instance的日志:

[root@localhost canal]# vim logs/example/example.log

2017-12-13 09:22:53.931 [main] INFO  c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [canal.properties]
2017-12-13 09:22:53.937 [main] INFO  c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [example/instance.properties]
2017-12-13 09:22:54.164 [main] WARN  org.springframework.beans.TypeConverterDelegate - PropertyEditor [com.sun.beans.editors.EnumEditor] found through deprecated global PropertyEditorManager fallback - consider using a more isolated form of registration, e.g. on the BeanWrapper/BeanFactory!
2017-12-13 09:22:54.462 [main] INFO  c.a.otter.canal.instance.spring.CanalInstanceWithSpring - start CannalInstance for 1-example
2017-12-13 09:22:54.513 [main] INFO  c.a.otter.canal.instance.spring.CanalInstanceWithSpring - start successful....
五、关闭
[root@localhost canal]# ./bin/stop.sh 
localhost.localdomain: stopping canal 6237 ... 
Oook! cost:1

相关文章