IIS7Appcmd 命令詳解


IIS7 Appcmd 命令詳解

 廢話不說!雖然有配置界面管理器!但是做安裝包的時候命令創建是必不可少的!最近使用NSIS制作安裝包仔細研究了一下Appcmd的命令,可謂是功能齊全.

上網查了些資料,那些博客大部分都是轉載的別人的。都是些基本的介紹,很多命令都沒介紹到(不知道是不是我走眼了)。

就連微軟的 技術資源庫 也不詳細:

附地址:http://technet.microsoft.com/zh-cn/library/cc772200(WS.10).aspx(反正我找了一遍!沒找到我要的)

 

微軟的 技術資源庫 有的我就不介紹了,點開上面的鏈接自己去看。

(介紹我們能用到的一些命令,目前只包含site 的操作,其他apppool config app vdir 后續有時間在加入)


 

一:准備工作

APPcmd.exe 位於 C:\Windows\System32\inetsrv 目錄

使用 Cd c:\Windows\System32\inetsrv 切換到該目錄


 

二:命令操作簡介

IIS 命令行管理工具基本格式:

APPCMD (命令) (對象類型) <標識符> </參數1:值1 ...>

支持的對象類型:

SITE      虛擬站點的管理
APP       管理應用程序
VDIR      管理虛擬目錄
APPPOOL   管理應用程序池
CONFIG    管理常規配置節
WP        管理工作進程
REQUEST   管理 HTTP 請求
MODULE    管理服務器模塊
BACKUP    管理服務器配置備份
TRACE     使用失敗請求跟蹤日志

 -----------這個就不解釋很詳細了,懂的人都知道這個IIS的層次。

 


 

三:對Site的命令詳解

  1.命令介紹

虛擬站點的管理

APPCMD <命令> SITE [標識符] [-參數1:值1 ...]    如: appcmd list site (列出當前存在的站點)

支持的命令:

list      列出虛擬站點
set       配置虛擬站點
add       添加新虛擬站點
delete    刪除虛擬站點
start     啟動虛擬站點
stop      停止虛擬站點

  2.詳解

列出虛擬站點

APPCMD list SITE [標識符] [-參數1:值1 ...]

列出計算機上的虛擬站點。此命令可用於使用特定站點的標識符或 url 查找該站點,或者
基於指定的站點屬性匹配零個或多個站點。

示例:

 appcmd list sites

    列出計算機上的所有站點。

 appcmd list site "Default Web Site"

    查找站點“Default Web Site”。

 appcmd list site http://localhost/app1

    查找與指定的 url 關聯的站點。

 appcmd list site /serverAutoStart:false

    查找“serverAutoStart”配置屬性設置為“false”的所有站點。

添加新虛擬站點

APPCMD add SITE [標識符] [-參數1:值1 ...]

使用指定的設置創建新的虛擬站點。至少,必須提供站點名稱和 ID。

支持的參數:

 /name (必需) 站點名稱

 /id 站點 ID

 /bindings “http://domain:port,...”好記格式或“protocol/bindingInformation,...”原始格式的綁定列表

 /physicalPath

如果指定,將導致為該站點創建包含指向指定路徑的根虛擬目錄的根應用程序。如果忽
略,將創建一個沒有根應用程序的站點,並且該站點在創建根應用程序之前將無法啟動。


示例:

 appcmd add site /name:"My New Site" /id:2 /bindings:http://www.domain.com:80

    使用指定的好記綁定創建一個新站點“我的新站點”,以便在端口 80 上偵聽對 www.d
omain.com 的 http 請求。

 appcmd add site /name:"My New Site" /id:2 /bindings:http://*:81

    使用指定的好記綁定創建一個新站點“我的新站點”,以便在端口 81 上偵聽對任何域
