• 使用PowerShell 自动安装IIS 及自动部署网站


    执行环境:Windows Server 2012 R2

    安装iis核心代码,可自定义安装项

    注意这里不能使用add-windowsfeature  "Web-Filtering","Web-IP-Security"方式自定义安装,会抛出异常,我猜测是安装顺序的问题

    $iisInstallPro = "Web-Filtering","Web-IP-Security","Web-Url-Auth","Web-Windows-Auth","Web-Basic-Auth","Web-Http-Errors","Web-Static-Content","Web-Default-Doc","Web-Dir-Browsing","Web-Stat-Compression","Web-Http-Logging","Web-ODBC-Logging","Web-Mgmt-Console","Web-WHC","Web-Net-Ext","Web-Net-Ext45","Web-ASP","Web-Asp-Net","Web-Asp-Net45","Web-CGI","Web-ISAPI-Ext","Web-ISAPI-Filter","Web-WebSockets","Web-Includes","Web-AppInit";
    $features = get-windowsfeature web-*
    foreach($item in $features)
    {
      if($item.installed -eq $false -and $iisInstallPro -Match $item.Name)
      {
        Write-Host "安装:" $item.displayname
        $item | add-windowsfeature -WarningAction silentlyContinue
      }
    }

    自动安装IIS

    $features = get-windowsfeature web-*
    foreach($item in $features)
    {
      if($item.installed -eq $false)
      {
        Write-Host "安装:$item.displayname"
        $item | add-windowsfeature
      }
    }
    
    function RegisterAndEnableIsapi
    {
     $isapiPath ="$env:windirMicrosoft.NETFrameworkv4.0.30319aspnet_isapi.dll"
      
      $isapiConfiguration = get-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$isapiPath']/@allowed"
      if($null -eq $isapiConfiguration)
      {
        Write-Host "IIS尚未注册aspnet_isapi.dll"
        $tmpPath=""
       
       
        $tmpPath = "$env:windirMicrosoft.NETFrameworkv4.0.30319"
        
        set-location $tmpPath
        .aspnet_regiis.exe -i
        $isapiConfiguration = get-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$isapiPath']/@allowed"
      }
      if($isapiConfiguration.Value -eq $false)
      {
          Write-Host "IIS已经注册过aspnet_isapi.dll,但未启用"
        set-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$isapiPath']/@allowed" -value true
        if(Is64Bit)
        { 
          set-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$env:windirMicrosoft.NETFrameworkv4.0.30319aspnet_isapi.dll']/@allowed" -value true
        }
        Write-Host "isapi已启用"
      }
      else
      {
          Write-Host "IIS已经注册过aspnet_isapi.dll,且已启用"
      }
    }
    
     RegisterAndEnableIsapi
    View Code

     自动部署网站     参考链接

    Import-Module WebAdministration
    New-Item –Path IIS:AppPoolsMyAppPool
    New-Website –Name MyWebApp –PhysicalPath D:apidd
    New-WebApplication -Name testApp -Site 'MyWebApp' -PhysicalPath D:apidd -ApplicationPool DefaultAppPool

      

    powershell自动安装iis,点击打开。打开之后如下图

    1.输入get-windowsfeature web* 查看已经安装过的IIS 功能(IIS的安装包全部以web开头的),结果如下(没有安装任何功能,安装过的前面[ ]会有X)。

    2.安装web-server,就是IIS 服务了。

    install-windowsfeature web-server 

    安装后会如果提示 Success 就是安装成功了。

  • 相关阅读:
    AutomaticallyProfile 自动化引擎 MyBatis和DB沟通的引擎 (根据数据库信息自动给生成实体类那些...)
    经典aop,
    IOC和DI区别,aop的第一个案例,注入方式(7种),aop的7个专业术语,注解的DI,代理(动态代理,静态代理)
    AOP(AOP概念,AOP专业术语,单例模式,bean的id和name属性,基于xml的DI, 构造注入,命名空间p注入,集合属性注入, List 配置文件)
    ajax
    spring基础
    一对多,多对一,自关联,多对多,一级缓存,二级缓存
    hql语法
    sql操作语言
    Oracle函数
  • 原文地址:https://www.cnblogs.com/GoCircle/p/11226683.html
Copyright © 2020-2023  润新知