Finally the help of IT is here

Blog de soluciones informaticas.

Remote Desktop load balancing without NLB.

Escrito por albertfr on enero 7th, 2012

Hello,

Today we will explain how to do a load balancing terminal server without NLB product. Only using Round Robin DNS, some scripts and 1 GPO in Active Directory.

The system is composed by the following elements:

Terminal Servers (A) and (B) are Windows Server 2008 R2 with the following characteristics:

It has in the same LAN to avoid client-server latency over WAN.

 

Uses Thinprint Application Server Engine 8.6 to compress spooler traffic between terminal server and client. It’s perfect to print using WAN environment.

 

Both Terminal Servers can do load balancing and failover.

 

Uses Microsoft Office 2007 (Word, Excel, Powerpoint).

Balancing and failover system

The solution we have chosen will use a simple batch file (CMD) controlling server which users are going to connect using a Round Robin DNS register (which adds balancing) and, if it fails will try to connect to other servers (Failover). Here you have a picture with the schema:

 

NLBwithRoundRobin_2

With this method we improve the standard Round Robin DNS functionality because this method every time you request name, you get an ip address defined in the cluster, even if server is working or not.

With this script also is controlled the last server that user had logged on. This is to maintain session if connection is broken before user log off.

This system uses 3 scripts:

Connection Script(Used to start application from client.)

Launches an RDP connection file depending on the following algorithm:

 

  • Check if user has a disconnected session on the current system to connect to the same server. This requires a data generated for Logon script (which saves the current logged on server). If user closes the application, then logoff script, will remove that data.

 

  • If doesn’t exist a disconnected session, it tries to connect to Round Robin DNS name. This DNS name answers a different IP from a defined pool (which are the terminal servers) using the round robin method.

 

  • If it can’t connect, it retries the same name requesting the next server on the pool.

This is the script (ConnecttoRDP.CMD):

@ECHO OFF

SET PROFILEPATH=<Your Desired Server with LAN connectivty>profiles
SET RRAPPSERVER=<DNS Server Name by Round Robin activated>
SET LOGPATH=%PROFILEPATH%_Logs
SET LOGLASTSERVER=%LOGPATH%%Username%_LastServer.txt
SET LOGCONNECTION=%LOGPATH%%Username%_Connection.txt
SET RDPPATH=<server connection>.rdp
SET RRTRIES=10

ECHO Connecting, please wait…                              …..
REM ECHO                                                           .                     

ECHO STARTING CONNECTION SCRIPT… > %LOGCONNECTION%

IF NOT EXIST %LOGLASTSERVER% (
ECHO No last server log exists >> %LOGCONNECTION%
GOTO RRNAME
)

SET /p LASTSERVER=< %LOGLASTSERVER%
SET LASTSERVER=%LASTSERVER: =%
ECHO Last server used was %LASTSERVER% >> %LOGCONNECTION%

IF EXIST %LASTSERVER%.<yourdomain>.com%RDPPATH% (
ECHO Connecting to last server used ^(%LASTSERVER%^)… >> %LOGCONNECTION%
MSTSC %LASTSERVER%.<yourdomain>.com%RDPPATH%
GOTO END
) ELSE (ECHO Last server used not available! >> %LOGCONNECTION%)

:RRNAME

FOR /L %%T IN (1,1,%RRTRIES%) DO (
ECHO %RRAPPSERVER% connection attempt #%%T >> %LOGCONNECTION%
IPCONFIG /FLUSHDNS > NUL
IF EXIST %RRAPPSERVER%%RDPPATH% (
ECHO Connected to %RRAPPSERVER% >> %LOGCONNECTION%
MSTSC %RRAPPSERVER%%RDPPATH%
GOTO END
)
)
ECHO Unable to connect! >> %LOGCONNECTION%
ECHO Unable to connect! Press any key to try again…
PAUSE > NUL
GOTO RRNAME

:END
ECHO END CONNECTION SCRIPT. >> %LOGCONNECTION%

You need to create an icon in every user desktop with this script. For example an icon named Connection pointing to <desiredserverprofiles_ConnectionConnecttoRDP.CMD

Logon Script (Login.cmd)

  • It’s executed on Terminal Servers users log on process.

 

  • Restores previous application settings. If doesn’t exist any previous data it sets the minimum ones (database connection string,…).

This is the script:

@echo off
SET FILESERVER=<yourdesiredserver>profiles
SET LOGPATH=%FILESERVER%_Logs
SET LOGLASTSERVER=%LOGPATH%%Username%_LastServer.txt
SET LOGFILE=%LOGPATH%%Username%.txt
SET USERPATH=%FILESERVER%%USERNAME%
SET USERWINDOWSPATH=%USERPATH%WINDOWS
SET USERPROFILEWINDOWSDIR=%USERPROFILE%WINDOWS
SET CUSTOMREGFILEPERUSER=%USERPATH%USER_REGISTRY_CUSTOM.reg
SET REGISTRYBACKUP=%USERPATH%BACKUP_REGISTRY.reg

IF NOT EXIST %LOGPATH% MKDIR %LOGPATH%

ECHO LOGIN SCRIPT START 1.1 > %LOGFILE%

echo/|set /p =%COMPUTERNAME%> %LOGLASTSERVER%

ECHO CHECKING IF %USERWINDOWSPATH% EXISTS… >> %LOGFILE%
IF EXIST %USERWINDOWSPATH% (
ECHO COPYING USER WINDOWS FOLDER PROFILE… >> %LOGFILE%
COPY %USERWINDOWSPATH% %USERPROFILEWINDOWSDIR% /Y > NUL
)ELSE (ECHO NO, IT DOESN’T EXIST >> %LOGFILE%)

