Centos7搭建Shadowsocks

搭建shadowsocks很简单,直接yum安装即可。

安装相关组件

yum install -y gcc automake autoconf libtool make
yum install -y curl-devel zlib-devel openssl-devel perl-devel expat-devel gettext-devel

通过github安装shadowsocks

git clone https://github.com/madeye/shadowsocks-libev.git
cd shadowsocks-libev
./configure && make
make install

创建开机脚本

vi /etc/init.d/shadowsocks   #填写下方脚本
#!/bin/bash
#
# Script to run Shadowsocks in daemon mode at boot time.
# ScriptAuthor: icyboy
# Revision 1.0 - 14th Sep 2013
#====================================================================
# Run level information:
# chkconfig: 2345 99 99
# Description: lightweight secured scoks5 proxy
# processname: ss-server
# Author: Max Lv <[email protected]>;
# Run "/sbin/chkconfig --add shadowsocks" to add the Run levels.
#====================================================================

#====================================================================
# Paths and variables and system checks.

# Source function library
. /etc/rc.d/init.d/functions

# Check that networking is up.
#
[ ${NETWORKING} ="yes" ] || exit 0

# Daemon
NAME=shadowsocks-server
DAEMON=/usr/local/bin/ss-server

# Path to the configuration file.
#
CONF=/etc/shadowsocks/config.json

#USER="nobody"
#GROUP="nobody"

# Take care of pidfile permissions
mkdir /var/run/$NAME 2>/dev/null || true
#chown "$USER:$GROUP" /var/run/$NAME

# Check the configuration file exists.
#
if [ ! -f $CONF ] ; then
echo "The configuration file cannot be found!"
exit 0
fi

# Path to the lock file.
#
LOCK_FILE=/var/lock/subsys/shadowsocks

# Path to the pid file.
#
PID=/var/run/$NAME/pid


#====================================================================

#====================================================================
# Run controls:

RETVAL=0

# Start shadowsocks as daemon.
#
start() {
if [ -f $LOCK_FILE ]; then
echo "$NAME is already running!"
exit 0
else
echo -n $"Starting ${NAME}: "
#daemon --check $DAEMON --user $USER "$DAEMON -f $PID -c $CONF > /dev/null"
daemon $DAEMON -c $CONF -f $PID
fi

RETVAL=$?
[ $RETVAL -eq 0 ] && success
echo
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
return $RETVAL
}


# Stop shadowsocks.
#
stop() {
echo -n $"Shutting down ${NAME}: "
killproc -p ${PID}
RETVAL=$?
[ $RETVAL -eq 0 ]
rm -f $LOCK_FILE
rm -f ${PID}
echo
return $RETVAL
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
condrestart)
if [ -f $LOCK_FILE ]; then
stop
start
RETVAL=$?
fi
;;
status)
status $DAEMON
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=1
esac

exit $RETVAL

创建config.json并填写相关账号信息

mkdir -p /etc/shadowsocks
vi /etc/shadowsocks/config.json  #填写下方参数
{
    "server":"服务器 IP 地址",
    "server_port":8388,
    "local_address": "127.0.0.1",
    "local_port":1080,
    "password":"mypassword",
    "timeout":300,
    "method":"aes-256-cfb",
    "fast_open": false,
    "workers": 1
}

各个字段的意思:

字段名 含义
server 服务端监听的地址,服务端可填写 0.0.0.0
server_port 服务端的端口
local_address 本地端监听的地址
local_port 本地端的端口
password 用于加密的密码
timeout 超时时间,单位秒
method 默认 “aes-256-cfb”,参见加密方法
fast_open 是否使用 TCP_FASTOPEN, true / false
workers worker 数量,Unix/Linux 可用,如果不理解含义请不要改

最后赋予shadowsocks执行权限并添加开机启动即可

chmod 755 /etc/init.d/shadowsocks
chkconfig --add shadowsocks
systemctl start shadowsocks

 
 
本文标题:Centos7搭建Shadowsocks
使用说明:https://github.com/clowwindy/shadowsocks/wiki
               https://github.com/madeye/shadowsocks-libev
本文地址:https://miefen.com/201410/how-to-install-shadowsocks-on-centos-7

3 thoughts on “Centos7搭建Shadowsocks

  1. Pingback引用通告: Centos7搭建Shadowsocks | Plus7's Blog WordPress Unknow Os

发表评论

电子邮件地址不会被公开。 必填项已用*标注