(go) Build SQL Server AlwaysOn Third (configure AlwaysOn) starting from 0

Source: Internet
Author: User
Tags failover readable



Original address : http://www.cnblogs.com/lyhabc/p/4682986.html



This is the third in SQL Server AlwaysOn from 0, and this article really started to build AlwaysOn, the first two is to build AlwaysOn to prepare






Steps



This article still uses step by step to introduce how to build AlwaysOn






Please log in to both cluster nodes with local user administrator first and do the following, do not log in with domain user Dcadmin first









1, two cluster nodes are required to install the. NET Framework 3.5 (Install using the Add feature in Windows Server R2) first.















2. Installing SQL Server



Note: Be sure to log in to the Windows Server installation with a administrator account instead of a domain account Dcadmin



Select a new SQL Server standalone installation, and do not select a newer SQL Server failover cluster installation






As for the installation process, the default next step is no different from the standalone installation of SQL Server, where the installation process is ignored






Note: Because my installation package has been brought SP1 patch pack , in order to avoid stepping on the pit, if not installed SP1 or above the patch pack, please install first












Note: If you start using domain user dcadmin to log on to the cluster node machine and you encounter a pit when installing SQL Server, SQL Server Setup will connect to the failover cluster, but in fact the standalone installation SQL Server does not need to connect to the failover cluster at all









3. Log off the cluster node computer, and then log on with the domain user dcadmin, and then set the SQL Server startup account to be a domain user dcadmin






Open Service Manager, first modify the SQL Agent startup account for the domain user dcadmin, and then modify the SQL engine's startup account to be a domain user dcadmin









Click "Location", modify the Find location, select ABC.com



Click on "Advanced"






Click "Find Now" and select Dcadmin









Click "OK"






Enter the password for the domain user dcadmin









Restart the SQL Agent service






After restarting you can see the login user as [email protected]









Similarly, the SQL Engine service requires the same settings









In this way, both the SQL Engine service and the SQL Agent service are started with the domain user dcadmin



SQL Server for another cluster node also needs to do the same






Note : After the cluster node is out of domain, both the SQL Engine service and the SQL Agent service are started with the local service account and can no longer be started with domain users









4. Add the dcadmin domain user to the SQL Server login user of two cluster nodes, select the sysadmin server role



Log on to SQL Server with SA first






Add the logged-on user to add the dcadmin domain user as a logged-in user as the SQL service adds the start account step












Grant sysadmin permission






Two cluster nodes can log in to SQL Server with Dcadmin domain Users


















5. Back to SQL Server Configuration Manager, enable AlwaysOn availability groups









Note : The cluster node must be able to communicate, if the cluster node is disconnected from the communication, then enable AlwaysOn when the error









Restart SQL Server






If AlwaysOn is enabled successfully, you can see that enable Hadr is true in the server properties












6. In one of the cluster nodes in SQL Server, verify the number of votes for each node, and execute it on the SQL Server of one of the cluster nodes
Use the following SQL statement


SELECT * from  sys.dm_hadr_cluster_members;




SELECT * from SYS. [Dm_hadr_cluster]








7, again ensure that the node has shut down the firewall, if the firewall is not closed, then the creation of the availability group will be the following error pop-up


Unable to join database "test" to availability Group "XX" for availability replica "XXX"

The connection to the primary replica is not active. Unable to process the command (Error: 35250)

















8. Create the initial database at each node



First back up a database anuoapc.bak you want to use on all nodes, and then restore at each node with the following SQL:


--Note that you must use NORECOVERY to restore the backup
USE [master]
RESTORE DATABASE [test] FROM DISK = N‘C: \ DBBackup \ AnuoApc.bak ’WITH FILE = 1,
NOUNLOAD, NORECOVERY, REPLACE, STATS = 5

GO





What it looks like after a log backup is restored on WIN-5PMSDHUI0KQ












9. Right-Select the New Availability Group Wizard on the AlwaysOn High Availability node



Note: databases that are joined to AlwaysOn availability groups must meet the following requirements



(1) The recovery model of the database must be a "full" recovery model



(2) A full backup of the database has been made



