Appfabric caching 使用半年总结
一.原理
和Memcached类似,采用C/S的模式,在 server 端启动服务进程,在启动时可以指定监听的 ip,自己的端口号,所使用的内存大小等几个关键参数。一旦启动,服务就一直处于可用状态。
二.常用命令
1.Start-CacheCluster
2.Stop-CacheCluster
3.Get-CacheHost 可以得到所有的Cache主机
4.Start-CacheHost GFTEST:22233 启动一个Cache主机
5.Stop-CacheHost GFTEST:22233 停止一个Cache主机
6.Get-CacheAllowedClientAccounts 得到授权的用户.
7.Grant-CacheAllowedClientAccount NetworkService 给用户授权
8.Export-CacheClusterConfig -File E:\VelocityCache\ClusterConfig.xml
9.Import-CacheClusterConfig -File E:\VelocityCache\ClusterConfig.xml
10.Get-CacheStatistics default 得到默认或当前cache的详细统计结果。
三.安全设置
在开发机上可以设置授权用户如下:
<securityProperties mode="None" protectionLevel="None">
<authorization>
<allow users="administrator" />
<allow users="NetworkService" />
</authorization>
</securityProperties>
但放服务器上不工作,可能因为服务器的种种安全设置,没仔细找到具体原因。知道要让程序顺利访问cache, 最好将securityProperties 的模式设置为None。
<securityProperties mode="None" protectionLevel="None">
</securityProperties>
四.多个node
在多台机器上装cache服务时,第一台服务器叫做lead host,用来创建一个new cluster,其他服务器joint就可以了。
通过get-cachehost命令可以查到现在工作中的host列表。
PS C:\Windows\System32\WindowsPowerShell\v1.0\Modules\DistributedCacheAdministration> get-cachehost
HostName : CachePort Service Name Service Status Version Info
-------------------- ------------ -------------- ------------
DesktopPc:22233 AppFabricCachingService UP 1 [1,1][1,1]
TESTServer:22233 AppFabricCachingService UP 1 [1,1][1,1]
五.配置文件不能访问导致的cache服务瘫痪(crash), 报出的异常是:An error occurred loading a configuration file: The network path was not found.
平时配置文件都能访问,cache 服务也工作正常,不知怎的,每隔些日子,就会因为这个原因瘫痪一下,因为服务器放在机房,不知道是否是被机房所害.
AppFabric Caching service crashed with exception {Microsoft.ApplicationServer.Caching.DataCacheException: ErrorCode<ERRCMS0001>:SubStatus<ES0001>:Error while trying to load configuration: An error occurred loading a configuration file: The network path was not found.
(//companywebserver/AppFabricConfig/ClusterConfig.xml) ---> System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: The network path was not found.
(//companywebserver/AppFabricConfig/ClusterConfig.xml) ---> System.IO.IOException: The network path was not found.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForRead(String streamName, Boolean assertPermissions)
at System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
--- End of inner exception stack trace ---
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.Configuration..ctor(String locationSubPath, Type typeConfigHost, Object[] hostInitConfigurationParams)
at System.Configuration.ClientConfigurationHost.OpenExeConfiguration(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath)
at Microsoft.ApplicationServer.Caching.GlobalConfigReader.LoadConfigurationFromFile(String path, Boolean throwIfSectionNotFound)
--- End of inner exception stack trace ---
at Microsoft.ApplicationServer.Caching.ConfigFile.ThrowException(Exception e)
at Microsoft.ApplicationServer.Caching.GlobalConfigReader.LoadConfigurationFromFile(String path, Boolean throwIfSectionNotFound)
at Microsoft.ApplicationServer.Caching.ClusterConfigurationFactory.GetReader(ClusterConfigElement cs)
at Microsoft.ApplicationServer.Caching.ServiceConfigurationManager..ctor()
at Microsoft.ApplicationServer.Caching.VelocityWindowsService.StartService(Boolean deleteTKT)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()}. Check debug log for more information
查了一下, 分析说很可能是dns服务器的问题, 我测试了一下果然如此, 又上网搜了搜北京dns (202.96.199.133 202.96.0.133 202.106.0.20 202.106.148.1 202.106.0.20 202.106.196.115) , 结果都不行, 不知道怎么回事, 总之不太相信这个结果.
暂时的解决办法是修改host文件,将companywebserver 和127.0.0.1绑定,这样读cache时不出本机,观察几天看能否解决这个问题,但这样一来,多点cache集群就做不成了, 或许可以用内网ip代替127.0.0.1来解决这个问题。
最后找到google有个公共dns: 8.8.8.8, 还找到个河北的, 202.99.168.8, 也可以用, 先这样观察几天吧!
Hosts文件位置
C:\Windows\System32\drivers\etc
Hosts文件
http://zh.wikipedia.org/wiki/Hosts%E6%96%87%E4%BB%B6\
六.重起cache服务到真正可用的gap
经过测试, cache服务重起后, 已经是started状态了, 但程序一连还是不成, 也就是此时cache还没有ready, 等大概2-18分钟就好了, 没找到ms官方的解释, 纯粹个人经验.
七.参考
使用微软分布式缓存服务Velocity(Windows Server AppFabric Caching Service)
http://www.cnblogs.com/mlj322/archive/2010/04/05/1704624.html
The Network Path was not Found - Server 2008
八.一个完整的配置文件 ClusterConfig.xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="dataCache" type="Microsoft.ApplicationServer.Caching.DataCacheSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<dataCache size="Small">
<caches>
<cache consistency="StrongConsistency" name="default">
<policy>
<eviction type="Lru" />
<expiration defaultTTL="10" isExpirable="false" />
</policy>
</cache>
</caches>
<hosts>
<host replicationPort="22236" arbitrationPort="22235" clusterPort="22234"
hostId="883100817" size="4093" leadHost="true" account="CompanyWEBSERVER\AppFabricUser"
cacheHostName="AppFabricCachingService" name="CompanyWEBSERVER"
cachePort="22233" />
</hosts>
<advancedProperties>
<securityProperties mode="None" protectionLevel="None">
</securityProperties>
</advancedProperties>
</dataCache>
</configuration>
邮箱:lzd_ren@hotmail.com
出处:http://www.cnblogs.com/liuzhendong
本文版权归作者所有,欢迎转载,未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。