Shadowsocks Python版一键安装脚本

技术 秋水逸冰 2570782浏览 1333评论

本脚本适用环境:
系统支持:CentOS 6,7,Debian,Ubuntu
内存要求:≥128M
日期:2018 年 02 月 07 日

关于本脚本:
一键安装 Python 版 Shadowsocks 的最新版。
友情提示:如果你有问题,请先参考这篇《Shadowsocks Troubleshooting》后再问。

默认配置:
服务器端口:自己设定(如不设定,默认从 9000-19999 之间随机生成)
密码:自己设定(如不设定,默认为 teddysun.com)
加密方式:自己设定(如不设定,默认为 aes-256-gcm)
备注:脚本默认创建单用户配置文件,如需配置多用户,安装完毕后参照下面的教程示例手动修改配置文件后重启即可。

Shadowsocks for Windows 客户端下载:
https://github.com/shadowsocks/shadowsocks-windows/releases

使用方法:
使用root用户登录,运行以下命令:

wget --no-check-certificate -O shadowsocks.sh https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks.sh
chmod +x shadowsocks.sh
./shadowsocks.sh 2>&1 | tee shadowsocks.log

安装完成后,脚本提示如下:

Congratulations, Shadowsocks-python server install completed!
Your Server IP        :your_server_ip
Your Server Port      :your_server_port
Your Password         :your_password
Your Encryption Method:your_encryption_method

Welcome to visit:https://teddysun.com/342.html
Enjoy it!

卸载方法:
使用root用户登录,运行以下命令:

./shadowsocks.sh uninstall

单用户配置文件示例(2015 年 08 月 28 日修正):
配置文件路径:/etc/shadowsocks.json

{
    "server":"0.0.0.0",
    "server_port":your_server_port,
    "local_address":"127.0.0.1",
    "local_port":1080,
    "password":"your_password",
    "timeout":300,
    "method":"your_encryption_method",
    "fast_open": false
}

多用户多端口配置文件示例(2015 年 08 月 28 日修正):
配置文件路径:/etc/shadowsocks.json

{
    "server":"0.0.0.0",
    "local_address":"127.0.0.1",
    "local_port":1080,
    "port_password":{
         "8989":"password0",
         "9001":"password1",
         "9002":"password2",
         "9003":"password3",
         "9004":"password4"
    },
    "timeout":300,
    "method":"your_encryption_method",
    "fast_open": false
}

使用命令(2015 年 08 月 28 日修正):
启动:/etc/init.d/shadowsocks start
停止:/etc/init.d/shadowsocks stop
重启:/etc/init.d/shadowsocks restart
状态:/etc/init.d/shadowsocks status

更多版本 Shadowsocks 服务端一键安装脚本:
ShadowsocksR 版一键安装脚本(CentOS,Debian,Ubuntu)
CentOS 下 Shadowsocks-libev 一键安装脚本
Debian 下 Shadowsocks-libev 一键安装脚本
Shadowsocks-go 一键安装脚本(CentOS,Debian,Ubuntu)
Shadowsocks 一键安装脚本(四合一)

参考链接:
https://teddysun.com/339.html

更新日志

(2018 年 02 月 07 日)
1、修改:将默认端口从 8989 改为从 9000-19999 之间随机生成。

(2017 年 07 月 21 日)
1、修正:默认加密方式从 aes-256-cfb 改为 aes-256-gcm(官方原版客户端支持该加密方式);
2、新增:安装时可选 16 种加密方式的其中之一。如下所示:

aes-256-gcm
aes-192-gcm
aes-128-gcm
aes-256-ctr
aes-192-ctr
aes-128-ctr
aes-256-cfb
aes-192-cfb
aes-128-cfb
camellia-128-cfb
camellia-192-cfb
camellia-256-cfb
chacha20-ietf-poly1305
chacha20-ietf
chacha20
rc4-md5