(3) need to be user library, System library cannot join availability Group



(4) The database can be read and written, read-only libraries cannot be added to the availability group



(5) database in multi-user mode



(6) The database does not use Auto_Close



(7) does not belong to any other availability group



(8) database is not configured for database mirroring



One availability group supports up to 100 databases












10. Click "Next" to enter a high availability group name that has never been used Testag









11. Click Next to select the database you want to add









12. Click "Next", use Add Copy to add additional nodes to the availability group, and select the automatic failover node and the synchronous commit node, because we only have two nodes






We set the secondary replica to be readable, able to fail over automatically, synchronous commit mode






13. Click on the "Endpoints" tab page to set the endpoint









Note: The endpoint URL uses IP, do not use the FQDN long name, because the server will usually have two network cards, a public network card, a private network card, the endpoint is recommended to use the private network card address



In this way, the data transmitted directly at the endpoint is routed through the private network card, and using tcp://test.abc.com:5022 , the long name of the FQDN does not guarantee that the endpoint data is routed through the private network card.



The SQL Server service account uses domain user dcadmin to authenticate to avoid the way certificates are used






14, "Backup preferences" and "listener" do not need to set, keep the default on the line, the availability of listeners we add later, you can directly click "Next"






Click "Yes"






15, select the initial data synchronization, here Select "Join only" mode












16, click "Next" to verify the configuration, the corresponding listener configuration warning can be ignored, late to add listeners



Because you are using the "join only" Database initialization method, verify that the check is skipped like free disk space












17, click "Next" to check and confirm the previous configuration information, if correct, click "Done". In addition, you can save an availability group script here to step through the troubleshooting.












18. All summaries are completed successfully, showing Green checkmark. If a yellow warning is present, further judgment is required for success. If a red error occurs, the AG creation is unsuccessful









Note: If you use an odd-number cluster node and the quorum configuration uses the majority of the nodes, the WSFC quorum voting configuration displays a warning when the availability group is created



Click on the warning link will pop up the following dialog box, this warning can actually ignore












19. View server and database changes



Primary replica



The database has become synchronized






Secondary replicas



The secondary replica is readable at this time, and changes made to the Test1 table on the primary replica can be synchronized to the Test1 table on the secondary replica









Look again at Failover Cluster Manager



Availability group becomes a clustered role









Click on the display panel to display the availability panel












20, after creating the availability group, right-click on the "Availability Group listener" to add a listener to create the listener, select the network mode of the static IP (try not to select the DHCP network mode),



Enter a name that has never been used (this name will be used to create a network Name resource) and access port












Click OK









Created successfully






An A record is registered on the domain-controlled DNS Manager






A failover cluster virtual network Name account is added to the Computers container in the ad









In the failover Cluster Manager, the role node, you can see the client Access name and IP address, the client through this access name to access the database












Sign in to SQL Server with listener name












Of course, you can also use listener IP to connect to SQL Server















Add the logged-on user to the secondary replica so that the logged-on user on the primary replica can also read the secondary replica data
Step 1: View the SID of the account on the main library [test] for the library name
SELECT * FROM [test]: sysusers
For example: Dalogin 0x99ad266afd26f841b3e49ef9633b0d4b

Step 2: Create the corresponding account on the replica database, where the SID corresponds to the value of the SID found on the main library
CREATE LOGIN [Dalogin] with password=n ' xxxxxxx ',
SID =0x99ad266afd26f841b3e49ef9633b0d4b, Default_database=[test],
Check_expiration=off, Check_policy=off






Basic management of availability groups



Note: try to use the SSMs UI or TSQL statement to manipulate the availability group, and do not use failover Cluster Manager






Fail over



First use the listener name to log on to SQL Server and see which machine is currently in the primary replica









Manual Fail-Over



Select Testag This availability group, right-"failover









Click "Next"






Click "Next"






Connect to WIN-5PMSDHUIOKQ this auxiliary copy machine









Click "Finish"






Start a failover









Execute query once again






Has failed over to WIN-5PMSDHUIOKQ this machine



View the properties of the Testag availability Group












