zoukankan      html  css  js  c++  java
  • 使用脚本管理IIS

    参考资料
    https://technet.microsoft.com/zh-cn/library/cc779108(WS.10).aspx
    https://technet.microsoft.com/zh-cn/library/cc757536(WS.10).aspx
    https://technet.microsoft.com/zh-cn/library/cc781546
    http://blog.zhanxb.com/post/86/
    http://stackoverflow.com/questions/17454355/create-iis-6-application-pool
    http://www.perimeterless.org/2008/08/17-automatically-create-iis-application-pools/
    http://www.cnblogs.com/delphinet/archive/2010/03/25/1695531.html

    ADSUTIL.VBS CREATE w3svc/AppPools/MyAppPool IIsApplicationPool --创建程序池
    ADSUTIL.VBS set w3svc/AppPools/MyAppPool/AppPoolIdentityType 2 -------NetworkService 3-------自定义模式
    adsutil.vbs set w3svc/appPools/MyAppPool/enable32bitapponwin64 1 --启用32位
    ADSUTIL.VBS set w3svc/AppPools/MyAppPool/ManagedPipelineMode 0---集成模式 1 ---经典模式
    ADSUTIL.VBS set w3svc/AppPools/MyAppPool/managedruntimeversion v4.0 or v2.0---设置.net 版本


    adsutil.vbs get w3svc/appPools/MyAppPool/CPULimit -----CPU百分比限制
    adsutil.vbs set W3SVC/AppPools/ ApplicationPoolName /CPUAction ActionValue
    将 ActionValue 替换成相应的值:0 记录错误但不关闭进程;1 记录错误并关闭进程。


    ---创建程序池 --NetWorkService --集成模式 --启用32位 --.net 4.0 --CPU百分比限制 60% --KillW3Wp进程

    REM CREATEA APPPOOLS SCRPTS

    CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\ADSUTIL.VBS CREATE w3svc/AppPools/1 IIsApplicationPool CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\ADSUTIL.VBS SET w3svc/AppPools/1/ManagedPipelineMode 0 CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\ADSUTIL.VBS SET w3svc/AppPools/1/AppPoolIdentityType 2 CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs set w3svc/AppPools/1/CPULimit 60000 CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs set W3SVC/AppPools/1/CPUAction 1 CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\adsutil.vbs set w3svc/appPools/1/enable32bitapponwin64 1 CSCRIPT %SYSTEMDRIVE%\Inetpub\AdminScripts\ADSUTIL.VBS set w3svc/AppPools/1/managedruntimeversion v4.0

    pause


    ASP.NET程序在编译的时候默认是Any CPU,即编译的程序可以在X86、X64系统平台上运行。若希望我们的ASP.NET程序运行在X64系统上,我们所要做的仅仅是部署IIS,修改配置。
    若想程序运行于IIS32位模式下,即运行在.net framwork32位下进行如下配置:
    1.cscript %systemdrive%inetpubadminscriptsadsutil.vbs set w3svc/appPools/enable32bitapponwin64 1 修改IIS配置,允许32位程序运行
    2.C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_regiis -i 为IIS注册asp.net32。注册后在IIS的web扩展里显示的是Asp.net2.0.*32bit。
    3.Web扩展里允许 Asp.net2.0.*32bit运行。运行的是w3wp32.exe进程。
    二.64位模式
    1.cscript %systemdrive%inetpubadminscriptsadsutil.vbs set w3svc/appPools/enable32bitapponwin64 0 默认就是0,若原来运行了32位程序,则需要重新设置为0。
    2.C:WINDOWSMicrosoft.NETFramework64v2.0.50727aspnet_regiis - i 为IIS注册64为Asp.NET。注册了64位ASP.NET的IIS在Web扩展里显示的是Asp.net2.0.*。
    3.Web扩展里允许 Asp.net2.0.*运行。运行的是w3wp.exe进程

    -------------基于脚本创建IIS 应用程序池

    rem // Creates a new application pool called MyAppPool
    CSCRIPT %SYSTEMDRIVE%InetpubAdminScriptsADSUTIL.VBS CREATE w3svc/AppPools/MyAppPool IIsApplicationPool

    rem // if running under different user name and password
    rem CSCRIPT %SYSTEMDRIVE%InetpubAdminScriptsADSUTIL.VBS SET w3svc/AppPools/MyAppPool/WamUserName "domainusername"
    rem CSCRIPT %SYSTEMDRIVE%InetpubAdminScriptsADSUTIL.VBS SET w3svc/AppPools/MyAppPool/WamUserPass "pass"
    rem CSCRIPT %SYSTEMDRIVE%InetpubAdminScriptsADSUTIL.VBS SET w3svc/AppPools/MyAppPool/AppPoolIdentityType 3
    ========================================

    rem // create a new virtual directory (creates vdir "Test" and set it to D:WebSitesMyWebSite
    CSCRIPT %SystemRoot%system32iisvdir.vbs /Create W3SVC/1/ROOT Test D:WebSitesMyWebSite
    =================================

    rem // assign MyAppPool to "Test" web site
    CSCRIPT %SYSTEMDRIVE%InetpubAdminScriptsADSUTIL.VBS SET W3SVC/1/ROOT/Test/AppPoolId MyAppPool

    @ECHO OFF
    ECHO.
    FOR /F "eol=# delims=; tokens=1,2*" %%f in (apppools.txt) DO (
    ECHO Creating AppPool "%%f" with user identity "%%g"
    CSCRIPT %SYSTEMDRIVE%InetpubAdminScriptsADSUTIL.VBS CREATE "w3svc/AppPools/%%f" IIsApplicationPool
    CSCRIPT %SYSTEMDRIVE%InetpubAdminScriptsADSUTIL.VBS SET "w3svc/AppPools/%%f/WamUserName" "%%g"
    CSCRIPT %SYSTEMDRIVE%InetpubAdminScriptsADSUTIL.VBS SET "w3svc/AppPools/%%f/WamUserPass" "%%h"
    CSCRIPT %SYSTEMDRIVE%InetpubAdminScriptsADSUTIL.VBS SET "w3svc/AppPools/%%f/AppPoolIdentityType" 3
    ECHO.
    )
    pause


    And the correspondign text file:
    #
    # ";"-delimited file to create application pools
    # Beware of strange characters in password,
    # though ; should work
    # Structure is
    #
    # AppPool Name ; User ; Password
    tmpAppPool;tmpUser;tmpPass


    在 IIS 6.0 中启用 CPU 监视

    1(共 1)对本文的评价是有帮助 - 评价此主题
    更新时间: 2005年8月
    应用到: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1
    CPU 监视功能可以监视并自动关闭消耗大量 CPU 时间的工作进程。CPU 监视针对单个应用程序池启用。
    在启用 CPU 监视之前,请注意以下事项:
    IIS 必须以Worker Process Isolation Mode工作。

    CPU 监视只适用于应用程序池。

    CPU 监视不适用于 CGI 应用程序。

    Important重要事项
    只有本地计算机上 Administrators 组的成员才能执行以下过程。作为安全性最佳操作,请使用不属于 Administrators 组的帐户登录计算机,然后使用 runas 命令以管理员身份运行 IIS 管理器。在命令提示符下,键入 runas /user:Administrative_AccountName "mmc %systemroot%system32inetsrviis.msc"。
    通过使用 IIS 管理器来启用 CPU 监视
    在您通过使用 IIS 管理器启用 CPU 监视后,默认情况下 IIS 允许的最大 CPU 使用率为 50%。要更改默认值,请遵照此过程进行操作。
    启用 CPU 监视
    在 IIS 管理器中,依次展开本地计算机、“应用程序池”文件夹,右键单击要启用 CPU 记帐的应用程序池,然后单击“属性”。
    单击“性能”选项卡,然后选中“启用 CPU 监视”复选框。
    在“最大 CPU 使用率”框中,单击向上和向下箭头来设置应用程序池应使用的 CPU 的最大百分比。如果应用程序池的 CPU 使用率超出指定的最大限制,IIS 会在 Windows 事件日志中生成一条错误信息。
    在“刷新 CPU 使用率值(分钟)”框中,单击向上和向下箭头,设置刷新率。
    在“CPU 使用率超过最大使用率时执行的操作”列表框中,为指定的应用程序池单击选择所需的操作。
    要使 IIS 在应用程序池达到最大 CPU 使用率时将事件写入系统日志,同时不关闭应用程序池,请单击“无操作”。

    除了将事件记入系统日志之外,要关闭应用程序池,请单击“关闭”。

    默认情况下选择的是“无操作”。

    Important重要事项
    关闭应用程序池将会关闭为该应用程序池提供服务的所有工作进程。
    单击“应用”,然后单击“确定”。
    从命令行启用 CPU 监视
    从命令行启用 CPU 监视的过程可分三步进行:
    设置 CPULimit 配置数据库属性,以便将指定应用程序池中的工作进程限制为 CPU 时间的某个百分比。

    设置 CPUResetInterval 配置数据库属性,以指定 CPU 监视的时间间隔。

    设置 CPUAction 配置数据库属性,以指定您希望 IIS 执行的操作类型,如写入事件日志或关闭超出 CPU 限制的工作进程。

    设置 CPU 限制
    CPULimit属性配置了在 CPUResetInterval 属性设置的时间段内,允许应用程序池中的工作进程消耗 CPU 时间的最大百分比。如果超出了 CPULimit 属性设置的限制,将在事件日志中写入一个事件,并且将触发一个由 CPUAction 属性确定的可选事件集。将 CPULimit 属性的值设置为 0 可以禁用 CPU 监视。
    要对应用程序池启动 CPU 监视,请将 CPULimit 属性设置为大于 0 的值。要计算待设置的值,请确定您希望应用程序池中的工作进程使用的 CPU 时间的最大百分比,例如 50%(该值为默认值)。接下来将该百分比乘以 1,000 (50 1,000 = 50,000)。因此,要将 CPU 使用率限制为 50%,应将 CPU 限制的值设置为 50000。
    通过使用 Adsutil.vbs 设置 CPU 监视的 CPU 限制
    在“运行”对话框,键入 cmd,然后单击“确定”。
    在命令提示符下,键入:
    cscript %Systemroot%InetpubAdminScriptsadsutil.vbs set W3SVC/AppPools/ ApplicationPoolName /CPULimit n
    将 n 替换成允许该应用程序池使用的 CPU 的最大百分比与一个百分比的千分之一之比得到的值。
    设置 CPU 复位间隔
    对应用程序启用 CPU 监视之后,请使用 Adsutil.vbs 来设置 CPUResetInterval 属性的值,以指定 CPU 监视和限制应用程序池的复位时段(以分钟计)。如果自从上次 CPU 监视复位后,经过的时间达到此属性所指定的数值时,IIS 将复位用于日志记录和限制间隔的 CPU 计时器。默认值为 5 分钟。此属性的值设置为 0 将禁用 CPU 监视。
    Important重要事项
    CpuResetInterval 属性的值必须大于日志记录操作之间的时间;否则,IIS 将在进行日志记录之前复位计数器,这样就不会进行 CPU 监视。
    通过使用 Adsutil.vbs 设置 CPU 监视复位间隔
    在“运行”对话框,键入 cmd,然后单击“确定”。
    在命令提示符下,键入:
    cscript %SystemDrive%InetpubAdminScriptsadsutil.vbs set W3SVC/AppPools/ ApplicationPoolName /CPUResetInterval n
    将 n 替换成复位间隔的分钟数。要禁用 CPU 监视,请键入 0。
    设置 CPU 操作
    最后,设置 CPUAction 属性,以配置 Microsoft® Windows NT® 作业对象运行时 IIS 将执行的操作。每个应用程序池仅存在一个 Windows NT 作业对象;因此,您必须分别为每个应用程序池配置 CPUAction 属性。如果您未设置 CPUAction 配置数据库属性,则 IIS 将指定默认值,即 0(仅对事件进行日志记录)。
    通过使用 Adsutil.vbs 设置 CPUAction 值
    在“运行”对话框,键入 cmd,然后单击“确定”。
    在命令提示符下,键入:
    cscript %SystemDrive%InetpubAdminScriptsadsutil.vbs set W3SVC/AppPools/ ApplicationPoolName /CPUAction ActionValue
    将 ActionValue 替换成相应的值:0 记录错误但不关闭进程;1 记录错误并关闭进程。
    有关设置 CPU 操作的详细信息,请参阅 CPULimit Metabase Property、CPUResetInterval Metabase Property和CPUAction Metabase Property。
    相关信息
    有关 CPU 监视的详细信息,包括与 Windows 系统资源管理器的高级 CPU 监视对应的配置数据库属性及选项的描述,请参阅Enabling CPU Monitoring。

    有关当 IIS 在工作进程隔离模式下运行时可帮助管理和节省资源的相关功能的信息,请参阅Managing Resources in Worker Process Isolation Mode。

    使用 Adsutil.vbs 管理脚本

    3(共 5)对本文的评价是有帮助 - 评价此主题
    更新时间: 2005年8月
    应用到: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1
    Adsutil.vbs 是一个 IIS 管理实用程序,它通过结合使用 Microsoft Visual Basic Scripting Edition (VBScript) 与 Active Directory 服务界面 (ADSI) 来处理 IIS 配置。该脚本应通过随 Windows 脚本主机一同安装的 CScript 运行。
    Important重要事项
    只有本地计算机上 Administrators 组的成员才能运行脚本和可执行文件。作为安全性最佳操作,请使用不属于 Administrators 组的帐户登录计算机,然后使用 runas 命令以管理员身份运行脚本或可执行文件。在命令提示符下,键入 runas /profile /user:mymachineadministrator cmd,使用管理员权限打开一个命令窗口,然后键入 cscript.exe ScriptName(包括脚本的完整路径和任何参数)。
    使用
    Cscript.exe adsutil.vbs COMMAND <path> [<param>...]
    Cscript.exe adsutil.vbs COMMAND [<path> [<parameters>...]]

    命令 描述
    GET Path
    显示选择的参数。
    SET Path Value
    指定新值。
    ENUM Path "/P"
    枚举该路径的所有参数。/P 仅枚举路径(无数据)。
    ENUM_ALL "/P"
    枚举所有参数。/P 仅枚举路径(无数据)。
    DELETE Path
    删除路径或参数。
    CREATE Path [KeyType]
    创建路径并为其分配 KeyType。
    APPCREATEINPROC Path
    创建进程内应用程序。
    APPCREATEOUTPROC Path
    创建进程外应用程序。
    APPDELETE Path
    删除应用程序(如果存在)。
    APPUNLOAD Path
    卸载进程外应用程序。
    APPGETSTATUS Path
    获取应用程序状态。
    FIND Path
    查找设置了参数的路径。
    START_SERVER Path
    启动网站。
    STOP_SERVER Path
    停止网站。
    PAUSE_SERVER Path
    暂停网站。
    CONTINUE_SERVER Path
    网站取消暂停。
    HELP
    打印所有可用命令。
    注意
    <Path> 是指要设置其属性(包括要设置的属性名称)的节点路径。例如,要将 ServerComment 设置为“Web Server Number 1”,则命令如下:

    adsutil SET w3svc/1/ServerComment "Web Server Number 1"

    下一次打开 IIS 管理器时,Web 服务器的名称将变为“Web Server Number 1”。

    为了在远程计算机上执行开关“-s:server name”,可以在任何命令后面使用该命令。(参见下面第一个示例。)

    示例
    Cscript.exe adsutil.vbs GET W3SVC/1/ServerBindings -s:remotecomputer1

    Cscript.exe adsutil.vbs SET W3SVC/1/ServerBindings ":81:"

    Cscript.exe adsutil.vbs CREATE W3SVC/1/Root/MyVdir "IIsWebVirtualDir"

    Cscript.exe adsutil.vbs START_SERVER W3SVC/1

    Cscript.exe adsutil.vbs ENUM /P W3SVC


    利用adsutil.vbs脚本创建自定义web站点 不指定
    詹兴斌 , 2010/04/12 21:29 , 应用程序 » IIS , 评论(0) , 阅读(1830) , Via 本站原创 大 | 中 | 小
      //资源:C:InetpubAdminScriptscscript adsutil.vbs ,C:WINNTsystem32cscript.exe
      
      adsutil.vbs HELP //获得帮助信息
      cscript.exe adsutil.vbs //编译脚本
      cscript adsutil.vbs ENUM w3svc/1/root //通过查看默认80站点信息来获取更多信息
      
      //在默认站点下创建虚拟目录并指定工作文件夹和默认页面
      
      C:InetpubAdminScripts>cscript adsutil.vbs create_vdir w3svc/1/root/789 //虚拟目录名称:789
      
      created "w3svc/1/root/789"
      
      C:InetpubAdminScripts>cscript adsutil.vbs set w3svc/1/root/789/path e:html //虚拟目录磁盘路径
      
      path : (STRING) "e:html"
      
      C:InetpubAdminScripts>cscript adsutil.vbs set w3svc/1/root/789/defaultdoc login.asp //虚拟目录起始页面
      
      defaultdoc : (STRING) "login.asp"
      
      //创建一个全新的web站点,指定端口,指定工作目录
      
      C:Documents and SettingsAdministrator>cd C:InetpubAdminScripts //启动命令行
      
      C:InetpubAdminScripts>cscript adsutil.vbs enum /p w3svc //列出当前主机下所有站点信息,80站点为[/w3svc/1]
      
      [/w3svc/Info]
      [/w3svc/1]
      [/w3svc/Filters]
      [/w3svc/2]
      [/w3svc/3]
      [/w3svc/4]
      [/w3svc/5]
      [/w3svc/6]
      [/w3svc/7]
      [/w3svc/8]
      [/w3svc/9]
      [/w3svc/99]
      
      C:InetpubAdminScripts>cscript adsutil.vbs delete w3svc/99 //删除99站点 ,99为主机站点索引,可任意,不可重复
      
      deleted path "w3svc/99"
      
      C:InetpubAdminScripts>cscript adsutil.vbs create_vserv w3svc/99 //创建99站点
      
      created "w3svc/99"
      
      C:InetpubAdminScripts>cscript adsutil.vbs set w3svc/99/serversize 1 //设置99站点大小
      
      serversize : (INTEGER) 1
      
      C:InetpubAdminScripts>acscript dsutil.vbs set w3svc/99/servercomment "my test websit" //设置99站点别名
      
      servercomment : (STRING) "my test websit"
      
      C:InetpubAdminScripts>cscript adsutil.vbs set w3svc/99/serverbindings ":10003:" //设置99站点端口
      
      serverbindings : (LIST) ":10003:"
      
      C:InetpubAdminScripts>cscript adsutil.vbs set w3svc/99/enabledefaultdoc true //设置99站点默认文档
      
      enabledefaultdoc : (BOOLEAN) True
      
      C:InetpubAdminScripts>cscript adsutil.vbs create_vdir w3svc/99/root //设置99站点下root虚拟目录,必须存在
      
      created "w3svc/99/root"
      
      C:InetpubAdminScripts>cscript adsutil.vbs set w3svc/99/root/path e:html //设置99站点root工作目录
      
      path : (STRING) "e:html"
      
      C:InetpubAdminScripts>cscript adsutil.vbs set w3svc/99/root/accessread true //设置99站点root可读
      
      accessread : (BOOLEAN) True
      
      C:InetpubAdminScripts>cscript adsutil.vbs set w3svc/99/root/accesswrite true //设置99站点root可写
      
      accesswrite : (BOOLEAN) True
      
      C:InetpubAdminScripts>cscript adsutil.vbs set w3svc/99/root/enabledirbrowsing true //设置99站点root可浏览
      
      enabledirbrowsing : (BOOLEAN) True
      
      C:InetpubAdminScripts>cscript adsutil.vbs set w3svc/99/root/enabledefaultdoc true //设置99站点root默认文档
      
      enabledefaultdoc : (BOOLEAN) True
      
      C:InetpubAdminScripts>cscript adsutil.vbs set w3svc/99/root/accessscript true //设置99站点root可执行脚本
      
      accessscript : (BOOLEAN) True
      
      
      C:InetpubAdminScripts>cscript adsutil.vbs set w3svc/99/root/appfriendlyName 默认应用程序 //设置99站点root应用程序属性
      
      appfriendlyName : (STRING) "默认应用程序"
      
      C:InetpubAdminScripts>cscript adsutil.vbs start_server w3svc/99 //启动99站点
      
      Server w3svc/99 Successfully STARTED
      
      Application Pool Settings
      The initial IIS 6.0 application pool settings can be complex, and are frequently modified. Use Adsutil.vbs to create application pools in IIS, view their properties, and change application pool membership or recycle thresholds.
      
      To remotely create an application pool, run the following command.
      
      adsutil.vbs CREATE W3SVC/AppPools/ "IIsApplicationPool" –s:
      
      To remotely create an application pool on multiple servers, create a servers.txt file that lists server names and run the following command.
      
      for /f %i in (c:servers.txt) do adsutil.vbs CREATE
      W3SVC/AppPools/ “IIsApplicationPool” –s:%i
      
      Note: The -s switch instructs adsutil.vbs to execute the action on a remote server and is not found in adsutil.vbs HELP.
      
      The resulting application pool structure can be programmatically viewed on a remote Web server by running the following command.
      
      adsutil enum W3SVC/AppPools –s:
      
      To view a specific application pool on a remote Web server, run the following command.
      
      adsutil enum W3SVC/AppPools/ –s:
      
      After the application pool structure is created on a Web server, specific Web applications can then be moved to it. Adsutil.vbs can be used to move a Web application to a new application pool by changing the metabase AppPoolId entry.
      
      To remotely reassign an application's application pool membership, run the following command where 1 indicates the first Web site on the server, root indicates to start in the top level of site hierarchy.
      
      adsutil.vbs SET W3SVC/1/root//AppPoolId ""–
      s:
      
      After the applications are in the proper application pools, adsutil.vbs can be used to configure the application pool recycle settings. The default application pool recycling setting is based on elapsed time; however, the operations team prefers to modify the application pool recycling setting to be based on virtual memory limits due to the large volume of traffic and the characteristics of the code running in each of the application pools on Microsoft.com. For the current 64-bit Web servers with IIS configured to run 32-bit worker processes, the operations has configured a recycle to occur when an application pool reaches a virtual memory threshold of 4 GB. Keep in mind that these settings are tuned for a specific environment and they may not be appropriate for all environments. When the Microsoft.com site consisted of 32-bit Web servers, the application pool recycle limit was set at 2 GB. For more information about virtual memory differences on the x64-based platform, refer to the IT Showcase white paper Microsoft.com Moves to x64 Version of Windows at http://www.microsoft.com/technet/itsolutions/msit/ .
      
      To remotely set the virtual memory recycle limit to 2 GB for all application pools on a 32-bit Web server, run the following command.
      
      adsutil SET W3SVC/AppPools/PeriodicRestartMemory 2048000 –
      s:
      
      To remotely set the virtual memory recycle limit to 2 GB for a specific application pool on a 32-bit Web server, run the following command.
      
      adsutil SET W3SVC/AppPools//PeriodicRestartMemory
      2048000 –s:
      

  • 相关阅读:
    静态区,堆,栈
    C语言位操作
    引用形参
    联合体/共同体 union
    typedef的使用
    有源晶振和无源晶振
    什么是SMT钢网
    点名游戏~自己先作
    我同学——应聘阿里巴巴之经过
    阳光明媚的一天~|~
  • 原文地址:https://www.cnblogs.com/micro-chen/p/4441472.html
Copyright © 2011-2022 走看看