(2016 年 08 月 18 日)
1、修正:默认安装 Github 上 master 分支最新版本(目前为 2.9.0)。
2、修正:由于原作者已经不再更新 pip 下的源代码,故不再使用 pip 安装 Shadowsocks,而是改为下载 Github 的 master 分支来安装。如果在一段时间后,版本升级了,则先卸载,并再次执行本脚本就可以升级为最新版。

(2016 年 05 月 12 日)
1、新增在 CentOS 7 下的防火墙规则设置。

(2015 年 08 月 28 日)
1、修正控制脚本 /etc/init.d/shadowsocks 在 CentOS 7 无法查看 status 的问题。

(2015 年 08 月 01 日)
1、新增自定义服务器端口功能(如不设定,默认端口为 8989);

(2015 年 03 月 10 日)
1、新增在 Debian、Ubuntu 下的一键安装;

(2015 年 01 月 21 日)
1、修正配置文件,与官方给出的 Sample 一致;
2、修改启动脚本,使用官方给出的后台启动和停止命令。

(2014 年 10 月 10 日)
跟作者反馈了多用户多端口问题,作者已更新 Wiki 页面。本教程新增多用户多端口配置文件的 sample 。

(2014 年 09 月 24 日)
如何配置多用户?详见:这里
备注:Shadowsocks 已经支持多用户,在配置文件中增加不同的端口,对应不同的密码即可。

(2014 年 07 月 12 日)
1、修正获取公网 IP 时的一个问题。建议不要使用共享公网 IP 的 VPS 来搭建 Shadowsocks 服务。

(2014 年 05 月 29 日)
1、增加 chkconfig 配置,实现 service 命令。
2、配置文件名从 /etc/config.json 改为 /etc/shadowsocks.json(与官方的命名一致)。
3、配置文件中新增 workers ,值默认为 1(与官方配置同步)。

(2014 年 05 月 27 日)
1、修正开机自启动失效的问题。
2、优化是否后台启动成功的判断逻辑。

(2014 年 05 月 04 日)
1、修正对增加防火墙端口逻辑的判断bug,对于已经放行 8989 端口的情况下,则无需再次增加。
2、修正获取服务器 IP 的判断bug,对于多 IP 的 VPS 或服务器,默认只取第一个公网 IP 写到配置文件(/etc/config.json)里。
3、加入开机自启动。

转载请注明:秋水逸冰 » Shadowsocks Python版一键安装脚本

发表我的评论
取消评论

