Files
vps/install/23-Sub2API.sh
T
2026-06-06 03:41:58 +08:00

68 lines
1.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# chmod +x 23-Sub2API.sh && ./23-Sub2API.sh
# curl -sS -O https://gitea.tohub.top/Share/vps/raw/branch/main/install/23-Sub2API.sh && chmod +x 23-Sub2API.sh && ./23-Sub2API.sh
ipv4_address=$(curl -s ipv4.ip.sb)
port80=8230
# 1、更新包
apt update -y && apt upgrade -y #更新一下包
# 2、创建安装目录
mkdir -p /root/data/docker_data/Sub2API
cd /root/data/docker_data/Sub2API
# 3、填写docker-compose配置
cat <<EOF > docker-compose.yml
services:
db:
image: postgres:15-alpine
container_name: sub2api-db
restart: unless-stopped
volumes:
- ./data/postgres:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=changeme # 改成你自己的密码
- POSTGRES_USER=postgres # 改成你自己的用户名
- POSTGRES_DB=sub2api
redis:
image: redis:7-alpine
container_name: sub2api-redis
restart: unless-stopped
volumes:
- ./data/redis:/data
app:
image: weishaw/sub2api:latest
container_name: sub2api-app
restart: unless-stopped
ports:
- "$port80:8080" # 左边的端口可以更换,右边不要动!
depends_on:
- db
- redis
environment:
# 主机用容器服务名 db / redis,不要写宿主机 IP
- DATABASE_URL=postgres://postgres:changeme@db:5432/sub2api?sslmode=disable # 用户名/密码/库名要与上面 db 对应!
- REDIS_URL=redis://redis:6379
- SERVER_PORT=8080 # 镜像用的是 SERVER_PORT,必须与 ports 右边的容器端口一致
- GIN_MODE=release
EOF
# 4、安装
docker-compose up -d
# 5、打开防火墙的端口
ufw allow $port80
ufw status
# 打印访问链接
echo "------------------------"
echo "访问链接:"
echo "https://sub2api.ghuang.top"
echo "User: admin@localhost"
echo "Password: admin"
echo "------------------------"