2018/11/11

socks5代理搭建


shadowsocks.org官网:https://shadowsocks.org

准备环境

yum install -y asciidoc.noarch  xmlto.x86_64 mbedtls-devel libsodium

如果出现 The Sodium crypto library libraries not found. 需要安装最新的 libsodium

./configure && make && make install

下载 shadowsocks-libev ,请下载v3.1.3版本,v3.2.0以上废除了./configure

mkdir /usr/local/ss5
./configure --prefix=/usr/local/ss5/
make
make install

安装完毕创建配置文件 mkdir /usr/local/ss5/etc

{
    "server":"0.0.0.0", <==服务器的ip地址
    "server_port":1081, <==服务器监听的端口
    "password":"123456", <==授权用户的密码
    "method":"aes-256-cfb" <==加密的协议,socks5加密的协议有很多,这里选择“aes-256-cfb”的方式
}

启动

./ss-server -c /usr/local/ss5/etc/config.json  -f /tmp/ss5.pid &

查看端口监听是否启动成功

netstat -lnutp|grep 1081

编写启动脚本,并加入chkconfig管理:vi ss.sh

#!/bin/bash
# ss          Start up the ss server daemon
#
# chkconfig: 2345 90 92
# description: ss is a protocol for secure remote shell access. \
#              This service starts up the ss server daemon.

. /etc/init.d/functions

function ss_start(){
          if [ -e /tmp/ss5.pid ];then
               action "ss5 already running..." /bin/false
          else
               /usr/local/ss5/bin/ss-server -c /usr/local/ss5/etc/config.json -f /tmp/ss5.pid & >/dev/null 2>&1
           sleep 1
               netstat -lnutp |grep ss-server >/dev/null 2>&1
               [ $? -eq 0 ] && action "ss5 start successful" /bin/true || action "ss5 start failed" /bin/false
      fi
}

function ss_stop(){
    if [ -e /tmp/ss5.pid ];then
         pkill ss-server
         rm -f /tmp/ss5.pid
         sleep 1
         [ -f /tmp/ss5.pid ] && action "ss5 stop failed" /bin/false || action "ss5 stop successful" /bin/true
    else
         action "ss5 already stop..." /bin/false
    fi
}
case $1 in
     start)
       ss_start
       ;;
     stop)
       ss_stop
           ;;
    restart)
      ss_stop
      sleep 2
      ss_start
      ;;
    *)
      echo "USEAGE: $0{start|stop|restart}"
esac

chmod +x ss.sh

附上各个客户端工具

https://github.com/shadowsocks/shadowsocks-android
https://github.com/shadowsocks/shadowsocks-windows
https://github.com/shadowsocks/ShadowsocksX-NG