记录总结搬瓦工上Shadowsocks-libev和kcptun的安装配置 2017year
Shadowsocks-libev介绍
shadowsocks-libev is a lightweight and full featured port for embedded devices and low end boxes. It’s a pure C implementation and has a very small footprint (several megabytes) for thousands of connections. This port is maintained by @madeye.
c版本的shadowsocks服务端描述是 轻量级和全功能端口 并且适合安装在嵌入式设备或低端boxes(低配vps)
Debian/Ubuntu:Shadowsocks-libev is available in the official repository for Debian 9(“Stretch”), unstable, Ubuntu 16.10 and later derivatives:
Shadowsocks-libev 在Debian 9(“Stretch”)和Ubuntu 16.10的库中可以直接安装。曾在网上找到过Shadowsocks-libev的官方源但是已经失效。github上还有编译和deb的安装方式,这里使用编译安装。
安装需要的支持
安装需要的组件
sudo apt-get install --no-install-recommends build-essential autoconf libtool libssl-dev gawk debhelper dh-systemd init-system-helpers pkg-config asciidoc xmlto apg libpcre3-dev zlib1g-dev libev-dev libudns-dev gettext automake libmbedtls-dev
安装 libsodium
wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.12.tar.gz --no-check-certificate
tar xvf libsodium-1.0.12.tar.gz
pushd libsodium-1.0.12
./configure --prefix=/usr && make
sudo make install
popd
sudo ldconfig
安装 mbed库
wget https://tls.mbed.org/download/start/mbedtls-2.4.2-gpl.tgz --no-check-certificate
tar xvf mbedtls-2.4.2-gpl.tgz
pushd mbedtls-2.4.2
make SHARED=1 CFLAGS=-fPIC
sudo make DESTDIR=/usr install
popd
sudo ldconfig
(官方github上使用的是gpl版本,但之前使用apache版本也行。另外如weget下载文件的用时少于3s,可能下载出错,建议更换下载方式)
开始安装shadowsocks-libev
git clone https://github.com/shadowsocks/shadowsocks-libev.git
cd shadowsocks-libev
git submodule update --init
./autogen.sh && ./configure && make
sudo make install
配置
准备必须的文件
mkdir -p /etc/shadowsocks-libev
cp ./debian/shadowsocks-libev.init /etc/init.d/shadowsocks-libev
cp ./debian/shadowsocks-libev.default /etc/default/shadowsocks-libev
cp ./debian/shadowsocks-libev.service /lib/systemd/system/
cp ./debian/config.json /etc/shadowsocks-libev/config.json
chmod +x /etc/init.d/shadowsocks-libev
编辑配置文件vim /etc/shadowsocks-libev/config.json
{
"server":"0.0.0.0",
"server_port":xxxx,#服务器开放端口号
"local_port":1080,#可以默认,没有影响
"password":"xxxxx",#密码
"timeout":60,
"method":"chacha20"#加密方式
}
添加开机自启动服务update-rc.d shadowsocks-libev defaults
启动服务service shadowsocks-libev start
但是我使用服务启动失败了,于是就用ss-server来启动ss-server -c /xxxxx/config.json -a nobody -u &
安装kcptun
https://github.com/xtaci/kcptun/releases/ 下载对应系统的server端client端
https://github.com/dfdragon/kcptun_gclient/releases win下的一个比较方便的client启动器
解压出server_linux_amd64cp server_linux_amd64 /usr/local/bin/
创建配置文件cat xxxxx/kcptunconfig.json
{
"listen": ":xxxx",
"target": "127.0.0.1:xxxx",
"key": "xxxxxxxxxxxxxxx",
"crypt": "salsa20",
"mode": "manual",
"mtu": 1350,
"sndwnd": 128,
"rcvwnd": 512,
"datashard": 80,
"parityshard": 5,
"dscp": 46,
"nocomp": true,
"nodelay": 0,
"interval": 50,
"resend": 2,
"nc": 1
}
运行sudo -u nobody server_linux_amd64 -c xxxxx/kcptunconfig.json &
手动参数设定探讨 · Issue #137 · xtaci/kcptun · GitHub kcptun参数设置
GitHub - skywind3000/kcp: KCP - A Fast and Reliable ARQ Protocol kcp协议的一些解释
设置开机启动 比较笨的办法
vim /etc/rc.local 添加
/usr/local/bin/ss1
/usr/local/bin/ss2
cat ss1
/usr/local/bin/ss-server -c /xxxxx/config.json -a nobody -u &
cat ss2
sudo -u nobody server_linux_amd64 -c /xxxxx/kcptunconfig.json &
记录
Shadowsocks-libev 在Debian 9(“Stretch”)和Ubuntu 16.10的库中可以直接安装
我的ubuntu os的最高版本是16.04,apt install shadowsocks-libev 并没有
ubuntu版本升级用 do-release-upgrad ,但需要先安装 update-manager-core
apt-get install update-manager-core
do-release-upgrade -c
没有可用升级。。。估计是源的问题,想了下还是换回原来的minimal的系统(感觉连接重启关机反应慢了很多,毕竟是小vps),用git下源码来编译
GitHubBuild and install the project from source codes.
$ sudo apt-get install –no-install-recommends build-essential autoconf libtool
libssl-dev gawk debhelper dh-systemd init-system-helpers pkg-config asciidoc
xmlto apg libpcre3-dev zlib1g-dev libev-dev libudns-dev libsodium-dev
$ git clone https://github.com/shadowsocks/shadowsocks-libev.git
$ cd shadowsocks-libev
$ git submodule update –init
$ ./autogen.sh && ./configure && make
$ sudo make install
shadowsocks-libev is licensed under the GNU General Public License v3.0.
./autogen.sh && ./configure && make后提示如下:
Can’t exec “aclocal”: No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory
这是缺失automake造成的
apt-get install automake
然后报错
configure: error: mbed TLS libraries not found.
需要先安装mbed库
wget https://tls.mbed.org/download/start/mbedtls-2.4.2-apache.tgz
tar解压总是报错,根据wget下载的时候用时不到2秒判断可能是下载的文件损坏。
tar zxvf mbedtls-2.4.2-apache.tgz
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
本地用迅雷下下来然后用rz上传后解压成功(浏览器下载到一半就失败)
然后
cd mbedtls-2.4.2
make
# make check
make install
再次执行./autogen.sh && ./configure && make
configure: error: Wrong libsodium: version >= 1.0.4 required
ss如果要使用 salsa20 或 chacha20 或 chacha20-ietf 算法,需要安装 libsodium
ubuntu/debian:
apt-get install build-essential
wget https://github.com/jedisct1/libsodium/releases/download/1.0.11/libsodium-1.0.11.tar.gz
wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.12.tar.gz
tar xf libsodium-1.0.12.tar.gz && cd libsodium-1.0.12
./configure && make && make install
ldconfig
再次执行./autogen.sh && ./configure && make
/ss/shadowsocks-libev/src/stream.c:130: undefined reference to `crypto_stream_chacha20_ietf_xor_ic'
collect2: error: ld returned 1 exit status
Makefile:675: recipe for target 'ss-local' failed
make[2]: *** [ss-local] Error 1
make[2]: Leaving directory '/root/ss/shadowsocks-libev/src'
Makefile:477: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/root/ss/shadowsocks-libev'
Makefile:386: recipe for target 'all' failed
make: *** [all] Error 2
原来是没有卸载老版本libsodium
sudo apt-get remove libsodium-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libsodium13
Use 'apt-get autoremove' to remove it.
The following packages will be REMOVED:
libsodium-dev
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 915 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 21516 files and directories currently installed.)
Removing libsodium-dev:amd64 (1.0.3-1) ...
然后make成功make install成功
shadowsocks-libev/debain/config.json
{
"server":"0.0.0.0",
"server_port":8000,
"local_port":1080,
"password":"xxxxx",
"timeout":60,
"method":"rc4-md5"
}
find / -name config.json
cd xxx
ss-server -c config.json -a root -u &
但是没有shadowsocks-libev.service只有写一个,之后发现/debain 目录下有相关系统文件系统
准备必须的文件
mkdir -p /etc/shadowsocks-libev
cp ./debian/shadowsocks-libev.init /etc/init.d/shadowsocks-libev
cp ./debian/shadowsocks-libev.default /etc/default/shadowsocks-libev
cp ./debian/shadowsocks-libev.service /lib/systemd/system/
cp ./debian/config.json /etc/shadowsocks-libev/config.json
chmod +x /etc/init.d/shadowsocks-libev
编辑配置文件
vim /etc/shadowsocks-libev/config.json
添加开机自启动服务
update-rc.d shadowsocks-libev defaults
启动服务
service shadowsocks-libev start
服务启动失败
最后还是用 ss-server
deb安装失败
https://github.com/shadowsocks/shadowsocks-libev
Add kcptun package build support to build_deb.sh script 包含了kcptun包
Build deb package from source
更换os为ubuntu14.04
sudo apt-get install git
sudo git clone https://github.com/shadowsocks/shadowsocks-libev.git
sudo git submodule update –init –recursive
sudo mkdir /ss/build-area/
./build_deb.sh
然后在build-area/shadowsocks-libev-3.0.3+ds/debian中拷贝配置文集
mkdir -p /etc/shadowsocks-libev
cp shadowsocks-libev.init /etc/init.d/shadowsocks-libev
cp shadowsocks-libev.default /etc/default/shadowsocks-libev
cp shadowsocks-libev.service /lib/systemd/system/
cp config.json /etc/shadowsocks-libev/config.json
chmod +x /etc/init.d/shadowsocks-libev
编辑配置文件
vim /etc/shadowsocks-libev/config.json
添加开机自启动服务
update-rc.d shadowsocks-libev defaults
启动服务
service shadowsocks-libev start
启动失败