SPN(Service Principal name)服务器主体名称。
SPN 是服务在使用 Kerberos 身份验证的网络上的唯一标识符,它由服务类、主机名和端口组成。在使用 Kerberos 身份验证的网络中,必须在内置计算机帐户(如 NetworkService 或 LocalSystem)或用户帐户下为服务器注册 SPN。对于内置帐户,SPN 将自动进行注册。但是,如果在域用户帐户下运行服务,则必须为要使用的帐户手动注册SPN。

客户端连接Sqlserver实例报SPN错误的处理方法
1、先登录Sqlserver实例服务器执行setspn -L dai\sqlprocess |find "machine name"查看相关Sqlserver实例对应的服务器信息,看是否有无效信息,有无效信息或重复信息则使用setspn -D删除它
2、再通过Microsoft Kerberos Configuration Manager for SQL Server客户端工具,连接相关Sqlserver实例的服务器,只输入服务器名即可,检查相关服务器是否正常
3、最后使用setspn -D、setspn -A重建该Sqlserver实例对应服务器的所有SPN信息,使用setspn时需要administrator模式运行cmd
4、换一个客户端机器试试,有时是某个客户端机器自身无法获得域、dns、dhcp服务器上的信息,或该机器还没及时同步到域、dns、dhcp服务器上的信息,连接Sqlserver也会报SPN错误
5、如果服务器有别名,然后AG的监听使用了别名,则必须使用服务器别名alias注册到spn中,即setspn -A aliasname:1433 dai\sqlprocess
6、邮件报警Server Name对应DBPROD2表示DBPROD2的spn出了问题,对应DBPROD2\BI1表示DBPROD2\BI1的spn出了问题,DBPROD2可能是别名也可能是服务器名
7、重建SPN后,如果没有及时生效,可能需要等等过一会才会生效。
8、最好的验证方法就是,直接点击某个linked server,看能否连接测试成功,如下表示DBDEV1访问不了12.2.37.123对应的linked server。
DBDEV1 Logon Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'. Reason: Could not find a login matching the name provided. [CLIENT:12.2.37.123]
9、linked server报错,Cannot generate SSPI context,是因为netlogon服务起不来导致,computer management--local user and groups--groups--adminstrator组下面的用户都是一些阿拉伯数字,看不到域用户。netlogon起不来是因为workstation起不来,而workstation起不来,是因为使用了local system account,使用network service用户并保留密码框为空即可,这种情况下,kerberos里面输入这台服务器都无法登录,会报错:The was an issue with accessing UserAccount information from the system
10、linux服务器访问sqlserver实例报错SSPI Provider: Server not found in Kerberos database (851968) (SQLDriverConnect)
解决方法1:
一般windows服务器访问sqlserver实例,在SPN里面写的是sqlserver实例对应的服务器名称,linux的话,看linux配置的字符串,如果字符串里面是实例名称,则需要把实例名称写入SPN,比如开发的配置文件写的是sqlserver实例名称ibdwonstagedbalias,该服务器名称stagingdbaws1,SPN里面的信息只有服务器stagingdbaws1名称,添加实例名称到SPN即可
setspn -A MSSQLSvc/ibdwonstagedbalias.d.com:1433 dai\sqlprocess
setspn -A MSSQLSvc/ibdwonstagedbalias.d.com dai\sqlprocess
解决方法2:
如果不是以上1的情形,那么原因可能是linux服务器上crontab服务出现问题导致crontab的里面游戏的credential-renew.sh没有运行,可以通过less /var/log/cron |grep "credential-renew.sh"查看这个crontab的运行记录,credential-renew.sh可执行文件里面命令是kinit
解决方法3:
如果不是以上1、2的情形,通过date查看linux服务器时间,如果是linux服务器的时间和域控时间不一样,这个时候在linux服务器上依次执行systemctl status ntpd、systemctl stop ntpd、ntpdate 12.2.10.66(域控服务器ip)、systemctl start ntpd

1、In SSMS, connect to the SQL instance that you are going to recreate the SPN records for
2、Open the SQL Server logs
3、Filter results based on "spn" in the message text
Don't forget to click the "Apply filter" checkbox
4、You may have to filter through older logs and not just the "Current" log to find the records that start with the message:
"The SQL Server Network Interface library succesfully registered the Service Principal Name..."
5、Copy the SPN portion of both messages and paste them into a Notepad
One record has the port number at the end and the other has the instance name
If it is the default instance then the port number will be 1433 and the instance name will be absent
6、With the two SPN records in Notepad, replace the machine name of the server with the alias
The alias is either a C-NAME DNS record or an Availability Group listener such as: PROD2, PDBALIAS, etc
7、Remote into the server as your domain-admin account
8、In your RDP session to the server, run CMD as administrator
9、Use the following syntax to delete the existing SPN record (if it exists) then recreate iwww.sangpi.comsetspn -D MSSQLSvc/PROD2.d.com:52219 dai\sqlprocesssetspn -A MSSQLSvc/PROD2.d.com:52219 dai\sqlprocess

10、Do the same for both records (port and instance name)

setspn -D MSSQLSvc/PROD2.d.com:BI1 dai\sqlprocess

setspn -A MSSQLSvc/PROD2.d.com:BI1 dai\sqlprocess

个人域账号登录服务器,运行cmd以administrator权限模式,执行如下
setspn -L dai\sqlprocess | find "服务器名称PROD2" > C:\spn.txt

setspn -D MSSQLSvc/PROD2.d.com:52219 dai\sqlprocess
setspn -A MSSQLSvc/PROD2.d.com:52219 dai\sqlprocess

setspn -D MSSQLSvc/PROD2.d.com:BI1 dai\sqlprocess
setspn -A MSSQLSvc/PROD2.d.com:BI1 dai\sqlprocess

验证Sqlserver SPN的图形界面的客户端工具Microsoft Kerberos Configuration Manager for SQL Server,下载安装包后安装到某台域服务器中,直接登录该域服务器,打开这个工具,输入要连接的服务器A,就可以看到这个服务器A里面的所有的Sqlserver实例的SPN信息是否OK就可以了。

06-18 21:46