Photon Server LoadBalancing搭建

Posted Foto_cjShow

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Photon Server LoadBalancing搭建相关的知识,希望对你有一定的参考价值。

 

准备:申请3台Windows虚拟机。

  

3台虚拟机上都部署上Photon Server. 

 

一、主虚拟机上部署MasterServer。

  (1)在第一台虚拟机中,部署的Photon Server目目录下找到Loadbalancing目录,删除GameServer文件夹

 

  (2)修改Master的配置文件。Photon.LoadBalancing.dll.config (在目录Master/bin/中)

 

  (3)修改PhotonServer.config 配置文件。(在目录 bin_Win64/ 中) 删除跟Game相关的配置

<?xml version="1.0" encoding="Windows-1252"?>
<!--
    (c) 2015 by Exit Games GmbH, http://www.exitgames.com
    Photon server configuration file.
    For details see the photon-config.pdf.

    This file contains two configurations:
        
        "LoadBalancing"
                Loadbalanced setup for local development: A Master-server and a game-server.
                Starts the apps: Game, Master, CounterPublisher
                Listens: udp-port 5055, tcp-port: 4530, 843 and 943        
    
-->

<Configuration>
    <!-- Multiple instances are supported. Each instance has its own node in the config file. -->
    
    <LoadBalancing
        MaxMessageSize="512000"
        MaxQueuedDataPerPeer="512000"
        PerPeerMaxReliableDataInTransit="51200"
        PerPeerTransmitRateLimitKBSec="256"
        PerPeerTransmitRatePeriodMilliseconds="200"
        MinimumTimeout="5000"
        MaximumTimeout="30000"
        DisplayName="LoadBalancing (MyCloud)">

        <!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here. -->
        <!-- Port 5055 is Photon\'s default for UDP connections. -->
        <UDPListeners>
            <UDPListener
                IPAddress="0.0.0.0"
                Port="5055"
                OverrideApplication="Master">
            </UDPListener>
        </UDPListeners>
        
        <!-- 0.0.0.0 opens listeners on all available IPs. Machines with multiple IPs should define the correct one here. -->        
        <TCPListeners>
            <!-- TCP listener for Game clients on Master application -->
            <TCPListener
                IPAddress="0.0.0.0"
                Port="4530"
                OverrideApplication="Master"
                PolicyFile="Policy\\assets\\socket-policy.xml"
                InactivityTimeout="10000"
                >
            </TCPListener>
            
            <!-- DON\'T EDIT THIS. TCP listener for GameServers on Master application -->
            <TCPListener
                IPAddress="0.0.0.0"
                Port="4520">
            </TCPListener>
        </TCPListeners>
        
        <!-- Policy request listener for Unity and Flash (port 843) and Silverlight (port 943)  -->
        <PolicyFileListeners>
          <!-- multiple Listeners allowed for different ports -->
          <PolicyFileListener
            IPAddress="0.0.0.0"
            Port="843"
            PolicyFile="Policy\\assets\\socket-policy.xml">
          </PolicyFileListener>
          <PolicyFileListener
            IPAddress="0.0.0.0"
            Port="943"
            PolicyFile="Policy\\assets\\socket-policy-silverlight.xml">
          </PolicyFileListener>
        </PolicyFileListeners>
        
        <!-- WebSocket (and Flash-Fallback) compatible listener -->
        <WebSocketListeners>
            <WebSocketListener
                IPAddress="0.0.0.0"
                Port="9090"
                DisableNagle="true"
                InactivityTimeout="10000"
                OverrideApplication="Master">
            </WebSocketListener>
            
        </WebSocketListeners>

        <!-- Defines the Photon Runtime Assembly to use. -->
        <Runtime
            Assembly="PhotonHostRuntime, Culture=neutral"
            Type="PhotonHostRuntime.PhotonDomainManager"
            UnhandledExceptionPolicy="Ignore">
        </Runtime>

        <!-- Defines which applications are loaded on start and which of them is used by default. Make sure the default application is defined. -->
        <!-- Application-folders must be located in the same folder as the bin_win32 folders. The BaseDirectory must include a "bin" folder. -->
        <Applications Default="Master">        
            <Application
                Name="Master"
                BaseDirectory="LoadBalancing\\Master"
                Assembly="Photon.LoadBalancing"
                Type="Photon.LoadBalancing.MasterServer.MasterApplication"
                ForceAutoRestart="true"
                WatchFiles="dll;config"
                ExcludeFiles="log4net.config"
                >
            </Application>

            <!-- CounterPublisher Application -->
            <Application
                Name="CounterPublisher"
                BaseDirectory="CounterPublisher"
                Assembly="CounterPublisher"
                Type="Photon.CounterPublisher.Application"
                ForceAutoRestart="true"
                WatchFiles="dll;config"
                ExcludeFiles="log4net.config">
            </Application>    
        </Applications>
    </LoadBalancing>
    
