我正在一个码头容器内运行两个进程,一个是Nginx服务器,一个是PHP,它有监督and,但它只是继续以状态1(意外)退出。
这是原木
2016-12-09 21:37:35,529 CRIT Supervisor running as root (no user in config file)
2016-12-09 21:37:35,596 INFO RPC interface 'supervisor' initialized
2016-12-09 21:37:35,598 INFO supervisord started with pid 1
2016-12-09 21:37:36,602 INFO spawned: 'nginx' with pid 7
2016-12-09 21:37:36,606 INFO spawned: 'php-fpm' with pid 8
2016-12-09 21:37:36,671 INFO exited: nginx (exit status 1; not expected)
2016-12-09 21:37:36,722 INFO exited: php-fpm (exit status 1; not expected)
2016-12-09 21:37:37,727 INFO spawned: 'nginx' with pid 20
2016-12-09 21:37:37,737 INFO spawned: 'php-fpm' with pid 21
2016-12-09 21:37:37,801 INFO exited: nginx (exit status 1; not expected)
2016-12-09 21:37:37,848 INFO exited: php-fpm (exit status 1; not expected)
2016-12-09 21:37:39,856 INFO spawned: 'nginx' with pid 33
2016-12-09 21:37:39,863 INFO spawned: 'php-fpm' with pid 34
2016-12-09 21:37:39,917 INFO exited: nginx (exit status 1; not expected)
2016-12-09 21:37:39,997 INFO exited: php-fpm (exit status 1; not expected)
2016-12-09 21:37:43,007 INFO spawned: 'nginx' with pid 46
2016-12-09 21:37:43,011 INFO spawned: 'php-fpm' with pid 47
2016-12-09 21:37:43,071 INFO exited: nginx (exit status 1; not expected)
2016-12-09 21:37:43,072 INFO gave up: nginx entered FATAL state, too many start retries too quickly
2016-12-09 21:37:43,130 INFO exited: php-fpm (exit status 1; not expected)
2016-12-09 21:37:43,132 INFO gave up: php-fpm entered FATAL state, too many start retries too quickly我在Nginx和PHPFPM中都添加了守护进程,但是它在这里仍然不能工作,这就是Nginx.conf。
user nginx;
daemon off;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 120;
gzip on;
include /etc/nginx/conf.d/*.conf;
}此外,我还运行了以下命令,以便在PHP中关闭守护进程。
RUN sed -i 's/;daemonize = yes/daemonize = no/g' /usr/local/php-7.0.12/etc/php-fpm.conf这是我的supervisord.conf文件
[supervisord]
nodaemon=true
[program:nginx]
command: service nginx start
[program:php-fpm]
command: service php-fpm start
[supervisorctl]
serverurl=http://localhost:8091
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[inet_http_server]
port = 8091有人能指导我如何在码头集装箱的监督管理中运行这些过程吗?
码头集装箱日志
/usr/lib/python2.7/site-packages/supervisor-3.3.1-py2.7.egg/supervisor/options.py:298: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
'Supervisord is running as root and it is searching '
2016-12-09 22:06:43,939 CRIT Supervisor running as root (no user in config file)
2016-12-09 22:06:43,992 INFO RPC interface 'supervisor' initialized
2016-12-09 22:06:43,994 INFO supervisord started with pid 1
2016-12-09 22:06:44,999 INFO spawned: 'nginx' with pid 8
2016-12-09 22:06:45,003 INFO spawned: 'php-fpm' with pid 9
2016-12-09 22:06:45,065 INFO exited: nginx (exit status 1; not expected)
2016-12-09 22:06:45,124 INFO exited: php-fpm (exit status 1; not expected)
2016-12-09 22:06:46,131 INFO spawned: 'nginx' with pid 21
2016-12-09 22:06:46,138 INFO spawned: 'php-fpm' with pid 22
2016-12-09 22:06:46,223 INFO exited: nginx (exit status 1; not expected)
2016-12-09 22:06:46,275 INFO exited: php-fpm (exit status 1; not expected)
2016-12-09 22:06:48,282 INFO spawned: 'nginx' with pid 34
2016-12-09 22:06:48,288 INFO spawned: 'php-fpm' with pid 35
2016-12-09 22:06:48,346 INFO exited: nginx (exit status 1; not expected)
2016-12-09 22:06:48,426 INFO exited: php-fpm (exit status 1; not expected)
2016-12-09 22:06:51,435 INFO spawned: 'nginx' with pid 47
2016-12-09 22:06:51,443 INFO spawned: 'php-fpm' with pid 48
2016-12-09 22:06:51,526 INFO exited: nginx (exit status 1; not expected)
2016-12-09 22:06:51,528 INFO gave up: nginx entered FATAL state, too many start retries too quickly
2016-12-09 22:06:51,555 INFO exited: php-fpm (exit status 1; not expected)
2016-12-09 22:06:52,558 INFO gave up: php-fpm entered FATAL state, too many start retries too quickly发布于 2022-01-21 11:55:38
让我们谈谈码头工人和监管人员
首先-不需要在一个容器中使用Nginx和php。
那是很糟糕的练习。你不应该这样做。Nginx应该使用一个容器,php应该使用一个容器。例如,我的Nginx default.conf就是这样的:
server {
listen 80 default_server;
listen [::]:80 default_server;
index index.html index.php;
server_name race_lab.local;
error_log /var/log/nginx/error.log;
root /var/www/html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\.ht {
deny all;
}
}如您所见,我正在使用fastcgi_pass php:9000;。这是因为在我的docker-compose.yml中,我有名为'php‘的服务,并公开了9000端口。
主管(D)
如您所知,supervisord的工作原理如下:它创建自己的进程,配置中指定的内容将由子进程创建。这样做是为了让监督部门能够控制这些过程。
我的.conf示例:
[supervisord]
nodaemon=true
[program:nginx]
command=nginx -g "daemon off;"
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:php-fpm]
command=php-fpm7.4 --nodaemonize
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0如果我们讨论的是supervisord和php-fpm和nginx,那么我要提到的唯一一件事就是指向PHP-FPM二进制文件的路径。
php-fpm -明智选择
一开始,我试图像这样启动supervisord:/etc/init.d/php7.4-fpm start
这不是它的工作方式。我尝试使用php7.4-fpm -n (-n类似于--nodaemonize),这是可行的。为什么?让我们进入容器并搜索一些有关php的信息。docker ps -> docker exec -ti <container> /bin/bash或简单的docker exec -ti <container> /bin/bash -c "which php7.4-fpm"响应:/usr/sbin/php-fpm7.4仅此而已。您需要为主管守护进程选择正确的二进制文件。
因此,总结一下:php-fpm使用了大量的二进制文件和信任,您应该知道它们在做什么(这很难,非常愚蠢,但我们不能用它做任何事情:( ) )。如果您想使用supervisord与守护进程一起使用--只需搜索一个允许关闭这个选项的二进制文件就行了!
https://stackoverflow.com/questions/41077039
复制相似问题