ECHO CHECKING IF %REGISTRYBACKUP% EXISTS… >> %LOGFILE%
IF EXIST %REGISTRYBACKUP% (
ECHO YES, IT EXIST! RESTORING USER REGISTRY BACKUP… >> %LOGFILE%
regedit /S %REGISTRYBACKUP%
GOTO END
)ELSE (ECHO NO, IT DOESN’T EXIST >> %LOGFILE%)

ECHO NEW USER… >> %LOGFILE%
ECHO CHECKING IF %USERPATH% EXISTS… >> %LOGFILE%
IF NOT EXIST %USERPATH% (
ECHO NO, IT DOESN’T EXIST! CREATING DIRECTORY… >> %LOGFILE%
MKDIR %USERPATH%
)

ECHO Creating standard settings… >> %LOGFILE%
REG ADD HKCUSoftware<Your Desired Registry Keys> /v TYPE_CONNEXION /t REG_SZ /d «<text>» /f
REG ADD HKCUSoftware<Your Desired Registry Keys> /v TYPE_CONNEXION /t REG_SZ /d «<text>» /f

:END
REG ADD HKCUSoftware<Your Desired Registry Keys> /v TYPE_CONNEXION /t REG_SZ /d «<text>» /f
REG ADD HKCUSoftware<Your Desired Registry Keys> /v TYPE_CONNEXION /t REG_SZ /d «<text>» /f
ECHO Disabling language bar… >> %LOGFILE%
REG ADD HKCUSoftwareMicrosoftCTF /v LangBar /t REG_DWORD /d «3» /f

ECHO CHECKING IF %CUSTOMREGFILEPERUSER% EXISTS… >> %LOGFILE%
IF EXIST %CUSTOMREGFILEPERUSER% (
ECHO YES, IT EXIST! APPLYING CUSTOM USER REGISTRY SETTINGS… >> %LOGFILE%
regedit /S %CUSTOMREGFILEPERUSER%
)ELSE (ECHO NO, IT DOESN’T EXIST >> %LOGFILE%)

ECHO LOGON SCRIPT END >> %LOGFILE%

Logoff Script (Logoff.cmd)

  • Backup current settings. Settings of WINDOWS user profile folder.

This is the script:

@echo off
SET FILESERVER=<yourdesiredserver>profiles
SET LOGPATH=%FILESERVER%_Logs
SET LOGFILE=%LOGPATH%%Username%.txt
SET LOGLASTSERVER=%LOGPATH%%Username%_LastServer.txt
SET USERPATH=%FILESERVER%%USERNAME%
SET USERWINDOWSPATH=%USERPATH%WINDOWS
SET USERPROFILEWINDOWSDIR=%USERPROFILE%WINDOWS
SET REGISTRYBACKUP=%USERPATH%BACKUP_REGISTRY.reg
SET REGISTRYHIVE=HKEY_CURRENT_USERSoftware<Your Desired Registry Keys>

IF NOT EXIST %LOGPATH% MKDIR %LOGPATH%

ECHO. >> %LOGFILE%
ECHO LOGOFF SCRIPT START 1.1 >> %LOGFILE%

ECHO CHECKING IF %USERPATH% EXISTS… >> %LOGFILE%
IF NOT EXIST %USERPATH% (
ECHO NO, IT NOT EXIST! CREATING DIRECTORY… >> %LOGFILE%
MKDIR %USERPATH%
)ELSE (ECHO YES, IT EXIST >> %LOGFILE% )

ECHO CHECKING IF %USERWINDOWSPATH% EXISTS… >> %LOGFILE%
IF NOT EXIST %USERWINDOWSPATH% (
ECHO YES, IT EXIST >> %LOGFILE%
MKDIR %USERWINDOWSPATH%
)ELSE (ECHO YES, IT EXIST >> %LOGFILE%)

ECHO COPYING USER WINDOWS FOLDER PROFILE… >> %LOGFILE%
COPY %USERPROFILEWINDOWSDIR% %USERWINDOWSPATH% /Y >> %LOGFILE%

ECHO EXPORTING  REGISTRY SETTINGS… >> %LOGFILE%
regedit.exe /e %REGISTRYBACKUP% %REGISTRYHIVE%

ECHO REMOVING LAST SERVER INFO… >> %LOGFILE%
DEL /Q %LOGLASTSERVER%

ECHO LOGOFF SCRIPT END

When scripts was working we saw that Windows XP computers doesn’t work as expected using Round Robin DNS Name.

This occurs because when check if Terminal server node is alive, we try to see if exists a file in a network share. It worked on Windows 7 computers but not in Windows XP.

To solve this problem we had to add the following registry values in both terminal servers (A and B):

HKLMSYSTEMCurrentControlSetServiceslanmanserverparameters

DisableStrictNameChecking (type DWORD) to 1.

NOTE: To be applied requires a reboot.

You need to create new GPO (Group Policy Object) and move terminal servers computer object to new OU Structure in Active Directory to apply this GPO.

NLBwithRoundRobin_3

OK. Now you have desired Load Balancing and failover Terminal Servers without NLB.

 

If you requires to grant Single Sign On properties on those Terminal Server connections please read next article:

https://www.megacrack.es/2012/01/07/how-to-do-single-sign-on-on-terminal-server-connections/

That’s all folks. We are waiting your comments bellow. We hope this information will be usable for you.

See you soon MegaCracks.

Related Posts Plugin for WordPress, Blogger...
Etiquetas: , , , , ,


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>