</Configuration>
View Code

 

   (4)启动服务。

 

二、在另外两台虚拟机上部署GameServer服务

  (1)在目前中删除Master

 

  (2)修改GameServer/bin/Photon.LoadBalancing.dll.config 配置文件。

先删除MasterServer配置项

  

修改GameServerSetting项中的  MasterIPAddress 一项。

 

   总体配置

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="Photon.LoadBalancing.Common.CommonSettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
              requirePermission="false" />
      <section name="Photon.LoadBalancing.GameServer.GameServerSettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
               requirePermission="false" />
      <section name="Photon.LoadBalancing.MasterServer.MasterServerSettings"
               type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
               requirePermission="false" />
      <section name="Photon.Common.Authentication.Settings"
           type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
           requirePermission="false" />
    </sectionGroup>
    <section name="Photon" type="Photon.SocketServer.Diagnostics.Configuration.PhotonSettings, Photon.SocketServer" />
    <section name="PluginSettings" type="Photon.Hive.Configuration.PluginSettings, PhotonHive" />
    <section name="WebRpcSettings" type="Photon.Hive.WebRpc.Configuration.WebRpcSettings, PhotonHive" />
    <section name="AuthSettings" type="Photon.Common.Authentication.Configuration.Auth.AuthSettings, Photon.Common" />
  </configSections>
  <applicationSettings>

    <Photon.LoadBalancing.Common.CommonSettings>
      <setting name="NodesFileName" serializeAs="String">
        <value>Nodes.txt</value>
      </setting>
      <setting name="NodesFilePath" serializeAs="String">
        <value>..\\..\\</value>
      </setting>
      <setting name="EnablePerformanceCounters" serializeAs="String">
        <value>True</value>
      </setting>
    </Photon.LoadBalancing.Common.CommonSettings>

    <Photon.Common.Authentication.Settings>
      <setting name="AuthCacheUpdateInterval" serializeAs="String">
        <value>300</value>
      </setting>

      <setting name="AuthTokenKey" serializeAs="String">
        <value>76B2814E-2A50-4E29-838A-20411D335FC9</value>
      </setting>

      <setting name="AuthTokenExpiration" serializeAs="String">
        <value>10000</value>
      </setting>

      <!-- Custom Authentication Queue Settings -->
      <setting name="MaxConcurrentRequests" serializeAs="String">
        <value>50</value>
      </setting>
      <setting name="MaxQueuedRequests" serializeAs="String">
        <value>5000</value>
      </setting>
      <setting name="MaxErrorRequests" serializeAs="String">
        <value>10</value>
      </setting>
      <setting name="MaxTimedOutRequests" serializeAs="String">
        <value>10</value>
      </setting>
      <setting name="HttpRequestTimeoutMS" serializeAs="String">
        <value>30000</value>
      </setting>
      <setting name="ReconnectIntervalS" serializeAs="String">
        <value>60</value>
      </setting>
      <setting name="QueueTimeoutS" serializeAs="String">
        <value>20</value>
      </setting>
      <setting name="MaxBackoffTimeInMiliseconds" serializeAs="String">
        <value>10000</value>
      </setting>
    </Photon.Common.Authentication.Settings>

    <Photon.LoadBalancing.GameServer.GameServerSettings>
      <setting name="AppStatsPublishInterval" serializeAs="String">
        <value>1000</value>
      </setting>
      <!-- GameServer-to-Master connections. -->
      <setting name="ConnectReytryInterval" serializeAs="String">
        <value>15</value>
      </setting>
      <setting name="EnableNamedPipe" serializeAs="String">
        <value>False</value>
      </setting>
      <!-- Path for Client-to-Gameserver HTTP connections -->
      <setting name="GamingHttpPath" serializeAs="String">
        <value>photon/g</value>
      </setting>
      <!-- Client-to-Gameserver HTTP connections. Needs to match the RHTTPListener in PhotonServer.config -->
      <setting name="GamingHttpPort" serializeAs="String">
        <value>80</value>
      </setting>
      <!-- Client-to-Gameserver HTTPS connections. Needs to match the RHTTPListener in PhotonServer.config -->
      <setting name="GamingHttpsPort" serializeAs="String">
        <value>443</value>
      </setting>
      <!-- Client-to-Gameserver Secure WebSocket connections. Needs to match the secure WebSocketListener in PhotonServer.config -->
      <setting name="GamingSecureWebSocketPort" serializeAs="String">
        <value>19091</value>
      </setting>
      <!-- Client-to-Gameserver TCP connections. Needs to match the TCPListener in PhotonServer.config -->
      <setting name="GamingTcpPort" serializeAs="String">
        <value>4531</value>
      </setting>
      <!-- Client-to-Gameserver UDP connections. Needs to match the UDPListener in PhotonServer.config -->
      <setting name="GamingUdpPort" serializeAs="String">
        <value>5056</value>
      </setting>
      <!-- Client-to-Gameserver WebSocket connections. Needs to match the WebSocketListener in PhotonServer.config -->
      <setting name="GamingWebSocketPort" serializeAs="String">
        <value>9091</value>
      </setting>
      <setting name="HttpQueueMaxErrors" serializeAs="String">
        <value>30</value>
      </setting>
      <setting name="HttpQueueMaxTimeouts" serializeAs="String">
        <value>30</value>
      </setting>
        <setting name="HttpQueueRequestTimeout" serializeAs="String">
            <value>30000</value>
        </setting>
        <setting name="HttpQueueMaxBackoffTime" serializeAs="String">
            <value>10000</value>
        </setting>
        <setting name="HttpQueueMaxQueuedRequests" serializeAs="String">
            <value>5000</value>
        </setting>
        <setting name="HttpQueueQueueTimeout" serializeAs="String">
            <value>90000</value>
        </setting>
        <setting name="HttpQueueReconnectInterval" serializeAs="String">
            <value>60000</value>
        </setting>
        <setting name="HttpQueueMaxConcurrentRequests" serializeAs="String">
            <value>1</value>
        </setting>
        <setting name="LastTouchCheckIntervalSeconds" serializeAs="String">
        <value>60</value>
      </setting>
      <setting name="LastTouchSecondsDisconnect" serializeAs="String">
        <value>0</value>
      </setting>
      <!-- Set to the IP Address of the Photon instance where your Master application is running. -->
      <setting name="MasterIPAddress" serializeAs="String">
        <value>15.24.15.114</value>
      </setting>
      <setting name="MaxEmptyRoomTTL" serializeAs="String">
        <value>60000</value>
      </setting>
      <!-- Gameserver-to-Master connections. -->
      <setting name="OutgoingMasterServerPeerPort" serializeAs="String">
        <value>4520</value>
      </setting>
      <setting name="PublicIPAddress" serializeAs="String">
        <value></value>
      </setting>
      <setting name="PublicIPAddressIPv6" serializeAs="String">
        <value></value>
      </setting>
      <!-- the hostname for this gameserver. Required for HTTP & websocket connections. Change it to a useful entry, like hostname.mydomain.com, for a production scenario. -->
      <setting name="PublicHostName" serializeAs="String">
        <!--<value>%COMPUTERNAME%.mydomain.com</value>-->
        <value>localhost</value>
      </setting>
      
      <!-- The domain name for this gameserver. Required for websocket connections and needs to match the certificate for secure websocket / https connections. 
           For example:  mydomain.com -->
      <setting name="PublicDomainName" serializeAs="String">
        <value />
      </setting>
      <以上是关于Photon Server LoadBalancing搭建的主要内容,如果未能解决你的问题,请参考以下文章

photon引擎的photon引擎5分钟快速入门

Photon Server 连接 Demo 在 Android studio 上执行错误

Photon Server 实现注册与登录 --- 服务端代码整理

What is Photon Server?

Photon Server鍒濊瘑(涓? ---ORM鏄犲皠鏀硅繘

Photon Server 实现注册与登录 --- 服务端响应登陆和注册