名的 http 請求。

 appcmd add site /name:"My New Site" /id:2 /bindings:http/*:81:

    使用指定的 ID 和綁定創建新站點“我的新站點”。創建后,新站點中不包含任何應用
程序。

 appcmd add site /name:"My New Site" /id:2 /bindings:http/*:81: /physicalPath:"c
:\inetpub\mynewsite"

    使用指定的 ID 和綁定創建新站點“我的新站點”。系統將自動創建根虛擬目錄指向指
定物理路徑的根應用程序。

 appcmd add site /name:"My New Site" /bindings:http/*:81:

    使用綁定創建新站點“我的新站點”,並自動生成站點 ID。創建后,該新站點不包含
任何應用程序。

 

配置虛擬站點

APPCMD set SITE [標識符] [-參數1:值1 ...]

允許設置指定虛擬站點的屬性。必須提供准確的站點標識符,並且必須將該標識符解析為現
有站點。

支持的參數:

 identifier (必需)

    要修改的站點的站點名稱或 url

 /site.name

    要修改的站點的站點名稱或 url (與標識符相同)

 /bindings

    “http://domain:port,...”好記格式或“protocol/bindingInformation,...”原始
格式的綁定列表


示例:

 appcmd set site "Default Web Site" /serverAutoStart:false /id:100

    設置“Default Web Site”站點的“serverAutoStart”和“id”屬性。

這里對  set 操作附加一些高級操作(重要)

當時用 appcmd set site "Default Web Site"  當時用后其他高級參數

解釋后續補上............

-name 名稱
-id ID標識
-serverAutoStart 是否自動啟動
-bindings.[protocol='string',bindingInformation='string'].p
-bindings.[protocol='string',bindingInformation='string'].b
-limits.maxBandwidth
-limits.maxConnections
-limits.connectionTimeout
-logFile.logExtFileFlags
-logFile.customLogPluginClsid
-logFile.logFormat
-logFile.directory
-logFile.period
-logFile.truncateSize
-logFile.localTimeRollover
-logFile.enabled
-traceFailedRequestsLogging.enabled
-traceFailedRequestsLogging.directory
-traceFailedRequestsLogging.maxLogFiles
-traceFailedRequestsLogging.maxLogFileSizeKB
-traceFailedRequestsLogging.customActionsEnabled
-applicationDefaults.path
-applicationDefaults.applicationPool
-applicationDefaults.enabledProtocols
-virtualDirectoryDefaults.path 
-virtualDirectoryDefaults.physicalPath 網站的物理路徑
-virtualDirectoryDefaults.userName  物理路徑憑據的賬戶
-virtualDirectoryDefaults.password  物理路徑憑據的密碼
-virtualDirectoryDefaults.logonMethod 
-virtualDirectoryDefaults.allowSubDirConfig 
-[path='string'].path
-[path='string'].applicationPool
-[path='string'].enabledProtocols
-[path='string'].virtualDirectoryDefaults.path
-[path='string'].virtualDirectoryDefaults.physicalPath
-[path='string'].virtualDirectoryDefaults.userName
-[path='string'].virtualDirectoryDefaults.password
-[path='string'].virtualDirectoryDefaults.logonMethod
-[path='string'].virtualDirectoryDefaults.allowSubDirConfig
-[path='string'].[path='string'].path
-[path='string'].[path='string'].physicalPath
-[path='string'].[path='string'].userName
-[path='string'].[path='string'].password
-[path='string'].[path='string'].logonMethod
-[path='string'].[path='string'].allowSubDirConfig
 

刪除虛擬站點

APPCMD delete SITE [標識符] [-參數1:值1 ...]

描敘: 從計算機刪除指定的虛擬站點。必須提供准確的站點標識符,並且必須將該標識符解析為現有站點。

支持的參數:

 identifier    (必需)要刪除的站點的站點名稱或 url

 /site.name   要刪除的站點的站點名稱或 url (與標識符相同)


示例:

 appcmd delete site "Default Web Site"           刪除站點“Default Web Site”。

 

啟動虛擬站點

APPCMD start SITE [標識符] [-參數1:值1 ...]

啟動指定的虛擬站點並啟用該站點,以開始偵聽其所有綁定端點上的新請求。必須提供准確的站點標識符,並且必須將該標識符解析為現有站點。

支持的參數:

 identifier    (必需)要啟動的站點的站點名稱或 url

 /site.name    要啟動的站點的站點名稱或 url (與標識符相同)


示例:

 appcmd start site "Default Web Site"

    啟動站點“Default Web Site”。

 

停止虛擬站點

APPCMD stop SITE [標識符] [-參數1:值1 ...]

停止指定的虛擬站點,阻止在其綁定端點上接收新請求。必須提供准確的站點標識符,並且
必須將該標識符解析為現有站點。

支持的參數:

 identifier    (必需)要停止的站點的站點名稱或 url

 /site.name    要停止的站點的站點名稱或 url (與標識符相同)


示例:

 appcmd stop site "Default Web Site"

    停止站點“Default Web Site”。

 

1 添加應用程序進城池

appcmd.exe add apppool  /name:test.com  /managedRuntimeVersion:"v4.0" /managedPipelineMode:"Integrated"

2 添加站點,指定站點名,綁定,物理路徑 

appcmd.exe add site /name:"test.com"  /id:1 /bindings:http/*:81:  /physicalpath:"E:\webroot\test.com\Web"  

3 指定站點的進城池

appcmd.exe set site /site.name:"test.com" /[path='/'].applicationPool:test.com

4 指定站點的默認文檔為index.aspx

 

appcmd.exe set config "test.com/" /section:defaultDocument /+files.[@start,value='index.aspx'] /commit:"test.com"

 

5 把特定目錄的腳本執行權限關閉

 

appcmd set config "test.com/Download" /section:handlers /accessPolicy:Read

6導出一個機器上的所有應用進程池

%windir%/system32/inetsrv/appcmd list apppool /config /xml > c:/apppools.xml

7 導出1個機器上的所有站點

 %windir%/system32/inetsrv/appcmd list site /config /xml > c:/sites.xml

8 導入所有進程池

%windir%/system32/inetsrv/appcmd add apppool /in < c:/apppools.xml

9 導入所有站點

%windir%/system32/inetsrv/appcmd add site /in < c:/sites.xml

以下是批處理腳本

10 給站點文件授權

ICACLS e:\webroot\test.com\  /inheritance:e /grant:R "IIS AppPool\test.com":R 

ICACLS e:\webroot\test.com\*  /inheritance:e /grant:R "IIS AppPool\test.com":R 

ICACLS e:\webroot\test.com\download   /grant:M "IIS AppPool\test.com":R

ICACLS e:\webroot\test.com\download\*   /grant:M "IIS AppPool\test.com":R 

 

*******************************************************
set Sitename=test.com
set SitePath=E:\webroot\test.com
set LogPath=G:\logfile
set defaultDocument='index.aspx'
set Is32BitApp =False
set BackPort=99
set netversion=v4.0
set Cache=Cache
%windir%\system32\inetsrv\Appcmd add apppool  /name:%Sitename%  /managedRuntimeVersion:%netversion% /managedPipelineMode:"Integrated" /enable32BitAppOnWin64:False
%windir%\system32\inetsrv\Appcmd add site /name:"%Sitename%"  /id:100 /bindings:http/*:%BackPort%:,http/*:80:%sitename%  /physicalpath:%SitePath% /logfile.directory:%LogPath%
%windir%\system32\inetsrv\Appcmd set site /site.name:"%Sitename%" /[path='/'].applicationPool:%Sitename%
%windir%\system32\inetsrv\Appcmd set config "%Sitename%/" /section:defaultDocument /+files.[@start,value=%defaultDocument%] /commit:"%Sitename%"
ICACLS %SitePath% /inheritance:e /grant:R "IIS AppPool\%SiteName%":R
ICACLS %SitePath%\* /inheritance:e /grant:R "IIS AppPool\%SiteName%":R
ICACLS %SitePath%\%Cache% /inheritance:e /grant:R "IIS AppPool\%SiteName%":R
ICACLS %SitePath%\%Cache% /inheritance:e /grant:R "IIS AppPool\%SiteName%":R

水域 2017-04-04 14:44:51
set Sitename=test.com
set SitePath=E:\webroot\test.com
set LogPath=G:\logfile
set defaultDocument='index.aspx'
set Is32BitApp =False
set BackPort=99
set netversion=v4.0
set Cache=Cache
%windir%\system32\inetsrv\Appcmd add apppool  /name:%Sitename%  /managedRuntimeVersion:%netversion% /managedPipelineMode:"Integrated" /enable32BitAppOnWin64:False
%windir%\system32\inetsrv\Appcmd add site /name:"%Sitename%"  /id:100 /bindings:http/*:%BackPort%:,http/*:80:%sitename%  /physicalpath:%SitePath% /logfile.directory:%LogPath%
%windir%\system32\inetsrv\Appcmd set site /site.name:"%Sitename%" /[path='/'].applicationPool:%Sitename%
%windir%\system32\inetsrv\Appcmd set config "%Sitename%/" /section:defaultDocument /+files.[@start,value=%defaultDocument%] /commit:"%Sitename%"
ICACLS %SitePath% /inheritance:e /grant:R "IIS AppPool\%SiteName%":R
ICACLS %SitePath%\* /inheritance:e /grant:R "IIS AppPool\%SiteName%":R
ICACLS %SitePath%\%Cache% /inheritance:e /grant:R "IIS AppPool\%SiteName%":R
ICACLS %SitePath%\%Cache% /inheritance:e /grant:R "IIS AppPool\%SiteName%":R

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM