KMS,是 Key Management System 的缩写,也就是密钥管理系统。网络中的那些KMS激活工具、软件,大多数也是通过KMS服务器地址激活的。然而使用那些不知道来源的软件很不安心,所以何不尝试自己搭建一个呢?
说明
本次记录使用的环境如下:
- 服务器:Vultr 的 CentOS 7 x64
- 脚本:秋水逸冰
脚本适用环境:
- 系统支持:
CentOS 6+,Debian 7+,Ubuntu 12+ - 虚拟技术:任意
- 内存要求:
≥ 128M
关于脚本:
- 脚本适用于三大 Linux 发行版,其他版本不支持。
- KMS 服务安装完成后会加入开机自启动
- 默认记录日志,其日志位于
/var/log/vlmcsd.log - 脚本源码在文章的最后面
可激活版本
KMS 服务,用于在线激活 VOL 版本的 Windows 和 Office。
--支持 Windows Vista/7/8/8.1/10 Windows 2008/2008R2/2012/2012R2/2016/2019
--支持 Office 2010/2013/2016/2019 Office 365
激活的前提是你的系统是批量授权版本,即 VL 版,一般企业版都是 VL 版。而 VL 版本的镜像一般内置 GVLK key,用于 KMS 激活。
KMS激活几乎能够激活所有Vista以后的版本,除了Vista和7的旗舰版封装所对应的系统映像,并且激活速度很快。可以放心的安装微软官方镜像,而不必担心激活问题。不会因为安装第三方提供的镜像或者Ghost系统而自带后门和流氓推广软件。
- 自行搭建KMS激活服务器和KMS软件一样,实现每180天一次的自动激活,使得系统一直保持激活状态。
搭建方法
本脚本安装完成后,会将 KMS 服务加入开机自启动。
下载脚本
使用root用户登录,运行以下命令, 自动完成脚本下载和安装。
wget --no-check-certificate https://github.com/teddysun/across/raw/master/kms.sh && chmod +x kms.sh && ./kms.sh
查看端口的情况
安装完成后,输入以下命令查看端口号 1688 的监听情况,脚本默认端口号是1688
netstat -nxtlp | grep 1688
返回值类似于如下这样就 OK 了:
tcp 0 0 0.0.0.0:1688 0.0.0.0:* LISTEN 3200/vlmcsd
tcp 0 0 :::1688 :::* LISTEN 3200/vlmcsd
查看1688监听情况如果返回netstat: command not found
请运行 yum install net-tools选 y 安装
脚本命令
启动:/etc/init.d/kms start
停止:/etc/init.d/kms stop
重启:/etc/init.d/kms restart
状态:/etc/init.d/kms status
卸载脚本
使用 root 用户登录,运行以下命令:
./kms.sh uninstall
更改默认端口号
编辑/etc/init.d/kms文件
将$DAEMON -p $PID_FILE这段改成$DAEMON -P(端口号) -p $PID_FILE
如$DAEMON -P30000 -p $PID_FILE,即端口号改成30000。然后重启KMS服务,搞定。
其他问题
- 在Vultr的
Ubuntu 18.04 x64服务器上使用这个脚本安装会报错,需要额外安装glibc-doc和libc6-dev,命令如下:
apt install glibc-doc
apt install libc6-dev
Windos激活方法
首先使用管理员权限运行cmd 。
设置KMS服务器地址
使用管理员权限运行 cmd 将 KMS 服务器地址设置为你自己的 IP 或域名,后面最好再加上端口号(:1688),命令如下:
slmgr /skms 你的IP或者域名:1688
手动激活
使用管理员权限运行 cmd 手动激活系统,命令如下:
slmgr /ato
查看激活状态
slmgr /dlv
激活失败原因
激活失败可能有两种原因。
- 无意中修改或卸载了系统自带的激活密钥
- 安装的系统为RTL版,需要先转换为VOL版才能激活
第一种解决方法
使用命令查看系统版本
wmic os get caption
从下面列表中找到对应的KEY。
- Windows:docs.microsoft.com/zh-cn/windo…
- Office 2019 & Office 2016:docs.microsoft.com/en-us/Deplo…
- Office 2013:technet.microsoft.com/zh-cn/libra…
- Office 2010:technet.microsoft.com/zh-cn/libra…
使用管理员权限运行 cmd 安装从上面列表得到的 key,命令如下:
slmgr /ipk xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
第二种解决方法
需要更换系统为VOL版。
Office 激活方法
关于 Office 的激活,要求必须是 VOL 版本,否则无法激活。
首先使用管理员权限运行cmd 。
进入Office目录
找到你的 Office 安装目录
32 位默认一般为 C:\Program Files (x86)\Microsoft Office\Office16`
64 位默认一般为 C:\Program Files\Microsoft Office\Office16`
Office16 是 Office 2016
Office15 是 Office 2013
Office14 是 Office 2010
打开以上所说的目录,应该有个 OSPP.VBS 文件。
使用管理员权限运行 cmd 进入 Office 目录,命令如下:
cd "C:\Program Files (x86)\Microsoft Office\Office16"
设置KMS服务器地址
使用管理员权限运行 cmd 注册 KMS 服务器地址:
cscript ospp.vbs /sethst:你的IP或者域名
cscript ospp.vbs /setprt:1688
手动激活
使用管理员权限运行 cmd 手动激活 Office,命令如下:
cscript ospp.vbs /act
查询Office激活详情
cscript ospp.vbs /dstatus
激活失败原因
- Office激活失败的原因和windos的原因以及方法相同。可以参照上面的解决办法
脚本源码
#!/usr/bin/env bash
#
# Auto install KMS Server
# System Required: CentOS 6+, Debian7+, Ubuntu12+
# Copyright (C) 2017-2018 Teddysun <i@teddysun.com>
# URL: https://teddysun.com/530.html
#
# Thanks: https://github.com/Wind4/vlmcsd
#
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
cur_dir=$(pwd)
[[ $EUID -ne 0 ]] && echo -e "${red}Error:${plain} This script must be run as root!" && exit 1
if [ -f /etc/redhat-release ]; then
release="centos"
elif grep -Eqi "debian" /etc/issue; then
release="debian"
elif grep -Eqi "ubuntu" /etc/issue; then
release="ubuntu"
elif grep -Eqi "centos|red hat|redhat" /etc/issue; then
release="centos"
elif grep -Eqi "debian" /proc/version; then
release="debian"
elif grep -Eqi "ubuntu" /proc/version; then
release="ubuntu"
elif grep -Eqi "centos|red hat|redhat" /proc/version; then
release="centos"
else
release=""
fi
boot_start(){
if [[ x"${release}" == x"debian" || x"${release}" == x"ubuntu" ]]; then
update-rc.d -f "${1}" defaults
elif [[ x"${release}" == x"centos" ]]; then
chkconfig --add "${1}"
chkconfig "${1}" on
fi
}
boot_stop(){
if [[ x"${release}" == x"debian" || x"${release}" == x"ubuntu" ]]; then
update-rc.d -f "${1}" remove
elif [[ x"${release}" == x"centos" ]]; then
chkconfig "${1}" off
chkconfig --del "${1}"
fi
}
# Get version
getversion(){
if [[ -s /etc/redhat-release ]]; then
grep -oE "[0-9.]+" /etc/redhat-release
else
grep -oE "[0-9.]+" /etc/issue
fi
}
# CentOS version
centosversion(){
if [[ x"${release}" == x"centos" ]]; then
local code=$1
local version="$(getversion)"
local main_ver=${version%%.*}
if [ "$main_ver" == "$code" ]; then
return 0
else
return 1
fi
else
return 1
fi
}
get_opsy() {
[ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return
[ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return
[ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return
}
get_char() {
SAVEDSTTY=$(stty -g)
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty "$SAVEDSTTY"
}
set_firewall() {
if centosversion 6; then
/etc/init.d/iptables status > /dev/null 2>&1
if [ $? -eq 0 ]; then
iptables -L -n | grep -i 1688 > /dev/null 2>&1
if [ $? -ne 0 ]; then
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 1688 -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables restart
fi
else
echo -e "${yellow}Warning:${plain} iptables looks like shutdown or not installed, please enable port 1688 manually set if necessary."
fi
elif centosversion 7; then
systemctl status firewalld > /dev/null 2>&1
if [ $? -eq 0 ]; then
firewall-cmd --permanent --zone=public --add-port=1688/tcp
firewall-cmd --reload
else
echo -e "${yellow}Warning:${plain} firewalld looks like shutdown or not installed, please enable port 1688 manually set if necessary."
fi
fi
}
install_main() {
[ -f /usr/bin/vlmcsd ] && echo -e "${yellow}Warning:${plain} KMS Server is already installed. nothing to do..." && exit 1
clear
opsy=$( get_opsy )
arch=$( uname -m )
lbit=$( getconf LONG_BIT )
kern=$( uname -r )
echo "---------- System Information ----------"
echo " OS : $opsy"
echo " Arch : $arch ($lbit Bit)"
echo " Kernel : $kern"
echo "----------------------------------------"
echo " Auto install KMS Server"
echo
echo " URL: https://teddysun.com/530.html"
echo "----------------------------------------"
echo
echo "Press any key to start...or Press Ctrl+C to cancel"
char=$(get_char)
if [[ x"${release}" == x"centos" ]]; then
yum -y install gcc git make nss curl libcurl
if ! wget --no-check-certificate -O /etc/init.d/kms https://raw.githubusercontent.com/teddysun/across/master/kms; then
echo -e "[${red}Error:${plain}] Failed to download KMS Server script."
exit 1
fi
elif [[ x"${release}" == x"debian" || x"${release}" == x"ubuntu" ]]; then
apt-get -y update
apt-get install -y gcc git make libnss3 curl libcurl3-nss
if ! wget --no-check-certificate -O /etc/init.d/kms https://raw.githubusercontent.com/teddysun/across/master/kms-debian; then
echo -e "[${red}Error:${plain}] Failed to download KMS Server script."
exit 1
fi
else
echo -e "${red}Error:${plain} OS is not be supported, please change to CentOS/Debian/Ubuntu and try again."
exit 1
fi
cd "${cur_dir}" || exit
git clone https://github.com/Wind4/vlmcsd.git > /dev/null 2>&1
[ -d vlmcsd ] && cd vlmcsd || echo -e "[${red}Error:${plain}] Failed to git clone vlmcsd."
make
if [ $? -ne 0 ]; then
echo -e "${red}Error:${plain} Install KMS Server failed, please check it and try again."
exit 1
fi
cp -p bin/vlmcsd /usr/bin/
chmod 755 /usr/bin/vlmcsd
chmod 755 /etc/init.d/kms
boot_start kms
/etc/init.d/kms start
if [ $? -ne 0 ]; then
echo -e "${red}Error:${plain} KMS server start failed."
fi
if [[ x"${release}" == x"centos" ]]; then
set_firewall
fi
cd "${cur_dir}" || exit
rm -rf vlmcsd
echo
echo "Install KMS Server success"
echo "Welcome to visit:https://teddysun.com/530.html"
echo "Enjoy it!"
echo
}
install_kms() {
install_main 2>&1 | tee "${cur_dir}"/install_kms.log
}
# Uninstall KMS Server
uninstall_kms() {
printf "Are you sure uninstall KMS Server? (y/n) "
printf "\n"
read -p "(Default: n):" answer
[ -z "${answer}" ] && answer="n"
if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
/etc/init.d/kms status > /dev/null 2>&1
if [ $? -eq 0 ]; then
/etc/init.d/kms stop
fi
boot_stop kms
# delete kms server
rm -f /usr/bin/vlmcsd
rm -f /etc/init.d/kms
rm -f /var/log/vlmcsd.log
echo "KMS Server uninstall success"
else
echo
echo "Uninstall cancelled, nothing to do..."
echo
fi
}
# Initialization step
action=$1
[ -z "$1" ] && action=install
case "$action" in
install|uninstall)
${action}_kms
;;
*)
echo "Arguments error! [${action}]"
echo "Usage: $(basename $0) [install|uninstall]"
;;
esac