分类目录归档:Windows

使用 KCPTun 加快 VPS 到本地的连接速度

碰上垃圾 VPS 提供商怎么办,商家说是亚洲优化,到本地还是绕 GTT 怎么办?不用担心,KCPTun 来帮你。

说来,网上那堆教程实在是写得不怎么好,要么太复杂,我就想加速一下网络连接,写那么多原理干什么……要么就是太简单,我真的不喜欢一键包。所以还是自己来吧。

KCP 简单来说,就是一个 UDP 暴力发包软件,如果原先建立的连接是这样
Client -> (TCP) -> Server
那么加入 KCP 以后就变成了这样
Client -> (TCP) -> KCP Client -> (UDP) -> KCP Server -> (TCP) -> Server

KCP 无论是客户端,还是服务端,都涉及到两个端口,在客户端有一个 listening port 和 remote,服务端有 一个 listening port 和一个 target。从连接的角度来说,是这样的一个流程:

Client -> KClient_Listening_Port -> KClient -> KRemote
KRemote = KServer_Listening_Port -> KServer -> KTarget = Server

原先 C->S 怎么连接,只要把地址改成对应的 KCP 端地址就可以无缝工作。

举个例子来说,比如我本地有个程序需要连接 Server:8388,原先直接连接就可以了,但是特别慢,打算用 KCP 来加速一下,且 KServer 监听 3389 端口。那么本地需要做的事情是:

"client_windows_amd64.exe" -l :1081 -r Server:3389 -key "test" -crypt none -mode fast2

这个的意思是说,KClient 监听 1081 端口并转发至 Server 的 3389 端口,密码是 test,没有加密,使用的模式是 fast2。

服务端要做的事情是:

server_linux_amd64 -l :3389 -t 127.0.0.1:8388 --key test --crypt none --mode fast2 --quiet

监听 3389 端口的传入连接,转发至本地的 8388 端口,也就是原来的服务端,其他和 Client 的配置相同。

这么简单就配置好了。

项目的 Github 在这里:https://github.com/xtaci/kcptun

这是一个图形化的 Windows 客户端:https://github.com/dfdragon/kcptun_gclient

Windows OpenCV 环境配置

系统版本

  • Windows 10 1703
  • OpenCV 3.3.1
  • Visual Studio 2017 (v141)

配置过程

  1. 下载 OpenCV 3.3.1 安装包,双击自解压到 D 盘,即放在 D:\OpenCV 目录下。进入该文件夹后,可以看到 sources 和 build 两个文件夹,分别存放着源代码和编译好的文件。设置一个环境变量 OPENCV_DIR(也可以不设置),指向 D:\OpenCV\build
  2. 创建一个新的 C++ 工程,比如叫做 CV_Demo
  3. 右键 CV_Demo 这个 Project,进入 Property Page
  4. 在 C/C++ 中的 General 下的 Additional Include Directories 添加 $(OPENCV_DIR)\include
  5. 在 Linker 中的 General 下的 Additional Library Directories 添加 $(OPENCV_DIR)\x64\vc14\lib
  6. 在 Linker -> Input -> Additional Dependencies 下,Debug 模式添加 opencv_world331d.lib,Release 模式添加 opencv_world331.lib
  7. 将 $(OPENCV_DIR)\x64\vc14\bin 目录下的 opencv_world331d.dll 和 opencv_world331.dll 分别放入 CV_Demo\x64(输出目录) 目录的 Debug 和 Release 目录下,并同时放入 CV_Demo\CV_Demo (源代码文件)目录下

至此配置工作完成,运行一个 Demo 试试吧。

#include "stdafx.h"
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    if (argc != 2)
    {
        cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
        return -1;
    }
    Mat image;
    image = imread(argv[1], IMREAD_COLOR); // Read the file
    if (image.empty()) // Check for invalid input
    {
        cout << "Could not open or find the image" << std::endl;
        return -1;
    }
    namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
    imshow("Display window", image); // Show our image inside it.
    waitKey(0); // Wait for a keystroke in the window
    return 0;
}

 

从零开始的盒子:Online Dedibox 盒子配置记录

讲真,我也记不得这是我第几次配盒子了,但是这次我的主力盒子 & 杂活独立服务器挂掉还是给我造成了很大的损失。一方面,我损失了所有的盒子配置,包括澄空学园字幕组和 LoliHouse 的公网分流记录和文件,还有一些刷 PT 的环境;另一方面,我损失了虚拟机上的 Windows 压制环境;还有一些特定用途的杂活类服务,比如 Node.js 环境、Python / Anaconca 环境等等。为了以后维护方便,也为了给有同样需求的人一个参考,我在这里记录一下配置的历程。

