注意:以下内容仅供已购买 Microsoft Office Volume Licensing 的机构的网络管理员参考。个人用户请购买零售版或Office 365订阅。
由于非法使用KMS服务带来的法律风险请自担。
我看到很多地方都有人给了各种教程,安装KMS服务。但是,总违背了我的一个原则,不执行未知来源的可执行文件。
而且,可能大多数人都不知道用root跑这些程序意味着什么,尤其是在路由器上。
所以我找了一个python的版本,github地址在 https://github.com/SystemRage/py-kms 。
由于ERX的存储空间限制,大部分操作都没法直接在路由上执行。所以接下来的笔记分两部分,第一部分在本地电脑上,第二部分在路由器上。
环境
路由器 Ubnt EdgeRouter X,IP 192.168.1.1,SSH端口 2345
EdgeRouter X, 固件 1.10.5
假设网络里没有配置domain,临时设置成 beijing.local
1 准备文件
先把源码clone下来,并将 py2-kms 目录上传到路由器上。
1 2 3 |
git clone https://github.com/SystemRage/py-kms cd py-kms/ scp -P 2345 -pr py2-kms ubnt@192.168.1.1:/tmp/ |
2 路由配置
要执行的命令比较多,所以我直接root了。
1 2 |
ssh -p 2345 ubnt@192.168.1.1 sudo su |
1 清理磁盘空间
删掉一个没用的镜像,否则 apt-get update 可能会磁盘空间不足
1 |
delete system image |
2 修改 apt sources.list
我把配置里的干掉了,自己在 /etc/apt/sources.list 加了
1 2 3 |
deb http://ftp2.cn.debian.org/debian/ wheezy main contrib deb http://ftp2.cn.debian.org/debian/ wheezy-updates main contrib deb http://ftp2.cn.debian.org/debian/ wheezy-backports main contrib |
修改完成后,执行
1 |
apt-get update |
3 准备python环境
python环境自带,但是没有pip。
直接apt-get装python-pip会被搞死,所以从官网直接拿安装脚本安装。
1 2 |
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py |
py-kms的wiki里提到,需要安装 python 的两个包,pytz 和 pysqlite,前者可以pip,后者就别用pip了,否则又会让安装一堆gcc等环境。
1 2 |
apt-get install python-sqlite pip install pytz |
4 准备代码目录
为了升级考虑,我把所有的脚本放在 /config/scripts,刚才从本机器已经传文件到 /tmp了,现在该挪到正确的位置
1 2 |
cd /config/scripts/ mv /tmp/py2-kms . |
5 准备网络环境
1 2 3 4 5 6 7 |
configure set service dhcp-server shared-network-name LAN subnet 192.168.1.0/24 domain-name beijing.local set service dns forwarding options srv-host=_vlmcs._tcp.beijing.local,192.168.1.1,1688,0,100 commit save |
6 启动脚本
py-kms wiki里给了upstart的配置,这里给个sysvinit的,毕竟erx你没得选
/etc/init.d/py2-kms
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
#! /bin/sh # # init script for the py2-kms service : py2-kms ### BEGIN INIT INFO # Provides: py2-kms # Required-Start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: py2-kms ### END INIT INFO # Author: sskaje <sskaje@gmail.com> PATH=/sbin:/bin:/usr/sbin:/usr/bin NAME="py2-kms" DAEMON=/config/scripts/py2-kms/server.py DESC="py2-kms service" # Don't run if not installed test -f $DAEMON || exit 0 # Evaluate the config for the Debian scripts daemon_interval=300 PIDFILE=/var/run/$NAME.pid OPTIONS="" # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh # Define LSB log_* functions. . /lib/lsb/init-functions # # Function that starts the daemon/service # do_start() { # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started start-stop-daemon --test --start --quiet \ --pidfile $PIDFILE --exec $DAEMON \ >/dev/null \ || return 1 start-stop-daemon --start --background --make-pidfile \ --pidfile $PIDFILE --exec $DAEMON \ -- $OPTIONS \ || return 2 } # # Function that stops the daemon/service # do_stop() { # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred start-stop-daemon --stop --retry=TERM/30/KILL/5 \ --pidfile $PIDFILE return "$?" } case "$1" in start) [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" do_start case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; stop) [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; status) echo -n "Status of $DESC: " if [ ! -r "$PIDFILE" ]; then echo "$NAME is not running." exit 3 fi if read pid < "$PIDFILE" && ps -p "$pid" > /dev/null 2>&1; then echo "$NAME is running." exit 0 else echo "$NAME is not running but $PIDFILE exists." exit 1 fi ;; restart|force-reload) log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; *) N=/etc/init.d/$NAME # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2 log_success_msg "Usage: $N {start|stop|restart|force-reload}" exit 1 ;; esac exit 0 |
保存文件后,处理文件权限
1 2 |
chmod +x /etc/init.d/py2-kms chmod +x /config/scripts/py2-kms/server.py |
完成之后,就可以
1 |
/etc/init.d/py2-kms start |