本项目部分定时任务用nodejs的pm2管理,代码位于后台
CronController
(另一部分在trunk/api/protected/tasks目录,未采用pm2管理)
sudo npm install -g pm2
sudo chmod +x /data/webapps/test-shoes-admin.funfet.com/cli.php
由于服务器环境配置的问题,PHP和PM2都要用sudo,否则redis扩展会读取不到
sudo pm2 list
sudo pm2 info Shoes-UpdateCommentLikeNum
tailf -n 100 ~/.pm2/logs/Shoes-UpdateCommentLikeNum-out.log
sudo pm2 log Shoes-UpdateCommentLikeNum
sudo pm2 restart Shoes-UpdateCommentLikeNum
/home/oujia/.pm2/logs/
安装模块
sudo pm2 install pm2-logrotate
配置分割参数
- pm2 set pm2-logrotate:retain 50
- pm2 set pm2-logrotate:max_size 200M
- pm2 set pm2-logrotate:compress true
- pm2 set pm2-logrotate:workerInterval 5
- pm2 set pm2-logrotate:rotateModule true
- pm2 set pm2-logrotate:rotateInterval 0 0 * * *
- pm2 set pm2-logrotate:dateFormat YYYY-MM-DD_HH-mm-ss
停止日志切割
sudo pm2 stop pm2-logrotate
手动清理日志
pm2 flush
sudo pm2 save
sudo pm2 resurrect
sudo pm2 kill
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aAfterSubjectPost --env=test" --name 'Shoes-AfterSubjectPost'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aupdateSubjectLikeNum --env=test" --name 'Shoes-updateSubjectLikeNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateSubjectCmtNum --env=test" --name 'Shoes-UpdateSubjectCmtNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateSubjectShareNum --env=test" --name 'Shoes-UpdateSubjectShareNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateSubjectPopularity --env=test" --name 'Shoes-UpdateSubjectPopularity'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateSubjectViewNum --env=test" --name 'Shoes-UpdateSubjectViewNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateCommentLikeNum --env=test" --name 'Shoes-UpdateCommentLikeNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateCommentChildNum --env=test" --name 'Shoes-UpdateCommentChildNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateCommentReplyNum --env=test" --name 'Shoes-UpdateCommentReplyNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateCommentShareNum --env=test" --name 'Shoes-UpdateCommentShareNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateCommentPopularity --env=test" --name 'Shoes-UpdateCommentPopularity'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateForumStats --env=test" --name 'Shoes-UpdateForumStats'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateHotSubject --env=test" --name 'Shoes-UpdateHotSubject'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateGameLikeNum --env=test" --name 'Shoes-UpdateGameLikeNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateBlockNum --env=test" --name 'Shoes-UpdateBlockNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aUpdateDailyPlayNum --env=test" --name 'Shoes-UpdateDailyPlayNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aClearNotices --env=test" --name 'Shoes-ClearNotices'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aStatGameuserDurNum --env=test" --name 'Shoes-StatGameuserDurNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aStatJoguserDurNum --env=test" --name 'Shoes-StatJoguserDurNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/test-shoes-admin.funfet.com/cli.php -ccron -aStatForumuserNum --env=test" --name 'Shoes-StatForumuserNum'
PM2安装:
参考:https://github.com/nodesource/distributions/blob/master/README.md#debinstall
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
正式环境部署命令集
PM2部署命令类似于测试环境,把命令里目录的"test-"去掉,并修改环境参数为 --env=form
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aAfterSubjectPost --env=form" --name 'Shoes-AfterSubjectPost'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aupdateSubjectLikeNum --env=form" --name 'Shoes-updateSubjectLikeNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateSubjectCmtNum --env=form" --name 'Shoes-UpdateSubjectCmtNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateSubjectShareNum --env=form" --name 'Shoes-UpdateSubjectShareNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateSubjectPopularity --env=form" --name 'Shoes-UpdateSubjectPopularity'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateSubjectViewNum --env=form" --name 'Shoes-UpdateSubjectViewNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateCommentLikeNum --env=form" --name 'Shoes-UpdateCommentLikeNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateCommentChildNum --env=form" --name 'Shoes-UpdateCommentChildNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateCommentReplyNum --env=form" --name 'Shoes-UpdateCommentReplyNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateCommentShareNum --env=form" --name 'Shoes-UpdateCommentShareNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateCommentPopularity --env=form" --name 'Shoes-UpdateCommentPopularity'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateForumStats --env=form" --name 'Shoes-UpdateForumStats'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateHotSubject --env=form" --name 'Shoes-UpdateHotSubject'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateGameLikeNum --env=form" --name 'Shoes-UpdateGameLikeNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateBlockNum --env=form" --name 'Shoes-UpdateBlockNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aUpdateDailyPlayNum --env=form" --name 'Shoes-UpdateDailyPlayNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aClearNotices --env=form" --name 'Shoes-ClearNotices'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aStatGameuserDurNum --env=form" --name 'Shoes-StatGameuserDurNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aStatJoguserDurNum --env=form" --name 'Shoes-StatJoguserDurNum'
- sudo pm2 start "sudo /usr/local/php/bin/php /data/webapps/shoes-admin.funfet.com/cli.php -ccron -aStatForumuserNum --env=form" --name 'Shoes-StatForumuserNum'
其它优化建议
pm2可以设置 --restart-delay <毫秒数> 来控制进程重启间隔。
这样就可以考虑把部分PHP代码的sleep去掉