先说点别的吧,关于这个盒子为什么会突然挂掉。起因是昨天(2017 年 10 月 9 日)下午至晚上,某国的大型网络过滤系统突然发威,在全国范围内干掉了我盒子的 IP 地址,我就很奇怪,我盒子一不做代理、二不放网站,就几个 BT 客户端的 WebUI 跑在上面,怎么就无缘无故给我过滤掉了。发现了 IP 问题之后,我尝试订购了一个 Failover IP 地址作为备用 IP。在配置的时候,由于我想要把这个 IP 作为我的主 IP 而改动了路由表,然后就被上级交换机锁了网络端口,与客服沟通之后,由于问题在短时间内无法解决,进而选择换机,我也丢失了所有数据。

先整理一下大致需求:

  1. Server As a Seedbox
    1. Update Kernel & BBR & BBR_powered
    2. Deluge ( Main BT/PT Client )
    3. Transmission ( Secondary PT Client )
    4. UTserver ( Specialized BT Client for SumiSora_Initial )
    5. Tixati ( Specialized BT Client for SumiSora_Main )
    6. qBittorrent ( Specialized BT Client for LoliHouse )
    7. Jailed SSH User ( For SumiSora_Initial SFTP Upload )
    8. SSHFS (Map Wishosting Stroage KVM Disk, not decided yet; maybe let Tixati work on this disk )
  2. Server As an Encoding Server
    1. VMware WorkStation
    2. gcc6
    3. Windows 7 & Activation
    4. Runtime Library
    5. Python & VapourSynth
    6. BaiduNetDisk
  3. Server As a Computer
    1. Node.js Http Server
    2. Anaconda Environment in Windows VM
    3. IPv6 Configuration
    4. Xfce & VNCserver
    5. Wine
    6. Firefox
  4. Server As a Storage Box
    1. Jailed SSH User ( Website Backup )

接下来开始安装:

  • 系统安装

系统仍然选择了我熟悉的 Ubuntu 16.04 LTS Server,由于我的服务器硬盘是 SoftRaid,在配置的时候还遇到了一些问题。最主要的问题就是 SWAP 分区不能使用 RAID0,如果这么选择安装操作系统就会报错。

  • 预配置及软件源添加
sudo apt-get install python-software-properties software-properties-common
sudo add-apt-repository ppa:transmissionbt/ppa
sudo add-apt-repository ppa:deluge-team/ppa
sudo add-apt-repository ppa:qbittorrent-team/qbittorrent-stable
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo dpkg --add-architecture i386 
wget -nc https://dl.winehq.org/wine-builds/Release.key 
sudo apt-key add Release.key 
sudo apt-add-repository https://dl.winehq.org/wine-builds/ubuntu/
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
  • 安装一系列软件
sudo apt update
sudo apt install xfce4 vnc4server deluged deluge-web qbittorrent transmission-daemon sshfs nodejs firefox build-essential fonts-noto gtk3-engines-xfce xfce4-goodies xfce4-power-manager
sudo apt-get install --install-recommends winehq-stable
sudo apt-get install gcc-7 g++-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60 --slave /usr/bin/g++ g++ /usr/bin/g++-7
sudo update-alternatives --config gcc
  • Kernel Update & BBR_powered

在 http://kernel.ubuntu.com/~kernel-ppa/mainline/ 上下载 4.11 版本的内核,4.12 存在 VirtIO 方面的 bug,4.13+ 无法适配 BBR_powered 模块,所以采用 4.11.12

wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.11.12/linux-headers-4.11.12-041112_4.11.12-041112.201707210350_all.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.11.12/linux-headers-4.11.12-041112-generic_4.11.12-041112.201707210350_amd64.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.11.12/linux-image-4.11.12-041112-generic_4.11.12-041112.201707210350_amd64.deb
sudo dpkg -i linux*.deb
sudo update-grub
sudo reboot

