日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
使用Nginx搭建WCF集群

WCF)是由微軟開發(fā)的一系列支持?jǐn)?shù)據(jù)通信的應(yīng)用程序框架,可以翻譯為Windows 通訊開發(fā)平臺。WCF 整合了原有的windows通訊的 .net Remoting,WebService,Socket的機(jī)制,并融合有HTTP和FTP的相關(guān)技術(shù),本篇文章重點(diǎn)為大家講解一下使用Nginx搭建WCF集群具體方法。

成都創(chuàng)新互聯(lián)公司專注于企業(yè)成都全網(wǎng)營銷、網(wǎng)站重做改版、澤普網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5技術(shù)、商城開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價格優(yōu)惠性價比高,為澤普等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

一:準(zhǔn)備的材料

\1. 話不多說,一圖勝千言,圖中的服務(wù)器都是采用vmware虛擬化,如下圖:

三臺windows機(jī)器 ,兩個WCF的windows服務(wù)器承載(192.168.23.187,192.168.23.188),一臺Client的服務(wù)器(192.168.23.1)

一臺Centos機(jī)器,用來承載web復(fù)雜均衡nginx(192.168.23.190)。

在所有的Client的Hosts文件中增加host映射:【192.168.23.190 cluster.com】,方便通過域名的形式訪問nginx所在服務(wù)器的ip地址。

二:環(huán)境搭建

1、WCF程序

既然是測試,肯定就是簡單的程序,代碼就不完全給出了。

public class HomeService : IHomeService
{
   public string DoWork(string msg)
   {
       var ip = Dns.GetHostAddresses(Dns.GetHostName()).FirstOrDefault(i => i.AddressFamily ==
                                                          AddressFamily.InterNetwork).ToString();
       return string.Format("當(dāng)前 request 由 server={0} 返回", ip);
   }
}

App.Config代碼


  "1.0" encoding="utf-8" ?>

  
   
    
     "v4.0" sku=
     ".NETFramework,Version=v4.5.2" /> 
    
   
   
    
     
      
       ""> 
       
        "true" httpsGetEnabled=
        "true" /> 
        
         "false" /> 
        
       
      
     
    
    
     
      "WcfService.HomeService"> 
      
       "/HomeService" binding=
       "basicHttpBinding" contract=
       "WcfService.IHomeService"> 
       
        
         "localhost" /> 
        
       
      
      
       "mex" binding=
       "mexHttpBinding" contract=
       "IMetadataExchange" /> 
       
        
         
          "http://192.168.23.187:8733" /> 
         
        
       
      
     
    
   
  

因?yàn)閣indows的兩臺機(jī)器的ip地址是192.168.23.187,192.168.23.188,所以部署的時候注意一下config中的baseAddress地址。

2、centos上的nginx搭建

nginx我想大家用的還是比較多的,去官網(wǎng)下載最新的就好【nginx-1.13.6】:http://nginx.org/en/download.html,下載之后,就是常規(guī)的三板斧安裝!!!

[root@localhost nginx-1.13.6]# ./configure --prefix=/usr/myapp/nginx
[root@localhost nginx-1.13.6]# make && make install

然后在nginx的安裝目錄下面找到conf文件,修改里面的nginx.conf 配置。

詳細(xì)配置如下,注意下面“標(biāo)紅”的地方,權(quán)重按照1:5的方式進(jìn)行調(diào)用,關(guān)于其他的配置,大家可以在網(wǎng)上搜一下就可以了。

#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;
upstream cluster.com{
server 192.168.23.187:8733 weight=1;
server 192.168.23.188:8733 weight=5;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://cluster.com;
#設(shè)置主機(jī)頭和客戶端真實(shí)地址,以便服務(wù)器獲取客戶端真實(shí)IP
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
#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;
# }
#}
}

3、 client端的程序搭建

第一件事就是將 192.168.23.190 映射到本機(jī)的host中去,因?yàn)榉?wù)不提供給第三方使用,所以加host還是很輕松的。

192.168.23.190 cluster.com

然后就是client端程序添加服務(wù)引用,因?yàn)樘砑恿薶ost映射,所以服務(wù)引用地址就是”http://cluster.com“。 代碼如下:

class Program
{
static void Main(string[] args)
{
for (int i = 0; i "hello world!");
Console.WriteLine(info);
System.Threading.Thread.Sleep(1000);
}
Console.Read();
}

最后來執(zhí)行以下程序,看看1000次循環(huán)中,是不是按照權(quán)重1:5 的方式對后端的wcf進(jìn)行調(diào)用的???


看到?jīng)]有,是不是很牛逼,我只需要通過cluster.com進(jìn)行服務(wù)訪問,nginx會自動給我復(fù)雜均衡,這就是我們開發(fā)中非常簡單化的wcf復(fù)雜均衡。


標(biāo)題名稱:使用Nginx搭建WCF集群
文章起源:http://www.5511xx.com/article/dhheeoo.html