Package management
As we have learnt earlier Nano Server does not come with roles or features that are required in the server. In this section, we will learn to install roles on VM which is connected to Azure and create a custom VHD with roles already installed. Nano server comes with online package repository which allows us to connect to any online repository, install and download roles and features that are available. In order to connect to online package repository, the server should be connected to the internet, in the next section I will show you how to install packages on servers not connected to the internet.
As a first step let us get the list of package providers supported on Nano Server, run the following command from WinRM session connected to Nano Server on Azure:
Find-PackageProvider
Notice most of the famous package providers are supported on Nano Server, let us install the NanoServer package provider by running the following command. With the Windows Management Framework 5.0 preview, Microsoft released a PowerShell module called OneGet. OneGet is the new way to discover and install software packages from around the Web:
Install-PackageProvider NanoServerPackage
NanoServerPackage internally depends on NuGet provider so you will be prompted to download the dependent packages as well. Once installed you can import the package any time using the following command:
Import-PackageProvider NanoServerPackage
The following command shows the package providers installed on the machine:
Get-PackageSource
Run the following command given to see the packages available as part of NanoServerPackage:
Find-NanoServerPackage -Name *
The following command installs IIS on Nano Server:
Find-NanoServerPackage *iis* | install-NanoServerPackage
-culture en-us
Restart the server using the following command:
restart-computer
The following command creates a new site under IIS and set the physical path location:
cd\
md mysite
Import-module iis*
New-iissite -Name mysite -BindingInformation
"*:80:mysite" -PhysicalPath c:\mysite
If we browse by using the public IP or DNS Name of the Nano Server, we should see the default IIS page. Ensure the Nano Server contains the inbound security rule for port 80 open. After you have installed the package you can list by using Get-Package cmdlet or uninstall a package by using the Uninstall-Package cmdlet.
Installing packages on a server connected to Internet is easy as you have seen. In some enterprises, the machines in private data centers are not connected to internet due to security reasons, in such cases we must perform an offline installation of roles or features in Nano Server. There are a couple of ways to do this; one way is to create a custom image. If you are planning to build a farm or a cluster of hundreds of Nano server machines seemingly this is the best option, it allows you to create a custom Nano Server image with the required software installed which can be re-used to create any number of Nano Server machines. To create a custom Nano Server image, we should download the Windows Server 2016 ISO. You can download the 6.5 GB ISO image from https://www.microsoft.com/en-us/evalcenter/evaluate-windows-server-2016/. In the following section, we will build a custom Nano Server image with IIS installed and create a virtual machine using the custom image:
On a Windows 10 machine, right-click the downloaded ISO file and say Mount.
Open the mounted disk in Windows Explorer and copy the contents of d:\NanoServer to a separate folder on the host like c:\nano. Here D:\ drive is where the ISO is mounted on my machine.
Open a new PowerShell windows under elevated permissions and run the following command to import the image preparation module for Nano Server.
Import-Module C:\nano\NanoServerImageGenerator.psm1
The following command creates a new Nano Server image using standard edition. In the following command, media path points to the drive where the ISO is mounted, BasePath will be used to store temporary files, TargetPath is where the result is stored and package option mentions the package to be installed on the server:
New-NanoServerImage -Edition Standard -MediaPath D:\
-BasePath C:\Nano -TargetPath c:\nano\nanowebserver.vhdx
-DeploymentType Guest -ComputerName nanowebserver -Storage
-Package Microsoft-NanoServer-IIS-Package -verbose
Enter the administrator password when prompted. The image preparation takes a couple of minutes, the following image shows the verbose log and the progress indicator:
After successful completion the .vhdx file should be available at c:\nano\nanowebserver.vhdx. Let us create a new virtual machine using this .vhdx file and the steps as mentioned in the section Provisioning Nano Server on Windows 10
As shown, I'm attempting to create a new virtual machine using Hyper-V manager and the .vhdx file created previously:
Ensure the machine is running and WinRM is configured on the virtual machine.
Login to the machine from a PowerShell window using WinRM command shown:
Set-Item WSMan:\localhost\Client\TrustedHosts -Value
<<IP address of the VM>>
Enter-PSSession -VMName nanowebserver -credential
<<IP Address of the VM>>\administrator
You can now manage IIS using PowerShell commands, enable/disable IIS features, create websites, app pools, certificates and so on using the PowerShell cmdlets. The following image shows few commands used to create a default website:
Let us image you have a set of Nano Servers running and you are asked to install a new Package like IIS or DSC, the above method would not help. For such cases, we can move the packages folder to the remote virtual machine and perform and offline installation. The following line creates a PowerShell session which will used to copy files to the remote server.
$session = New-PSSession -VMName nanowebserver
-Credential nanowebserver\administrator
Next, let us copy the packages folder from the host machine to the remote machine using the following command. The packages folder contains the .cab file one for each package as shown in the following command. These files can be found under D:\Nanoserver\Packages inside the ISO file when mounted:
copy-item 'C:\nano\packages' -Destination c:\nano -recurse
-ToSession $session -verbose
Now remote login into the virtual machine and run the following commands to install the IIS package on the Nano Server:
dism /online /add-package /PackagePath:c:\nano\Microsoft
-NanoServer-Storage-Package.cab
dism /online /add-package /PackagePath:c:\nano\Microsoft
-NanoServer-IIS-Package.cab
For more information on managing IIS on Windows Server 2016 - Nano Server please visit https://technet.microsoft.com/en-us/windows-server-docs/get-started/iis-on-nano-server#application-development.
No comments:
Post a Comment