mysql安装完后一般会注册为服务,使用service来管理启动、关闭,虽然很好用,但是没法在进程挂掉后自动重启。
Supervisor可以解决这个烦恼。下面是配置步骤。
1、进入到Supervisor的配置目录,在 /etc/supervisord.conf 的配置文件中有指定的。添加mysql的配置文件
vim mysql.conf
[program:mysql]
command=/usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
;directory= ; 执行前要不要先cd到目录去,一般不用
priority=1 ;数字越高,优先级越高
numprocs=1 ; 启动几个进程
autostart=true ; 随着supervisord的启动而启动
autorestart=true ; 自动重启。。当然要选上了
startretries=10 ; 启动失败时的最多重试次数
exitcodes=0 ; 正常退出代码
stopsignal=KILL ; 用来杀死进程的信号
stopwaitsecs=10 ; 发送SIGKILL前的等待时间
redirect_stderr=true ; 重定向stderr到stdout
stdout_logfile_maxbytes = 1024MB
stdout_logfile_backups = 10
stdout_logfile = /var/run/log/mysql.log
重新启动
ps -aux|grep supervisor
sudo kill -9 xxxx
supervisord -c /etc/supervisord.conf