1.首先创建用户名和密码,并给予权限
SHOW VARIABLES LIKE '%binlog%';
CREATE DATABASE maxwell;
##SET GLOBAL validate_password_length=4;
##SET GLOBAL validate_password_policy=0;
CREATE USER 'maxwell'@'%' IDENTIFIED BY 'maxwell';
GRANT ALL ON maxwell.* TO 'maxwell'@'%';
GRANT SELECT, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO 'maxwell'@'%';
GRANT ALL PRIVILEGES ON test.* TO 'maxwell'@'%' IDENTIFIED BY 'maxwell';
GRANT SELECT,REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO 'maxwell'@'%' IDENTIFIED BY 'maxwell'
GRANT ALL PRIVILEGES ON maxwell.* TO 'maxwell'@'%' IDENTIFIED BY 'maxwell';
FLUSH PRIVILEGES;
2.编写脚本mxw.sh,并赋予执行权限
3.脚本内容
#!/bin/bash
if [ $# -lt 1 ]
then
echo "参数不能为空!!!"
exit ;
fi
#MAXWELL_HOME=/opt/module/maxwell
status_maxwell(){
result=`ps -ef | grep com.zendesk.maxwell.Maxwell | grep -v grep | wc -l`
return $result
}
start_maxwell(){
status_maxwell
if [[ $? -lt 1 ]]; then
echo "启动Maxwell"
#$MAXWELL_HOME/bin/maxwell --config $MAXWELL_HOME/config.properties --daemon
#注意这里的ip、Maxwell启动路径和输出路径
nohup /usr/local/mysql/module/maxwell/maxwell-1.29.2/bin/maxwell --user='maxwell' --password='maxwell' --host='xxx.xx.xxx.x' --producer=stdout > /usr/local/mysql/module/maxwell/BinlogChangeFile/output_file20240126.txt 2>&1 &
else
echo "Maxwell正在运行"
fi
}
stop_maxwell(){
status_maxwell
if [[ $? -gt 0 ]]; then
echo "停止Maxwell"
ps -ef | grep com.zendesk.maxwell.Maxwell | grep -v grep | awk '{print $2}' | xargs kill -9
else
echo "Maxwell未在运行"
fi
}
case $1 in
start )
start_maxwell
;;
status )
#echo =============== 1代表maxwell正在运行 0是未在运行 ===============
#ps -ef | grep com.zendesk.maxwell.Maxwell | grep -v grep | wc -l
# 执行命令,并将结果赋给变量
result=$(ps -ef | grep com.zendesk.maxwell.Maxwell | grep -v grep | wc -l)
# 检查结果,并输出相应信息
if [ $result -eq 1 ]; then
echo "maxwell正在运行"
else
echo "maxwell未在运行"
fi
;;
stop )
stop_maxwell
;;
restart )
stop_maxwell
start_maxwell
;;
esac