IIS 7.0 Appcmd 使用
IIS 7.0:Appcmd.exe
IIS 7.0 提供了一个新的命令行工具 Appcmd.exe,可以使用该工具来配置和查询 Web 服务器上的对象,并以文本或 XML 格式返回输出。下面是一些可以使用 Appcmd.exe 完成的任务的示例:
? 创建和配置站点、应用程序、应用程序池和虚拟目录。
? 停止和启动站点。
? 启动、停止和回收应用程序池。
? 查看有关在 Web 服务器上运行的工作进程和请求的信息。
Appcmd.exe 为常见的查询和配置任务提供了一致的命令,从而降低了学习语法的复杂性。例如,您可以使用 list 命令来搜索有关对象(如应用程序)的信息,也可以使用 add 命令来创建对象(如站点)。
另外,您还可以将命令组合在一起使用,以返回与 Web 服务器上对象相关的更为复杂的数据,或执行更为复杂的任务。例如,您可以完成类似如下任务的复杂任务:停止所有具有运行时间超过六十秒的请求的站点。
IIS 7.0:启动 Appcmd.exe
如果要通过使用命令 shell 窗口来配置 IIS 7.0 设置,请打开 Appcmd.exe。Appcmd.exe 位于 %windir%\system32\inetsrv 目录中,只有管理员帐户或身为相应计算机上 Administrators 组成员的用户才可以访问此目录。此外,Administrators 组的成员必须在 Windows Vista® 和 Windows Server® 2008 中以提升的权限启动 Appcmd.exe,才能查看和更改以下服务器级配置文件中的设置:Machine.config、根 Web.config 文件(位于 .NET Framework 目录中)以及 ApplicationHost.config。查看或更改站点或应用程序目录中的 Web.config 文件的用户必须对这些目录中的文件具有读取和写入权限。
|
|
| 如果您运行的是 64 位 Windows,请从 本地驱动器\system32\inetsrv 目录而不是 本地驱动器\syswow64\inetsrv 目录使用 Appcmd.exe。 |
| 启动 Appcmd.exe | |||||||||||||
设置path环境 path=%path%;%SystemRoot%\System32\inetsrv 列出站点名称 appcmd list site /text:site.name 列出站点物理路径 APPCMD list vdirs /text:physicalPath
备份 >AppCmd Add Backup “BackupName” 罗列备份 >AppCmd List Backup 恢复 >AppCmd Restore Backup “BackupName”
1) Creating a backupTo create a backup, simply type in: >AppCmd Add Backup “BackupName” You can omit the name, in which case AppCmd is going to generate the backup name automatically using the current date and time. When a backup is created, the following happens:
2) Managing existing backupsTo list the backups that exist on the server, type in: >AppCmd List Backup This will list the backup objects, including their names that can be used to restore or delete them. To delete any of these backups if its no longer needed, type in: >AppCmd List Backup “BackupName” 3) Restoring a backupTo restore a backup, type in: >AppCmd Restore Backup “BackupName” This will stop IIS (equivalent to calling IISRESET.EXE /STOP), and overwrite the server’s state with the files in the specified backup directory. Then, IIS will be re-started (equivalent to calling IISRESET.EXE /START). If you do no want AppCmd to stop IIS (which can take a while), and instead want to stop and start services yourself, you can include the /stop:false parameter. Typically, only the IISADMIN service requires to be stopped so that the mbschema.xml file can be restored, if services like FTP or SMTP are being used. Other files, including applicationHost.config and administration.config, are not locked by the configuration system so they can be restored without stopping IIS, and IIS components will pick up the changes. I recommend that you make backups every time before making significant changes to the IIS7 configuration, which can save you a lot of time when something doesnt go as planned. I’ve watched “AppCmd Restore Backup” come to the rescue more times then I can count, so its almost always the first thing that I do when I begin working with a new server, or help someone on the team investigate an issue. In Windows Server “Longhorn” beta 3, we are adding a Configuration History service that automatically makes configuration backups every 2 minutes whenever configuration is changed. This often eliminates the need to do manual backups, but not completely – often its desireable to make a backup at a specific point before making changes, so that that exact state is saved and can be restored at any point. More info on the Configuration History service in a future post 转载来源
更详细用法
Application Pools appcmd list apppool /xml | appcmd recycle apppool /in
2. Stop application pools with word “cheap” in it 3. Set property enable32BitAppOnWin64 to true for all apppools (Filter apppools as in 2 if needed) appcmd list apppool /xml | appcmd set apppool /in /enable32BitAppOnWin64:true 4. Start apppools which are stopped 5. Recycle application pools which are used in some applications 6. Recycle apppools serving website “Default Web Site” appcmd list site “Default Web Site” /xml | appcmd list app /in /xml | appcmd list apppool /in /xml | appcmd recycle apppool /in
appcmd list app /site.name:”Default Web Site” /xml | appcmd list apppool /in /xml | appcmd recycle apppool /in Sites 8. Start the sites which are stopped 9. Set serverAutoStart to false for all sites 10. Keep sites config data and restore later appcmd list site /config /xml > sites.xml
appcmd add sites /in < sites.xml Applications and Vdirs 12. Move all applications in a site to NewAppPool apppool 13. List all sites with “/test” app 14. List apps created by user10 (assuming all his apps under a folder whose name contains user10) 15. List sites which read from C:\inetput\wwwroot 16. List the vdirs of sites which are stopped Worker processes and Requests 18. List apps served by wp 3600 Modules 20. Uninstall all native modules 21. Unlock all module entries under system.webServer/modules (won’t work on vista) Configuration Backups and Traces 24. List sites generating 404 转载来源 http://blogs.iis.net/ksingla/archive/2007/06/17/things-you-can-do-by-piping-appcmd-commands.aspx |
|||||||||||||
最新评论