Chinaunix首页 | 论坛 | 博客
  • 博客访问: 36328
  • 博文数量: 12
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 123
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-27 11:20
个人简介

Passion for technology and design!

文章分类
文章存档

2015年(8)

2014年(4)

我的朋友

分类: LINUX

2014-10-09 21:37:14

This document covers stopping and restarting Apache HTTP Server on Unix-like systems. Windows NT, 2000 and XP users should see "Running httpd as a Service" and Windows 9x and ME users should see "Running httpd as a Console Application" for information on how to control httpd on those platforms.
本文档涵盖了在类Unix系统上停止和重启Apache。Windows NT, 2000和XP用户请参见《以服务方式运行Apache》,Windows 9x和ME用户则参见《在控制台中运行Apache》。

 Introduction 简介

In order to stop or restart the Apache HTTP Server, you must send a signal to the running httpd processes.
为了要停止或重启Apache HTTP服务器,你必须向运行中的httpd进程发送信号。
There are two ways to send the signals. First, you can use the unix kill command to directly send signals to the processes. You will notice many httpd executables running on your system, but you should not send signals to any of them except the parent, whose pid is in the PidFile.
有两种发送信号的方式。首先,你可以用unix kill命令直接向进程发信号。你会注意到在系统中运行着许多httpd进程,但你不应该直接对它们中的任何一个发送信号,除了父进程之外,父进程的进程id在PidFile文件中。(注:配置文件httpd.conf中,如"PidFile run/httpd.pid")
That is to say you shouldn't ever need to send signals to any process except the parent. There are four signals that you can send the parent: TERM, USR1, HUP, and WINCH, which will be described in a moment.
也就是说你不应该向除父进程外的任何进程发信号。你可以向父进程发送4种信号: TERM(15), USR1(10), HUP(1), 和 WINCH(28) ,下文再表。

To send a signal to the parent you should issue a command such as:
你应该像这样向父进程发信号:
kill -TERM `cat /usr/local/apache2/logs/httpd.pid`

The second method of signaling the httpd processes is to use the -k command line options: stop, restart, graceful and graceful-stop, as described below. These are arguments to the httpd binary, but we recommend that you send them using the apachectl control script, which will pass them through to httpd.
第二种向httpd进程发信号的方法是用 -k 命令选项(就是httpd -k):stop, restart, graceful 和 graceful-stop,如下文。它们是对httpd二进制程序的参数,但是我们建议你用 apachectl 控制脚本,它会把参数传给httpd。

▼ Stop Now 立即停止

Signal: TERM
信号: TERM(15)
apachectl -k stop

Sending the TERM or stop signal to the parent causes it to immediately attempt to kill off all of its children. It may take it several seconds to complete killing off its children. Then the parent itself exits. Any requests in progress are terminated, and no further requests are served.
向父进程发送TERM(15)或STOP(19)信号,会使父进程立即试图关闭所有子进程。大约会花几秒钟时间关闭所有子进程,然后父进程自己也退出。在这个过程中所有的请求都被终止,并且不再接受请求。

▼ Graceful Restart 温和重启

Signal: USR1
信号: USR1(10)
apachectl -k graceful

