Preparation
First, you need to prepare the failover cluster on Windows Server. For the steps, please refer to the previous article.
https://blog.csdn.net/u012869793/article/details/127560270?spm=1001.2014.3001.5501
Then install SqlServer on the server, and I installed 2019 here.
text
Check Enable Always ON Availability Group and restart the service.
Then add a database to the database on the master server and prepare a little test data.
In Always On High Availability, right-click, select New Availability Group, and enter a name SQLAG
. Then click Next.
A full backup is required here.
Then let's back up the database first, and cancel the window for creating a new availability group. Then right click on the database, select Tasks, Backup. Take a full backup of the database.
After the backup is complete, copy the backup file to the slave server, and open SQL Server to restore the database.
There is one thing to note here, select the option , remember to select the recovery state
RESTORE WITH NORECOVERY
, and then restore the database.
After restoring the database, the database should remain in the restoring state.
Then we proceed to create a new availability group. The prerequisites are met here, check the database that needs to be synchronized. Then click Next.
Here you need to connect to the database on another server to join the copy, choose to add a copy.
Enter the host name or IP address, user name, and password of another server to connect. Note that the TCP and IP of the corresponding server and the proxy service need to be enabled.
After configuration, the copy page is set as shown in the figure below, and
the endpoint page is set as shown in the figure below, and the domain name can be changed to IP. Then click Next and
this prompt may pop up.
This is because the SQL Server service was changed by me to the administrator account for logging in to Windows Server. Click Yes.
Here we choose to connect only, and then click Next.
Because there is already a database being restored on the replica server, there is no need to select a complete database and log backup. If there is no database on the replica server, you can select this option and enter a shared file address to restore the database.
Then go directly to the next step, next step, and then click Finish.
Wait for the configuration to complete.
Normally, it should be completed in the end, as shown in the figure below.
But if it fails in the end, click on the error and find the following error. It may be a problem with the login account of the SqlServer service or a problem with the firewall.
The firewall settings are as follows. In the inbound rules, add ports 1433 and 5022 to the newly created rules.
For the login problem of the SQL Server service, first enter the database software to open it, find the administrator account, and check all the permissions.
Then change the account of the SqlServer service to the administrator account and password of the current computer, save and restart the service.
After the above configuration is complete, follow the steps below to add a listener.
testing phase
In the main library, create a new table, add test data, go back to the slave library, query, and find that the data has been synchronized.