Using SQL Database
Mirroring to Improve
Citrix XenApp Server Farm
Disaster Recovery
Page 2
Summary ... 3
Environment ... 3
SQL Server Configuration ... 3
XenApp Server Configuration ... 14
Verification ... 17
Troubleshooting ... 18
Summary
This document describes how to improve the disaster recovery capabilities of a Citrix XenApp farm by leveraging the high availability database mirroring feature in Microsoft SQL 2005 / 2008 / 2008 R2. This feature allows transparent failover of the data store in the event of the loss of the principal SQL Server. The data store never physically resides on the witness server at any time, but SQL is required on that device so it can monitor the other two SQL servers and allow for automatic failover without losing any transactions (high safety). For the XenApp server to “pick up” the mirror in the event of a failure, two things are required on the XenApp servers:
1. The SQL Native Client must be installed on every XenApp server.
2. The MF20.DSN file must be modified on every XenApp server to match the example in this document. The Driver and Failover_Partner parameters are the only two lines that need modification.
Environment
Citrix XenApp 5.0 / 6.5
o XenApp 6.5 / Windows 2008 R2 Will require updated SQL Native Client 10.0 reference to MF20.DSN file
Three Microsoft Standard or Enterprise Edition SQL 2005 / 2008 / SQL 2008 R2 Servers with latest SQL Service Pack (Roles Principal Mirror Witness)
SQL Server Configuration
1. Create the data store database and have at least one XenApp join the server farm.
2. Verify the data store database by selecting Full in the Recovery model drop-down list in the
Page 4
3. Verify the SQL Server is using an Active Directory account. Ideally, use the same account for all three SQL Servers.
4. Back up the database on the principal SQL Server. 5. Create a database to the mirroring server.
6. From the Options page under Restore Database, back up the database to the mirroring server by selecting the Overwrite the existing database.
7. Under Recovery state, select the RESTORE WITH NORECOVERY as shown below:
The following is a sample script, but you can use the wizard in SQL Server Management Studio (right-click database tasks > backup):
RESTORE DATABASE [CPS4Farm] FROM DISK = N'C:\CPS4Farm.bak' WITH FILE = 1, NORECOVERY, NOUNLOAD, REPLACE, STATS = 10
8. Start the mirroring process. Right-click the Database > Properties > Mirroring and click
Page 6
Page 8
Page 10
10. Enter the SQL Server service accounts. Note: If all SQL Servers are using the same existing account, leave everything blank.
Page 12
11. Start the mirroring process by clicking Start Mirroring.
The following screen shot shows the two successfully synchronized databases in the SQL Server Management Studio:
Note: The database on the mirroring server is not available until a failover has occurred. All database transactions are first committed on the mirror database before the principal database. This might slow transactions, depending on the network performance.
Page 14
XenApp Server Configuration
1. Citrix recommends that a data store timeout be in place before proceeding. For more information see Citrix article CTX107708. Adjust this value to accommodate the failure over the transition period.
2. Stop the IMA Service (use the net stop imaservice command) or in the Services MMC.
3. Install the SQL Native Client from
http://www.microsoft.com/downloads/details.aspx?FamilyId=DF0BA5AA-B4BD-4705-AA0A-B477BA72A9CB&DisplayLang=en.
4. Edit the Data Source Name (DSN) MF20.DSN located under C:\Program Files
(x86)\Citrix\Independent Management Architecture or C:\Program Files\Citrix\Independent Management Architecture as follows:
Example DSN:
[ODBC]
DRIVER=SQL Native Client UID=administrator Trusted_Connection=Yes DATABASE=XA DS WSID=DHARMAEXA02 APP=Citrix IMA SERVER=DHARMAESQ02 Failover_Partner=DHARMAESQ01
Description=ds
XenApp 6.5 Windows 2008 R2 Example DSN
[ODBC]
DRIVER={SQL Server Native Client 10.0} DATABASE=XA6Database APP=Citrix IMA UID=administrator SERVER=SQLPRINCIPAL Failover_Partner=SQLMIRRORSERVER Trusted_Connection=No
5. Start the IMA Service (use the net start imaservice command).
Note: The SQL Client and the DSN modification must be installed on every XenApp server. Only the Driver and Failover_Partner fields need to be changed. An login account must present on the SQL mirror server for IMA.
If the SQL Client is not found the Citrix IMA service may fail to connect to the principal database with the following even log error
Citrix XenApp failed to connect to the Data Store. ODBC error while connecting to the database: IM002 -> [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Verification
Note: During the failover transition there is a short duration of time where the IMA data store is not available. This is as expected.
1. Initiate a failover on the principal SQL Server either by using the Failover button (go to
Page 18
Troubleshooting
XenApp Server:
1. Verify that the transparent redirection is working using the SQL Profiler. If the DSN is not set up properly as described above, the failure over feature does not work. The following error message is received: “SQL Profiler trace running on the previous principal SQL server after failover.” The following error message shows IMA still trying to connect to the original database: “Error 954 – The database IMADataStore cannot be opened. It is acting as a mirror database. Login failed for user 'xxxxxx’.”
2. Verify the SQL connection on the Presentation Server by running netstat –an and verifying the 1433 port connection.
3. Issue the qfarm command at the command prompt of the Presentation Server to verify that it has a connection to the database. If the connection is dropped you might need to run this twice. Qfarm needs to connect to the data store to enumerate all the servers in the farm. Make sure no command line switches are passed for this test.
SQL Server:
1. Verify all SQL Server 2005 servers have Service Pack 1 installed. The build version should be at least 9.0.2047.
2. You can view use the Database Mirroring monitor to see if there any SQL errors. You can also set up alerts if a problem does occur.
Page 20
More Information
http://msdn.microsoft.com/en-us/library/ms190941.aspx http://technet.microsoft.com/en-us/library/cc917681.aspx http://msdn2.microsoft.com/en-us/library/aa337204.aspx http://msdn2.microsoft.com/en-us/library/ms131373.aspx