The USR1 or graceful signal causes the parent process to advise the children to exit after their current request (or to exit immediately if they're not serving anything). The parent re-reads its configuration files and re-opens its log files. As each child dies off the parent replaces it with a child from the new generation of the configuration, which begins serving new requests immediately.
USR1信号或者“温和”信号使父进程建议子进程在完成他们现在的请求后退出(如果他们没有服务则立刻退出)。父进程重新读取它的配置文件并重新打开它的日志文件。每当一个子进程关闭,父进程会立刻从新的配置文件中生成一个子进程,子进程立刻开始服务于新的请求。

This code is designed to always respect the process control directive of the MPMs, so the number of processes and threads available to serve clients will be maintained at the appropriate values throughout the restart process. Furthermore, it respects StartServers in the following manner: if after one second at least StartServers new children have not been created, then create enough to pick up the slack. Hence the code tries to maintain both the number of children appropriate for the current load on the server, and respect your wishes with the StartServers parameter.
该重启代码被设计成始终遵守MPM的进程控制指令,所以在重启过程中有适当数量的进程和线程以响应客户端的请求。此外,它按照如下的方式执行StartServers指令(注:StartServers是一个MPM指令):如果在至少一秒钟后StartServers的子进程还没有被创建,则创建足够的进程填补空缺。因此,该代码试图既维持足够数量子进程以适合服务器的当前负载,又通过StartServers的参数(注:StartServers number 设置启动时子服务进程的数量)按你的意愿运作。

Users of mod_status will notice that the server statistics are not set to zero when a USR1 is sent. The code was written to both minimize the time in which the server is unable to serve new requests (they will be queued up by the operating system, so they're not lost in any event) and to respect your tuning parameters. In order to do this it has to keep the scoreboard used to keep track of all children across generations.
使用mod_status的用户会注意到在USR1信号发出后,服务器的统计信息没有被清零。代码被写成既让服务器无法响应新请求的时间降到最低(无法响应的请求会被操作系统放入队列,所以他们无论如何不会丢失),又能遵循你参数的优化。为了做到这一点,它在生成过程中一直使用scoreboard跟踪所有子进程的状态。

The status module will also use a G to indicate those children which are still serving requests started before the graceful restart was given.
状态模块还会将那些在温和重启前就已经开始而没有结束伺服请求的子进程用一个G来标志。

At present there is no way for a log rotation script using USR1 to know for certain that all children writing the pre-restart log have finished. We suggest that you use a suitable delay after sending the USR1 signal before you do anything with the old log. For example if most of your hits take less than 10 minutes to complete for users on low bandwidth links then you could wait 15 minutes before doing anything with the old log.
目前,日志循环写入脚本(注:达到一定条件后循环覆写(overwrite)原有日志)还无法使用USR1确定所有重启前写入日志的子进程都已结束。我们建议你在发出了USR1信号后等待一个适当的时间,然后再对旧的日志做处理。比如说如果对于一个窄带用户来说,大部分的点击处理将在10分钟之内完成,那么你应该在处理旧的日志前等待15分钟。(注:可用 lsof -p [httpd进程号] 查看打开了哪些些日志文件)

When you issue a restart, a syntax check is first run, to ensure that there are no errors in the configuration files. If your configuration file has errors in it, you will get an error message about that syntax error, and the server will refuse to restart. This avoids the situation where the server halts and then cannot restart, leaving you with a non-functioning server.
当你执行重启的时候,会首先运行一个语法检查,确保在配置文件中没有语法错误。如果配置文件中有语法错误,你会得到一个语法错误的消息,而服务器也会拒绝重启。这避免了服务器停机而且不能重启的情况,留给你一个不能工作的服务器。

This still will not guarantee that the server will restart correctly. To check the semantics of the configuration files as well as the syntax, you can try starting httpd as a non-root user. If there are no errors it will attempt to open its sockets and logs and fail because it's not root (or because the currently running httpd already has those ports bound). If it fails for any other reason then it's probably a config file error and the error should be fixed before issuing the graceful restart.
这仍然不能保证服务器会正常地重启。为了从语法和语义的方面检查配置文件,你可以以一个非root用户来启动httpd。如果没有错误,它将尝试去打开它的套接字和日志文件,继而因没有root权限而失败(或是因为现在运行的httpd已经绑定了这些端口)。如果是因为其他原因那么这就可能是一个配置文件产生的错误,而你就应当在进行温和重启之前来改正这个错误。(重启之前可以用httpd -t来检查配置文件语法的正确性)

▼ Restart Now 立即重启

Signal: HUP
信号: HUP(1)
apachectl -k restart

Sending the HUP or restart signal to the parent causes it to kill off its children like in TERM, but the parent doesn't exit. It re-reads its configuration files, and re-opens any log files. Then it spawns a new set of children and continues serving hits.
向父进程发送HUP或restart信号,会使它象收到TERM信号一样关掉所有的子进程,不同之处在于父进程本身并不退出。它重新读入它的配置文件,重新打开日志文件,然后产生一系列新的子进程来继续它的服务。

Users of mod_status will notice that the server statistics are set to zero when a HUP is sent.
使用mod_status的用户会注意到在HUP信号发出后,服务器统计会清零。

As with a graceful restart, a syntax check is run before the restart is attempted. If your configuration file has errors in it, the restart will not be attempted, and you will receive notification of the syntax error(s).
如同温和重启一样,在试图重启之前会进行一个语法检查。如果你的配置文件里有错误,将不会试图重启,你会收到语法错误的提示。

▼ Graceful Stop 温和停止

Signal: WINCH
信号: WINCH(28)
apachectl -k graceful-stop

The WINCH or graceful-stop signal causes the parent process to advise the children to exit after their current request (or to exit immediately if they're not serving anything). The parent will then remove its PidFile and cease listening on all ports. The parent will continue to run, and monitor children which are handling requests. Once all children have finalised and exited or the timeout specified by the GracefulShutdownTimeout has been reached, the parent will also exit. If the timeout is reached, any remaining children will be sent the TERM signal to force them to exit.
WINCH信号或者“温和停止”信号使父进程建议子进程在处理完当前请求后退出(如果他们没有服务则立刻退出)。父进程接下来会删除他的PidFile文件,并停止监听任何端口。父进程会继续运行,并监控正在处理请求的子进程。一旦所有的子进程都完成处理并退出,或者达到了由GracefulShutdownTimeout定义的超时时间,父进程也会退出。如果达到了超时时间,剩余的子进程会被发送TERM信号以强制它们退出。

A TERM signal will immediately terminate the parent process and all children when in the "graceful" state. However as the PidFile will have been removed, you will not be able to use apachectl or httpd to send this signal.
TERM信号会立即终止父进程和子进程,当他们在“温和退出”的状态中。然而,因为PidFile会被删除,你将不能用apachectl或者httpd命令去发送这个信号。

The graceful-stop signal allows you to run multiple identically configured instances of httpd at the same time. This is a powerful feature when performing graceful upgrades of httpd, however it can also cause deadlocks and race conditions with some configurations.
温和停止信号允许你运行同时运行多个相同配置的httpd实例。这在执行httpd的温和更新的时候是非常强大的功能,然而它在某些配置中也能引起死锁和竞争状态。

Care has been taken to ensure that on-disk files such as lock files (Mutex) and Unix socket files (ScriptSock) contain the server PID, and should coexist without problem. However, if a configuration directive, third-party module or persistent CGI utilises any other on-disk lock or state files, care should be taken to ensure that multiple running instances of httpd do not clobber each other's files.
必须要注意的是,磁盘上的文件如锁文件(设置Mutex,如Mutex sysvsem default)和Unix套接字文件(设置ScriptSock,如ScriptSock /var/run/cgid.sock)都包含了服务器PID,并且应该会正常地共存。然而,如果一个配置指令,第三方模块或者持续的CGI使用了其他磁盘文件锁或者状态文件,就应该注意确保多个httpd的运行实例不会破坏对方的文件。

You should also be wary of other potential race conditions, such as using rotatelogs style piped logging. Multiple running instances of rotatelogs attempting to rotate the same logfiles at the same time may destroy each other's logfiles.
你也应该提防其他有可能的竞争状态,比如使用rotatelogs方式(注:可按时间间隔或日志最大尺寸而循环写入)的管道日志。多重运行的rotatelogs实例在试图同时循环写入同一个日志文件的时候,可能会破坏彼此的日志文件。
阅读(529) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~