php iis 负载均衡,24*7*365 web 系统建设<一>——nginx+iis实现负载均衡

介绍

如果一个web程序,只部署在一台机器上,那么如果这个机器出现宕机或者其他不可知事件,那么这个web程序,就over了,直到下次恢复……

那么,如何打造 247365 不间断提供服务的web系统呢?采用的是iis集群,也就是说,部署多台web服务,通过nginx来实现iis集群功能,当一台服务不工作的时候,其他服务可以顶上,甚至,平摊web服务工作。

代码准备工作

1.abp

通过 参4创建web程序,并根据文档正确运行 程序。

2. 部署

在本地开启iis服务,并且创建三个网站,每个网站分别绑定接口为10091/10092/10093,三个网站的物理路径不一致,结果如下

cfc80a3e4fe7

iis站点.png

cfc80a3e4fe7

物理路径.png

3. 发布代码

右击 vs,选择发布,配置如下,这里需要掌握vs的发布方法

cfc80a3e4fe7

图片.png

cfc80a3e4fe7

图片.png

发布成功后,在解决方案下会多出一个文件,如下所示

cfc80a3e4fe7

图片.png

复制 demo.pubxml文件并从命名 demo1.pubxml/demo2.pubxml,如下

cfc80a3e4fe7

图片.png

修改 demo1 对应的物理路径为文件夹2,修改 demo2对应的物理文件夹为3,修改后的内容如下

cfc80a3e4fe7

图片.png

cfc80a3e4fe7

图片.png

发布三个网站

4. 运行

三个网站正常运行

cfc80a3e4fe7

图片.png

nginx,参考2 参考3

1. nginx配置

修改 nginx的配置文件nginx.conf,配置如下

#user nobody;

worker_processes 1;

#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/nginx.pid;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '

# '$status $body_bytes_sent "$http_referer" '

# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

# 服务器集群 sky_test

upstream sky_test{

server 127.0.0.1:10091 max_fails=3 fail_timeout=4s weight=9;

server 127.0.0.1:10092 max_fails=3 fail_timeout=4s weight=9;

server 127.0.0.1:10093 max_fails=3 fail_timeout=4s weight=9;

}

server {

listen 10080;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root html;

index index.html index.htm;

# 添加集群

proxy_pass http://sky_test;

# 设置主机头和客户端真实地址,以便服务器获取到客户端真实IP

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

# proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

# root html;

# fastcgi_pass 127.0.0.1:9000;

# fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

# include fastcgi_params;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

# deny all;

#}

}

# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

# listen 8000;

# listen somename:8080;

# server_name somename alias another.alias;

# location / {

# root html;

# index index.html index.htm;

# }

#}

# HTTPS server

#

#server {

# listen 443 ssl;

# server_name localhost;

# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;

# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;

# ssl_prefer_server_ciphers on;

# location / {

# root html;

# index index.html index.htm;

# }

#}

}

主要是一下两部分

cfc80a3e4fe7

图片.png

cfc80a3e4fe7

图片.png

来实现集群

通过

cfc80a3e4fe7

图片.png

实现监听 10080 服务

2.运行 nginx

运行命令如下

cfc80a3e4fe7

图片.png

发现任务管理器中右 nginx.exe 表示 运行成功

cfc80a3e4fe7

图片.png

3. 运行

cfc80a3e4fe7

图片.png

通过结果发现,可以正常访问网站

4.进一步测试

现在,假设 10091的服务器出现了问题,我们手动停止站点

cfc80a3e4fe7

图片.png

F5 刷新 http://127.0.0.1:10080/account/login

10080正常访问

cfc80a3e4fe7

图片.png

cfc80a3e4fe7

图片.png

10091 不能访问了

总结

通过以上,我们可以看到,即使其中一个网站挂掉了,但是我们仍然可以正常访问我们的web程序。

但是,由于我们的web程序是部署三个地方,这就导致了其他问题,比如

session 如何共享?

log日志如何处理?现在的log日志,是分散在三个物理路径的。

我们刚才是手动部署了三个站点,如何实现部署一个站点,其他站点内容同事更新部署?

上传文件如何处理?因为上传的文件,可能是分散在三个物理机器上。

....

这些内容,将在后面继续分享。

QQ:1260825783

我的公众号

cfc80a3e4fe7

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值