AWS+SS配置记录
由于近期研究需求看一些油管MIT的网课…谷歌翻译也退出了,github的DNS污染也让人无语,懒人如我也决定寻求解决方案。
参考了baidu搜索到的中文网页,资源内容一言难尽,稍微有用的都在墙外,想起了那个经典梗——
“我想科学上网!”
“——那你用梯子啊!”
“我找到的教程都需要梯子才能看到!”
“那你科学上网啊!”
当然最终还是在广搜罗情况下解决了(虽然在这方面完全是一窍不通的newbie),有空还是需要补充计网的知识啊…
AWS EC2
AWS最高12个月的免费云服务器,EC2简介也就不贴了,(几年前薅过羊毛的没想到现在还有)。 这里随机选了美东的: https://us-east-1.console.aws.amazon.com/ec2
- 注册一个新账号(网易邮箱就行)
- 创建EC2实例,选择了18.04的ubuntu(22.04会有其他问题修复,见后续记录)一路默认,配置安全组
安全组配置这里后续可以更改,开始默认即可。 生成密钥对。下载保存在本地单独的文件夹,e.g.
C:\myvpn\myvpn.pem
- 启动实例
- 点击连接,查看SSH,连接到实例
查看示例的
ssh
command,复制即可 启动远程终端工具(这里用的mobaxterm),cd
到密钥对目录,粘贴上面的ssh
command。例
cd C:\myvpn ssh -i "myvpn.pem" ubuntu@ec2-xx-xxx-xx-xx.compute-1.amazonaws.com
ss vs. ss-libev
首先下载windows版的ss,这部分配置见下文。 刚开始直接用ss搭了,速度很好,然后几分钟之后断了,ping不通ip,应该是被屏蔽(浅陋猜测)。由于没有绑定弹性ip,所以重启EC2实例就会生成新的,使用新的ip又会进入新的循环;修改ss配置 → 可用 → 断开(time out/ connection closed by peer)
查了下原因(不可描述),理解接受了事实就寻求其他解决方案,感谢ss git下面的讨论,非常有效。
参考:(见前文的笑话)
- https://gfw.report/blog/ss_tutorial/zh/
- ping工具:https://ping.pe/18.212.176.171
提到了16.04以上版本自带了snap,所以可以直接检测是否安装。snap安装ss-libev,后续代码整合在下面了。
Note
需要修改EC2安全组! 需要修改EC2安全组! 需要修改EC2安全组,根据下面json配置中开放的端口
server_port
修改。
# ssh登录server之后
$ sudo snap install core
core 16-2.57.2 from Canonical✓ installed
$ sudo snap install shadowsocks-libev --edge
shadowsocks-libev (edge) 3.3.5-1 from Max Lv (max-c-lv) installed
# 随机生成强密码
$ openssl rand -base64 16
# 修改配置文件
# 你还可以考虑将`server_port`的值从`8388`改为`1024`到`65535`之间的任意整数。
$ sudo vim /var/snap/shadowsocks-libev/common/etc/shadowsocks-libev/config.json
# password用上面生成的强密码
# 加密方式可以更改,注意,cfb加密在最新的ss中都不再使用了,旧的教程一般都写的aes-256-cfb需要修改
# 右键将下面的内容贴到json文件中,保存退出vim
{
"server":["::0","0.0.0.0"],
"server_port":8388,
"method":"chacha20-ietf-poly1305",
"password":"PASSWORD",
"mode":"tcp_and_udp",
"fast_open":false
}
# 防火墙设置
$ sudo apt update && sudo apt install -y ufw
$ sudo ufw allow ssh
Rules updated
Rules updated (v6)
# 根据上面json配置中开放的端口修改
$ sudo ufw allow 8388
Rules updated
Rules updated (v6)
# 启动防火墙
$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
$ sudo ufw status
Status: active
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
8388 ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
8388 (v6) ALLOW Anywhere (v6)
ss配置
ss教程很多就不赘述了。
一些参考:
- https://www.bilibili.com/read/cv17325367
- https://ishare.ifeng.com/c/s/7uj73q8yjij
- Amazon 云安装 shadowsocks - 知乎
系统代理:PAC模式
PAC or 全局的选择 服务器:编辑服务器,根据json文件修改,记得选择正确的加密模式。
Troubleshooting
在使用ss(不是ss-libev!!!)遇到了一些问题也解决了,做下记录(虽然随着墙的升高,单纯的ss实在不太好用了…)
Q1. 加密方式的选择 参考:
- https://github.com/shadowsocks/shadowsocks-windows/issues/3063
最新的ss已经将cfb删掉了,但是2.8.2的ss不支持gcm算法,将版本升级,或者直接安装3.0.0的版本
# AWS实例默认是有python的,所以直接安装python-pip
# sudo apt-get install python3-pip # python3
# pip install shadowsocks # 这样默认是装2.8.2的版本
$ pip install https://github.com/shadowsocks/shadowsocks/archive/master.zip -U
...
Successfully installed shadowsocks-3.0.0
Q2. 如果选择安装了22.04的ubuntu或者python版本默认是3.10的,启动ssserver会报错
$ ssserver
Traceback (most recent call last):
File "/usr/local/bin/ssserver", line 5, in <module>
from shadowsocks.server import main
File "/home/ubuntu/.local/lib/python3.10/site-packages/shadowsocks/server.py", line 27, in <module>
from shadowsocks import shell, daemon, eventloop, tcprelay, udprelay, \
File "/home/ubuntu/.local/lib/python3.10/site-packages/shadowsocks/udprelay.py", line 71, in <module>
from shadowsocks import encrypt, eventloop, lru_cache, common, shell
File "/home/ubuntu/.local/lib/python3.10/site-packages/shadowsocks/lru_cache.py", line 34, in <module>
class LRUCache(collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
# 因为3.10版本的python更改了mutablemapping的语法,cd到改目录下修改
# vim权限不够需求sudo
$ sudo vim lru_cache.py
# 如下修改:
# from collections.abc import MutableMapping
Q3. EVP_CIPHER_CTX_cleanup 报错 参考:
- AttributeError: /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1: undefined symbol: EVP_CIPHER_CTX_cleanup_ddee的博客-CSDN博客
- Ubuntu 18.04 LTS搭建Shadowsocks科学上网
将报错目录下的openss.py修改,cleanup修改为reset
Q4. 启动ss报错:pid和log permission denied
$ ssserver -c /etc/shadowsocks/shadowsocks.json -d start
报错:
ERROR [Errno 13] Permission denied: '/var/run/shadowsocks.pid'
...
ERROR [Errno 13] Permission denied: '/var/log/shadowsocks.log'
解决:改下权限
sudo chmod 777 /var/run
sudo chmod 777 /var/log
ssserver显示started就是成功开启
Q5. 查看ss运行状态
$ sudo ps aux | grep ssserver
# 或者查看net
# $ sudo apt install net-tools
$ netstat -tln
Q6. 配置开机项 参考:
- https://www.dazhuanlan.com/youzipi870/topics/1821005
$ cd /etc/init.d/
# 发现都不在了,查看目录下README说是传统的init脚本被替代了blabla
# 下面是尝试其他方法
$ sudo vim /etc/rc.local
$ ssserver -c /etc/shadowsocks/shadowsocks.json --user nobody -d start
# 配置文件方式后台挂起运行
$ nohup ssserver -c /etc/shadowsocks/shadowsocks.json >/dev/null 2>&1 &
使用协议混淆插件
git里post的list:
Kcptun: [https://github.com/xtaci/kcptun](https://github.com/xtaci/kcptun)
Simple-obfs: [https://github.com/shadowsocks/simple-obfs](https://github.com/shadowsocks/simple-obfs)
V2Ray-Plugin: [https://github.com/shadowsocks/v2ray-plugin](https://github.com/shadowsocks/v2ray-plugin)
GoQuite: [https://github.com/cbeuw/GoQuiet](https://github.com/cbeuw/GoQuiet)
Cloak: [https://github.com/cbeuw/Cloak](https://github.com/cbeuw/Cloak)
simple-tls: [https://github.com/IrineSistiana/simple-tls](https://github.com/IrineSistiana/simple-tls)
gost-plugin: [https://github.com/maskedeken/gost-plugin](https://github.com/maskedeken/gost-plugin)
xray-plugin: [https://github.com/teddysun/xray-plugin](https://github.com/teddysun/xray-plugin)
尝试使用了cloak还是不行(可能是因为是在22.04版本的实例上安装的,虽然能正常启动ss,但是依然无法访问) cloak有一键安装的脚本: 参考:
- https://github.com/HirbodBehnam/Shadowsocks-Cloak-Installer
- https://github.com/cbeuw/Cloak/releases
# ssh登录后,首先取得root权限,输密码(没有设置过的先重置密码)
$ su root
$ curl -o Cloak-Installer.sh -L https://git.io/fj5mh && bash Cloak-Installer.sh
# 根据实际问题选择,基本上可以一路回车下来
# 再次上面的curl命令,会进行提问选择需求什么操作,选4,就能看到配置详情,根据配置再去设置ss windows,记得修改插件位置(根据实际情况下载)
# https://github.com/cbeuw/Cloak/releases
关于安装cloak后ss windows设置原文
Windows
At first install shadowsocks windows. Then download cloak for windows from here. If you are using a 32-bit system, download ck-client-windows-386-X.exe if your system is 64-bit use ck-client-windows-amd64-X.exe. Then use the QR Code or ss:// link to import the server. The program will give you an error that shadowsocks cannot find ck-client or something like this. Click OK and go to Edit Servers. Then write the absolute path to ck-client file in Plugin Program. Example of path: C:\Users\Hirbod\Downloads\Programs\ck-client-windows-amd64-2.1.3.exe