Kill掉MySQLd_Safe进程会影响MySQLd进程?


Kill掉MySQLd_Safe进程会影响MySQLd进程?

文章插图
MySQLd_safe 命令启动,kill 父进程(非会话首进程),不会导致子进程退出;重新启动父进程,报错子进程已存在 。可以使用mysqld_safe命令启动 改造mysqld_safe脚本,实现【启、停mysqld_safe进程,不会影响mysqld进程】 。1、背景公司内部看到一则问题
  • ill -9 mysqld_safe 进程
  • systemd 检测到 mysqld_safe 进程不存在后,重新拉起 mysqld_safe 进程
  • mysqld_safe 进程启动后,发现 mysqld 进程也被重启
期望:启、停 mysqld_safe 进程,不会影响 mysqld 进程
2、systemd 服务启动2.1、复现问题1)、查看数据库服务状态
[greatsql@greatsql-1 ~]$ sudo systemctl status db-4306● db-4306.service - db-4306 ServerLoaded: loaded (/usr/lib/systemd/system/db-4306.service; disabled; vendor preset: disabled)Active: active (running) since Wed 2023-07-19 11:15:18 CST; 6h ago MAIn PID: 14917 (mysqld_safe)CGroup: /system.slice/db-4306.service├─14917 /bin/sh /greatsql/svr/greatsql/bin/mysqld_safe --defaults-file=/greatsql/conf/greatsql4306.cnf└─16340 /greatsql/svr/greatsql/bin/mysqld --defaults-file=/greatsql/conf/greatsql4306.cnf --basedir=/greatsql/svr/greatsql --datadir=/greatsql/dbdata/data4306/data -...Jul 19 11:15:18 greatsql-1 systemd[1]: Started db-4306 Server.Jul 19 11:15:19 greatsql-1 mysqld_safe[14917]: mysqld_safe Adding '/greatsql/svr/GreatSQL-8.0.32-24-linux-glibc2.17-x86_64/lib/mysql/libjemalloc.so.1' t...or mysqldJul 19 11:15:19 greatsql-1 mysqld_safe[14917]: 2023-07-19T03:15:19.907338Z mysqld_safe Logging to '/greatsql/logs/error4306.log'.Jul 19 11:15:19 greatsql-1 mysqld_safe[14917]: 2023-07-19T03:15:19.953728Z mysqld_safe Starting mysqld daemon with databases from /greatsql/dbdata/data4306/dataHint: Some lines were ellipsized, use -l to show in full.2)、kill -9 mysqld_safe 进程,并再次查看数据库服务状态
[greatsql@greatsql-1 ~]$ kill -9 14917[greatsql@greatsql-1 ~]$ sudo systemctl status db-4306● db-4306.service - db-4306 ServerLoaded: loaded (/usr/lib/systemd/system/db-4306.service; disabled; vendor preset: disabled)Active: active (running) since Wed 2023-07-19 18:00:33 CST; 43s ago Main PID: 15195 (mysqld_safe)Tasks: 50CGroup: /system.slice/db-4306.service├─15195 /bin/sh /greatsql/svr/greatsql/bin/mysqld_safe --defaults-file=/greatsql/conf/greatsql4306.cnf└─16613 /greatsql/svr/greatsql/bin/mysqld --defaults-file=/greatsql/conf/greatsql4306.cnf --basedir=/greatsql/svr/greatsql --datadir=/greatsql/dbdata/data4306/data -...Jul 19 18:00:33 greatsql-1 systemd[1]: Started db-4306 Server.Jul 19 18:00:34 greatsql-1 mysqld_safe[15195]: mysqld_safe Adding '/greatsql/svr/GreatSQL-8.0.32-24-Linux-glibc2.17-x86_64/lib/mysql/libjemalloc.so.1' t...or mysqldJul 19 18:00:34 greatsql-1 mysqld_safe[15195]: 2023-07-19T10:00:34.640240Z mysqld_safe Logging to '/greatsql/logs/error4306.log'.Jul 19 18:00:34 greatsql-1 mysqld_safe[15195]: 2023-07-19T10:00:34.679333Z mysqld_safe Starting mysqld daemon with databases from /greatsql/dbdata/data4306/dataHint: Some lines were ellipsized, use -l to show in full.确实在 kill -9 mysqld_safe 后,重新拉起了 mysqld_safe 和 mysqld 进程(它们的 PID 和之前不一样) 
3)、查看数据库错误日志
【Kill掉MySQLd_Safe进程会影响MySQLd进程?】2023-07-19T18:00:31.933020+08:00 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.32-24).4)、查看 service 文件
[greatsql@greatsql-1 ~]$ cat /usr/lib/systemd/system/db-4306.service[Unit]Description=db-4306 ServerAfter.NETwork.target[Install]WantedBy=multi-user.target[Service]User=greatsqlGroup=greatsqlType=simpleExecStart=/greatsql/svr/greatsql/bin/mysqld_safe --defaults-file=/greatsql/conf/greatsql4306.cnfRestart=on-failureLimitNOFILE=1024000LimitNPROC=1024000TimeoutStopSec=15PrivateTmp=false2.2、分析原因1)、查看进程信息
[greatsql@greatsql-1 ~]$ ps axj |head -1;ps axj |grep 4306 |grep -v grep PPIDPIDPGIDSID TTYTPGID STATUIDTIME COMMAND1 15195 15195 15195 ?-1 Ss9860:00 /bin/sh /greatsql/svr/greatsql/bin/mysqld_safe --defaults-file=/greatsql/conf/greatsql4306.cnf15195 16613 15195 15195 ?-1 Sl9860:06 /greatsql/svr/greatsql/bin/mysqld --defaults-file=/greatsql/conf/greatsql4306.cnf --basedir=/greatsql/svr/greatsql --datadir=/greatsql/dbdata/data4306/data --plugin-dir=/greatsql/svr/greatsql/lib/plugin --log-error=/greatsql/logs/error4306.log --open-files-limit=65535 --pid-file=/greatsql/dbdata/data4306/data/mysql.pid --socket=/greatsql/dbdata/data4306/data/mysql.sock --port=4306mysqld_safe:PID(进程 ID)=PGID(进程组 ID)=SID(会话 ID),说明它是会话首进程,也是该进程组的组长


推荐阅读