Debian Jessie 上安装搭建 Shadowsocks 服务,debianshadowsocks


在使用了一段时间后,决定由 CentOS 转移到 Debian 上,原因是因为 Debian 占用的系统内存更少。对于小内存的 VPS 来说更加的合适,而且 Shadowsocks 服务也有之前的 python 版本转移到了 shadowsocks-libev 版本,原因是 libev 的版本是用 C 语言写的,会更加的节省内存,而且更重要的是该 libev 一直在不断的维护着,而且更新很频繁,故选用了该版本。

搭建相应的环境

本人还是在 Vultr.com 的 VPS 上安装了 Debian 8.0 x86 minimal 系统,在 Debian 8(Jessie) 编译 libev 版本需要开启 debian-backports 来安装 dh-systemdinit-system-helpers.
首先要在 debian 的源列表中添加 backports 源

$ vi /etc/apt/sources.list

然后在末尾出添加

deb http://ftp.debian.org/debian Jessie-backports main

然后保存之后运行

$ apt-get update

然后就要去安装 dh-systemdinit-system-helpers

$ apt-get -t Jessie-backports install "dh-systemd"
$ apt-get -t Jessie-backports install "init-system-helpers"

安装上面的两个 packages 后还没有完成, 还有一些别的依赖需要确保安装上了

$ apt-get install --no-install-recommends build-essential autoconf libtool libssl-dev gawk debhelper pkg-config asciidoc xmlto apg

然后需要从 github 上把源代码 git 下来

$ git clone https://github.com/shadowsocks/shadowsocks-libev.git

然后进入 shadowsocks-libev 目录下进行编译

$ cd shadowsocks-libev
$ dpkg-buildpackage -b -us -uc -i
$ cd ..
$ dpkg -i shadowsocks-libev*.deb

编译是通过生成 deb 包然后进行安装,其实也可以通过 make 的方式来进行安装,但使用 deb 包安装会自动生成开启启动的脚步在 /etc/init.d 目录下,采用哪种方式安装就因人而异了
接下来就需要编译配置文件

$ vi /etc/shadowsocks-libev/config.json

然后将配置文件改为

{
    "server":"0.0.0.0",
    "server_port":443,
    "password":"yourpassword",
    "method":"aes-256-cfb",
    "timeout":60
}

其中

server:主机域名或者IP地址,尽量填 0.0.0.0 来代表了本机 ip
server_port:服务器监听端口
password:自定义密码
method:加密方式 默认为table,其他有rc4,rc4-md5,aes-128-cfb, aes-192-cfb, aes-256-cfb,**bf-cfb, camellia-128-cfb, camellia-192-cfb,**camellia-256-cfb, cast5-cfb, des-cfb
timeout:连接超时时间,单位秒。要适中。

如果客户端有OpenWRT路由器等设备,推荐rc4-md5,性能更好;否则可以选用安全性更好的aes-256-cfb等,不过计算复杂度上升,会有性能的损失,不过对于PC机以及现在的只能手机来说没有任何问题。路由器性能较弱所以可以考虑rc4-md5
保存配置文件后,就重启 shadosocks-libev 服务

$ service shadowsocks-libev restart

然后就搭建完成了,查看shadowsocks是否正确启动并监听相应端口,看到有ss-server 进程 LISTEN 正确的端口就表示成功:

$ netstat -lnp

还有很多 ss-server 相关的命令可以通过下面来进行参考:

usage:

    ss-[local|redir|server|tunnel]

          -s <server_host>           host name or ip address of your remote server
          -p <server_port>           port number of your remote server
          -l <local_port>            port number of your local server
          -k <password>              password of your remote server


          [-m <encrypt_method>]      encrypt method: table, rc4, rc4-md5
                                     aes-128-cfb, aes-192-cfb, aes-256-cfb,
                                     bf-cfb, camellia-128-cfb, camellia-192-cfb,
                                     camellia-256-cfb, cast5-cfb, des-cfb,
                                     idea-cfb, rc2-cfb and seed-cfb
          [-f <pid_file>]            file to store the pid
          [-t <timeout>]             socket timeout in seconds
          [-c <config_file>]         config file in json


          [-i <interface>]           network interface to bind,
                                     not available in redir mode
          [-b <local_address>]       local address to bind,
                                     not available in server mode
          [-u]                       enable udprelay mode
                                     not available in redir mode
          [-L <addr>:<port>]         setup a local port forwarding tunnel,
                                     only available in tunnel mode
          [-v]                       verbose mode


          [--fast-open]              enable TCP fast open,
                                     only available on Linux kernel > 3.7.0
          [--acl <acl_file>]         config file of ACL (Access Control List)

notes:

    ss-redir provides a transparent proxy function and only works on the 
    Linux platform with iptables.

一个例子如:

$ setsid ss-server -c /etc/shadowsocks/config.json -u

原文发布时间:2016-10-12 本文来自linuxboy合作伙伴“Debian社区”,了解相关信息可以关注“Debian社区”。

相关内容