wget -O ./tcp_tsunami.c https://down.gloriousdays.pw/Tools/tcp_tsunami.c
echo "obj-m:=tcp_tsunami.o" > Makefile
make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc
sudo cp tcp_tsunami.ko /lib/modules/$(uname -r)/kernel/drivers/
echo 'tcp_tsunami' | sudo tee -a /etc/modules
sudo depmod
sudo modprobe tcp_tsunami
sudo bash -c "echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf"
sudo bash -c "echo "net.ipv4.tcp_congestion_control=tsunami" >> /etc/sysctl.conf"
sudo sysctl -p
  • IPv6 配置

鉴于 Online 的蛋疼实现,另起一篇在这里

  • BT 客户端配置
sudo systemctl stop transmission-daemon.service
sudo vi /var/lib/transmission-daemon/info/settings.json
#Change the following lines to the content that you want
"rpc-password": "{62b16db87b89a91dd49a5110a7cafc06d20eb4f2wtK6kqPj",
"rpc-username": "transmission",
"rpc-whitelist": "*",
"umask": 2,

一、utserver
这个比较简单

前往utserver的官网: http://www.utorrent.com/downloads/linux 下载编译好的程序
文件名一般是utserver.tar.gz
注意适用的发行版。

目前最新的3.3已经可用。

部署:
sudo tar xvzf utserver.tar.gz -C /opt/

#释放到opt目录

sudo chmod -R 777 /opt/utorrent-server-alpha-v3_3/
#给予目录权限,这里的目录名视情况而定。可以先敲sudo chmod -R 777 /opt/ut 再按下TAB自动补全

sudo ln -s /opt/utorrent-server-alpha-v3_3/utserver /usr/bin/utserver

#链接可执行文件,建立快捷方式。目录名问题同上。
utserver -settingspath /opt/utorrent-server-alpha-v3_3/
#(测试)运行。目录名问题同上。

如果这是没有出错提示,恭喜已经成功了
访问 [server_ip]:8080/gui 登陆webui
用户名 admin, 密码为空
登陆后开始设置

如果提示libssl.so package missing
运行
sudo apt-get install libssl0.9.8:i386
#补全依赖

因为一旦登出,utserver -settingspath /opt/utorrent-server-alpha-v3_3 这个命令终止导致ut停止运行
可以使用tmux或者nohup后台运行
nohup utserver -settingspath /optutorrent-server-alpha-v3_3 >/dev/null 2>&1 &

[Unit]
Description=utserver
After=network-online.target

[Service]
ExecStart=/usr/bin/sudo -u <username> /path/to/utserver/bin -settingspath /path/to/utserver/dir/
ExecStop=kill -9 $(cat /run/utserver.pid)
Restart=always
PIDFile=/run/utserver.pid
TimeoutStopSec=300
RestartSec=3

[Install]
WantedBy=multi-user.target
  • VNCserver 配置

修改 ~/.vnc/xstartup 以启动 Xfce 桌面环境

#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
startxfce4 &

修改 /usr/bin/vncserver 中 VNCserver 的配置,这个需要 root 权限

$geometry="1024x768"
$vncPort = 5900 + $displayNumber
$depth = 16 #(may cause problems with Windows VM if set to 24)
  • Jailed SSH User 进一步配置

由于我不想打开 SSH 的 Password Authentication, 但是 LNMP 脚本的备份又需要通过密码认证的 SSH 连接实现,因此寻找了可以打开单个用户的密码认证的方法:

在 /etc/ssh/sshd_config 中写入如下代码块即可

Match User <username1>,<username2>
    PasswordAuthentication yes
Match all  #This line is to end the match block
  • systemd 自启动脚本的设定

参照之前我写的这篇文章和 SSHFS 设置的这篇文章

VMware 在 Ubuntu 上运行 Windows 虚拟机会造成 khugepaged CPU 高占用的问题

这个问题一直存在,没有很好的解决方法,是内核中 transparent huge page 不断尝试整理 vmware-vmx 申请的大量内存导致的。在 khugepaged 运行时会造成 VMware 虚拟机卡顿,且系统整体会非常慢。

可以在 /etc/rc.local 中写入如下代码关闭这个功能:

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi

 

搭建 JetBrains 激活服务器

首先需要 screen 和 curl 两个组件,apt-get install curl screen 进行安装

一键脚本:wget https://down.gloriousdays.pw/Tools/JetBrains/jetbrain.sh && sh ./jetbrain.sh

会出现两个空,用于输入端口号和默认用户名,建议直接回车,否则可能会出现莫名其妙的错误。

将最后那个License sever地址记下,之后激活用。

分分钟应该就会弹出提示,一劳永逸解决激活问题。