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