有一台测试机上Docker中部署了MSSQLServer2019,使用的时候突然发现SSMS无法连接,检查磁盘使用情况,发现磁盘空间剩余很小,删除部分无用文件之后,重启服务依然无法连接,遂又重启宿主机还是不行,检查日志发现输出如下:
The following diagnostic information is available:
Reason: 0x00000007
Status: 0xc0000022
Message: Access was denied setting up the persistent registry: \SystemRoot\security.hiv.
Stack Trace:
file://package4/windows/system32/sqlpal.dll+0x000000000000E16F
file://package4/windows/system32/sqlpal.dll+0x000000000000CDCF
file://package4/windows/system32/sqlpal.dll+0x000000000000A47B
file://package4/windows/system32/sqlpal.dll+0x000000000000A61F
file://package4/windows/system32/sqlpal.dll+0x0000000000008BDD
file://package4/windows/system32/sqlpal.dll+0x0000000000007085
file://package4/windows/system32/sqlpal.dll+0x0000000000202641
Modules:
file://package4/windows/system32/sqlpal.dll=E59EEA3917F70A1E2DB0DFD3370D69501
Process: 31 – sqlservr
Thread: 36 (application thread 0x8)
Instance Id: b0ca1dbe-5cac-4ea4-82ff-d7fe223faf38
Crash Id: 0012c4a5-7c66-450b-806c-59e15e70694c
Build stamp: f708684a2cfcb51177273c54f975ed8c62029cbc89aa962bf7d6b956f01a0c27
Distribution: Ubuntu 20.04.5 LTS
Processors: 4
Total Memory: 12411117568 bytes
Timestamp: Mon Apr 22 17:41:40 2024
Last errno: 13
Last errno text: Permission denied
Capturing a dump of 31
Successfully captured dump: /var/opt/mssql/log/core.sqlservr.4_22_2024_17_41_40.31
Executing: /opt/mssql/bin/handle-crash.sh with parameters
handle-crash.sh
/opt/mssql/bin/sqlservr
31
/opt/mssql/bin
/var/opt/mssql/log/
b0ca1dbe-5cac-4ea4-82ff-d7fe223faf38
0012c4a5-7c66-450b-806c-59e15e70694c
/var/opt/mssql/log/core.sqlservr.4_22_2024_17_41_40.31
由于我是整个mssql文件夹直接映射到宿主机,查阅资料之后发现可能是security.hiv文件没有访问权限,security.hiv文件对应容器内的路径为 /var/opt/mssql/.system/system/security.hiv
,直接在宿主机的映射文件夹内找到该文件,添加读写权限即可。同样也对 lsa.hiv 文件和 licensing.hiv文件添加读写权限。参考命令如下
chmod u+rw /xxx/.system/system/security.hiv
chmod u+rw /xxx/.system/system/lsa.hiv
chmod u+rw /xxx/.system/system/licensing.hiv
执行完重启容器发现依然错误
2024-04-22 17:42:43.18 Server Error: 17058, Severity: 16, State: 1.
2024-04-22 17:42:43.18 Server initerrlog: Could not open error log file ‘/var/opt/mssql/log/errorlog’. Operating system error = 5(Access is denied.).
再给errorlog文件添加读写权限
chmod u+rw /xxx/log/errorlog
再重启sql服务就启动正常了。
这错误真的是莫名奇妙。。。
参考资料:
MS SQL on Ubuntu 18.04 configuration setup not working as expected