正在加载...
分页: 32/55 第一页 上页 27 28 29 30 31 32 33 34 35 36 下页 最后页 [ 显示模式: 摘要 | 列表 ]

nginx upstream 的几种分配方式

[ 2009/06/05 18:34 | by selboo ]
nginx的upstream目前支持4种方式的分配

1、轮询(默认)

每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。

2、weight
指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
例如:
upstream bakend {
server 192.168.0.14 weight=10;
server 192.168.0.15 weight=10;
}

2、ip_hash
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
例如:
upstream bakend {
ip_hash;
server 192.168.0.14:88;
server 192.168.0.15:80;
}

3、fair(第三方)
按后端服务器的响应时间来分配请求,响应时间短的优先分配。
upstream backend {
server server1;
server server2;
fair;
}

4、url_hash(第三方)

按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效。

例:在upstream中加入hash语句,server语句中不能写入weight等其他的参数,hash_method是使用的hash算法

upstream backend {
server squid1:3128;
server squid2:3128;
hash $request_uri;
hash_method crc32;
}

tips:

upstream bakend{#定义负载均衡设备的Ip及设备状态
ip_hash;
server 127.0.0.1:9090 down;
server 127.0.0.1:8080 weight=2;
server 127.0.0.1:6060;
server 127.0.0.1:7070 backup;
}
在需要使用负载均衡的server中增加
proxy_pass http://bakend/;

每个设备的状态设置为:
1.down 表示单前的server暂时不参与负载
2.weight 默认为1.weight越大,负载的权重就越大。
3.max_fails :允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误
4.fail_timeout:max_fails次失败后,暂停的时间。
5.backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。

nginx支持同时设置多组的负载均衡,用来给不用的server来使用。

client_body_in_file_only 设置为On 可以讲client post过来的数据记录到文件中用来做debug
client_body_temp_path 设置记录文件的目录 可以设置最多3层目录

location 对URL进行匹配.可以进行重定向或者进行新的代理 负载均衡

Tags:

修改nginx日志的时间格式

[ 2009/06/05 09:15 | by selboo ]
我需要修改访问日志的时间格式:
原格式为:03/Jun/2009:07:06:53 +0800
需要修改为:2009-06-03 07:06:53

第一个要修改的文件:
nginx-0.7.59/src/core/ngx_times.c

1、(计算字符串的长度?)
static u_char            cached_http_log_time[NGX_TIME_SLOTS]
                                    [sizeof("28/Sep/1970:12:00:00 +0600")];
修改为
static u_char            cached_http_log_time[NGX_TIME_SLOTS]
                                    [sizeof("1970-09-28 12:00:00")];

2、(计算字符串的长度?)
ngx_cached_http_log_time.len = sizeof("28/Sep/1970:12:00:00 +0600") - 1;
修改为
ngx_cached_http_log_time.len = sizeof("1970-09-28 12:00:00") - 1;

3、(关键的地方,修改格式)
    p2 = &cached_http_log_time[slot][0];

    (void) ngx_sprintf(p2, "%02d/%s/%d:%02d:%02d:%02d %c%02d%02d",
                       tm.ngx_tm_mday, months[tm.ngx_tm_mon - 1],
                       tm.ngx_tm_year, tm.ngx_tm_hour,
                       tm.ngx_tm_min, tm.ngx_tm_sec,
修改为
p2 = &cached_http_log_time[slot][0];

    (void) ngx_sprintf(p2, "%4d-%02d-%02d %02d:%02d:%02d",
                       tm.ngx_tm_year, tm.ngx_tm_mon,
                       tm.ngx_tm_mday, tm.ngx_tm_hour,
                       tm.ngx_tm_min, tm.ngx_tm_sec,
注:这里其实将p2格式改成和p1格式基本上相同了,完全可以直接将log_time的格式改成p1,但是为了做个试验,还是手动修改了p2格式。

第二个要修改的文件:
nginx-0.7.59/src/http/modules/ngx_http_log_module.c

    { ngx_string("time_local"), sizeof("28/Sep/1970:12:00:00 +0600") - 1,
修改为
    { ngx_string("time_local"), sizeof("1970-09-28 12:00:00") - 1,

OK,编译即可。
Tags:

防止用户查看其他用户进程

[ 2009/06/05 09:12 | by selboo ]
echo 'security.bsd.see_other_uids=0' >> /etc/sysctl.conf
echo 'security.bsd.see_other_gids=0' >> /etc/sysctl.conf

sysctl security.bsd.see_other_uids=0
sysctl security.bsd.see_other_gids=0

sysctl -a | grep security
Tags: ,

Suse防火墙开放端口

[ 2009/05/28 10:05 | by selboo ]
手动修改:
#vi /etc/sysconfig/SuSEfirewall2

#TCP端口的情况:
FW_SERVICES_EXT_TCP = "8080"
#UDP端口的情况:
FW_SERVICES_EXT_UDP = "110"
防火墙设置的生效:
#rcSuSEfirewall2 restart
Tags:

SuSE防火墙手动永久关闭方法

[ 2009/05/28 09:44 | by selboo ]
发现SuSE的启动机制很有意思,有些特殊的启动标识。而这次防火墙无法关闭后,开机后仍然启动。就是这个原因。

[ ha02:/srv ] # chkconfig --list  | grep fire
SuSEfirewall2_init        0:off  1:off  2:off  3:off  4:off  5:off  6:off  B:on
SuSEfirewall2_setup       0:off  1:off  2:off  3:off  4:off  5:off  6:off
[ ha02:/srv ] # chkconfig --level B SuSEfirewall2_init off
[ ha02:/srv ] # chkconfig --list  | grep fire
SuSEfirewall2_init        0:off  1:off  2:off  3:off  4:off  5:off  6:off
SuSEfirewall2_setup       0:off  1:off  2:off  3:off  4:off  5:off  6:off
Tags:
分页: 32/55 第一页 上页 27 28 29 30 31 32 33 34 35 36 下页 最后页 [ 显示模式: 摘要 | 列表 ]