环境: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 root@192.168.0.119:/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
测试两台机子都会执行任务。。
六:开启任务监控
{
"Enable": true,
"To": ["***@qq.com"],
"#HttpAPI": "",
"#Keepalive": "如果此时间段内没有邮件发送,则关闭 SMTP 连接,单位/秒",
"Keepalive": 60,
"#doc": "https://godoc.org/github.com/go-gomail/gomail#Dialer",
"Host": "smtp.163.com",
"Port": 25,
"Username": "***@163.com",
"Password": "***",
"SSL": false,
"#LocalName": "LocalName is the hostname sent to the SMTP server with the HELO command. By default, 'localhost' is sent.",
"LocalName": ""
}
发现配置好mail.json后启动 cronweb 报错:
找了很多原因,换了好几个邮箱,作者说换成163的邮箱也是报错, 然后看源码:
67行:有错误输出, 是因为调用cronsun.NewMail()报错。找了找原因没有找到, 就么有深入找了
然后看到可以HttpApi方法可以跳过错误, 如是使用HTTPAPI方法。
在自己项目里面写了个接口,接收cronsun 请求过来的数据,请求方法为POST
发送的数据格式
[
'Subject' => '', # 邮件titile
'To' => [], # 接受者
'Body' => '', # 内容
]
在接口写个邮件发送就ok 了。