2017-12-16更新
修復(fù)centos7
下提示service kcptun does not support chkconfig
導(dǎo)致不能開機(jī)啟動(dòng)的bug
前言
tcp加速方案有很多,比如銳速,谷歌bbr,以及很多已經(jīng)放棄維護(hù)的雙邊TCP加速方案,這次為大家介紹的是KCPTun
項(xiàng)目地址 https://github.com/xtaci/kcptun
服務(wù)器端搭建
服務(wù)器采用centos7系統(tǒng)
案例
我使用kcp 888端口為ssh 22端口加速
創(chuàng)建kcptun目錄
mkdir /kcp
cd /kcp
下載kcptun
wget https://github.com/xtaci/kcptun/releases/download/v20180316/kcptun-linux-amd64-20180316.tar.gz
tar xfvz kcptun-linux-amd64-20180316.tar.gz
防火墻開放端口 注意:kcp是UDP端口
[root@baidu kcp]# firewall-cmd --zone=public --permanent --add-port=888/udp
success
[root@baidu kcp]# firewall-cmd --reload
Asuccess
[root@baidu kcp]# firewall-cmd --zone=public --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: venet0
sources:
services: ssh dhcpv6-client
ports: 22/tcp 80/tcp 443/tcp 888/udp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
簡(jiǎn)單測(cè)試
./server_linux_amd64 -t 127.0.0.1:22 -l :888 --key mima --crypt aes-128 --mode fast2
編寫啟動(dòng)腳本
touch /etc/init.d/kcptun
chmod +x /etc/init.d/kcptun
vi /etc/init.d/kcptun
內(nèi)容如下
#!/bin/bash
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
BASE=$(basename $0)
# modify these in /etc/sysconfig/$BASE (/etc/sysconfig/kcptun)
KCPTUN=/kcp/server_linux_amd64
KCPTUN_PIDFILE=/var/run/$BASE.pid
KCPTUN_LOGFILE=/var/log/$BASE.log
KCPTUN_LOCKFILE=/var/lock/subsys/$BASE
KCPTUN_OPTS="-t 127.0.0.1:22 -l :888 --key mima --crypt aes-128 --mode fast2"
KCPTUN_DESC="KCPTUN"
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/$BASE ]; then
. /etc/sysconfig/$BASE
fi
# Check kcptun server is present
if [ ! -x $KCPTUN ]; then
echo "$KCPTUN not present or not executable!"
exit 1
fi
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
start() {
if [ -f ${KCPTUN_LOCKFILE} ]; then
if [ -s ${KCPTUN_PIDFILE} ]; then
echo "$BASE might be still running, stop it first!"
killproc -p ${KCPTUN_PIDFILE} -d ${STOP_TIMEOUT} $KCPTUN
else
echo "$BASE was not shut down correctly!"
fi
rm -f ${KCPTUN_PIDFILE} ${KCPTUN_LOCKFILE}
sleep 2
fi
echo -n $"Starting $BASE: "
$KCPTUN --log ${KCPTUN_LOGFILE} $KCPTUN_OPTS &
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
success
sleep 2
ps -A o pid,cmd | grep "$KCPTUN --log ${KCPTUN_LOGFILE} $KCPTUN_OPTS" | awk '{print $1}' | head -n 1 > ${KCPTUN_PIDFILE}
else
failure
fi
echo
[ $RETVAL = 0 ] && touch ${KCPTUN_LOCKFILE}
return $RETVAL
}
stop() {
echo -n $"Stopping $BASE: "
killproc -p ${KCPTUN_PIDFILE} -d ${STOP_TIMEOUT} $KCPTUN
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${KCPTUN_PIDFILE} ${KCPTUN_LOCKFILE}
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${KCPTUN_PIDFILE} $KCPTUN
RETVAL=$?
;;
restart)
stop
start
;;
*)
echo $"Usage: $BASE { start | stop | restart | status }"
RETVAL=2
;;
esac
exit $RETVAL
啟動(dòng)管理
systemctl daemon-reload
systemctl start kcptun
systemctl status kcptun
systemctl enable kcptun
chkconfig kcptun on
如果你發(fā)現(xiàn)無(wú)法運(yùn)行kcp,請(qǐng)?jiān)儐?wèn)運(yùn)營(yíng)商是否禁用了kcp,解決方法,給程序改個(gè)名字
客戶端
下載客戶端主程序
https://github.com/xtaci/kcptun/releases
下載客戶端GUI
https://github.com/dfdragon/kcptun_gclient/releases/
將gui和主程序放在同一目錄,運(yùn)行g(shù)ui
使用管理員運(yùn)行
添加 - 程序開機(jī)自啟 - 啟動(dòng)后最小化
kcptun客戶端 - 本地監(jiān)聽端口 - kcp服務(wù)器地址 - 端口 -通訊密鑰 - 加密方式
傳輸模式 - 模式選擇
啟動(dòng)
測(cè)試結(jié)果
ssh之前連接服務(wù)器22端口,現(xiàn)在只需要連接127.0.0.1的3300端口即可。
連接前
連接后
ssh均有3倍左右提升
而在網(wǎng)頁(yè)加速下提升為10倍左右