Execute the following SQL statement to set the WIN-7107JJJ2BCC machine as a readable copy


USE [master]
GO
ALTER AVAILABILITY GROUP [testAG]
MODIFY REPLICA ON N‘WIN-7107JJJ2BCC‘ WITH (SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL))
GO





Execute the following SQL statement to test



In the current primary replica execution


Insert into Test1 Select 3, ' Test3 '








You can see that the data is synchronized to the WIN-7107JJJ2BCC machine, and the database is readable.



A readable secondary copy is read-only and an error occurs if data changes are to be made to it


print ‘servername: ‘[email protected]@SERVERNAME 


insert into [test].[dbo].[test1] select 4, ‘test4‘








AlwaysOn Related views


-You can query AlwaysOn delay through these two views
SELECT b.replica_server_name,
        a. *
FROM sys.dm_hadr_database_replica_states a
        INNER JOIN sys.availability_replicas b ON a.replica_id = b.replica_id

--The Windows failover cluster where the availability group is located
SELECT * FROM sys.dm_hadr_cluster;
SELECT * FROM sys.dm_hadr_cluster_members;
SELECT * FROM sys.dm_hadr_cluster_networks;
SELECT * FROM sys.dm_hadr_instance_node_map;
SELECT * FROM sys.dm_hadr_name_id_map

--Availability group
SELECT * FROM sys.availability_groups;
SELECT * FROM sys.availability_groups_cluster;
SELECT * FROM sys.dm_hadr_availability_group_states;

--Availability copy
SELECT * FROM sys.availability_replicas;
SELECT * FROM sys. [Availability_read_only_routing_lists]
SELECT * FROM sys.dm_hadr_availability_replica_cluster_nodes;
SELECT * FROM sys. [Dm_hadr_availability_replica_cluster_states]
SELECT * FROM sys. [Dm_hadr_availability_replica_states]

--Availability database
SELECT * FROM sys.availability_databases_cluster;
SELECT * FROM sys.dm_hadr_database_replica_cluster_states;
SELECT * FROM sys. [Dm_hadr_auto_page_repair]
SELECT * FROM sys. [Dm_hadr_database_replica_states]

--Availability group listener
SELECT * FROM sys.availability_group_listener_ip_addresses;
SELECT * FROM sys.availability_group_listeners;
SELECT * FROM sys.dm_tcp_listener_states;



-Add a read-only routing list
ALTER AVAILABILITY GROUP [agtest2]
MODIFY REPLICA ON N‘WIN-5PMSDHUI0KQ ’WITH (SECONDARY_ROLE (ALLOW_CONNECTIONS = READ_ONLY));


