Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql Docker,具有独立的基于文件的日志文件和日志旋转_Mysql_Docker_Logrotate - Fatal编程技术网

mysql Docker,具有独立的基于文件的日志文件和日志旋转

mysql Docker,具有独立的基于文件的日志文件和日志旋转,mysql,docker,logrotate,Mysql,Docker,Logrotate,因此,我启动了一个mysql Docker并运行了3个日志文件(general、error、slow query log),它们被写入/var/log/mysql/(mysql容器内的路径),实际上是Docker主机上的一个目录(名为“log”),并作为Docker-compose.yml中指定的卷装入容器 我们选择了这种方式,因为我们不希望在标准输出上合并常规和慢速的查询日志,我们更喜欢每天轮换3个单独的日志文件,因为找到4天前发布的某个查询对我们来说似乎更舒服 由于mysql Docker(

因此,我启动了一个mysql Docker并运行了3个日志文件(general、error、slow query log),它们被写入/var/log/mysql/(mysql容器内的路径),实际上是Docker主机上的一个目录(名为“log”),并作为Docker-compose.yml中指定的卷装入容器

我们选择了这种方式,因为我们不希望在标准输出上合并常规和慢速的查询日志,我们更喜欢每天轮换3个单独的日志文件,因为找到4天前发布的某个查询对我们来说似乎更舒服

由于mysql Docker(afaik)不附带logrotate和/或cron,我们决定在Docker-compose.yml中提供另一个名为logrotator的服务,该服务在其入口点启动cron,然后使用给定的logrotate.conf定期运行logrotate。“log”目录也被装载到logrotator容器中,因此它可以在mysql日志文件上执行它的旋转工作

现在看来,mysql在每次旋转后都需要“mysqladmin flush logs”来开始写入新的文件描述符,但logrotator容器无法在mysql容器内发出此命令

简而言之(呃):我确信有更好的方法通过日志循环来完成单独的日志文件。怎么做?任何想法都非常感谢。谢谢

更新:


由于我们现在使用的是mysql 5.7,因此可能无法通过@buaacss提出的解决方案解决问题(这可能绝对有效),因此我们决定使用“cron”容器。此外,我们在cron容器中安装了docker.io,并将docker主机的/var/run/docker.sock安装到cron容器中。这允许我们使用“docker exec”从cron容器发出命令(在本例中为“mysqladmin flush logs”),以便在mysql容器中执行。问题已解决。

您确实可以使用SIGHUP而不是基于doc的
刷新日志
语句

但可能会产生一些不期望的影响,即将大量报告信息写入错误日志

所以,正如我在评论中提到的,他们开发了一个轻版本的SIGHUP,即SIGUSR1来完成下面的功能

FR1: When SIGUSR1 is sent to the server, it must flush the error log.

FR2: When SIGUSR1 is sent to the server, it must flush the general log.

FR3: When SIGUSR1 is sent to the server, it must flush the slow query log.

FR4: SIGUSR1 must not send MySQL status report. 
Currently when SIGHUP is sent to the server a large report of information is 
printed to stdout, the status report. 

FR5: The server must not fail when SIGUSR1 is sent, even though slow log is not 
enabled.

FR6: The server must not fail when SIGUSR1 is sent, even though slow log output 
is set to a table (log_output).

FR7: The server must not fail when SIGUSR1 is sent, even though general log is 
set to OFF.

NFR1: SIGALRM must be undisguisable from how SIGUSR1 behaved before. 

不幸的是,这种信号仅在MySQL 8或更高版本中可用

您确实可以使用SIGHUP而不是基于doc的
刷新日志
语句

但可能会产生一些不期望的影响,即将大量报告信息写入错误日志

所以,正如我在评论中提到的,他们开发了一个轻版本的SIGHUP,即SIGUSR1来完成下面的功能

FR1: When SIGUSR1 is sent to the server, it must flush the error log.

FR2: When SIGUSR1 is sent to the server, it must flush the general log.

FR3: When SIGUSR1 is sent to the server, it must flush the slow query log.

FR4: SIGUSR1 must not send MySQL status report. 
Currently when SIGHUP is sent to the server a large report of information is 
printed to stdout, the status report. 

FR5: The server must not fail when SIGUSR1 is sent, even though slow log is not 
enabled.

FR6: The server must not fail when SIGUSR1 is sent, even though slow log output 
is set to a table (log_output).

FR7: The server must not fail when SIGUSR1 is sent, even though general log is 
set to OFF.

NFR1: SIGALRM must be undisguisable from how SIGUSR1 behaved before. 

不幸的是,这种信号仅在MySQL 8或更高版本中可用

如何在同一进程名称空间中运行两个容器,并在不使用mysqladmin的情况下直接发送信号?例如,使用sighup或sigusr1如何在同一进程名称空间中运行两个容器,并在不使用mysqladmin的情况下直接发送信号?例如,使用sighup或sigusr1