xxl-job集群搭建
[TOC]
xxl-job集群搭建
1.前期准备
- 1.1.mysql节点:创建xxl-job数据库和账号,导入初始化脚本
curl -sL http://iso.sqlfans.cn/linux/xxl-job-tables-2.3.0.sql -o /opt/xxl-job-tables-2.3.0.sql
mysql -uroot -p -S /tmp/mysql_3306.sock -e"CREATE DATABASE IF NOT EXISTS xxl_job DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
mysql -uroot -p -S /tmp/mysql_3306.sock -e"CREATE USER IF NOT EXISTS 'user_xxl_job'@'%' IDENTIFIED BY 'KKi3Vr4aHB_SkmX2';"
mysql -uroot -p -S /tmp/mysql_3306.sock -e"GRANT ALL PRIVILEGES ON xxl_job.* TO 'user_xxl_job'@'%';"
mysql -uroot -p -S /tmp/mysql_3306.sock -e"FLUSH PRIVILEGES;"
mysql -uroot -p -S /tmp/mysql_3306.sock xxl_job -e"source /opt/xxl-job-tables-2.3.0.sql;"
- 1.2.所有节点:安装 jdk 1.8.0_391
curl -sL http://iso.sqlfans.cn/jdk/install_jdk_8u391.sh | bash
source /etc/bashrc
java -version
2.搭建xxl-job集群
- 2.1.所有节点:下载 xxl-job 2.3.0
mkdir -p /data/xxljob_7777/{conf,logs}
curl -L http://iso.sqlfans.cn/linux/xxl-job-admin-2.3.0.jar -o /data/xxljob_7777/xxl-job-admin-2.3.0.jar
- 2.2.所有节点:修改配置文件,主要修改 mysql的ip、库名、账号及密码,示例 mysql的ip为
10.30.3.234
curl -sL http://iso.sqlfans.cn/linux/xxl-job-application-2.3.0.properties -o /data/xxljob_7777/conf/application-xxl-job.properties
sed -i "s/127.0.0.1:3306/10.30.3.234:3306/" /data/xxljob_7777/conf/application-xxl-job.properties
sed -i "s/xxl_job_db/xxl_job/" /data/xxljob_7777/conf/application-xxl-job.properties
sed -i 's/^spring.datasource.username.*$/spring.datasource.username=user_xxl_job/g' /data/xxljob_7777/conf/application-xxl-job.properties
sed -i 's/^spring.datasource.password.*$/spring.datasource.password=KKi3Vr4aHB_SkmX2/g' /data/xxljob_7777/conf/application-xxl-job.properties
cat /data/xxljob_7777/conf/application-xxl-job.properties | egrep "(server.port|datasource.url|datasource.username|datasource.password|host)"
- 2.3.所有节点:配置启停脚本
curl -sL http://iso.sqlfans.cn/linux/xxl-job-start-2.3.0.sh -o /data/xxljob_7777/start.sh
chmod +x /data/xxljob_7777/start.sh
cat /data/xxljob_7777/start.sh | grep -n ^[^#]
- 2.4.所有节点:启动 xxl-job
cd /data/xxljob_7777/
sh start.sh
sleep 10 && netstat -lnpt | grep 7777
#.以appadmin用户启动
# groupadd appadmin
# useradd appadmin -g appadmin -d /home/appadmin -s /bin/bash
# echo 'Admin_147' | passwd appadmin --stdin
# cat /etc/sudoers | grep appadmin || echo "appadmin ALL=NOPASSWD:ALL" >> /etc/sudoers
# chown -R appadmin.appadmin /data/xxljob_7777
# su - appadmin -c "cd /data/xxljob_7777 && sh start.sh" > /dev/null
- 2.5.任意节点:登录 xxl-job 页面控制台,示例
10.30.3.231
比如:http://10.30.3.231:7777/xxl-job-admin
账号:admin
密码:123456
- 2.6.所有节点:加入开机启动
cat /etc/rc.local | grep xxljob_7777 || echo "cd /data/xxljob_7777 && sh start.sh" >> /etc/rc.local
遇到的问题
场景1:如何彻底卸载xxl-job
- 所有节点:杀掉进程、删除目录、清除开机启动
cd /opt/
ps -ef | grep "xxl-job" | grep -v grep | awk '{print $2}' | xargs kill -9 2> /dev/null
rm -rf /data/xxljob_7777
sed -i '/xxljob_7777/d' /etc/rc.local
- mysql节点:删库、删账号
mysql -uroot -p -S /tmp/mysql_3306.sock -e"drop database if exists xxl_job;"
mysql -uroot -p -S /tmp/mysql_3306.sock -e"drop user 'user_xxl_job'@'%';"