概念:
负载均衡建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽、增加吞吐量、加强网络数据处理能力、提高网络的灵活性和可用性nginx:配置
[Java] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
upstream tomcatserver1 {
server 192.168 . 3.43 : 8080 ;
server 192.168 . 3.43 : 8082 ; #多加了此台服务器
}
upstream tomcatserver2 {
server 192.168 . 3.43 : 8082 ;
}
server {
listen 80 ;
server_name 8080 .zcinfo.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http: //tomcatserver1;
index index.html index.htm;
}
}
server {
listen 80 ;
server_name 8082 .zcinfo.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http: //tomcatserver2;
index index.html index.htm;
}
}
如果两台服务器性能差不多这样设置重启nginx就行了,但是现在假如两台服务器性能不一样,还需要设置性能权重,让性能高服务器做更多事情。只需要加入weight=?就行了,如下:
upstream tomcatserver1 {
server 192.168 . 3.43 : 8080 weight= 2 ;
server 192.168 . 3.43 : 8082 weight= 1 ;
}
upstream tomcatserver2 {
server 192.168 . 3.43 : 8082 ;
}
server {
listen 80 ;
server_name 8080 .zcinfo.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http: //tomcatserver1;
index index.html index.htm;
}
}
server {
listen 80 ;
server_name 8082 .zcinfo.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http: //tomcatserver2;
index index.html index.htm;
}
}
|