请输入正确答案后提交评论 *超出时限。 请再次填写验证码。

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1333)

  1. 你好,请问,我用阿里云安装ss,出现如下错误 Resolving raw.githubusercontent.com... failed: Name or service not known. wget: unable to resolve host address “raw.githubusercontent.com” Failed to download shadowsocks-libev start script! Shadowsocks-python一键脚本 也试过,同样的失败,都是 wget: unable to resolve host address 请问 该如何解决啊,还是说阿里云无法搭建ss
    呆呆8年前(2016-03-12)回复
  2. 秋大,为什么会出现这个 500 Internal Privoxy Error Privoxy encountered an error while processing your request: Could not load template fileno-server-dataor one of its included components. Please contact your proxy administrator. If you are the proxy administrator, please put the required file(s)in the(confdir)/templatesdirectory. The location of the(confdir)directory is specified in the main Privoxyconfigfile. (It's typically the Privoxy install directory).
    寻雨8年前(2016-03-12)回复
    • 你解决了吗 我连接自己的VPS就出现这种错误,连接别人的就没有 而且都是过两天就会出现
      坚定8年前(2016-03-25)回复
  3. 秋大,请问出现如下错误怎么解决? iptables start setting... iptables looks like shutdown, please manually set it if necessary. pip install failed! Please visit https://teddysun.com/342.html and contact.
    Gordon8年前(2016-03-10)回复
    • 这是安装 pip 的时候出错了。 估计又是安装 pip 的那个 ez_setup.py 又出啥幺蛾子了。 不行就换个版本的来,右侧有个 ShadowsocksR 的,也一样,这个版本的安装不依赖 pip
      秋水逸冰8年前(2016-03-10)回复
      • 这个错误解决了,我之前因为升级python版本导致pip和easy_install模块用不了了,还好是今天新买的VPS,直接重置了什么都不做直接使用你的一键脚本搭建成功了。不过奇怪的是一开始能用一下下,后来我手动配置了一下加密方式又用不了了,然后我又重置重新安装,还是用不了,无语了都。不知道是不是VPS本身的原因,买的conoha东京,延迟很高,300多
        Gordon8年前(2016-03-10)回复
        • 可以肯定的说,不是 VPS 的问题。 肯定你是配置文件没改对,或者防火墙没有对相应端口放行,或者你本地客户端配置错了,等等等等
          秋水逸冰8年前(2016-03-11)回复
  4. 秋大,我刚买的vultr的vps想使用SS通过ipv6连接,但是无法实现,shadowsocks.json中server设置为ipv6地址也无法连接,ipv4倒是可以顺利连接,大概是个什么问题呢?
    小鶸菌8年前(2016-03-10)回复
    • 大概是你本地没有 ipv6 吧,你确定你的电脑可以通过 ipv6 上网吗?
      秋水逸冰8年前(2016-03-10)回复
      • 没有问题的,我们是校园ipv6
        小鶸菌8年前(2016-03-14)回复
        • 你本地有 ipv6,vps也得有 ipv6,默认是监听所有的端口的。 首先你得 ping 一下服务器的 ipv6,是不是通的。
          秋水逸冰8年前(2016-03-14)回复
  5. 前辈,--2016-03-08 00:19:49-- https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-debian Resolving raw.githubusercontent.com... 199.27.79.133 Connecting to raw.githubusercontent.com|199.27.79.133|:443... connected. WARNING: certificate common name “www.github.com” doesn’t match requested host name “raw.githubusercontent.com”. HTTP request sent, awaiting response... 200 OK Length: 1525 (1.5K) [text/plain] Saving to: “/etc/init.d/shadowsocks” 0K . 100% 886M=0s 2016-03-08 00:19:49 (886 MB/s) - “/etc/init.d/shadowsocks” saved [1525/1525] pip install failed! Please visit https://teddysun.com/342.html and contact. 前一阵子大概15天左右这个命令还好好的。今天重装了一下OS就出错了。
    Nikain8年前(2016-03-08)回复
    • 这是提示你的 vps 安装 pip 时出错了。 或者你换一个版本的试试看,比如 go 版?
      秋水逸冰8年前(2016-03-08)回复
      • 秋大,go版本是可以的,但是用没多久,就很容易出现被屏蔽端口,日志里面出现 目标计算机积极拒绝。以前潘森版一键安装用的都好好的。不知道这两天是VPS那边换了系统还是怎么着。一键端就不行了。
        Nikain8年前(2016-03-09)回复
        • 其实还有个 ShadowsocksR一键安装脚本 可供选择。 这个版本是基于原来的 Python 版的。加入了流量混淆等特征。
          Teddysun8年前(2016-03-09)回复
          • 秋大,ShadowsocksR 这样 checking whether make sets $(MAKE)... no checking whether make supports nested variables... no checking whether UID '0' is supported by ustar format... yes checking whether GID '0' is supported by ustar format... yes checking how to create a ustar tar archive... gnutar checking whether make supports nested variables... (cached) no checking whether to enable maintainer-specific portions of Makefiles... no checking for style of include used by make... none checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/root/libsodium-1.0.8': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details ./shadowsocksR.sh: line 202: unzip: command not found mv: cannot stat `shadowsocks-manyuser/shadowsocks': No such file or directory Shadowsocks install failed! Please Email to Teddysun and contact.
            Nikain8年前(2016-03-10)回复
            • 这是缺少编译器造成的。应该都会通过 yum 或者 apt-get 安装好的才对。 所以有可能是你系统的问题,导致没有安装那些依赖包。
              秋水逸冰8年前(2016-03-10)回复
  6. 非常感谢大神分享,试了好多个方法,这个最简单有效!
    Jdlee8年前(2016-03-06)回复
  7. 秋大,我用你这个脚本搭建的服务器用了很久了,最近想做多用户,就修改 shadowsocks.json 但是只有8989这个端口可以用 其他端口都是无效的,我用的是Vultr 我看留言里面也有Vultr用户出现这个问题,应该就是防火墙的问题 但是不想关闭防火墙,如何在vultr中打开8989以外的端口呢? 您的一键脚本当时是怎么打开8989脚本的呢? 感激不尽
    Garipan8年前(2016-03-04)回复
    • 你就去搜索教程,iptables 防火墙如何放行端口。 一般情况下,执行如下命令即可 iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 端口号 -j ACCEPT
      秋水逸冰8年前(2016-03-04)回复
      • 非常感谢! 已解决! 路径在etc/sysconfig/iptables
        Garipan8年前(2016-03-04)回复
  8. 你好,安装了版本,使用多用户端口文件直接替换,但是替换后,只有8989端口的可以使用,查看发现9001,9002,9003端口都已经打开了,试过重启VPS和SS服务器端,求助一下
    RJZY8年前(2016-03-03)回复
  9. 博主你好,之前两次按您的说明操作都成功了,但这次在digtal ocean上安装后总是没法打开配置文件,一直出现-bash: /etc/shadowsocks.json: Permission denied。然后用shadowsocks也连不上。请问是怎么回事?谢谢。
    凤凰阿歇特8年前(2016-02-28)回复
    • 你需要用 vim 来打开配置文件 命令如下: vi /etc/shadowsocks.json
      秋水逸冰8年前(2016-02-28)回复
      • 十分感谢!已经成功开启!不过和以前一样都弄好后还是不能用。浏览器显示 500 Internal Privoxy Error Privoxy encountered an error while processing your request: Could not load template file no-server-data or one of its included components. Please contact your proxy administrator. If you are the proxy administrator, please put the required file(s)in the (confdir)/templates directory. The location of the (confdir) directory is specified in the main Privoxy config file. (It's typically the Privoxy install directory). 请问您知道是怎么回事吗?
        凤凰阿歇特8年前(2016-02-28)回复
        • 如果已经排除了是服务端的问题,那么请排查你本地客户端以及浏览器插件的配置情况。 根据提示信息只能说你的 proxy 有问题。具体是什么问题我并不知情,只能靠你自己去一一排查。
          秋水逸冰8年前(2016-02-28)回复
          • 好的 十分感谢
            凤凰阿歇特8年前(2016-02-28)回复
  10. 我修改配置文件,写入时出现如下错误信息,无法写入,请问这是什么问题呢 /etc/shadowsocks/config.json" E212: Can't open file for writing
    Glory8年前(2016-02-27)回复
    • Python 版的配置文件并不是这样的。 正确的路径是 /etc/shadowsocks.json
      秋水逸冰8年前(2016-02-27)回复
      • 已解决,谢谢指正
        Glory8年前(2016-02-27)回复
  11. 秋大,用了你的定时计划任务。每5分钟检查一次,但是我发现我在openvz的机器无法运行。 日志文件除了我自己运行了一次之外,就没有添加记录,奇怪了,但我在KVM 环境下就一次成功哦。。。
    calvin8年前(2016-02-27)回复
    • 这跟是什么架构无关,你在使用定时任务之前,确认过定时任务的进程是启动的状态吗?
      秋水逸冰8年前(2016-02-27)回复
  12. 在digitalocean上使用一切正常,但同样的方法使用vultr的服务器代理就不能用了,不知道为什么。可以ping到也可以用putty控制vultr的服务器。
    suxz05378年前(2016-02-23)回复
    • 看看是不是防火墙的锅。关闭防火墙后再试试看。
      秋水逸冰8年前(2016-02-24)回复
  13. 我记得你写过一个shadowsocks定时任务的sh,但是找不到了。希望劳您告知一下!!而且小小建议:如果收到评论回复,系统自动发邮件到用户邮箱,这样就不会错过评论啦。
    痴空见观8年前(2016-02-23)回复
  14. 博主您好,我在amazon ec2上按照您上面的教程进行了SS服务器端的安装,显示安装已完成。在安全组里针对全部ip地址打开22和8088端口(ss使用8088端口)。在windows 10 下用ss客户端登录时,无法连接,log文件提示如下: [2016-02-20 23:43:41] Shadowsocks started [2016-02-20 23:43:42] System.Reflection.TargetInvocationException: 操作过程中出现异常,结果无效。 有关异常的详细信息,请查看 InnerException。 ---> System.Net.WebException: 基础连接已经关闭: 发送时发生错误。 ---> System.IO.IOException: 由于远程方已关闭传输流,身份验证失败。 在 System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) 在 System.Net.PooledStream.EndWrite(IAsyncResult asyncResult) 在 System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) --- 内部异常堆栈跟踪的结尾 --- 在 System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result) 在 System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result) --- 内部异常堆栈跟踪的结尾 --- 在 System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() 在 Shadowsocks.Controller.UpdateChecker.http_DownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e) [2016-02-20 23:44:16] Shadowsocks started [2016-02-20 23:44:40] Shadowsocks started [2016-02-20 23:45:01] System.Net.Sockets.SocketException (0x80004005): 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。amazon server public ip:8088 在 System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) 在 Shadowsocks.Controller.Handler.ConnectCallback(IAsyncResult ar) [2016-02-20 23:45:01] System.Reflection.TargetInvocationException: 操作过程中出现异常,结果无效。 有关异常的详细信息,请查看 InnerException。 ---> System.Net.WebException: 远程服务器返回错误: (504) 网关超时。 在 System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result) 在 System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result) --- 内部异常堆栈跟踪的结尾 --- 在 System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() 在 Shadowsocks.Controller.UpdateChecker.http_DownloadStringCompleted(Object sender, DownloadStringCompletedEventArgse) 另用android客户端登录时,图标连接已连接,但实际无法访问墙外网站。 因计算机小白,完全不懂linux,目前只是机械地按照教程进行配置,无法知道解决问题的思路,还望赐教,非常感谢~
    philips8年前(2016-02-21)回复
    • 首先你要确认一下服务端是不是在正常运行。 其次,ping 一下你的服务器 IP,是否正常联通,如果能通,查看一下丢包率是否正常。 再次,检查一下本地客户端是否有输错配置信息。
      秋水逸冰8年前(2016-02-21)回复
  15. 博主大大你好,请问我搭建好了python版的ss,可以正常使用,但是谷歌商店下载软件的速度却只有200多kb/s。vps是香港的,10m的带宽,也用了你编写的那个测试vps网速的脚本测试了一下,速度很快,I/O的平均速度有260.667mb/s。那么有没有什么办法可以提高ss的下载网速呢?
    jamesjhy8年前(2016-02-17)回复
    • 怎么说呢,这取决于你的本地带宽,以及本地到 VPS 的实际速度。 实际上,可以通过安装 FinalSpeed 来进行提速,只需稍微 Google 搜索一下即可看到教程。
      秋水逸冰8年前(2016-02-17)回复
      • 建议您可以把FinalSpeed的安装使用教程添加进来,我的廉价vps平时最多跑100k还不稳定,用了FinalSpeed以后看youtube1080也没有问题。当然这只是个建议。
        xiersa8年前(2016-02-20)回复