快速搭建Hysteria 2代理服务
教程实践于Ubuntu、Debian系统,并成功运行。理论上适用于其他GNU/Linux 或 BSD 系统
关于Hysteria 2的更多说明,请直接访问中文官网
1.安装服务主程序
打开终端,以Root身份执行指令
1
| bash <(curl -fsSL https://get.hy2.sh/)
|
官方提供的安装程序会自动安装 Hysteria 2 服务
2.自签证书
Hysteria 2 服务必须使用tls证书,如果 VPS 没有证书,可以按以下方式生成自签证书
1 2
| mkdir -p /etc/hysteria/certs openssl req -x509 -newkey rsa:2048 -keyout /etc/hysteria/certs/key.pem -out /etc/hysteria/certs/cert.pem -days 365 -nodes -subj "/CN=localhost"
|
如果你的服务器已经有了其它证书,可以忽略这一步
3.编辑配置文件
默认配置文件放在 /etc/hysteria/ 下,使用root身份打开它
1
| sudo nano /etc/hysteria/config.yaml
|
以下是示例配置,按需修改:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| listen: :29581
tls: cert: /etc/hysteria/certs/cert.pem key: /etc/hysteria/certs/key.pem insecure: true
auth: type: userpass userpass: "yourusername": "yourpassword"
masquerade: type: proxy proxy: url: https://target.website rewriteHost: true
bandwidth: up: 50 down: 100
obfs: type: salamander salamander: password: yourpassword
socks5: listen: 127.0.0.1:1080
http: listen: 127.0.0.1:8080
|
设置证书权限
1 2 3 4 5 6 7 8 9
| chmod 644 /etc/hysteria/certs/*.pem
chown hysteria:hysteria /etc/hysteria/certs/*.pem
chmod +x /etc/hysteria chmod +x /etc/hysteria/certs
|
4.启动服务
配置完成后,启动 Hysteria 2 服务:
1 2
| sudo systemctl daemon-reexec sudo systemctl start hysteria-server
|
设置开机自启:
1
| sudo systemctl enable hysteria-server
|
查看服务状态:
1
| sudo systemctl status hysteria-server
|
5.客户端配置
客户端配置文件示例(config.yaml):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| server: your.server.address:29581
auth: yourusername
auth_str: yourpassword
bandwidth: up: 50 down: 100
obfs: type: salamander salamander: password: yourpassword
socks5: listen: 127.0.0.1:1080
http: listen: 127.0.0.1:8080
|
或者设置通用链接:
1
| hysteria2://eab6ccb8-9b95-407c-bc36-01a557e8d94e@us3do.interld123456789.com:36000?sni=1231231.1234567890spcloud.com&obfs=salamander&obfs-password=12345&insecure=1#BBBBhy2-do3
|
解释每一部分:
1 2 3 4 5 6
| eab6ccb8-9b95-407c-bc36-01a557e8d94e @us3do.interld123456789.com:36000 ?sni=1231231.1234567890spcloud.com &obfs=salamander&obfs-password=12345 &insecure=1
|
6.常见问题
6.1 端口无法访问
检查防火墙设置,确保端口已开放:
1 2 3 4 5 6
| sudo ufw allow 29581
sudo firewall-cmd --permanent --add-port=29581/tcp sudo firewall-cmd --reload
|
6.2 服务无法启动
检查配置文件语法:
1
| hysteria server check -c /etc/hysteria/config.yaml
|
查看服务日志:
1
| sudo journalctl -u hysteria-server -f
|
6.3 连接速度慢
尝试调整以下参数:
- 增加带宽限制
- 调整 QUIC 参数
- 尝试不同的伪装类型
7.进阶配置
7.1 使用 ACME 自动证书
如果你有域名,可以使用 ACME 自动申请证书:
1 2 3 4 5 6 7
| listen: :443
acme: domains: - your.domain.net email: your@email.com dir: /etc/hysteria/acme
|
7.2 多用户配置
1 2 3 4 5 6
| auth: type: userpass userpass: "user1": "password1" "user2": "password2" "user3": "password3"
|
7.3 流量统计
1 2 3
| traffic: stats: listen: 127.0.0.1:8080
|
