shadowsocks-libev并不像go版本或python版本的shadowsocks客户端/服务端软件那样直接支持多实例配置(相关说明看这里)。shadowsocks-libev需要通过加载不同的配置文件来实现多端口使用。
在CentOS启动脚本shadowsocks-libev的基础上做修改,实现多个配置文件自动加载:
#!/bin/bash
#
# Script to run Shadowsocks in daemon mode at boot time for multiple
# config.json file.
# ScriptAuthor: icyboy, update by nksmiles
# Revision 2.0 - 30th Dec. 2016
#============================================================
# Run level information:
# chkconfig: 2345 99 99
# Description: lightweight secured scoks5 proxy
# processname: ss-server
# Author: Max Lv <max.c.lv@gmail.com>;
# 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/bin/ss-server
##################################
# Path to the configuration file.
# Multiple config.json files are listed here.
CONF=/etc/shadowsocks-libev/config.json
CONF1=/etc/shadowsocks-libev/config1.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
if [ ! -f $CONF1 ] ; then
echo "The configuration file1 cannot be found!"
exit 0
fi
# Path to the lock file.
LOCK_FILE=/var/lock/subsys/shadowsocks
##################################
# Path to the pid file.
# Multiple pid files are listed here
PID=/var/run/$NAME/pid
PID1=/var/run/$NAME/pid1
##################################
#====================================================================
# 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
#multiple config.json file
daemon $DAEMON -c $CONF1 -f $PID1
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}
#killproc multiple PID
killproc -p ${PID1}
RETVAL=$?
[ $RETVAL -eq 0 ]
rm -f $LOCK_FILE
rm -f ${PID}
#remove multiple PID
rm -f ${PID1}
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
将上述脚本保存为/etc/init.d/shadowsocks-libev并添加执行权限,就可以用下面命令启动了:
在CentOS启动脚本shadowsocks-libev的基础上做修改,实现多个配置文件自动加载:
#!/bin/bash
#
# Script to run Shadowsocks in daemon mode at boot time for multiple
# config.json file.
# ScriptAuthor: icyboy, update by nksmiles
# Revision 2.0 - 30th Dec. 2016
#============================================================
# Run level information:
# chkconfig: 2345 99 99
# Description: lightweight secured scoks5 proxy
# processname: ss-server
# Author: Max Lv <max.c.lv@gmail.com>;
# 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/bin/ss-server
##################################
# Path to the configuration file.
# Multiple config.json files are listed here.
CONF=/etc/shadowsocks-libev/config.json
CONF1=/etc/shadowsocks-libev/config1.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
if [ ! -f $CONF1 ] ; then
echo "The configuration file1 cannot be found!"
exit 0
fi
# Path to the lock file.
LOCK_FILE=/var/lock/subsys/shadowsocks
##################################
# Path to the pid file.
# Multiple pid files are listed here
PID=/var/run/$NAME/pid
PID1=/var/run/$NAME/pid1
##################################
#====================================================================
# 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
#multiple config.json file
daemon $DAEMON -c $CONF1 -f $PID1
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}
#killproc multiple PID
killproc -p ${PID1}
RETVAL=$?
[ $RETVAL -eq 0 ]
rm -f $LOCK_FILE
rm -f ${PID}
#remove multiple PID
rm -f ${PID1}
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
将上述脚本保存为/etc/init.d/shadowsocks-libev并添加执行权限,就可以用下面命令启动了:
/etc/init.d/shadowsocks-libev start
启动后,可以通过以下命令查看ss-server是否监听了两个配置文件的端口:
netstat -tlnp
另外,也可以通过修改以上启动脚本来实现更多配置文件的加载。