【IT168技术文档】
每个AppPool要指定一个身份(identity)来运行。IIS6中AppPool默认运行身份为NT AUTHORITY\NETWORK SERVICE。这是一个系统内建帐户,完全受系统控制。它支持所有必要的以服务登录(Log on as a service)的权限,密码也是内部来维护——换句话说,我们可以把以服务登录理解为它可以控制了哪些帐户能够使用、操作远程资源。我们可以通过很多方法控制远程资源的访问。比如修改远程资源ACL表,并允许远端机器访问本地资源;或者在远程访问时换作远端授信帐户(impersonating)进行操作;或者索性让我们的程序运行在某一个配置帐户下——log on as a service。不同的是它是宿主在IIS的AppPool中的,必然收到IIS控制,用户本身没有办法像普通服务程序那样启动它。我要试验的就是指定 AppPool以配置帐户启动。
我们分几步来部署一个web程序以指定账户运行。
1. 打开IIS6,在AppPool节点找到我们要修改的web程序,右键属性。
默认IIS是选择Predefined帐户:Network Service。现在我们勾选Configurable,并指定帐户和密码。注意:这个帐号必须是一个域帐号!
2. 将我们之前指定的apppool帐号加入IIS_WPG用户组中。IIS_WPG用户组维护了所有可以以其中帐户启动worker Process的帐户。Worker Process是由IIS启动的。
做完这两步,本以为可以完美的开启自定义帐户运行的w3wp.exe。却不想得到"Service Unavailable”的异常。翻看event log,我们得到以下一些错误:
错误一:此错误基本就是重复一下Service Unavailable的意思。。。注意主谓关系:有某某后台要启动某个process来运行appPool。这个process肯定就是w3wp.exe。但那个后台是谁?这里还不知道。
错误二:已经告诉我们所指定的appPool帐户非法。另外一个极重要的提示回答了error一的疑惑:是World Wide Web Publishing Service无法启动w3wp.exe。(这里也回答了文章最初的问题)至此,唯一的问题就是为什么帐户非法?往下看。。。Event Type: Error Event Source: W3SVC Event Category: None Event ID: 1059 Date: 1/18/2008 Time: 11:48:27 AM User: N/A Computer: HITOMI Description: A failure was encountered while launching the process serving application pool 'HITOMIWS'. The application pool has been disabled. For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
错误三:谜底揭晓了。该账户没有被赋予logontype4,导致它非法。如果有经验的话,这种帐户-logonType控制是在local Security Settings\Local Policy\User Rights Assignments里定义的。具体来说就是log on as a service。Event Type: Warning Event Source: W3SVC Event Category: None Event ID: 1057 Date: 1/18/2008 Time: 11:48:27 AM User: N/A Computer: HITOMI Description: The identity of application pool 'HITOMIWS' is invalid, so the World Wide Web Publishing Service can not create a worker process to serve the application pool. Therefore, the application pool has been disabled. For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
Event Type: Failure Audit Event Source: Security Event Category: Logon/Logoff Event ID: 534 Date: 1/18/2008 Time: 11:48:08 AM User: NT AUTHORITY\SYSTEM Computer: HITOMI Description: Logon Failure: Reason: The user has not been granted the requested logon type at this machine User Name: HITOMIWEBSERVICE Domain: REDMOND Logon Type: 4 Logon Process: Advapi Authentication Package: Negotiate Workstation Name: HITOMI Caller User Name: HITOMI$ Caller Domain: REDMOND Caller Logon ID: (0x0,0x3E7) Caller Process ID: 640 Transited Services: - Source Network Address: - Source Port: - For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.