在如今的网络环境中,尤其是涉及跨国访问的场景中,hysteria2作为一个新兴的传输协议工具,凭借其高效的传输能力和灵活的配置方式,受到了越来越多用户的青睐。本教程将带您一步步完成hysteria2的部署,包括在服务端和客户端的安装与配置,适用于AlmaLinux 8和Ubuntu两种常用操作系统。
在正式开始部署之前,请确保您的服务器和客户端系统都已完成以下操作:
系统更新:
sudo dnf update -y
sudo apt update && sudo apt upgrade -y
安装必备工具:
sudo dnf install wget curl nano -y
sudo apt install wget curl nano -y
配置防火墙(如有需要):
wget -O hysteria2-linux-amd64.tar.gz https://github.com/apernet/hysteria/releases/latest/download/hysteria-linux-amd64.tar.gz
tar -zxvf hysteria2-linux-amd64.tar.gz
sudo mv hysteria /usr/local/bin/
wget -O hysteria2-linux-amd64.tar.gz https://github.com/apernet/hysteria/releases/latest/download/hysteria-linux-amd64.tar.gz
tar -zxvf hysteria2-linux-amd64.tar.gz
sudo mv hysteria /usr/local/bin/
在 /etc/hysteria
目录下创建 config.json
文件,并写入以下内容:
{
"listen": ":443",
"protocol": "udp",
"up_mbps": 100,
"down_mbps": 100,
"obfs": "password",
"auth": {
"mode": "password",
"config": {
"user": "password"
}
},
"alpn": "h2",
"tls": {
"cert": "/path/to/your/cert.crt",
"key": "/path/to/your/key.key"
}
}
注意:将/path/to/your/cert.crt
和/path/to/your/key.key
替换为您实际的TLS证书和私钥路径。
创建并启动服务:
sudo nano /etc/systemd/system/hysteria.service
填入以下内容:
[Unit]
Description=hysteria2 Service
After=network.target
[Service]
ExecStart=/usr/local/bin/hysteria -c /etc/hysteria/config.json
Restart=on-failure
[Install]
WantedBy=multi-user.target
保存并退出后,启用并启动服务:
sudo systemctl daemon-reload
sudo systemctl enable hysteria
sudo systemctl start hysteria
通过以下命令检查服务是否正常运行:
sudo systemctl status hysteria
如果状态显示为active (running)
,说明服务已成功启动。
与服务端相同,下载并安装hysteria2:
wget -O hysteria2-linux-amd64.tar.gz https://github.com/apernet/hysteria/releases/latest/download/hysteria-linux-amd64.tar.gz
tar -zxvf hysteria2-linux-amd64.tar.gz
sudo mv hysteria /usr/local/bin/
在客户端创建配置文件config.json
,内容如下:
{
"server": "your_server_ip:443",
"auth": {
"user": "password"
},
"alpn": "h2",
"obfs": "password",
"up_mbps": 10,
"down_mbps": 50,
"tls": {
"sni": "your.server.com"
}
}
注意:将your_server_ip
替换为服务端的实际IP地址,并将其他相关信息替换为实际值。
使用以下命令启动客户端:
hysteria -c /path/to/your/client/config.json
如果服务启动失败,可以通过以下命令检查443端口是否被其他程序占用:
sudo lsof -i :443
服务端和客户端的日志文件对于排查问题非常有帮助。可以通过以下方式查看日志:
journalctl -u hysteria -f
如果客户端无法连接到服务端,可能是防火墙或网络配置问题。确保服务端的防火墙规则正确配置,并且端口443已开放。
通过本教程,您已经成功在AlmaLinux 8和Ubuntu系统上完成了hysteria2的服务端和客户端部署。hysteria2强大的传输性能可以大幅提升网络访问体验。如果您在使用过程中遇到其他问题,请随时参考官方文档或进一步探索配置项来优化您的使用体验。