多くの場合、wcf に基づく複雑なバランシングには、より優れた制御粒度を備えた ZoKeeper が最初の選択肢となります。ただし、zk は C# に適しておらず、粒度が
場合、実際の実装は比較的面倒です。非常に大まかなロードメカニズムの場合は、最初に nginx を使用することで、複雑なバランスとデュアルマシンのホットバックアップを実現でき、最小限のコードでビジネスを実現できます。 。
1: 準備した資料
1. 百聞は一見に如かず、以下に示すように、写真内のサーバーはすべて vmware で仮想化されています。
《1》 Windows マシン 3 台、WCF ウィンドウ 2 台サーバーは (192.168.23.187、192.168.23.188)、クライアントサーバー (192.168.23.1) をホストします
《2》 Web 複合バランスのとれた nginx (192.168.23.190) をホストするために使用される Centos マシン。
《3》すべてのクライアントホストファイルにホストマッピングを追加します:[192.168.23.190cluster.com]。ドメイン名を通じてnginxが配置されているサーバーのIPアドレスにアクセスしやすくします。
2: 環境設定
1. WCF プログラム
テストなので簡単なプログラムでなければならず、コードは完全には与えられていません。
《1》 HomeService 実装クラスのコードは次のとおりです (見やすいように現在のサーバーの IP アドレスを出力します):
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("当前 request 由 server={0} 返回", ip); } }
《2》App.Config コード
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> </startup> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <services> <service name="WcfService.HomeService"> <endpoint address="/HomeService" binding="basicHttpBinding" contract="WcfService.IHomeService"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://192.168.23.187:8733" /> </baseAddresses> </host> </service> </services> </system.serviceModel> </configuration>
Windows の場合 2 台のマシンの IP アドレスは 192.168.23.187 と 192.168.23.188 であるため、デプロイするときは構成内の BaseAddress アドレスに注意してください。
2. centos で nginx をセットアップする
皆さんも nginx をよく使用していると思います。最新の Web サイト [nginx-1.13.6] をダウンロードしてください: http://nginx.org/en/download .html をダウンロードしたら、通常の Sanbanaxe のインストールです。 ! !
[root@localhost nginx-1.13.6]# ./configure --prefix=/usr/myapp/nginx
[root@localhost nginx-1.13.6]# make && make install
次に、nginx でインストール ディレクトリで conf ファイルを見つけ、その中の nginx.conf 設定を変更します。
[root@localhost nginx]# cd conf
[root@localhost conf]# ls
fastcgi.conf nginx.conf.default uwsgi_params.defaultfastcgi_params mime.types scgi_params win-utf
fastcgi_params.default mime.types.default scgi_paraさん。デフォルト[root@localhost conf]# vim 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; 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; #设置主机头和客户端真实地址,以便服务器获取客户端真实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; # } #} }
class Program { static void Main(string[] args) { for (int i = 0; i < 1000; i++) { HomeServiceClient client = new HomeServiceClient(); var info = client.DoWork("hello world!"); Console.WriteLine(info); System.Threading.Thread.Sleep(1000);14 } Console.Read(); } }
以上がnginx を使用して高可用性、高同時実行性の wcf クラスターを構築するの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

WebStorm Mac版
便利なJavaScript開発ツール

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

DVWA
Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)