ALTER AVAILABILITY GROUP [agtest2]
modify REPLICA ON N‘WIN-5PMSDHUI0KQ ’WITH (SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N‘TCP: //192.168.66.157: 1433‘))

ALTER AVAILABILITY GROUP [agtest2]
MODIFY REPLICA ON N‘WIN-4AE61RVA6UV ’WITH (SECONDARY_ROLE (ALLOW_CONNECTIONS = READ_ONLY));

ALTER AVAILABILITY GROUP [agtest2]
modify REPLICA ON N‘WIN-4AE61RVA6UV ’WITH (SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N‘TCP: //192.168.66.158: 1433’)) 


Summarize



AlwaysOn build steps are introduced here, I hope you follow me to experience the power of AlwaysOn






Similarly, add a secondary replica: domain, join failover cluster, change quorum configuration, add secondary replica



Follow the article to believe that it is not difficult to add a secondary copy






And there's a problem. Read more about SQL Server errorlog and WSFC event logs















For more information, refer to the "SQLSERVER2012 implementation and Management Guide" book



Address: http://product.dangdang.com/1419881008.html






Related articles



Http://www.cnblogs.com/stswordman/p/3821538.html



Http://www.cnblogs.com/stswordman/p/3850570.html



Http://www.cnblogs.com/stswordman/p/3936584.html



http://www.cnblogs.com/stswordman/p/3252549.html#3229105



Http://blogs.msdn.com/b/psssql/archive/2012/09/07/how-it-works-sql-server-alwayson-lease-timeout.aspx



http://blogs.msdn.com/b/alwaysonpro/archive/2014/11/26/ Diagnose-unexpected-failover-or-availability-group-in-resolving-state.aspx



https://msdn.microsoft.com/zh-cn/library/ff878308%28v=sql.120%29.aspx?f=255&MSPPError=-2147217396



Http://www.bubuko.com/infodetail-930336.html creates a weak event, but it is located on the wrong object to download patch resolution (https://www.microsoft.com/en-us/download/ details.aspx?id=36468)



http://blogs.msdn.com/b/alwaysonpro/archive/2013/10/30/ Errors-while-trying-to-create-an-availability-group-listener.aspx 19471 Error



Create Listener Error 19471,19476 problem
Http://blogs.msdn.com/b/alwaysonpro/archive/2013/10/30/errors-while-trying-to-create-an-availability-group-listener.aspx
http://blogs.msdn.com/b/alwaysonpro/archive/2014/03/25/ Create-listener-fails-with-message-the-wsfc-cluster-could-not-bring-the-network-name-resource-online.aspx






If there is a wrong place, welcome everyone to shoot brick O (∩_∩) o






2015-11-13 Supplement








Two-node AlwaysOn, using shared folders as a witness disk



When automatic failover occurs, sometimes the secondary replica is parsing, previously thought to be quorum lost (the WSFC lost contact with the file share witness), causing WSFC to hang, and later found to be caused by the problem of the maximum number of failures in the role attributes in the WSFC Control Panel.



It is recommended to set the maximum number of failures during a specified period to 10











View Code






2015-12-9 Supplement



Uninstalling a Cluster



1. Evict nodes first






2, cluster node (any cluster node) on the execution of the following command, cannot be executed on the DC, because the DC does not have failover cluster installed, SQLTESTDEMO1 is the cluster name



Get-cluster Sqltestdemo1 | Remove-cluster-force-cleanupad



3. The last node of the cluster cannot be evicted, only the cluster can be destroyed






4. After destroying the cluster, run the following command in PowerShell on each cluster to clear some garbage



Clear-clusternode









5, in the domain-controlled AD user and computer interface to remove the cluster virtual name









6. Re-enable and disable AlwaysOn, operate on all AlwaysOn nodes












Delete an availability group



1. Delete Secondary Replicas


Use [master]goalter availability GROUP [hagroup01]remove REPLICA on N ' SQLSVR2 '; GO





2. Delete the availability database


Use [master]goalter availability GROUP [Hagroup01]remove DATABASE [SQLDB02]; GO








3. Delete Listeners


Use [master]goalter availability GROUP [hagroup01]remove LISTENER N ' SQLAG01 '; GO






4. Delete an availability group


Use [Master]godrop availability GROUP [HAGROUP01]; GO





5. Remove the listener virtual name from the domain-controlled AD user and computer interface









AlwaysOn Attention Issues



Http://www.cnblogs.com/lyhabc/articles/5310781.html









About AlwaysOn Backups



The backup types supported by the primary replica are not mentioned on MSDN and in the SQL Server2012 implementation and Management Guide



Tested, the primary replica is the same as SQL Server for single instance, full backup, differential backup, log backup all support









Fault-Switching criteria



The first step
Lookalive 5 sec/Time Telnet 1433 port timeout 30 seconds
Step Two
IsAlive 60 sec/Time Sp_server_diagnoist timeout 60 seconds timeout after 3 times to prevent miscarriage



Start using sp_server_diagnoist from SQL server2012 more accurate than select @ @servername
Avoid miscalculation caused by SQL Server's high pressure
"SQL Server2012 Implementation and Management Guide" P42 P50 P53



10 seconds/times between replicas ping each other, if not, such as the secondary replica does not pass, will be displayed as disconnect






AlwaysOn Attention Issue: http://www.cnblogs.com/lyhabc/articles/5310781.html



About arbitration: http://www.tech-coffee.net/understand-failover-cluster-quorum/



(go) Build SQL Server AlwaysOn Third (configure AlwaysOn) starting from 0


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.