本帖最后由 meforall 于 2019-3-28 21:46 编辑
概念:
负载均衡建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽、增加吞吐量、加强网络数据处理能力、提高网络的灵活性和可用性nginx:配置
[Java] 纯文本查看 复制代码 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;
}
}
|