环境:centos7
安装包:
cronsun
wget https://github.com/shunfei/cronsun/releases/download/v0.3.5/cronsun-v0.3.5-linux-amd64.zip (unzip解压)
mongodb
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.2.tgz (tar -xzvf 解压)
etcd
wget https://github.com/etcd-io/etcd/releases/download/v3.3.13/etcd-v3.3.13-linux-amd64.tar.gz (tar -xzvf 解压)
下载完解压到 /opt
一, mongodb 启动
$ cd /opt/mongodb-v4.0.2
$ mkdir -p data/db
$mkdir logs
$touch mongodb.conf
$vim mongodb.com
dbpath=/opt/mongodb-v4.0.2/data/db
logpath=/opt/mongodb-v4.0.2/logs/mongo.log
bind_ip=0.0.0.0 #默认是127.0.0.1, 多节点需要允许其他的ip连接, 所有配置为0.0.0.0,允许其他ip连接
logappend=true
fork=true
port=27017
$nohup bin/mongod -f mongodb.conf > /dev/null 2>&1 &
二,etcd
$nohup ./etcd --advertise-client-urls=http://0.0.0.0:2379 --listen-client-urls=http://0.0.0.0:2379 --data-dir=/opt/etcd-v3.3.13/data >/dev/null 2>&1 &
注意:默认监听地址是127.0.0.1,允许远程连接需要改为0.0.0.0
三:cronsun
$cd /opt/ cronsun-v0.3.5
$nohup ./cronweb -conf conf/base.json > /dev/null 2>&1 &
$nohup ./cronnode -conf conf/base.json > /dev/null 2>&1 &
到此单节点任务系统就可以了 访问 http://ip:7079
四, 添加节点,
在需添加的节点执行scp命令, 把cronsun包拷贝过去
$scp -r [email protected]:/opt/cronsun-v0.3.5 /opt
$vim /opt/cronsun-v0.3.5/conf/db.json
"Hosts": [
"192.168.0.119:27017" # 这里改为mongodb监听的ip和端口
],
$vim /opt//cronsun-v0.3.5/conf/etcd.json
"Endpoints":[
"http://192.168.0.119:2379" # 这里改为etcd监听的ip和端口
],
$nohup ./cronnode -conf conf/base.json > /dev/null 2>&1 &
再打开 http://ip:7079 刷新页面 , 会发现增加节点了。。
五,测试
在两个节点写个测试shell
192.168.0.119
$cd /root
$vim test.sh
#!/bin/sh
echo '11aa' >> /root/cronsun.txt
echo '119-SUCCESS'
$chmod 777 test.sh
192.168.0.106
$cd /root
$vim test.sh
#!/bin/sh
echo '22bb' >> /root/cronsun.txt
echo '106-SUCCESS'
$chmod 777 test.sh
测试两台机子都会执行任务。。