破解SQLServer for Linux预览版的3.5GB内存限制 (UBUNTU篇)

上一篇中我提到了如何破解RHEL上SQLServer的内存大小限制,但是Ubuntu上还有一道检查

这篇我将会讲解如何在3.5GB以下内存的Ubuntu中安装和运行SQLServer for Linux

a. 首先按照微软的给出的步骤安装和配置

https://docs.microsoft.com/zh-cn/sql/linux/sql-server-linux-setup-ubuntu

b. 使用apt安装mssql的包时会提示这个错误

ERROR: This machine must have at least 3.25 gigabytes of memory to install Microsoft(R) SQL Server(R).

c. 通过分析deb包可以找到检查的地方在config脚本中

#!/bin/bash -e

# Source debconf library.
. /usr/share/debconf/confmodule db_version 2.0
db_capb backup let system_memory="$(awk '/MemTotal/ {print $2}' /proc/meminfo) / 1024" if [ $system_memory -lt 3250 ]; then
echo "ERROR: This machine must have at least 3.25 gigabytes of memory to install Microsoft(R) SQL Server(R)."
exit 1
fi

对于这种检查,可以修改这里的内容并重新打包deb包,也可以通过LD_PRELOAD来绕过错误的报告,接下来我会使用LD_PRELOAD

d. 使用LD_PRELOAD让所有进程的返回值都变成0

root@ubuntu:~# vi crack.c
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h> static void (*real_exit)(int status) = NULL; static void exit_init() {
real_exit = dlsym(RTLD_NEXT, "exit");
if (real_exit == NULL) {
fprintf(stderr, "dlsym error: %s\n", dlerror());
abort();
}
} void exit(int status) {
if (real_exit == NULL) {
exit_init();
}
real_exit(0);
}
root@ubuntu:~# gcc -Wall -shared -fPIC -o crack.so crack.c

e. 重新运行apt安装mssql包

root@ubuntu:~# env LD_PRELOAD=/root/crack.so apt-get install -y mssql-server

如果安装成功,你可以看到下面的消息

+-------------------------------------------------------------------+
| Please run /opt/mssql/bin/sqlservr-setup to complete the setup of |
| Microsoft(R) SQL Server(R). |
+-------------------------------------------------------------------+

f. 接下来和RHEL篇一样,破解程序文件

替换3250000000到512000000

root@ubuntu:~# cd /opt/mssql/bin/
root@ubuntu:/opt/mssql/bin# cp sqlservr sqlservr.old
root@ubuntu:/opt/mssql/bin# cp sqlpackage sqlpackage.old
root@ubuntu:/opt/mssql/bin# sed -i "s/\x80\x10\xb7\xc1/\x00\x80\x84\x1e/g" sqlservr
root@ubuntu:/opt/mssql/bin# sed -i "s/\x80\x10\xb7\xc1/\x00\x80\x84\x1e/g" sqlpackage

g. 重新配置mssql

root@ubuntu:/opt/mssql/bin# rm -rf /var/opt/mssql
root@ubuntu:/opt/mssql/bin# /opt/mssql/bin/sqlservr-setup
root@ubuntu:/opt/mssql/bin# systemctl status mssql-server

可以看到消息

● mssql-server.service - Microsoft(R) SQL Server(R) Database Engine
Loaded: loaded (/lib/systemd/system/mssql-server.service; disabled; vendor pr
Active: active (running) since Tue 2016-12-06 01:03:16 EST; 28s ago
Main PID: 9349 (sqlservr)
Tasks: 101
Memory: 458.7M
CPU: 4.296s
CGroup: /system.slice/mssql-server.service
├─9349 /opt/mssql/bin/sqlservr
└─9364 /opt/mssql/bin/sqlservr

到这里就已经大功告成了,上图

破解SQLServer for Linux预览版的3.5GB内存限制 (UBUNTU篇)

破解SQLServer for Linux预览版的3.5GB内存限制 (UBUNTU篇)

mssql刚启动就占了600MB的内存,所以微软设置3.5G的内存限制也不是没有道理的

mssql for linux似乎运行在一层windows的兼容层上,这也可能是内存占用大的原因

需要更低的资源消耗?考虑postgresql或mariadb吧

上一篇:破解SQLServer for Linux预览版的3.5GB内存限制 (RHEL篇) 转


下一篇:破解SQLServer for Linux预览版的3.5GB内存限制 (RHEL篇)