使用docker搭建hysteria2服务端
源链接:https://github.com/apernet/hysteria/discussions/1248
官网地址:https://v2.hysteria.network/zh/docs/getting-started/Installation/
首选需要安装docker
和docker compose
切换到合适的目录
cd /home
创建文件夹
mkdir hysteria
创建docker-compose文件
cd hysteria
vim docker-compose.yml
tobyxdd/hysteria:latest
是最新版可以去https://hub.docker.com/r/tobyxdd/hysteria/tags
安装其他版本替换到image
即可,例如:tobyxdd/hysteria:v2.5.1
此处的$PWD/
则代表将当前目录映射到docker内部,所以下面不用修改
services:
hysteria:
image: 'tobyxdd/hysteria:latest'
container_name: hysteria-server
restart: always
network_mode: host
volumes:
- '$PWD/:/etc/hysteria'
environment:
- HYSTERIA_DISABLE_UPDATE_CHECK = 1
cap_add:
- NET_ADMIN
- NET_BIND_SERVICE
- SYS_PTRACE
- DAC_READ_SEARCH
devices:
- '/dev/net/tun:/dev/net/tun'
ulimits:
nofile:
soft: 65535
hard: 65535
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
command: ["server", "-c", "/etc/hysteria/config.yaml"]
创建配置文件,删除#连接的文字,最好换一个端口例如29715,也要记得开放端口,或者关闭防火墙,密码记好,需要在客户端填上
listen: :443 # 这是服务端所使用的端口号,您可以按需修改(如可将443修改为您所需要的端口号)
ignoreClientBandwidth: false
speedTest: false
disableUDP: false
udpIdleTimeout: 60s
tls:
cert: /etc/hysteria/server.pem # 此处的cert和key放到上方步骤中提到的新建的目录下
key: /etc/hysteria/server.key
sniGuard: disable
quic:
initStreamReceiveWindow: 1048576 # 如果您的server剩余资源充裕,且您需要达到100mbps以上的速率,请删除此处的quic字段
maxStreamReceiveWindow: 1048576
initConnReceiveWindow: 4194304
maxConnReceiveWindow: 4194304
maxIdleTimeout: 30s
maxIncomingStreams: 65535
disablePathMTUDiscovery: true
bandwidth:
up: 100 mbps # brutal速度限制
down: 100 mbps
auth:
type: password
password: password1 # 认证密码,必须修改为别的值(不含特殊符号),请确保密码难以猜测
resolver:
type: tls # 如果您需要让程序直接使用系统的DNS解析,请直接删除此字段
tls:
addr: 208.67.220.220:853
timeout: 4s
sni: dns.opendns.com
insecure: true
sniff:
enable: true
timeout: 2s
rewriteDomain: false
tcpPorts: 80,443,8000-9000
udpPorts: all
outbounds:
- name: freedom # 若无特殊需要,则无需额外修改此处的字段
type: direct
direct:
mode: auto
masquerade: # 伪装字段,若不需要可删除,若需要可按需修改
type: string
string:
content: Invalid request, please use correct method.
headers:
Server: quic-server
Content-Type: application/octet-stream; charset=UTF-8
Cache-Control: no-store
Content-Length: 8
Content-Encoding: compress
Connection: close
statusCode: 200
生成证书,一路回车就行
openssl req -x509 -sha256 -nodes -days 3650 -newkey rsa:4096 -keyout server.key -out server.pem
启动
docker compose up -d
验证
docker logs 容器ID
出现server up and running {"listen": ":29715"}则代表成功
附上一张客户端配置