2008年的新浪播客由静态服务器集群和动态服务器集群两部分组成,静态服务器集群采用Squid做前端缓存,动态服务器也称接口服务器,主要用来实现显示播放数,记录播放日志等等。
接口服务器上采用F5 BIG-IP硬件四/七层负载均衡交换机,对4台Nginx反向代理服务器进行四层负载均衡,由这四台nginx服务器判断 URL,进行分组,对后端3组web服务器进行七层负载均衡。
F5 BIG-IP后端的3组web服务器,配置不一样,第一组内存密集型,技术主要是PHP+Mencache服务; 第2组为 CPU密集型服务,主要消耗CP资源;第三组为磁盘密集型,为记录日志等操作,要求大空间。
以下代码是接口服务器Nginx负载均衡配置;
<code><span>/***代码是N年前新浪接口服务器的nginx负载均衡配置,提供按URL分组服务,负载均衡服务***/</span>usr www www; worker_processes <span>10</span>; error_log /data1/logs/nginx_error.log crit; pid /tmp/nginx.pid worker_rlimt_nofile <span>51200</span>; events { <span>use</span><span>epull</span>; worker_connections <span>51200</span>; } http { <span>include</span> conf/mine.types; default_type application/octet-stream; charset gb2312; server_name_hash_bucket_size <span>128</span>; keeplaive_timeout <span>15</span>; sendfile on; tcp_mopush on; tcp_nodelay on; <span>#第一组接口机:Memcache相关(点击数)</span> upstream count.<span>interface</span>.video.sian.com.cn{ server xx.xx.xx<span>.55</span>:<span>80</span>; server xx.xx.xx<span>.58</span>:<span>80</span>; server xx.xx.xx<span>.47</span>:<span>80</span>; } <span>#第二组接口机:提供数据类程序</span> upstream data.<span>interface</span>.video.sian.com.cn{ server xx.xx.xx<span>.59</span>:<span>80</span>; server xx.xx.xx<span>.64</span>:<span>80</span>; server xx.xx.xx<span>.48</span>:<span>80</span>; } <span>#第三组接口机:打日志类程序,功能相关,嵌套页面</span> upstream log.<span>interface</span>.video.sian.com.cn{ server xx.xx.xx<span>.72</span>:<span>80</span>; server xx.xx.xx<span>.49</span>:<span>80</span>; } } server { listen <span>80</span>; server_name <span><span>interface</span>.<span>video</span>.<span>sian</span>.<span>com</span>.<span>cn</span>; <span>location</span> / {</span> proxy_redirect off; <span>#后端的web服务器可以直接通过X-Forward-For 获取用户真实ip</span> proxy_set_header X-Forward-<span>For</span><span>$remote_adr</span>; <span>#按URL进行分组,第一组:Memcache相关(点击数)</span><span>if</span> (<span>$request_uri</span> ~ <span>"^\/app\/count\/"</span>) { proxy_pass http:<span>//count.interface.video.sian.com.cn;</span> } <span>if</span> (<span>$request_uri</span> ~ <span>"^\/app\/online\/"</span>) { proxy_pass http:<span>//count.interface.video.sian.com.cn;</span> } <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/user\/getLoginGap.php"</span>) { proxy_pass http:<span>//count.interface.video.sian.com.cn;</span> } <span>#按URL进行分组,第二组:外部提供数据类程序</span><span>if</span> (<span>$request_uri</span> ~ <span>"^\/crossdomain.xml"</span>) { proxy_pass http:<span>//data.interface.video.sian.com.cn;</span> } <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/client\/topVideoClient.php"</span>) { proxy_pass http:<span>//data.interface.video.sian.com.cn;</span> } <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/common\/"</span>) { proxy_pass http:<span>//data.interface.video.sian.com.cn;</span> } <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/randplay\/randplay.php"</span>) { proxy_pass http:<span>//data.interface.video.sian.com.cn;</span> } <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/topic\/suggTop.php"</span>) { proxy_pass http:<span>//data.interface.video.sian.com.cn;</span> } <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/uploadClient\/"</span>) { proxy_pass http:<span>//data.interface.video.sian.com.cn;</span> } <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/xml\/"</span>) { proxy_pass http:<span>//data.interface.video.sian.com.cn;</span> } <span>if</span> (<span>$request_uri</span> ~ <span>"^\/outinterface\/"</span>) { proxy_pass http:<span>//data.interface.video.sian.com.cn;</span> } <span>#按URL进行分组,第三组:打日志类程序</span><span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/flash\/"</span>) { proxy_pass http:<span>//log.interface.video.sian.com.cn;</span> } <span>if</span> (<span>$request_uri</span> ~ <span>"^\/interface\/playrank\/playrank2008_10.php"</span>) { proxy_pass http:<span>//log.interface.video.sian.com.cn;</span> } <span>#按URL进行分组,其他组:功能相关,嵌套页面等未匹配到的URL</span> proxy_pass http:<span>//log.interface.video.sina.com.cn;</span> } <span>#定义日至格式</span> log_format count <span>'$remote_addr - $remote_user [$time_local] $request'</span><span>'"$status" $body_bytes_sent "$http_referer"'</span><span>'"$http_user_agent" "$http_x_forwarded_for"'</span>; <span>#打日志</span> access_log /data1/logs/<span><span>interface</span>.<span>log</span><span>count</span>; #允许客户端请求的最大单文件字节数 <span>client_max_body_size</span> 10<span>m</span>; #缓冲区代理缓冲用户端的最大字节数 可以理解为现存到本地再传给用户 <span>client_body_size</span> 128<span>k</span>; #跟后端服务器连接的超时时间<span>_</span>发起握手等候响应超时时间 <span>proxy_connect_time</span> 600; #连接成功后<span>_</span>等待后端服务器响应时间<span>_</span>其实已经进入后端的派对等候处理 <span>proxy_read_timeout</span> 600; #后端回传时间<span>_</span>规定时间内传完所有数据 <span>proxy_send_timeout</span> 600; #代理请求缓存区,保存用户的头信息以供<span>Nginx</span>进行规则处理 <span>proxy_buffer_size</span> 8<span>k</span>; <span>proxy_buffers</span> 4 32<span>k</span>; <span>proxy_busy_buffers_size</span> 64<span>k</span>; <span>proxy_temp_file_write_size</span> 64<span>k</span>; } }</span></code>
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了N年前Nginx负载均衡在新浪播客中的应用,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。