Compare commits
No commits in common. "master" and "v1.0" have entirely different histories.
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
config/config.json
|
|
||||||
acme/
|
|
||||||
156
README.md
156
README.md
@ -1,136 +1,114 @@
|
|||||||
# 使用说明
|
# 使用说明
|
||||||
|
项目使用自有证书搭建, 无需要准备域名.
|
||||||
## 项目描述
|
默认使用`bing.com`域名作为伪装.
|
||||||
项目使用自签名证书搭建 Hysteria 代理服务器,无需准备域名。
|
|
||||||
默认使用 `bing.com` 域名作为伪装。
|
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
|
|
||||||
### 方法一:使用交互脚本(推荐新手)
|
### 部署服务器端
|
||||||
确认安装好下列软件
|
确认安装好下列软件
|
||||||
- git
|
|
||||||
- curl
|
|
||||||
|
|
||||||
下载项目代码
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://gitea.9001001.xyz/William/hysteria_docker.git
|
|
||||||
```
|
|
||||||
|
|
||||||
进入项目目录
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd hysteria_docker
|
|
||||||
```
|
|
||||||
|
|
||||||
运行安装脚本,选择选项1(安装并启动)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bash ./install.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
脚本会自动检测并安装必要的软件(Docker、Docker Compose、jq),然后初始化配置并启动容器。
|
|
||||||
|
|
||||||
### 方法二:手动部署服务器端
|
|
||||||
|
|
||||||
如果您更喜欢手动控制,或需要在不同环境下进行自定义,请按以下步骤操作。
|
|
||||||
|
|
||||||
确认安装好下列软件
|
|
||||||
|
|
||||||
- docker
|
- docker
|
||||||
- docker-compose
|
- docker-compose
|
||||||
- git
|
- git
|
||||||
- jq
|
|
||||||
- curl
|
|
||||||
|
|
||||||
下载项目代码
|
下载项目代码
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://gitea.9001001.xyz/William/hysteria_docker.git
|
git clone https://gittea.wingogo.top/William/hysteria_docker.git
|
||||||
```
|
```
|
||||||
|
|
||||||
进入项目目录
|
进入项目目录
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd hysteria_docker
|
cd hysteria_docker
|
||||||
```
|
```
|
||||||
|
|
||||||
执行命令初始化配置并启动容器
|
配置初始化, **第一次运行必须执行**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bash ./bin/run.sh
|
bash ./bin/init.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
## 其他说明
|
启动项目
|
||||||
### install.sh 脚本说明
|
```bash
|
||||||
项目提供了 `install.sh` 交互脚本,可以帮助您轻松管理 Hysteria 服务。运行脚本后,根据提示选择数字编号来执行相应操作:
|
docker-compose up -d
|
||||||
|
```
|
||||||
1. **安装并启动** - 自动检测并安装所需软件(Docker、Docker Compose、jq),然后初始化配置并启动服务。
|
|
||||||
2. **生成配置/重置配置** - 重新生成 Hysteria 配置文件。
|
|
||||||
3. **启动容器** - 仅启动 Hysteria 容器(假设配置已存在)。
|
|
||||||
4. **查看分享链接** - 显示客户端可用的配置链接。
|
|
||||||
5. **停止容器** - 停止并移除运行中的容器。
|
|
||||||
6. **更新镜像** - 下载最新的 Hysteria docker镜像。
|
|
||||||
7. **更新端口** - 修改服务监听端口。
|
|
||||||
|
|
||||||
使用方法:进入项目目录后,运行 `bash ./install.sh` 并根据菜单选择。
|
|
||||||
|
|
||||||
### 查看日志
|
|
||||||
检查服务端是否启动成功
|
|
||||||
|
|
||||||
|
查看日志
|
||||||
```bash
|
```bash
|
||||||
docker-compose logs | head -n 50
|
docker-compose logs | head -n 50
|
||||||
```
|
```
|
||||||
|
|
||||||
### 查看分享链接
|
### 查看分享链接
|
||||||
|
进入项目目录, 执行以下命令
|
||||||
服务器端启动成功后, 进入项目目录, 执行以下命令
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bash ./bin/print_share_link.sh
|
bash ./bin/print_share_link.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
### 电脑配置客户端
|
### 客户端配置
|
||||||
|
|
||||||
客户端软件(选择其中一种)
|
客户端软件(选择其中一种)
|
||||||
|
- [v2rayN](https://github.com/2dust/v2rayN/releases)
|
||||||
- [V2rayN](https://github.com/2dust/v2rayN/releases)
|
- [nekoray](https://github.com/MatsuriDayo/nekoray/releases)
|
||||||
- [Nekoray](https://github.com/MatsuriDayo/nekoray/releases)
|
|
||||||
- [Hyteria 官方提及的第三方客户端](https://v2.hysteria.network/zh/docs/getting-started/3rd-party-apps/)
|
|
||||||
|
|
||||||
客户端配置
|
客户端配置
|
||||||
把分享链接直接粘贴到客户端
|
|
||||||
分享链接获取, 参考"查看分享链接"
|
|
||||||
|
|
||||||
|
- (方法1)把分享链接直接粘贴到客户端
|
||||||
|
|
||||||
## 文件解析
|
- (方法2)手工输入配置
|
||||||
|
无域名,使用IP搭建,download-bandwidth 根据实际填写
|
||||||
|
|
||||||
### 文件`bin/gen_self_tls.sh`
|
```yaml
|
||||||
|
地址: 服务器ip
|
||||||
用来生成自签证书和设置伪装域名。该脚本实际执行的 OpenSSL 命令:
|
端口: 8443 # 服务器端端口
|
||||||
|
密码: RhCLi%T&MFe5&de # 服务器端密码
|
||||||
|
传输安全层: tls
|
||||||
|
SNI: bing.com # 伪装域名
|
||||||
|
跳过证书验证: true
|
||||||
|
download-bandwidth=200
|
||||||
|
```
|
||||||
|
|
||||||
|
## 服务器端,修改域名
|
||||||
|
如果需要修改其他伪装域名, 进入项目目录, 执行以下命令
|
||||||
```bash
|
```bash
|
||||||
# 生成自签名的 ECDSA 证书并设置有效期为 100 年
|
bash ./bin/set_domain.sh expedia.com
|
||||||
|
|
||||||
openssl req \
|
|
||||||
-x509 \ # 生成自签名的X.509证书
|
|
||||||
-nodes \ # 不使用加密算法保护私钥
|
|
||||||
-newkey ec:<(openssl ecparam -name prime256v1) \ # 使用 bash process substitution 生成 ECDSA 私钥
|
|
||||||
-keyout ./key/server.key \ # 将生成的私钥保存到项目 key 目录
|
|
||||||
-out ./key/server.crt \ # 将生成的自签名证书保存到项目 key 目录
|
|
||||||
-subj "/CN=yourdomain.com" \ # 设置证书主题的 CN(Common Name)
|
|
||||||
-days 36500 # 设置证书有效期为 36500 天(约100年)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
- `openssl`是一个开源的加密工具包,提供了一系列用于处理安全通信的命令和库。它支持多种加密算法、数字证书和相关的功能,包括生成和签名证书、创建和验证数字签名、加解密数据等。常见用途包括创建和管理 SSL/TLS 证书、进行加密通信以及执行与加密相关的各种操作。
|
## 服务器端,修改端口
|
||||||
|
修改`config.json`配置文件
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"listen": ":9999", // 改为其他端口
|
||||||
|
// 省略其他代码...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 服务器端, 升级镜像
|
||||||
|
```bash
|
||||||
|
bash ./bin/update_docker_images.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## 文件解析
|
||||||
|
### 文件`set_domain.sh`
|
||||||
|
用来生成自签证书和设置伪装域名
|
||||||
|
```bash
|
||||||
|
# 生成自签名的 ECDSA 证书并设置有效期为 100 年
|
||||||
|
|
||||||
|
# 使用 OpenSSL 的证书请求工具
|
||||||
|
openssl req \
|
||||||
|
-x509 \ # 生成自签名的X.509证书
|
||||||
|
-nodes \ # 不使用加密算法保护私钥
|
||||||
|
-newkey ec:<(openssl ecparam -name prime256v1) \ # 生成 ECDSA 私钥和公钥,使用 prime256v1 曲线
|
||||||
|
-keyout /etc/hysteria/server.key \ # 将生成的私钥保存到指定路径
|
||||||
|
-out /etc/hysteria/server.crt \ # 将生成的自签名证书保存到指定路径
|
||||||
|
-subj "/CN=bing.com" \ # 设置证书的主题字段,CN是 Common Name (CN)
|
||||||
|
-days 36500 \ # 设置证书的有效期为 36500 天(约100年)
|
||||||
|
```
|
||||||
|
- `openssl`是一个开源的加密工具包,提供了一系列用于处理安全通信的命令和库。它支持多种加密算法、数字证书和相关的功能,包括生成和签名证书、创建和验证数字签名、加解密数据等。常见用途包括创建和管理SSL/TLS证书、进行加密通信以及执行与加密相关的各种操作。
|
||||||
|
|
||||||
- `-subj `参数用于在 OpenSSL 命令中设置证书主题字段,其中 "/CN=example.com" 指定了通用名称 (Common Name, CN),表示证书关联的主机名。
|
- `-subj `参数用于在 OpenSSL 命令中设置证书主题字段,其中 "/CN=example.com" 指定了通用名称 (Common Name, CN),表示证书关联的主机名。
|
||||||
|
|
||||||
### 文件`key/server.crt`是 Tls 证书, `key/server.key`是 Tls 私钥
|
|
||||||
|
|
||||||
|
### 文件`server.crt`和`server.key`是证书文件
|
||||||
|
|
||||||
|
### 文件`config.json`是服务器端配置文件
|
||||||
|
|
||||||
## 参考
|
## 参考
|
||||||
|
- https://v2.hysteria.network/zh/docs/getting-started/Server/
|
||||||
- https://v2.hysteria.network/zh/docs/getting-started/Server/
|
- https://v2rayssr.com/hysteria2.html
|
||||||
- https://v2rayssr.com/hysteria2.html
|
- https://www.iiiam.in/articles/server/deploy-hysteria2
|
||||||
- https://www.iiiam.in/articles/server/deploy-hysteria2
|
|
||||||
|
|||||||
@ -1,110 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
create_config_with_tls_cert() {
|
|
||||||
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
|
||||||
local config_file="$script_dir/../config/config.json"
|
|
||||||
|
|
||||||
cp "$script_dir/../config/template/tls_cert_config.json" "$config_file"
|
|
||||||
|
|
||||||
# 设置端口
|
|
||||||
bash "$script_dir/update_port.sh"
|
|
||||||
|
|
||||||
# 设置密码
|
|
||||||
bash "$script_dir/update_password.sh"
|
|
||||||
|
|
||||||
# 设置混淆密码
|
|
||||||
bash "$script_dir/update_obfs_password.sh"
|
|
||||||
|
|
||||||
# 获取邮箱
|
|
||||||
read -p "请输入你的邮箱(可留空): " user_email
|
|
||||||
if [[ -z "$user_email" ]]; then
|
|
||||||
user_email="example@example.com"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 获取域名
|
|
||||||
read -p "请输入你的域名 (例如: example.com): " user_domain
|
|
||||||
while [[ -z "$user_domain" ]]; do
|
|
||||||
echo "[错误] 域名不能为空"
|
|
||||||
read -p "请输入你的域名: " user_domain
|
|
||||||
done
|
|
||||||
|
|
||||||
# 获取 Cloudflare API Token
|
|
||||||
read -p "请输入你的 Cloudflare API Token: " cloudflare_token
|
|
||||||
while [[ -z "$cloudflare_token" ]]; do
|
|
||||||
echo "[错误] Cloudflare API Token 不能为空"
|
|
||||||
read -p "请输入你的 Cloudflare API Token: " cloudflare_token
|
|
||||||
done
|
|
||||||
|
|
||||||
# 使用 sed 替换邮箱
|
|
||||||
sed -i "s/你的邮箱/$user_email/g" "$config_file"
|
|
||||||
|
|
||||||
# 替换域名 (在 domains 数组和 masquerade url 中)
|
|
||||||
sed -i "s/你的域名/$user_domain/g" "$config_file"
|
|
||||||
|
|
||||||
# 替换 Cloudflare API Token
|
|
||||||
sed -i "s/你的cloudflare_api_token/$cloudflare_token/g" "$config_file"
|
|
||||||
|
|
||||||
echo "初始化设置完成"
|
|
||||||
}
|
|
||||||
|
|
||||||
create_self_tls_config() {
|
|
||||||
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
|
||||||
|
|
||||||
cp "$script_dir/../config/template/self_cert_config.json" "$script_dir/../config/config.json"
|
|
||||||
|
|
||||||
# 设置端口
|
|
||||||
bash "$script_dir/update_port.sh"
|
|
||||||
|
|
||||||
# 设置密码
|
|
||||||
bash "$script_dir/update_password.sh"
|
|
||||||
|
|
||||||
# 设置混淆密码
|
|
||||||
bash "$script_dir/update_obfs_password.sh"
|
|
||||||
|
|
||||||
# 生成自签名证书和设置域名
|
|
||||||
bash "$script_dir/gen_self_tls.sh" "bing.com"
|
|
||||||
|
|
||||||
echo "初始化设置完成"
|
|
||||||
}
|
|
||||||
|
|
||||||
create_config(){
|
|
||||||
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
|
||||||
local config_file="$script_dir/../config/config.json"
|
|
||||||
|
|
||||||
# 如果配置文件不存在, 创建空白配置文件
|
|
||||||
if [ ! -e "$config_file" ]; then
|
|
||||||
touch "$config_file"
|
|
||||||
fi
|
|
||||||
|
|
||||||
local config_password=$(jq -r '.auth.password' "$config_file")
|
|
||||||
if [ -s "$config_file" ] && [ "$config_password" != "你的密码" ]; then
|
|
||||||
local regenerate
|
|
||||||
read -p "检测到配置已存在,是否重新生成配置?(y/n): " regenerate
|
|
||||||
if [ "$regenerate" != "y" ] && [ "$regenerate" != "Y" ]; then
|
|
||||||
echo "取消重新生成配置."
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "请选择配置类型:"
|
|
||||||
echo "1. 自签名证书配置"
|
|
||||||
echo "2. tls证书配置"
|
|
||||||
local choice
|
|
||||||
read -p "输入您的选择: " choice
|
|
||||||
case $choice in
|
|
||||||
1)
|
|
||||||
echo "重置为自签名证书配置..."
|
|
||||||
create_self_tls_config
|
|
||||||
;;
|
|
||||||
2)
|
|
||||||
echo "重置为tls证书配置..."
|
|
||||||
create_config_with_tls_cert
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "无效的选择, 请重新选择."
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
create_config
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# 生成自签名证书
|
|
||||||
gen_self_tls() {
|
|
||||||
local domain="${1:-bing.com}"
|
|
||||||
local script_dir="$(dirname "$(realpath "$0")")"
|
|
||||||
local key_dir="$script_dir/../key"
|
|
||||||
local config_file="$script_dir/../config/config.json"
|
|
||||||
|
|
||||||
# 导入utils文件夹中的jq_util.sh脚本
|
|
||||||
source "$script_dir/utils/jq_util.sh"
|
|
||||||
|
|
||||||
# 生成自签名证书
|
|
||||||
openssl req -x509 -nodes -newkey ec:<(openssl ecparam -name prime256v1) \
|
|
||||||
-keyout "$key_dir/server.key" \
|
|
||||||
-out "$key_dir/server.crt" \
|
|
||||||
-subj "/CN=$domain" \
|
|
||||||
-days 36500
|
|
||||||
|
|
||||||
# 更新config.json文件中的域名信息
|
|
||||||
modify_json_file "$config_file" "masquerade.proxy.url" "https://$domain"
|
|
||||||
}
|
|
||||||
|
|
||||||
# 调用函数,传入第一个参数作为域名
|
|
||||||
gen_self_tls "${1:-bing.com}"
|
|
||||||
12
bin/init.sh
Normal file
12
bin/init.sh
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
script_dir=$(cd "$(dirname "$0")"; pwd) # 脚本绝对路径
|
||||||
|
|
||||||
|
# 更新密码
|
||||||
|
bash "$script_dir/update_password.sh"
|
||||||
|
|
||||||
|
# 更新证书和设置域名
|
||||||
|
bash "$script_dir/set_domain.sh" "bing.com"
|
||||||
|
|
||||||
|
# 打印分享链接
|
||||||
|
bash "$script_dir/print_share_link.sh"
|
||||||
@ -1,57 +1,32 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
print_share_link() {
|
# 检查 jq 命令是否可用
|
||||||
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
if ! command -v jq &> /dev/null
|
||||||
local config_dir=$(readlink -f "$script_dir/../")
|
then
|
||||||
source "${script_dir}/utils/base.sh"
|
echo "jq 命令未安装,请先安装 jq。"
|
||||||
|
exit 1
|
||||||
# 检查jq是否安装
|
fi
|
||||||
check_jq
|
|
||||||
|
|
||||||
# 检查配置文件是否存在
|
|
||||||
if [ ! -f "$config_dir/config/config.json" ]; then
|
|
||||||
red "error: 配置文件未生成, 查看配置失败"
|
|
||||||
echo '请选择"生成配置 / 重置配置"'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 检查是否已启动过容器
|
# 获取脚本所在目录的上级目录路径
|
||||||
local password=$(jq -r '.auth.password' "$config_dir/config/config.json")
|
script_dir=$(cd "$(dirname "$0")"; pwd)
|
||||||
if [ "$password" = "你的密码" ]; then
|
|
||||||
red "error: 容器未启动过, 查看配置失败"
|
|
||||||
echo '请选择"启动容器"'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 检查是否使用ACME证书
|
# 读取 config.json 文件
|
||||||
local allowInsecure=1 # 默认跳过证书验证
|
config=$(cat "$script_dir/../config.json")
|
||||||
if jq -e '.acme' "$config_dir/config/config.json" > /dev/null 2>&1; then
|
|
||||||
allowInsecure=0 # 不跳过证书验证
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 读取配置文件内容
|
# 提取所需信息
|
||||||
local config=$(cat "$config_dir/config/config.json")
|
password=$(echo "$config" | jq -r '.auth.password')
|
||||||
|
sni=$(echo "$config" | jq -r '.masquerade.proxy.url' | awk -F'/' '{print $3}')
|
||||||
# 提取所需信息
|
ipv4=$(curl -4 -sSL --connect-timeout 3 --retry 2 ip.sb || echo "null") # 本机IPV4地址
|
||||||
password=$(echo "$config" | jq -r '.auth.password')
|
port=$(echo "$config" | jq -r '.listen' | cut -d':' -f2) # 端口号
|
||||||
local sni=$(echo "$config" | jq -r '.masquerade.proxy.url' | awk -F'/' '{print $3}')
|
|
||||||
local ipv4=$(curl -4 -sSL --connect-timeout 3 --retry 2 ip.sb || echo "null")
|
|
||||||
local port=$(echo "$config" | jq -r '.listen' | cut -d':' -f2)
|
|
||||||
local obfs_password=$(echo "$config" | jq -r '.obfs.salamander.password')
|
|
||||||
|
|
||||||
# 构建分享链接
|
|
||||||
local share_link="hysteria2://${password}@${ipv4}:${port}/?sni=${sni}&insecure=1&obfs-password=${obfs_password}#${ipv4}&allowInsecure=${allowInsecure}"
|
|
||||||
|
|
||||||
# 输出分享链接
|
|
||||||
echo -e "\033[32m"
|
|
||||||
echo "IPV4: $ipv4"
|
|
||||||
echo "port: $port"
|
|
||||||
echo "password: $password"
|
|
||||||
echo "sni: $sni"
|
|
||||||
echo "混淆密码: $obfs_password"
|
|
||||||
echo ""
|
|
||||||
echo "分享链接: $share_link"
|
|
||||||
echo -e "\033[0m"
|
|
||||||
}
|
|
||||||
|
|
||||||
print_share_link # 输出分享链接
|
# 构建分享链接
|
||||||
|
share_link="hysteria2://${password}@${ipv4}:${port}/?sni=${sni}&insecure=1#${ipv4}"
|
||||||
|
|
||||||
|
# 输出分享链接
|
||||||
|
echo -e "\033[32m"
|
||||||
|
echo "IPV4: $ipv4"
|
||||||
|
echo "port: $port"
|
||||||
|
echo "password: $password"
|
||||||
|
echo "sni: $sni"
|
||||||
|
echo "分享链接: $share_link"
|
||||||
|
echo -e "\033[0m"
|
||||||
32
bin/run.sh
32
bin/run.sh
@ -1,32 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
|
|
||||||
run() {
|
|
||||||
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
|
||||||
local config_dir=$(readlink -f "$script_dir/../")
|
|
||||||
|
|
||||||
source "$script_dir/utils/base.sh"
|
|
||||||
|
|
||||||
# 检查jq是否安装
|
|
||||||
check_jq
|
|
||||||
|
|
||||||
# 检查bash是否安装
|
|
||||||
check_bash_installed
|
|
||||||
|
|
||||||
# 如果配置没有创建
|
|
||||||
if [ ! -e "$config_dir/config/config.json" ]; then
|
|
||||||
touch "$config_dir/config/config.json"
|
|
||||||
fi
|
|
||||||
local password=$(jq -r '.auth.password' "$config_dir/config/config.json")
|
|
||||||
if [ ! -s "$config_dir/config/config.json" ] || [ "$password" = "你的密码" ]; then
|
|
||||||
bash "$script_dir/create_config.sh" # 创建配置
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 启动docker容器
|
|
||||||
docker-compose -f "$script_dir/../docker-compose.yml" up -d
|
|
||||||
|
|
||||||
# 打印分享链接
|
|
||||||
bash "$script_dir/print_share_link.sh"
|
|
||||||
}
|
|
||||||
|
|
||||||
run # 启动容器
|
|
||||||
27
bin/set_domain.sh
Normal file
27
bin/set_domain.sh
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 当前脚本所在目录的绝对路径
|
||||||
|
script_dir="$(dirname "$(realpath "$0")")"
|
||||||
|
|
||||||
|
# 导入utils文件夹中的jq_util.sh脚本
|
||||||
|
source "$script_dir/utils/jq_util.sh"
|
||||||
|
|
||||||
|
gen_cert() {
|
||||||
|
local domain="$1"
|
||||||
|
local key_dir="$script_dir/../key" # key目录绝对路径
|
||||||
|
# 使用openssl生成自签名证书,设置密钥和有效期,并指定域名信息
|
||||||
|
openssl req -x509 -nodes -newkey ec:<(openssl ecparam -name prime256v1) -keyout "$key_dir/server.key" -out "$key_dir/server.crt" -subj "/CN=$domain" -days 36500
|
||||||
|
}
|
||||||
|
|
||||||
|
update_config() {
|
||||||
|
local domain="$1"
|
||||||
|
local config_file="$script_dir/../config.json" # config.json文件路径
|
||||||
|
# 使用jq_util.sh脚本中的modify_json_file函数修改config.json文件中的域名信息
|
||||||
|
modify_json_file $config_file "masquerade.proxy.url" "https://$domain"
|
||||||
|
}
|
||||||
|
|
||||||
|
domain="${1:-bing.com}" # 域名, 默认为"bing.com"
|
||||||
|
gen_cert "$domain" # 生成证书
|
||||||
|
update_config "$domain" # 更新config.json文件
|
||||||
|
|
||||||
|
|
||||||
@ -1,28 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# 更新容器的函数
|
script_dir="$(dirname "$(realpath "$0")")" # 当前脚本所在目录的绝对路径
|
||||||
update_docker_images() {
|
docker_compose_file=$(readlink -f "$script_dir/../docker-compose.yml") # docker-compose.yaml文件路径
|
||||||
local script_dir="$(dirname "$(realpath "$0")")"
|
|
||||||
local docker_compose_file=$(readlink -f "$script_dir/../docker-compose.yml")
|
|
||||||
|
|
||||||
# 检查是否存在 docker-compose.yml 文件
|
|
||||||
if [ ! -f "$docker_compose_file" ]; then
|
|
||||||
echo "Error: docker-compose.yml 文件不存在."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "正在关闭容器.."
|
|
||||||
docker-compose -f "$docker_compose_file" down
|
|
||||||
|
|
||||||
echo "正在更新镜像.."
|
|
||||||
docker-compose -f "$docker_compose_file" pull
|
|
||||||
|
|
||||||
echo "正在删除未使用的镜像..."
|
|
||||||
docker image prune -f
|
|
||||||
|
|
||||||
echo "正在启动容器.."
|
|
||||||
docker-compose -f "$docker_compose_file" up -d
|
|
||||||
}
|
|
||||||
|
|
||||||
# 调用函数
|
# 检查是否存在 docker-compose.yml 文件
|
||||||
update_docker_images
|
if [ ! -f $docker_compose_file ]; then
|
||||||
|
echo "Error: docker-compose.yml 文件不存在."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "正在关闭容器.."
|
||||||
|
docker-compose -f $docker_compose_file down
|
||||||
|
|
||||||
|
echo "正在更新镜像.."
|
||||||
|
docker-compose -f $docker_compose_file pull
|
||||||
|
|
||||||
|
echo "正在启动容器.."
|
||||||
|
docker-compose -f $docker_compose_file up -d
|
||||||
@ -1,25 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# 更新密码的函数
|
|
||||||
update_obfs_password() {
|
|
||||||
local script_dir="$(dirname "$(realpath "$0")")"
|
|
||||||
local config_file="$script_dir/../config/config.json"
|
|
||||||
|
|
||||||
# 加载工具脚本
|
|
||||||
source "$script_dir/utils/jq_util.sh"
|
|
||||||
source "$script_dir/utils/base.sh"
|
|
||||||
|
|
||||||
# 检查jq是否安装
|
|
||||||
check_jq
|
|
||||||
|
|
||||||
# 生成一个长度为16的随机密码
|
|
||||||
local new_password=$(gen_password 16)
|
|
||||||
|
|
||||||
# 使用jq_util.sh中的modify_json_file函数修改config.json文件中的auth.password字段
|
|
||||||
modify_json_file "$config_file" 'obfs.salamander.password' "$new_password"
|
|
||||||
|
|
||||||
echo "更新混淆密码成功"
|
|
||||||
}
|
|
||||||
|
|
||||||
# 调用函数
|
|
||||||
update_obfs_password
|
|
||||||
@ -1,25 +1,36 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# 更新密码的函数
|
# 检查是否安装了jq命令
|
||||||
update_password() {
|
if ! command -v jq &> /dev/null; then
|
||||||
local script_dir="$(dirname "$(realpath "$0")")"
|
echo "Error: jq command not found. Please install jq first."
|
||||||
local config_file="$script_dir/../config/config.json"
|
exit 1
|
||||||
|
fi
|
||||||
# 加载工具脚本
|
|
||||||
source "$script_dir/utils/jq_util.sh"
|
# 当前脚本所在目录的绝对路径
|
||||||
source "$script_dir/utils/base.sh"
|
script_dir="$(dirname "$(realpath "$0")")"
|
||||||
|
|
||||||
# 检查jq是否安装
|
# 加载jq_util.sh脚本
|
||||||
check_jq
|
source $script_dir/utils/jq_util.sh
|
||||||
|
|
||||||
# 生成一个长度为16的随机密码
|
# 函数生成随机密码
|
||||||
local new_password=$(gen_password 16)
|
gen_random_pass() {
|
||||||
|
local pass_length=$1 # 密码长度作为第一个参数
|
||||||
# 使用jq_util.sh中的modify_json_file函数修改config.json文件中的auth.password字段
|
local chars='[:alnum:]' # 只允许出现字母和数字
|
||||||
modify_json_file "$config_file" 'auth.password' "$new_password"
|
|
||||||
|
local rand
|
||||||
echo "设置密码成功"
|
rand=$(< /dev/urandom tr -dc "$chars" | head -c "$pass_length")
|
||||||
|
|
||||||
|
echo "$rand"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 调用函数
|
# 生成一个长度为16的随机密码
|
||||||
update_password
|
new_password=$(gen_random_pass 16)
|
||||||
|
|
||||||
|
# 更新config.json文件中的auth.password字段
|
||||||
|
config_file="$script_dir/../config.json"
|
||||||
|
|
||||||
|
# 使用jq_util.sh中的modify_json_file函数修改config.json文件中的auth.password字段
|
||||||
|
modify_json_file "$config_file" '.auth.password' "$new_password"
|
||||||
|
|
||||||
|
echo "New password: $new_password"
|
||||||
|
echo "config.json file updated with new password."
|
||||||
@ -1,57 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# 查找空闲端口
|
|
||||||
find_free_port() {
|
|
||||||
local start="${1:-10001}"
|
|
||||||
local max="${2:-65535}"
|
|
||||||
|
|
||||||
# 收集当前监听端口(TCP + UDP)
|
|
||||||
local used_ports raw
|
|
||||||
if command -v ss >/dev/null 2>&1; then
|
|
||||||
raw=$(ss -lntu 2>/dev/null || true)
|
|
||||||
used_ports=$(printf "%s\n" "$raw" | awk '{print $5}' | sed -n '2,$p' | sed -E 's/.*[:]//g' | sed '/^$/d')
|
|
||||||
elif command -v netstat >/dev/null 2>&1; then
|
|
||||||
raw=$(netstat -lntu 2>/dev/null || true)
|
|
||||||
used_ports=$(printf "%s\n" "$raw" | awk '{print $4}' | sed -n '2,$p' | sed -E 's/.*[:]//g' | sed '/^$/d')
|
|
||||||
elif command -v lsof >/dev/null 2>&1; then
|
|
||||||
raw=$(lsof -i -P -n 2>/dev/null || true)
|
|
||||||
used_ports=$(printf "%s\n" "$raw" | awk '/LISTEN/ {print $9}' | sed -E 's/.*[:]//g' | sed '/^$/d')
|
|
||||||
else
|
|
||||||
echo "Error: neither ss, netstat nor lsof is available to check listening ports." >&2
|
|
||||||
return 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 用关联数组记录已占用端口(需要 bash 4+)
|
|
||||||
declare -A used_map
|
|
||||||
local p
|
|
||||||
for p in $used_ports; do
|
|
||||||
# 过滤掉非数字
|
|
||||||
if [[ $p =~ ^[0-9]+$ ]]; then
|
|
||||||
used_map["$p"]=1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# 从 start 到 max 逐个检查
|
|
||||||
for ((port = start; port <= max; port++)); do
|
|
||||||
if [[ -z "${used_map[$port]}" ]]; then
|
|
||||||
echo "$port"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# 没找到可用端口
|
|
||||||
echo "Error: No available port found in range $start-$max" >&2
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
change_port(){
|
|
||||||
local script_dir=$(cd "$(dirname "$0")"; pwd)
|
|
||||||
local config_dir=$(readlink -f "$script_dir/../")
|
|
||||||
source "$script_dir/utils/jq_util.sh"
|
|
||||||
|
|
||||||
local port=$(find_free_port)
|
|
||||||
modify_json_file "$config_dir/config/config.json" ".listen" ":$port"
|
|
||||||
echo "已分配新的空闲端口, 设置端口成功"
|
|
||||||
}
|
|
||||||
|
|
||||||
change_port
|
|
||||||
@ -1,69 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
red(){
|
|
||||||
echo -e "\033[31m$1\033[0m"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# 获取系统包管理器
|
|
||||||
get_package_manager(){
|
|
||||||
if command -v apt-get &> /dev/null; then
|
|
||||||
echo "apt-get"
|
|
||||||
elif command -v yum &> /dev/null; then
|
|
||||||
echo "yum"
|
|
||||||
else
|
|
||||||
echo "未知的系统包管理器"
|
|
||||||
return 1 # 返回错误状态码
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# 检查 jq 是否已安装
|
|
||||||
check_jq(){
|
|
||||||
if command -v jq &> /dev/null; then
|
|
||||||
return 0 # jq 已安装,返回成功
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "jq 未安装,正在安装..."
|
|
||||||
install_package jq
|
|
||||||
}
|
|
||||||
|
|
||||||
# 检查 Bash 是否已安装
|
|
||||||
check_bash_installed() {
|
|
||||||
if ! command -v bash &> /dev/null; then
|
|
||||||
echo "错误: Bash 未安装!"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# 动态安装软件包
|
|
||||||
install_package() {
|
|
||||||
local package_name=$1
|
|
||||||
if command -v "$package_name" &> /dev/null; then
|
|
||||||
echo "$package_name 已安装, 跳过."
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "安装 $package_name..."
|
|
||||||
package_manager=$(get_package_manager)
|
|
||||||
if [ "$package_manager" == "apt-get" ]; then
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y "$package_name"
|
|
||||||
elif [ "$package_manager" == "yum" ]; then
|
|
||||||
sudo yum install -y "$package_name"
|
|
||||||
else
|
|
||||||
echo "未知的包管理器, 请手动安装 $package_name."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# 生成密码
|
|
||||||
gen_password() {
|
|
||||||
local pass_length=$1 # 密码长度作为第一个参数
|
|
||||||
local chars='[:alnum:]' # 只允许出现字母和数字
|
|
||||||
|
|
||||||
local rand
|
|
||||||
rand=$(< /dev/urandom tr -dc "$chars" | head -c "$pass_length")
|
|
||||||
|
|
||||||
echo "$rand"
|
|
||||||
}
|
|
||||||
@ -7,11 +7,6 @@ function modify_json_file() {
|
|||||||
local key=$2 # 要修改的key
|
local key=$2 # 要修改的key
|
||||||
local value=$3 # 要修改的value
|
local value=$3 # 要修改的value
|
||||||
|
|
||||||
#如果key的值是.开头, 则去掉.号
|
|
||||||
if [[ ${key} == "."* ]]; then
|
|
||||||
key=${key:1}
|
|
||||||
fi
|
|
||||||
|
|
||||||
jq ".${key} = \"${value}\"" ${json_file} > ${json_file}.tmp
|
jq ".${key} = \"${value}\"" ${json_file} > ${json_file}.tmp
|
||||||
mv ${json_file}.tmp ${json_file}
|
mv ${json_file}.tmp ${json_file}
|
||||||
}
|
}
|
||||||
|
|||||||
18
config.json
Normal file
18
config.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"listen": ":8443",
|
||||||
|
"tls": {
|
||||||
|
"cert": "/etc/hysteria/server.crt",
|
||||||
|
"key": "/etc/hysteria/server.key"
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "password",
|
||||||
|
"password": "La4AdWOoE57OdtwY"
|
||||||
|
},
|
||||||
|
"masquerade": {
|
||||||
|
"type": "proxy",
|
||||||
|
"proxy": {
|
||||||
|
"url": "https://bing.com",
|
||||||
|
"rewriteHost": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"listen": ":8004",
|
|
||||||
"tls": {
|
|
||||||
"cert": "/etc/hysteria/server.crt",
|
|
||||||
"key": "/etc/hysteria/server.key"
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "password",
|
|
||||||
"password": "你的密码"
|
|
||||||
},
|
|
||||||
"obfs": {
|
|
||||||
"type": "salamander",
|
|
||||||
"salamander": {
|
|
||||||
"password": "bLa4AdWOoE57OdtwYa"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"masquerade": {
|
|
||||||
"type": "proxy",
|
|
||||||
"proxy": {
|
|
||||||
"url": "https://你的域名",
|
|
||||||
"rewriteHost": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"bandwidth": {
|
|
||||||
"up": "50 mbps",
|
|
||||||
"down": "100 mbps"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
{
|
|
||||||
"listen": ":8445",
|
|
||||||
"acme": {
|
|
||||||
"domains": [
|
|
||||||
"你的域名"
|
|
||||||
],
|
|
||||||
"email": "你的邮箱",
|
|
||||||
"type": "dns",
|
|
||||||
"dns": {
|
|
||||||
"name": "cloudflare",
|
|
||||||
"config": {
|
|
||||||
"cloudflare_api_token": "你的cloudflare_api_token"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "password",
|
|
||||||
"password": "你的密码"
|
|
||||||
},
|
|
||||||
"obfs": {
|
|
||||||
"type": "salamander",
|
|
||||||
"salamander": {
|
|
||||||
"password": "你的混淆密码"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"masquerade": {
|
|
||||||
"type": "proxy",
|
|
||||||
"proxy": {
|
|
||||||
"url": "https://你的域名",
|
|
||||||
"rewriteHost": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"bandwidth": {
|
|
||||||
"up": "50 mbps",
|
|
||||||
"down": "100 mbps"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,13 +1,17 @@
|
|||||||
|
version: "3.9"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
hysteria:
|
hysteria:
|
||||||
image: tobyxdd/hysteria:latest
|
image: tobyxdd/hysteria:latest
|
||||||
container_name: "${COMPOSE_PROJECT_NAME}" # 容器名为文件夹名称
|
container_name: hysteria
|
||||||
restart: always
|
restart: always
|
||||||
network_mode: "host"
|
network_mode: "host"
|
||||||
volumes:
|
volumes:
|
||||||
- ./acme:/acme
|
- acme:/acme
|
||||||
- ./config/config.json:/etc/hysteria/config.json
|
- ./config.json:/etc/hysteria/config.json
|
||||||
- ./key/server.crt:/etc/hysteria/server.crt
|
- ./key/server.crt:/etc/hysteria/server.crt
|
||||||
- ./key/server.key:/etc/hysteria/server.key
|
- ./key/server.key:/etc/hysteria/server.key
|
||||||
command: ["server", "-c", "/etc/hysteria/config.json"]
|
command: ["server", "-c", "/etc/hysteria/config.json"]
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
acme:
|
||||||
|
|||||||
86
install.sh
86
install.sh
@ -1,86 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
script_dir="$(cd "$(dirname "$0")"; pwd)/bin" # 脚本所在目录
|
|
||||||
source "${script_dir}/utils/base.sh"
|
|
||||||
|
|
||||||
# 检查bash环境是否安装
|
|
||||||
check_bash_installed
|
|
||||||
|
|
||||||
install(){
|
|
||||||
if ! command -v curl >/dev/null 2>&1; then
|
|
||||||
install_package curl
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! command -v wget >/dev/null 2>&1; then
|
|
||||||
install_package wget
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! command -v jq >/dev/null 2>&1; then
|
|
||||||
echo 安装jq...
|
|
||||||
install_package jq
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! command -v docker >/dev/null 2>&1; then
|
|
||||||
echo 安装docker...
|
|
||||||
curl -fsSL https://get.docker.com | bash -s docker
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! command -v docker-compose >/dev/null 2>&1; then
|
|
||||||
echo 安装docker-compose...
|
|
||||||
wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/v2.29.0/docker-compose-linux-x86_64
|
|
||||||
chmod +x /usr/local/bin/docker-compose
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# 显示菜单
|
|
||||||
echo "请选择一个操作:"
|
|
||||||
echo "1. 安装并启动"
|
|
||||||
echo "2. 生成配置 / 重置配置"
|
|
||||||
echo "3. 启动容器"
|
|
||||||
echo "4. 查看分享链接"
|
|
||||||
echo "5. 停止容器"
|
|
||||||
echo "6. 更新镜像"
|
|
||||||
echo "7. 更新端口"
|
|
||||||
|
|
||||||
# 读取用户选择
|
|
||||||
read -p "输入您的选择: " choice
|
|
||||||
|
|
||||||
# 根据用户选择执行相应的操作
|
|
||||||
case $choice in
|
|
||||||
1)
|
|
||||||
# 安装并启动
|
|
||||||
install
|
|
||||||
bash ./bin/run.sh
|
|
||||||
;;
|
|
||||||
2)
|
|
||||||
# 生成配置
|
|
||||||
echo "重新生成配置.."
|
|
||||||
bash ./bin/create_config.sh
|
|
||||||
;;
|
|
||||||
3)
|
|
||||||
# 启动容器
|
|
||||||
echo "启动容器.."
|
|
||||||
bash ./bin/run.sh
|
|
||||||
;;
|
|
||||||
4)
|
|
||||||
# 查看分享链接
|
|
||||||
echo "查看分享链接.."
|
|
||||||
bash ./bin/print_share_link.sh
|
|
||||||
;;
|
|
||||||
5)
|
|
||||||
# 停止容器
|
|
||||||
echo "正在停止容器.."
|
|
||||||
docker-compose -f ./docker-compose.yml down
|
|
||||||
;;
|
|
||||||
6)
|
|
||||||
# 更新镜像
|
|
||||||
bash ./bin/update_docker_images.sh
|
|
||||||
;;
|
|
||||||
7)
|
|
||||||
# 更新端口
|
|
||||||
bash ./bin/update_port.sh
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "无效的选择, 请重新选择."
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
Loading…
Reference in New Issue
Block a user