shadowsocks加速插件kcptun搭建以及简单使用

shadowsocks加速插件kcptun搭建以及简单使用

Scroll Down

介绍

shadowsocks
kcptun

Docker安装

环境

CentOS7.x

卸载旧版本

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

从仓库安装

sudo yum install -y yum-utils
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

安装Docker引擎

sudo yum install docker-ce docker-ce-cli containerd.io

若安装指定版本

yum list docker-ce --showduplicates | sort -r
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

设置开机自启

sudo systemctl enable docker

启动Docker

sudo systemctl start docker

Docker-Compose工具

下载稳定版docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

赋予二进制文件可执行权限

sudo chmod +x /usr/local/bin/docker-compose

创建软连接

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

安装shadowsocks+kcptun

创建docker-compose.yml

version: '2'
services:
  shadowsocks:
    image: shadowsocks/shadowsocks-libev
    container_name: shadowsocks
    restart: always
    ports:
      - "8388:8388"
      - "8388:8388/udp"
    environment:
      - PASSWORD=your pass
      - METHOD=aes-256-gcm
      - TIMEOUT=3000
      - SERVER_ADDR=0.0.0.0
      - SERVER_ADDR_IPV6=::0
      - DNS_ADDRS=8.8.8.8,8.8.4.4
    networks:
      - vpn
  kcptun:
    image: xtaci/kcptun
    container_name: kcptun
    restart: always
    ports:
      - "29900:29900/udp"
    depends_on:
      - shadowsocks
    command: server -t "your_server_ip:shadowsocks_expose_port(8388)" -l ":kcptun_listen_port(kcptun_expose_port(29900))" -key "kcptun_pass" -crypt aes -datashard 10 -parityshard 3 -mtu 1350 -sndwnd 512 -rcvwnd 512 -dscp 0 -mode fast2
    networks:
      - vpn
networks:
  vpn:
    external: true

创建网络

docker network create vpn

启动服务

docker-compose -f docker-compose.yml up -d

查看服务状态

docker ps -a 或者 docker-compose -f docker-compose.yml ps

shadowsocks客户端

相关配置信息不做解释,根据服务器实际情况配置即可,给出下载地址链接

Windows
MacOS

kcptun客户端

1. 官方下载

下载链接

2. 源码构建

2.1 源代码下载

git clone https://github.com/xtaci/kcptun.git

2.2 编译(这个步骤依赖于go环境)

1> cd kcptun
2> ./build-release.sh
3> cd build

2.3 编译执行成功后,在build目录下会看到各个环境的可执行包以及安装包

kcptun客户端使用(基于macos)

使用方式

说明

./client_darwin_amd64 -r "KCP_SERVER_IP:4000" -l ":8388" -mode fast3 -nocomp -autoexpire 900 -sockbuf 16777217 -dscp 46
➜  ~ ./client_linux_amd64 -h
NAME:
   kcptun - client(with SMUX)

USAGE:
   client_linux_amd64 [global options] command [command options] [arguments...]

VERSION:
   20190924

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --localaddr value, -l value      local listen address (default: ":12948")
   --remoteaddr value, -r value     kcp server address (default: "vps:29900")
   --key value                      pre-shared secret between client and server (default: "it's a secrect") [$KCPTUN_KEY]
   --crypt value                    aes, aes-128, aes-192, salsa20, blowfish, twofish, cast5, 3des, tea, xtea, xor, sm4, none (default: "aes")
   --mode value                     profiles: fast3, fast2, fast, normal, manual (default: "fast")
   --conn value                     set num of UDP connections to server (default: 1)
   --autoexpire value               set auto expiration time(in seconds) for a single UDP connection, 0 to disable (default: 0)
   --scavengettl value              set how long an expired connection can live(in sec), -1 to disable (default: 600)
   --mtu value                      set maximum transmission unit for UDP packets (default: 1350)
   --sndwnd value                   set send window size(num of packets) (default: 128)
   --rcvwnd value                   set receive window size(num of packets) (default: 512)
   --datashard value, --ds value    set reed-solomon erasure coding - datashard (default: 10)
   --parityshard value, --ps value  set reed-solomon erasure coding - parityshard (default: 3)
   --dscp value                     set DSCP(6bit) (default: 0)
   --nocomp                         disable compression
   --sockbuf value                  per-socket buffer in bytes (default: 4194304)
   --smuxver value                  specify smux version, available 1,2 (default: 1)
   --smuxbuf value                  the overall de-mux buffer in bytes (default: 4194304)
   --streambuf value                per stream receive buffer in bytes, smux v2+ (default: 2097152)
   --keepalive value                seconds between heartbeats (default: 10)
   --snmplog value                  collect snmp to file, aware of timeformat in golang, like: ./snmp-20060102.log
   --snmpperiod value               snmp collect period, in seconds (default: 60)
   --log value                      specify a log file to output, default goes to stderr
   --quiet                          to suppress the 'stream open/close' messages
   --tcp                            to emulate a TCP connection(linux)
   -c value                         config from json file, which will override the command from shell
   --help, -h                       show help
   --version, -v                    print the version

我启动的方式

手动(可将kcptun服务加入系统服务,我认为没必要),需要加速才启动,启动命令如下(我的操作系统是macos),参数的具体配置得根据服务端参数实际配置

./client_darwin_amd64 -r "server_ip:shadowsocks_port" -l ":kcptun_server_port" --key kcptun_pass --crypt=aes --mode fast2 --mtu 1350 --sndwnd 512 --rcvwnd 512 --datashard=10 --parityshard 3 --dscp 0