Nginx调度器(反向代理),TCP/UDP调度器

一,nginx反向代理

环境

步骤一: 部署后端Web 服务器web1和web2:以web1为例:

yum -y install gcc pcre-devel openssl-devel
yum -y install gcc pcre-devel openssl-devel
tar -xf nginx-1.10.3.tar.gz 
cd nginx-1.10.3
useradd -s /sbin/nologin nginx
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module
make
make install
mv nginx-1.1* /usr/local/nginx/
ln -s /usr/local/nginx/sbin/nginx  /sbin/
nginx 
netstat -antulp |grep nginx
echo "192.168.1.100" > /usr/local/nginx/html/index.html 

二,安装nginx,修改配置,添加服务器池,实现反向代理功能

1,安装Nginx

yum -y install gcc pcre-devel openssl-devel
cd nginx-1.10.3
useradd -s /sbin/nologin nginx
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module
make & make install
ln -s /usr/local/nginx/sbin/nginx /sbin/
nginx
netstat -antulp | grep nginx

2,修改Nginx配置文件

vim /usr/local/nginx/conf/nginx.conf
 35     #使用upstream定义后端服务器集群,集群名称随意(如webserver)
 36     #使用server定义集群中服务器的IP和端口
 37     upstream webserver {
 38                 server 192.168.1.100:80;
 39                 server 192.168.1.200:80;
 40         }
 41 
... ...
 52         location / {
 53             proxy_pass http://webserver;
 54         #通过proxy_pass将用户的请求转发给webserver集群


nginx -s reload

 

三,客户端访问测试

http://192.168.0.2/     访问测试刷新出现不同的页面,配置成功!!

配置upstream服务器集群池属性

vim /usr/local/nginx/conf/nginx.conf
 37     upstream webserver {
 38                 server 192.168.1.100 weight=1 max_fails=1 fail_timeout=30;
 39                 server 192.168.1.200 weight=2 max_fails=2 fail_timeout=30;
 40                 server 192.168.1.101 down;
 41         }   
 42      #weight设置服务器权重值,默认值为1
 43      #max_fails设置最大失败次数
 44      #fail_timeout设置失败超时时间,单位为秒
 45      #down标记服务器已关机,不参与集群调度

 

配置upstream服务器集群的调度算法

vim /usr/local/nginx/conf/nginx.conf
 37     upstream webserver {
 38                 ip_hash;
 39     #通过ip_hash设置调度规则为:相同客户端访问相同服务器
 40                 server 192.168.1.100 weight=1 max_fails=1 fail_timeout=30;
 41                 server 192.168.1.200 weight=2 max_fails=2 fail_timeout=30;
 42                 server 192.168.1.101 down;
 43         }

 

# nginx -s reload

客户端使用浏览器访问代理服务器测试轮询效果
# curl http://192.168.0.2           //使用该命令多次访问查看效果

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

二 ,TCP/UDP调度器

 

================================================================================================

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

English太次郎

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值