Architecture & Performance
SQL Server22 December 20234 min de lectureArticle en anglais

SQL Server AlwaysOn Feature Tutorial : Part 3 - install SQL Server on a domain VM

In these articles, we’ll look at how to set up high availability on one or more databases with the AlwaysOn feature, using the « dbatools » PowerShell library. To do this, we’ll…

Pierre-Antoine Collet
Pierre-Antoine Collet
Expert en Performance IT
#SQL Server
Sommaire

In these articles, we’ll look at how to set up high availability on one or more databases with the AlwaysOn feature, using the « dbatools » PowerShell library. To do this, we’ll need to set up an active directory and install SQL Server on a domain VM, using Failover Clustering. In this article you will learn :

  • How to add a virtual machine to a domain
  • How to install and configure an SQL Server Instance with Dbatools

Add a virtual machine to a domain

First of all to install SQL Server on a domain VM, we need to create and configure the same VM as the one we created in part 1, but change its name.

Screenshot 2023-10-23 110926

Then connect to it. We can now configure our fixed IP address, so let's go to "Network Status" then "Change adapter options".Right-click on "Ethernet" and "Properties".

Screenshot 2023-10-23 111037

Select "Internet Protocol Version 4 (TCP/IPv4)" and right-click to select "Properties".

Screenshot 2023-10-23 135816

Then fill in the fields below, taking care to replace "IP address" and for "Preferred DNS Server" enter the IP address of the domain you've created.Test the ping with the Windows command prompt from the Active Directory server if your new VM responds.

Screenshot 2023-11-06 111543

Change the VM's domain name, type "About your PC" in the Windows menu.

Screenshot 2023-10-23 140803

Click on "Advanced system settings" and go to the "Computer Name" tab.

Screenshot 2023-10-23 140942

Click on "Change" and modify the "Computer name" and "Domain" fields.

Screenshot 2023-10-23 141141

Then enter the domain administrator user "perso_adm" and password.

Screenshot 2023-10-23 141420

Screenshot 2023-10-23 141300

Check in the Active Directory "Active Directory Users and Computers" whether your VM appears in "Computers".

Screenshot 2023-10-24 094942

Screenshot 2023-10-23 141512

Repeat this procedure for the second VM, remembering to change its IP address.

Install and configure an SQL Server instance

Let's now install SQL Server on a domain VM ! From your physical machine, download the SQL Server Evaluate Edition ISO file. Link : SQL Server 2022 | Microsoft Evaluation Center Then copy and paste it onto the VM where we're going to install a new instance.Install the dbatools powershell module by executing the powershell command below.

Install-Module -Name dbatools

To install the SQL server instance, use the powershell command below.

Screenshot 2023-10-24 104229

# Spécifiez le chemin du fichier ISO
$isoPath = "C:\SQLServer\SqlServer2022-x64-ENU.iso"
$version=2022
$InstanceName="EvaluationS2"
$feature="Engine"

# Montez le fichier ISO
Mount-DiskImage -ImagePath $isoPath
# Obtenez le chemin du lecteur monté
$mountedDrive = Get-DiskImage -ImagePath $isoPath | Get-Volume
# Affichez le chemin du lecteur monté
$driverLetter=$mountedDrive.DriveLetter

$path=$driverletter+":"

Install-DbaInstance -Version $version -InstanceName $InstanceName -Feature $feature -Path $path

Dismount-DiskImage -ImagePath $isoPath

Once the installation has been successfully completed and your VM has been restarted, run the SQL server 2022 configuration manager, located here : C:\Windows\SysWOW64\SQLServerManager16.mscOnce launched, you can execute the powershell command :  

Enable AlwaysOn Feature on SQL Server

$instancesql=Connect-DbaInstance -SqlInstance Server1\EVALUATIONS1 -TrustServerCertificate
Enable-DbaAgHadr -SqlInstance $instancesql -Force

Or, right-click on the instance you've just created, then "Properties", then check the box in the "Always On Availibility Groups" tab. Finally, you need to restart the instance by right-clicking "restart".Download the SSMS installer to your physical machine, then copy it to your VM to install it there.

Screenshot 2023-10-24 110110

Link : Download SQL Server Management Studio (SSMS) - SQL Server Management Studio (SSMS) | Microsoft LearnUsing SSMS, connect to your new instance.

Screenshot 2023-10-24 110945

SQL Server installation with powershell dbatools

Now we're going to create a login with the SQL service account we've created at domain level. To do this, go to "Security" then "Logins" and right-click "New Logins".Then "Search", look for the SQLSAV user and "CheckNames".

Screenshot 2023-10-24 111229

In the "Server Roles" tab, set the role to "sysadmin".

Screenshot 2023-10-24 111446

Finally, in the "Securables" tab, check the "Grant" box for "Alter any availibility group", "View server state" and "Connect SQL" on this instance.

Screenshot 2023-10-24 112232

Now we just need to modify the service account in the SQL server configuration manager.

Screenshot 2023-10-24 111647

By entering the "ADTEST\SQLSAV" service account and password.

Screenshot 2023-10-24 111820

You have now finish to install SQL Server on a domain VM but you need to go through this whole section again to create the second instance on the second VM, without forgetting to change the instance name.

Conclusion

You now know how to install SQL Server on a domain VM. So, you have your two SQL Server instances on two different VMs belonging to the same domain. In Part 4, we'll look at how to set up a Windows cluster failover.

Besoin d'aide sur ce sujet ?

Notre équipe d'experts est à votre disposition pour vous accompagner.

Contactez-nous