咳~

  • 又上不了网了
  • 我的Github好慢
  • 花钱买的服务,又叒又和谐了
    于是我毅然决定搭个自己VPN(虽然这些理由貌似有点牵强)!
    文章主要介绍如何在EC2上搭建自己的shadowsocks服务器。

准备工作

创建EC2服务器并连接

  • 各种亚马逊云的注册步骤省略
  • 创建EC2

    ec2-1

  • 勾选免费试用

    ec2-2

  • 选择服务器

    ec2-3

  • 开启

    ec2-4

  • 创建并下载密钥,点击下载的时候,就会有一个server-key.pem文件下载到本地计算机上

    down-key

  • 使用终端连接服务器(打开cmder), ssh -i "your.pem" yourserver, 如:ssh -i "server-key.pem" ec2-user@ec2-52-53-248-165.us-west-1.compute.amazonaws.com

    tim 20170629140737

安装shadowsocks服务器

  • sudo -s, 获取超级权限
  • yum install python-setuptools && easy_install pip, 安装python
  • pip install shadowsocks, 安装shadowsocks
  • vi /etc/shadowsocks.json, 编辑shadowsocks
    • 输入i, 插入
    • 复制一下文件,(修改password为你的密码)
    {
      "server":"0.0.0.0",
      "port_password": {
        "8383":"password1",
        "8384":"password2",
        "8385":"password3"
      },
      "timeout":600,
      "method":"aes-256-cfb"
    }
    
    • ESC键,输入wq, 保存并退出
  • export PATH=/usr/local/bin:$PATH 设置Path路径,

    因为我们选的Amazon Linux AMI镜像没有把/usr/local/bin设置到Path下,所以需要这一步,如果选择其他镜像的,可能不需要这一步

  • ssserver -c /etc/shadowsocks.json -d start,启动服务器。

    启动:ssserver -c /etc/shadowsocks.json -d start
    停止:ssserver -c /etc/shadowsocks.json -d stop
    重启:ssserver -c /etc/shadowsocks.json -d restart
    查看状态:ssserver -c /etc/shadowsocks.json -d status
    

所有命令记录

[ec2-user@ip-172-31-8-13 ~]$ sudo -s

[root@ip-172-31-8-13 ec2-user]# yum install python-setuptools && easy_install pip
Loaded plugins: priorities, update-motd, upgrade-helper
...
Complete!
Searching for pip
Best match: pip 6.1.1
Adding pip 6.1.1 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin

Using /usr/lib/python2.7/dist-packages
Processing dependencies for pip
Finished processing dependencies for pip

[root@ip-172-31-8-13 ec2-user]# pip install shadowsocks
You are using pip version 6.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting shadowsocks
  Downloading shadowsocks-2.8.2.tar.gz
Installing collected packages: shadowsocks
  Running setup.py install for shadowsocks
Successfully installed shadowsocks-2.8.2

[root@ip-172-31-8-13 ec2-user]# vi /etc/shadowsocks.json

[root@ip-172-31-8-13 ec2-user]# echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin

[root@ip-172-31-8-13 ec2-user]# ls /usr/local/bin
pip  pip2  pip2.7  sslocal  ssserver

[root@ip-172-31-8-13 ec2-user]# export PATH=/usr/local/bin:$PATH

[root@ip-172-31-8-13 ec2-user]# ssserver -c /etc/shadowsocks.json -d start
INFO: loading config from /etc/shadowsocks.json
2017-06-29 06:29:40 INFO     loading libcrypto from libcrypto.so.10
started
[root@ip-172-31-8-13 ec2-user]#

设置EC2防火墙

  • 实例列表中,最后一列安全组

    tim 20170629143106

  • 设置入网规则

    tim 20170629143247

开启shadowsocks并连接

  • 打开shadowsocks客户端,设置服务器地址,端口,密码

    tim 20170629144119

  • 设置SwitchySharp的代理,设置为本地127.0.0.1::1080

    tim 20170629143443

  • 选择私人VPN,开启网络之旅。如果要上国内网站,可选择Direct Connection,这样不走代理会更快。

    tim 20170629143712

参考