由于 libuv 版本的 SS 不稳定,并且安装步骤繁琐,因此推荐安装 libev 版本。安装参考如下
1、Shadowsocks 是什么
Shadowsocks 是一种安全的 socks5 代理,可以保护你的上网流量。基于多种加密方式,推荐使用 aes-256-cfb 加密。安装和使用需要本地端和服务端。 本地客户端已经包含了多种版本,包括iOS,Android,Windows,MAC,甚至是路由器 (基于OpenWRT),所以使用方便,各取所需。 远程服务端则一般安装在基于 Linux 的各种发行版操作系统,比如 Debian, CentOS, Fedora, Redhat, Ubuntu, openSUSE等。2、Shadowsocks 的作者是谁
最初只有 Python 版,由 @clowwindy 开发和维护,后来随着知名度提高,开始出现各种语言的版本,其中比较知名的是 libev , go, nodejs 等版本,需要注意的是,nodejs 的作者也是 @clowwindy,但最近已不再维护该版本。libev 的维护者是 @madeye,长期更新。3、Shadowsocks 一键安装脚本
虽然作者的安装教程已经很完备了,但还是有不少人不会安装和使用,因此我编写了 Shadowsocks 一键安装脚本,主要基于 CentOS 系统下的一键安装(也有 Debian 系统),分别有 Python, libev, nodejs 版,个人推荐使用 Python 和 libev 版。 该脚本会自动下载,编译安装最新版的 Shadowsocks,并且可以完全卸载 Shadowsocks ,自动生成配置文件,安装完成即可使用。4、Shadowsocks 如何升级
安装完 Shadowsocks,一段时间后,作者已经更新了版本(修正 bug 或升级功能),那么如何一键升级到最新版呢? Python 版,执行命令: pip install -U shadowsocks ,命令执行成功后,重新启动 Shadowsocks ,命令: service shadowsocks restart libev 版,先卸载旧版本,执行命令:./shadowsocks-libev.sh uninstall ,再安装新版本,执行命令: ./shadowsocks-libev.sh 安装 Debian 下的 libev 版,升级方式同上。 nodejs 版,也是先卸载再重新安装,因为作者已经不更新,所以不推荐用这版本。5、Shadowsocks 安装失败怎么办
由于 CentOS 5.x 的默认 gcc 版本过低,在编译 libev 版时会出错;同时默认 Python 的版本也过低,所以也无法安装 Python 版的。因此,请确保安装的环境为 CentOS 6.x 或 CentOS 7.x 。 更多其他错误,请根据实际错误提示,自行在 google 上搜索关键字。6、Shadowsocks 的客户端程序
大多数人都是在 Windows 下使用电脑,因此最好用的 Windows 客户端是 shadowsocks-gui ,下载最新版后解压即可使用。 shadowsocks-gui客户端下载地址:https://sourceforge.net/projects/shadowsocksgui/files/dist/7、Shadowsocks 本地代理上网
本地电脑启动客户端,连接上远程服务端后,即在本地开启了 socks5 代理,本地端口号默认为 1080,如果提示被占用,也可以改为其他端口号。在浏览器中安装插件,Chrome 下是 SwitchySharp, Firefox 下是 AutoProxy,新建配置文件,SOCKS Host 填 127.0.0.1,Port 填 1080(默认,跟 Shadowsocks 客户端的本地端口号一致即可) 参考链接: 1、http://shadowsocks.org/en/index.html 2、https://github.com/clowwindy/shadowsocks 3、https://github.com/madeye/shadowsocks-libev以下的一键安装脚本来源于网络:秋水逸冰的博客!【博主在搬瓦工的MICRO64型号VPS运行安装通过了】
CentOS下shadowsocks-libev一键安装脚本
搬瓦工Micro-64型号配置,博主是在某宝上面淘到的。价格是每年的。 Self-managed HDD: 1.5 GB RAM: 64 MB CPU: 1x Intel Xeon BW: 100 GB/mo本脚本适用环境: 系统支持:CentOS 6.x 32或64位 内存要求:≥128M 日期:2014年07月12日关于本脚本: 一键安装 libev 版的 shadowsocks 最新版本。该版本的特点是内存占用小(600k左右),低 CPU 消耗,甚至可以安装在基于 OpenWRT 的路由器上。 默认配置: 服务器端口:8989 客户端端口:1080 密码:自己设定(如不设定,默认为teddysun.com) 客户端下载: http://sourceforge.net/projects/shadowsocksgui/files/dist/使用方法: 使用root用户登录,运行以下命令:
wget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-libev.sh chmod +x shadowsocks-libev.sh ./shadowsocks-libev.sh 2>&1 | tee shadowsocks-libev.log安装完成后,脚本提示如下:
Congratulations, shadowsocks-libev install completed! Your Server IP:your_server_ip Your Server Port:8989 Your Password:your_password Your Local IP:127.0.0.1 Your Local Port:1080 Your Encryption Method:aes-256-cfb Welcome to visit:http://teddysun.com/357.html Enjoy it!卸载方法: 使用 root 用户登录,运行以下命令:
./shadowsocks-libev.sh uninstall其他事项: 安装完成后即已后台启动 shadowsocks ,运行:
ps -ef | grep ss-server | grep -v ps | grep -v grep可以查看进程是否存在。 本脚本安装完成后,会将 shadowsocks-libev 加入开机自启动。 使用命令: 启动:/etc/init.d/shadowsocks start 停止:/etc/init.d/shadowsocks stop 重启:/etc/init.d/shadowsocks restart 查看状态:/etc/init.d/shadowsocks status 更多版本 shadowsocks 安装: CentOS 下 shadowsocks-python 一键安装脚本CentOS 下 shadowsocks-nodejs 一键安装脚本Debian 下 shadowsocks-libev 一键安装脚本特别说明: 1、已安装旧版本的 shadowsocks 需要升级的话,需下载本脚本的最新版,运行卸载命令./shadowsocks-libev.sh uninstall 后,再次执行本脚本即可安装最新版。 2、关于 CentOS 的默认 iptables 防火墙规则 icmp-host-prohibited ,如果安装之后发现已经启动 shadowsocks,本地客户端却不能连接上,请检查 iptables 是不是有如下的一条规则:
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited运行命令:
/etc/init.d/iptables status可以查看。如果有这条规则,则添加的 8989 端口需手动更改一下,放到这条规则的上一行。编辑 /etc/sysconfig/iptables 文件,将:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8989 -j ACCEPT放在:
-A INPUT -j REJECT --reject-with icmp-host-prohibited的前面。最终效果如下:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8989 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited编辑完后,重启 iptables 防火墙。命令:
/etc/init.d/iptables restart
秋水逸冰博主的CentOS下shadowsocks-libev一键安装脚本内容: #! /bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH #=============================================================================================== # System Required: CentOS6.x (32bit/64bit) # Description: Install Shadowsocks(libev) for CentOS # Author: Teddysun <i@teddysun.com> # Intro: http://teddysun.com/357.html #=============================================================================================== clear echo "#############################################################" echo "# Install Shadowsocks(libev) for CentOS6.x (32bit/64bit)" echo "# Intro: http://teddysun.com/357.html" echo "#" echo "# Author: Teddysun <i@teddysun.com>" echo "#" echo "#############################################################" echo "" # Install Shadowsocks-libev function install_shadowsocks_libev(){ rootness disable_selinux pre_install download_files config_shadowsocks iptables_set install } # Make sure only root can run our script function rootness(){ if [[ $EUID -ne 0 ]]; then echo "Error:This script must be run as root!" 1>&2 exit 1 fi } # Disable selinux function disable_selinux(){ if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0 fi } # Pre-installation settings function pre_install(){ #Set shadowsocks-libev config password echo "Please input password for shadowsocks-libev:" read -p "(Default password: teddysun.com):" shadowsockspwd if [ "$shadowsockspwd" = "" ]; then shadowsockspwd="teddysun.com" fi echo "password:$shadowsockspwd" echo "####################################" get_char(){ SAVEDSTTY=`stty -g` stty -echo stty cbreak dd if=/dev/tty bs=1 count=1 2> /dev/null stty -raw stty echo stty $SAVEDSTTY } echo "" echo "Press any key to start...or Press Ctrl+C to cancel" char=`get_char` #Install necessary dependencies yum install -y wget unzip openssl-devel gcc swig python python-devel python-setuptools autoconf libtool libevent yum install -y automake make curl curl-devel zlib-devel openssl-devel perl perl-devel cpio expat-devel gettext-devel # Get IP address echo "Getting Public IP address, Please wait a moment..." IP=`curl -s checkip.dyndns.com | cut -d' ' -f 6 | cut -d'<' -f 1` if [ -z $IP ]; then IP=`curl -s ifconfig.me/ip` fi #Current folder cur_dir=`pwd` cd $cur_dir } # Download latest shadowsocks-libev function download_files(){ if [ -f shadowsocks-libev.zip ];then echo "shadowsocks-libev.zip [found]" else if ! wget --no-check-certificate https://github.com/madeye/shadowsocks-libev/archive/master.zip -O shadowsocks-libev.zip;then echo "Failed to download shadowsocks-libev.zip" exit 1 fi fi unzip shadowsocks-libev.zip if [ $? -eq 0 ];then cd $cur_dir/shadowsocks-libev-master/ else echo "" echo "Unzip shadowsocks-libev failed! Please visit http://teddysun.com/357.html and contact." exit 1 fi # Download start script if ! wget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-libev; then echo "Failed to download shadowsocks-libev start script!" exit 1 fi } # Config shadowsocks function config_shadowsocks(){ if [ ! -d /etc/shadowsocks-libev ];then mkdir /etc/shadowsocks-libev fi cat > /etc/shadowsocks-libev/config.json<<-EOF { "server":"${IP}", "server_port":8989, "local_address":"127.0.0.1", "local_port":1080, "password":"${shadowsockspwd}", "timeout":600, "method":"aes-256-cfb" } EOF } # iptables set function iptables_set(){ /sbin/service iptables status 1>/dev/null 2>&1 if [ $? -eq 0 ]; then /etc/init.d/iptables status | grep '8989' | grep 'ACCEPT' >/dev/null 2>&1 if [ $? -ne 0 ]; then /sbin/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 8989 -j ACCEPT /etc/init.d/iptables save /etc/init.d/iptables restart fi fi } # Install function install(){ # Build and Install shadowsocks-libev if [ -s /usr/local/bin/ss-server ];then echo "shadowsocks-libev has been installed!" exit 0 else ./configure make && make install if [ $? -eq 0 ]; then mv $cur_dir/shadowsocks-libev-master/shadowsocks-libev /etc/init.d/shadowsocks chmod +x /etc/init.d/shadowsocks # Add run on system start up chkconfig --add shadowsocks chkconfig shadowsocks on # Start shadowsocks /etc/init.d/shadowsocks start if [ $? -eq 0 ]; then echo "Shadowsocks-libev start success!" else echo "Shadowsocks-libev start failure!" fi else echo "" echo "Shadowsocks-libev install failed! Please visit http://teddysun.com/357.html and contact." exit 1 fi fi cd $cur_dir # Delete shadowsocks-libev floder rm -rf $cur_dir/shadowsocks-libev-master/ # Delete shadowsocks-libev zip file rm -f shadowsocks-libev.zip clear echo "" echo "Congratulations, shadowsocks-libev install completed!" echo -e "Your Server IP: \033[41;37m ${IP} \033[0m" echo -e "Your Server Port: \033[41;37m 8989 \033[0m" echo -e "Your Password: \033[41;37m ${shadowsockspwd} \033[0m" echo -e "Your Local IP: \033[41;37m 127.0.0.1 \033[0m" echo -e "Your Local Port: \033[41;37m 1080 \033[0m" echo -e "Your Encryption Method: \033[41;37m aes-256-cfb \033[0m" echo "" echo "Welcome to visit:http://teddysun.com/357.html" echo "Enjoy it!" echo "" } # Uninstall Shadowsocks-libev function uninstall_shadowsocks_libev(){ printf "Are you sure uninstall shadowsocks_libev? (y/n) " printf "\n" read -p "(Default: n):" answer if [ -z $answer ]; then answer="n" fi if [ "$answer" = "y" ]; then ps -ef | grep -v grep | grep -v ps | grep -i "ss-server" > /dev/null 2>&1 if [ $? -eq 0 ]; then /etc/init.d/shadowsocks stop fi chkconfig --del shadowsocks # delete config file rm -rf /etc/shadowsocks-libev # delete shadowsocks rm -f /usr/local/bin/ss-local rm -f /usr/local/bin/ss-tunnel rm -f /usr/local/bin/ss-server rm -f /usr/local/bin/ss-redir rm -f /usr/local/share/man/man8/shadowsocks.8 rm -f /etc/init.d/shadowsocks echo "Shadowsocks-libev uninstall success!" else echo "uninstall cancelled, Nothing to do" fi } # Initialization step action=$1 [ -z $1 ] && action=install case "$action" in install) install_shadowsocks_libev ;; uninstall) uninstall_shadowsocks_libev ;; *) echo "Arguments error! [${action} ]" echo "Usage: `basename $0` {install|uninstall}" ;; esacShadowsocks一键安装包(Debian/Ubuntu适用)脚本内容[脚本内容来源于网络]:
#!/bin/bash if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script" exit 1 fi ssport=443 echo -e "Shadowsocks server port(Default 443)>>\c" read ssport echo "===========shadowsocks port is $ssport============" sspasswd=5y2n echo -e "Shadowsocks server password(Default 5y2d)>>\c" read sspasswd echo "=========shadowsocks password is $sspasswd========" ssmethod=rc4-md5 echo -e "Shadowsocks server encrypte method" echo -e "Allow: rc4-md5(Default),aes-128,aes-256>>\c" read ssmethod echo "=====shadowsocks encrypte method is $ssmethod=====" apt-get -y update apt-get -y install git && mkdir /tmp/shadowsocks && cd /tmp/shadowsocks && git clone https://github.com/madeye/shadowsocks-libev.git cd shadowsocks-libev apt-get -y install build-essential autoconf libtool libssl-dev gawk debhelper dpkg-buildpackage cd .. dpkg -i shadowsocks*.deb cd ../.. && rm -rf shadowsocks sed -i 's/"server":"\<.*\>"/"server":"0.0.0.0"/g' /etc/shadowsocks/config.json var1=\"server_port\":\\\<.*\\\> var2=\"server_port\":$ssport sed -i "s/$var1/$var2/g" /etc/shadowsocks/config.json var1=\"password\":\"\\\<.*\\\>\" var2=\"password\":\"$sspasswd\" sed -i "s/$var1/$var2/g" /etc/shadowsocks/config.json var1=\"method\":\"\\\<.*\\\>\" var2=\"method\":\"$ssmethod\" sed -i "s/$var1/$var2/g" /etc/shadowsocks/config.json service shadowsocks restart && echo "===========================================================" echo "=" echo "= Your shadowsocks server install complete! " echo "= Congfig file: /etc/shadowsocks/config.json" echo "= Control: service shadowsocks {start|stop|restart}" echo "=" echo "==========================================================="