Shadowsocks Python版一键安装脚本

技术 秋水逸冰 2611474浏览 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. 看到您用了 update-rc.d shadowsocks defaults来启动,请问如何调整参数使得在shadowsocks.log 只记录 error 级别的日志呢。
    soar9年前(2015-12-20)回复
  2. 请问下关于ss的udp功能python版本有吗?用这个脚本安装是默认开启了吗?还是得自己手动开启
    MiuKaShi9年前(2015-12-17)回复
    • python 版应该是没有的,换 libev 版吧。
      秋水逸冰9年前(2015-12-17)回复
  3. 无法成功开启服务,出现以下错误,该如何解决 /etc/init.d/shadowsocks start Traceback (most recent call last): File "/usr/bin/ssserver", line 5, in from pkg_resources import load_entry_point ImportError: No module named 'pkg_resources' shadowsocks start failed
    lqhww9年前(2015-12-15)回复
    • 这应该是安装失败了。 建议去换 Go 版。
      秋水逸冰9年前(2015-12-16)回复
  4. shadowsocks is not running INFO: loading config from /etc/shadowsocks.json ERROR: found an error in config.json: Expecting property name enclosed in double quotes: line 10 column 5 (char 224) shadowsocks start failed 在建立多用户的时候出现这个问题怎么解决啊,老师
    卤蛋9年前(2015-12-15)回复
  5. 用了一键配置后,不知道是我的服务器问题还是脚本问题,被服务商说发垃圾邮件,请问如何处理
    Sean9年前(2015-12-14)回复
    • 建议你换成私钥登录 ssh,并且禁止使用密码登录。
      秋水逸冰9年前(2015-12-14)回复
  6. 在vultr上CentOS 7 x64,搭载成功,shadowsocks在进程中,但是在电脑上不能科学上网。使用Debian 7 x64,搭载成功,电脑上可以上网。设置密码,端口,加密方式一样,唯一不一样的就是IP和linux系统,无解。
    小威9年前(2015-12-08)回复
    • 因为 Debian 7 默认是没有开启 iptables 的,而 CentOS 7 默认是用 firewalld 的,端口不会放行导致的。
      秋水逸冰9年前(2015-12-08)回复
      • 是不是 我在CentOS 7中,把firewalld中,shadowsocks相应的端口打开,就应该可以科学上网了?
        小威9年前(2015-12-08)回复
      • 我尝试在Centos中disable firewalld # systemctl disable firewalld rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service' rm '/etc/systemd/system/basic.target.wants/firewalld.service' restart shadowsocks之后,没有什么变化,还是不能科学上网。 尝试iptables -t nat -A PREROUTING -p tcp --dport 995 -j REDIRECT --to-ports 8387, 我自己使用的是444端口,不能科学上网。
        小威9年前(2015-12-08)回复
      • 翻看你以前的留言,从三个角度 “要么配置文件错了;要么配置好了没有重启;要么对应的防火墙端口没开”,我把你说的iptables关闭了,依旧不能科学上网。 后来我发现使用disable firewalld之后,firewalld的status还是active,于是尝试使用stop firewalld之后,可以科学上网了。
        小威9年前(2015-12-09)回复
      • 安装了你的python ss脚本后,我还能不能在同一个服务器上安装你的LAMP脚本,挂一个博客?
        小威9年前(2015-12-09)回复
        • 两者不冲突的,除非你把 ss 用到 80 和 443 端口。
          秋水逸冰9年前(2015-12-09)回复
      • Teddysun,我打开了firewalld的端口,尝试在使用firewalld的状态下ss。 [root@vultr ~]# firewall-cmd --list-all public (default) interfaces: sources: services: dhcpv6-client ssh ports: 1210/tcp 1210/udp masquerade: no forward-ports: icmp-blocks: rich rules: 在关闭firewalld的情况下,1210端口是OK的,说明我的客户端与服务端的配置没有问题。 当打开了firewalld之后,就不能上网了。 linux端,你一般用什么作为防火墙?
        小威9年前(2015-12-10)回复
      • 按照方法https://blog-goritcly.rhcloud.com/archives/77 配置firewalld防火墙,并添加services: public (default) interfaces: sources: services: dhcpv6-client shadowsocks ssh ports: 1210/tcp masquerade: yes forward-ports: icmp-blocks: rich rules: 依旧不行~~
        小威9年前(2015-12-10)回复
        • 新建文件: /usr/lib/firewalld/services/shadowsocks.xml 添加内容: shadowsocks Shadowsocks 重启 firewalld 试试...
          doobom9年前(2015-12-11)回复
          • 你看我上面,我已经添加了xml的文件,并添加了service了。 我是按照方法https://blog-goritcly.rhcloud.com/archives/77 这个是我截取的打印信息: services: dhcpv6-client shadowsocks ssh
            小威9年前(2015-12-11)回复
          • 你有在Centos上面尝试吗?你的ss是放在哪个(Debian,Centos,Ubuntu)上面的?
            小威9年前(2015-12-11)回复
            • centos 7 上面用的,我自己的。
              doobom9年前(2015-12-11)回复
            • 然后添加好了 xml 文件后,用下面的命令。 firewall-cmd --permanent --add-service=shadowsocks firewall-cmd --reload 。。。
              doobom9年前(2015-12-11)回复
              • 我的是Centos 7 64 bit,你的xml脚本是在哪里看到的? 你可以科学上网? 你有没有用过nmap去测试的你的端口?
                小威9年前(2015-12-11)回复
                • xml 的脚本我是复制 sshd 的 xml 修改的。可以用的,不过没有用 nmap 去测试。 系统是跟你的一样。可以翻。。。
                  doobom9年前(2015-12-12)
              • 我的shadowsocks.xml文件是下面这样写的,去掉了部分括号 ?xml version="1.0" encoding="utf-8"? /service short>shadowsocksenable shadowsocks. port protocol="tcp" port="1210"/> port protocol="tcp" port="1512"/> port protocol="tcp" port="8896"/> /service>
                小威9年前(2015-12-11)回复
              • 我的端口开通情况,我用nmap看了一下: PORT STATE SERVICE 444/tcp open snpp 1210/tcp open eoss 1512/tcp open unknown 8896/tcp open unknown
                小威9年前(2015-12-11)回复
        • XML 内容贴不了。。。 :)
          doobom9年前(2015-12-11)回复
          • doobom,你这样,发一份xml到我邮箱[email protected],我真不知道哪里出错了,交个朋友也行。
            小威9年前(2015-12-12)回复
  7. 多用户配置,只有安装时的8989端口生效了是为什么呢
    蓝胖子9年前(2015-12-07)回复
    • iptables 里面要单独放行。。。
      ygly9年前(2015-12-07)回复
  8. libev版安装了的确是支持udp 那请问python版该如何支持?因为Libev版多端口貌似不如python方便
    ygly9年前(2015-12-05)回复
  9. ERROR: found an error in config.json: Expecting property name enclosed in double quotes: line 9 column 5 (char 198)配置多用户出现错误了,不知道为何?
    kuki5209年前(2015-11-26)回复
  10. 请问秋水大神,为什么使用一段时间以后会出现wifi下链接VPS不能使用,但是4G下链VPS又可以使用的情况?我已经好几次这样的情况了。。每次都是重新加服务器换个IP再搭SS。。有点郁闷
    David9年前(2015-11-26)回复
    • 抱歉,这个我真不知道。 只能建议你换个服务端的端口再试试。
      秋水逸冰9年前(2015-11-26)回复
  11. 秋大你好,请问怎么设置SS进程崩溃后自动重启,也就是进程保护?感激不尽。
    Anderson9年前(2015-11-25)回复
  12. 多用户配置,我自己的电脑能翻了,但是我朋友的电脑却翻不了,配置是没问题的,提示: 502 Read from server failed: Unknown error The following error occurred while trying to access http://google.com/: 502 Read from server failed: Unknown error Generated Wed, 25 Nov 2015 15:08:25 中国标准时间 by Polipo on tj-PC:8123.
    大老虎斯基9年前(2015-11-25)回复
    • 也许是他客户端配置错了? 我确实是猜不出来原因。 既然你OK了,那就说明不是服务端的问题了是吧。
      秋水逸冰9年前(2015-11-26)回复
      • 有这几种可能: 1,防火墙阻止了客户端联网; 2,宽带的国际出口问题,ping下服务器IP看看 3,其他奇葩问题。。
        Anderson9年前(2015-11-30)回复
        • 重启服务器试试
          单行道9年前(2015-12-02)回复
  13. Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-XIwdwP/M2Crypto/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-J4i7qf-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-XIwdwP/M2Crypto 有一段红字
    偶偶9年前(2015-11-24)回复
    • 不知道你是什么系统,谁家的VPS,光给我看这错误提示我也不清楚怎么回答你。
      秋水逸冰9年前(2015-11-26)回复
  14. 能设置个定时重启下服务就好了,有时会死服务
    意林笔记9年前(2015-11-23)回复
  15. 为什么我按照来设置怎么也连不上?
    大飞9年前(2015-11-22)回复
    • 连不上的排除故障的步骤,先排查下服务端,后排查客户端。 服务端无非是,启动与否,配置文件正确与否,端口开了与否,防火墙对应的端口放行与否。 客户端无非是,设置正确与否,网络连接正常与否。
      秋水逸冰9年前(2015-11-22)回复