月份:2017年6月

CentOS下用crontab设置自动重启MySQL计划

博客总有机器人发垃圾评论,用了一种验证码插件,不灵,今天换成了CaptchaBank的插件,不知道实际效果如何,测试几天看看结果,帮他们做了下本地化翻译,用wordpress的再用这个插件就有中文版用啦.

服务器上用的MySQL总自动停止工作,没查到原因,干脆建个计划让它自己重生.
是CentOS系统,没有crontab这个计划任务服务,在系统命令行上使用下面这两条命令安装crontabs,第一个vixie-cron主程序包,安装它后,系统一般会自动帮你装好crontabs软件包,即第二条命令可以忽略,具体看是否安装成功再定.

启动,停止crontabs服务和其它服务控制一样:

service crond start //启动服务
service crond stop //关闭服务
service crond restart //重启服务
service crond reload //重新载入配置
service crond status  //查看crond启动状态

用ntsysv命令查看自启动的服务,如果crontab没有自启动,使用下面命令让它自启动:

chkconfig –level 35 crond on

配置crond服务启动计划需要编辑etc目录下的crontab文件内容,直接用Vim编辑它:

vim /etc/crontab

看到默认里面有这些注释,说明了用法,无外乎就是计划的执行时间周期.

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
 # |  .------------- hour (0 - 23)
 # |  |  .---------- day of month (1 - 31)
 # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
 # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,w    ed,thu,fri,sat
 # |  |  |  |  |
 # *  *  *  *  * user-name command to be executed

vim编辑命令不熟的可以搜索一下,不难,添加一行,比如我要每天凌晨2:30自动重启一次mysql就添加下面这样一行:

30 2 * * * root service mysqld restart

保存重启下crontabs就可以了.

系统唤醒后ReportCrash占用CPU过高

打开本子后感觉系统卡顿,看了下时间机器在更新备份,就没在意,备份好了还是卡顿.就看了下Activity Monitor,发现 ReportCrash占了大量CPU,这崩溃报告说明有进程异常崩溃,查了一下系统日志.

$ tail -F /var/log/system.log
Jun  4 10:28:34 Xiaokes-RMBP com.apple.xpc.launchd[1] (com.apple.auditd[19470]): Endpoint has been activated through legacy launch(3) APIs. Please switch to XPC or bootstrap_check_in(): com.apple.auditd
Jun  4 10:28:43 Xiaokes-RMBP com.apple.xpc.launchd[1] (com.alipay.DispatcherService[19480]): Service exited due to signal: Trace/BPT trap: 5 sent by exc handler[0]
Jun  4 10:28:43 Xiaokes-RMBP com.apple.xpc.launchd[1] (com.alipay.DispatcherService): Service only ran for 2 seconds. Pushing respawn out by 8 seconds.
Jun  4 10:28:53 Xiaokes-RMBP com.apple.xpc.launchd[1] (com.alipay.DispatcherService[19487]): Service exited due to signal: Trace/BPT trap: 5 sent by exc handler[0]
Jun  4 10:28:53 Xiaokes-RMBP com.apple.xpc.launchd[1] (com.alipay.DispatcherService): Service only ran for 2 seconds. Pushing respawn out by 8 seconds.
Jun  4 10:29:03 Xiaokes-RMBP com.apple.xpc.launchd[1] (com.alipay.DispatcherService[19498]): Service exited due to signal: Trace/BPT trap: 5 sent by exc handler[0]
Jun  4 10:29:03 Xiaokes-RMBP com.apple.xpc.launchd[1] (com.alipay.DispatcherService): Service only ran for 2 seconds. Pushing respawn out by 8 seconds.
Jun  4 10:29:13 Xiaokes-RMBP com.apple.xpc.launchd[1] (com.alipay.DispatcherService[19505]): Service exited due to signal: Trace/BPT trap: 5 sent by exc handler[0]

alipay?支付宝什么鬼…,回忆了一下,昨天在没有网络的情况下唤醒了本子,wangwang在运行,后来退出了,今天唤醒有网络,究竟为什么这样崩溃,不清楚.直接结束退出ReportCrash进程,不管用,因为进程还在崩溃崩溃就会触发它启动,那干掉它吧,反正没什么用.在termainal里执行:

launchctl unload -w /System/Library/LaunchAgents/com.apple.ReportCrash.plist
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.ReportCrash.Root.plist

注:把unload改为load是重新启用ReportCrash.

搜了一下com.alipay.DispatcherService,网上说是检测新版本什么的,也有说收集用户隐私,把它禁用掉吧,大不了手动检查新版本.同样终端里输入:

sudo launchctl unload /Library/LaunchDaemons/com.alipay.DispatcherService.plist

mac下现在不需要阿里的输入控件了,所以把它全部清除,手动删除下面的这些文件,如果支付宝仍用,再安装也不迟:

sudo rm -rf /Library/Application\ Support/Alipay && rm -rf /Library/LaunchDaemons/com.alipay.DispatcherService.plist && rm -rf ~/Library/LaunchAgents/com.alipay.adaptor.plist && rm -rf ~/Library/LaunchAgents/com.alipay.refresher.plist && rm -rf ~/Library/Internet\ Plug-Ins/aliedit.plugin && rm -rf ~/Library/Internet\ Plug-Ins/npalicdo.plugin

我系统版本是10.12.5,前几天动手给本子换了电池,原来的电池起包了…起包了…