这是为你整理的 Hysteria 2 (Hy2) 完整部署教程。
这份教程修正了我们刚才排错过程中遇到的所有坑(包括权限问题、Systemd 启动命令错误、以及端口占用问题),你可以直接照着做,一次通过。
前置准备
- 服务端:ColoCrossing 小鸡(IP:
107.173.100.100) - 客户端:甲骨文机器(本机)
- 目标:在甲骨文上开启 10808 端口,通过 Hysteria 2 协议加速连接到小鸡。
第一部分:服务端部署 (在小鸡上执行)
登录你的 ColoCrossing (107.173.100.100) 执行以下步骤:
- 安装 Hysteria 2
bash <(curl -fsSL https://get.hy2.sh/)
- 生成自签证书 (有效期100年)
因为没有域名,我们用自签证书:
openssl req -x509 -nodes -newkey rsa:2048 -keyout /etc/hysteria/server.key -out /etc/hysteria/server.crt -days 36500 -subj "/CN=www.bing.com"
- 修改配置文件
编辑/etc/hysteria/config.yaml:
listen: :443
tls:
cert: /etc/hysteria/server.crt
key: /etc/hysteria/server.key
auth:
type: password
password: "YourStrongPasswordHere" # 【记得改个强密码】
masquerade:
type: proxy
proxy:
url: https://www.bing.com/
rewriteHost: true
bandwidth:
up: 100 mbps # 根据小鸡实际宽带填写
down: 100 mbps
ignoreClientBandwidth: false
- 修复权限 (关键步骤)
这是之前报错的原因,必须执行:
chown -R hysteria:hysteria /etc/hysteria/
chmod 600 /etc/hysteria/server.key
- 启动服务
systemctl enable hysteria-server.service
systemctl restart hysteria-server.service
systemctl status hysteria-server.service
看到绿色的 active (running) 即为成功。
第二部分:客户端部署 (在甲骨文机器上执行)
登录你的 Oracle Cloud 机器执行以下步骤:
- 清理旧代理 (防止端口冲突)
先杀掉之前的 SSH 代理:
systemctl stop socks-proxy.service 2>/dev/null
systemctl disable socks-proxy.service 2>/dev/null
fuser -k 10808/tcp # 强制杀掉占用 10808 的进程
- 安装 Hysteria 2
bash <(curl -fsSL https://get.hy2.sh/)
- 编写客户端配置
创建/etc/hysteria/client.yaml:
server: 107.173.10.10:443
auth: "YourStrongPasswordHere" # 【填上面服务端设置的密码】
tls:
insecure: true # 【必须开启,因为我们用的是自签证书】
sni: www.bing.com
socks5:
listen: 0.0.0.0:10808
http:
listen: 0.0.0.0:10809
bandwidth:
up: 50 mbps
down: 50 mbps
- 创建 Systemd 服务文件
创建/etc/systemd/system/hy2-client.service:
(注意:这里已经修正了之前 server 写错成 client 的 BUG)
[Unit]
Description=Hysteria 2 Client
After=network.target
[Service]
User=root
核心修正:这里必须是 client 模式
ExecStart=/usr/local/bin/hysteria -c /etc/hysteria/client.yaml client
Restart=always
RestartSec=3
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
- 启动客户端
systemctl daemon-reload
systemctl enable hy2-client
systemctl restart hy2-client
systemctl status hy2-client
第三部分:验证
在甲骨文机器上测试:
curl -x socks5h://127.0.0.1:10808 -I https://www.google.com
如果返回 HTTP/1.1 200 OK,说明隧道已打通,且速度应该比 SSH 快得多。
输入hysteria返回错误FATAL failed to initialize client {"error": "invalid config: server: server address is empty"}
up
这个方法可以解决甲骨文ip被谷歌限制上传吗