503 Service Unavailable 是一种HTTP协议的服务端错误状态代码,它表示服务器尚未处于可以接受请求的状态。
通常造成这种情困高的原因是由于服务停机维护或者已超载。注意在发送响应的时候,应该同时发送一个对用户友好的页面来解释问题发生的原因。改种响应应该用于临时状况下,与之同时,在可行的情况下,应该在Retry-After首部字段中包含服务回复的预期时间。
在分布式集群部署的环境下,如果采用http协议进行交互的话,出现503错误,考虑的问题则要相对多些。
方案
参考地址:[https://svn.apache.org/repos/asf/httpd/sandbox/mod_bw/mod_bw.txt]
在上面网址介绍的503错误。
BandWidthError (带宽错误)
This directives is useful to deliver a personalized error code.
At default, when max connections is reached, the mod will issue a 503 HTTP_SERVICE_UNAVAILABLE code. For some users, it is annoying to have an error message, and don't knowing why. You could use an ErrorDocument to a page explaining that you are under a heavy load of connections, but sometimes 503 isn't issued by the mod.
So, with this directive, you can set the error code to return when max connections is reached. You can use any error code between 300 and 599. Please note, that some of the error codes are already used, so before use any number, take a look to a list of the codes(search for http error codes in google).
When testing, i've used the error code 510, which hasn't been defined yet.
And Example, with Personalized Error Page:
ErrorDocument 510 /errors/maxconexceeded.html
BandWithError 510
Note : Sometimes, the personalized page didn't appear. I'm not sure, but in many cases, it got fixed, by making the page size over 1024 bytes. Anyways, if you need help using ErrorDocument, refer to the apache Documentation.
根据上面的介绍,主要人为是请求跳转的链路问题。根据不通的分布式环境进行不通的考虑:
1、如果是使用nginx进行内部服务的负载均衡,那么主要看nginx配置的最大连接数,是不是不能满足需求,通过增大最大连接数配置解决;
2、如果是使用阿里的slb进行内部服务间的负载,那么在阿里云上配置slb的最大连接数,来解决问题。slb默认的最大连接数是5000,这个数量是免费的,加大的话应该会收费。
如果使用的其他的方式部署的内部集群,则也是从扩大线路连接数的角度解决问题,这个问题不是访问的目标的服务器的问题。
网友评论