简介
canal是一款 开源 项目,纯Java开发。基于 数据库 增量日志解析,提供增量数据订阅和消费,目前主要支持了MySQL(也支持mariaDB)。
配置安装流程
1.配置安装环境
1)安装wget工具。
yum install wget -y
2)安装JDK。
yum install java-1.8.0-openjdk
3)配置环境变量。
echo “export JAVA_HOME=/usr/lib/jvm/java-1.8.0”>> /etc/profile && source /etc/profile
4)配置MySQL为“binlog”同步模式。
修改MySQL的配置文件“/etc/my.cnf”,添加如下内容:
log-bin=mysql-bin
binlog-format=ROW
server_id=1
5)修改完后,重启MySQL即可。
MySQL的安装请参考鲲鹏社区关于MySQL的安装使用教程。
----结束
2.获取软件包
1)下载canal软件包。
wget https://github.com/alibaba/canal/releases/download/canal-1.1.3/canal.deployer-1.1.3.tar.gz
2)复制至 云服务器 的“/usr/local/src”目录。
----结束
3.安装
1)解压软件包。
mkdir /usr/local/canal
tar -xvf canal.deployer-1.1.3.tar.gz -C /usr/local/canal
2)进入“/usr/local/canal”目录下。
cd /usr/local/canal
3)修改“instance.properties”文件。
vim conf/example/instance.properties
内容如下:
## mysql serverId
canal.instance.mysql.slaveId = 1
...
# position info
canal.instance.master.address = 127.0.0.1:3306
...
# username/password
canal.instance.dbUsername = root
canal.instance.dbPassword = [password]
canal.instance.connectionCharset = UTF-8
4)修改“canal.properties”文件。
vim conf/canal.properties
内容如下:
canal.id = 2
canal.ip = 127.0.0.1
canal.port = 11111
----结束
4. 运行和验证
1)启动canal。
sh /usr/local/canal/bin/startup.sh
2)查看进程是否存在。
ps -ef|grep canal
系统回显如下,表示进程已启动,运行正常。
root 1793 808 0 15:03 pts/2 00:00:00 grep --color=auto canal
root 27516 1 0 10:39 ? 00:00:17 /usr/lib/jvm/java-1.8.0/bin/java -server -Xms2048m -Xmx3072m -Xmn1024m -XX:SurvivorRatio=2 -XX:PermSize=96m -XX:MaxPermSize=256m -Xss
512k -XX:-UseAdaptiveSizePolicy -XX:MaxTenuringThreshold=15 -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:+UseF
astAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8 -DappName=otter-
canal -Dlogback.configurationFile=/usr/local/canal/bin/../conf/logback.xml -Dcanal.conf=/usr/local/canal/bin/../conf/canal.properties -classpath .:/usr/local/canal/bin/../conf:/usr/
local/canal/bin/../lib/ zookeeper -3.4.5.jar:/usr/local/canal/bin/../lib/zkclient-0.10.jar:/usr/local/canal/bin/../lib/spring-tx-3.2.18.RELEASE.jar:/usr/local/canal/bin/../lib/spring-
orm-3.2.18.RELEASE.jar:/usr/local/canal/bin/../lib/spring-jdbc-3.2.18.RELEASE.jar:/usr/local/canal/bin/../lib/spring-expression-3.2.18.RELEASE.jar:/usr/local/canal/bin/../lib/spring
-core-3.2.18.RELEASE.jar:/usr/local/canal/bin/../lib/spring-context-3.2.18.RELEASE.jar:/usr/local/canal/bin/../lib/spring-beans-3.2.18.RELEASE.jar:/usr/local/canal/bin/../lib/spring
-aop-3.2.18.RELEASE.jar:/usr/local/canal/bin/../lib/snappy-java-1.1.7.1.jar:/usr/local/canal/bin/../lib/slf4j-api-1.7.12.jar:/usr/local/canal/bin/../lib/simpleclient_pushgateway-0.4
.0.jar:/usr/local/canal/bin/../lib/simpleclient_httpserver-0.4.0.jar:/usr/local/canal/bin/../lib/simpleclient_hotspot-0.4.0.jar:/usr/local/canal/bin/../lib/simpleclient_common-0.4.0
.jar:/usr/local/canal/bin/../lib/simpleclient-0.4.0.jar:/usr/local/canal/bin/../lib/scala-reflect-2.11.12.jar:/usr/local/canal/bin/../lib/scala-logging_2.11-3.8.0.jar:/usr/local/can
al/bin/../lib/scala-library-2.11.12.jar:/usr/local/canal/bin/../lib/rocketmq-remoting-4.3.0.jar:/usr/local/canal/bin/../lib/rocketmq-logging-4.3.0.jar:/usr/
5.故障排除
现象描述
运行过程中提示“The stack size specified is too small, Specify at least 328k”。
可能原因
jvm的内存栈太小,导致启动不了canal。
处理步骤
1)增大内存栈,修改“/usr/local/canal/bin/startup.sh”,修改成如下加粗内容,将“256”改成了“512”。
if [ -n "$str" ]; then
JAVA_OPTS="-server -Xms2048m -Xmx3072m -Xmn1024m -XX:SurvivorRatio=2 -XX:PermSize=96m -XX:MaxPermSize=256m -Xss512k -XX:-UseAdaptiveSizePolicy -XX:MaxTenuringThreshold=15 -X
X:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:+Hea
pDumpOnOutOfMemoryError"
else
JAVA_OPTS="-server -Xms1024m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:MaxPermSize=128m "
fi
2)重启canal。
sh stop.sh
sh startup.sh
----结束