DOCS服务端二进制部署

前置系统要求

  • Debian 12

安装 Nginx

对于Nginx的安装,我们使用官方的Nginx DEB源

安装必要的软件

apt install curl wget gnupg2 ca-certificates lsb-release sudo

添加官方Nginx PGP密钥

curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

将官方Nginx源配置写入 nginx.list

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list

设置官方Nginx源的优先级高于系统内建源

echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx

更新APT缓存

apt update

安装Nginx

apt install nginx

最后,启动Nginx服务并设置开机自启

systemctl start nginx
systemctl enable nginx

安装 Redis

导入GPG密钥

curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

将官方Redis源配置写入 redis.list

echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

更新APT缓存

apt update

安装 redis-server

apt install redis

启动Redis服务并设置开机自启

systemctl start redis-server
systemctl enable redis-server

安装 MariaDB

MariaDB提供了一个完整的DEB仓库,和Nginx仓库类似,因此我们需要安装必要的包并导入GPG密钥

apt install apt-transport-https curl
mkdir -p /etc/apt/keyrings
curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp'

编辑 /etc/apt/sources.list.d/mariadb.sources 文件, 并写入以下配置:

X-Repolib-Name: MariaDB
Types: deb
URIs: https://deb.mariadb.org/11.4/debian
Suites: bookworm
Components: main
Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp

更新APT缓存

apt update

安装MariaDB 11.4

apt install mariadb-server

启动MariaDB服务并设置开机自启

systemctl start mariadb
systemctl enable mariadb

运行MariaDB的初始设置

mariadb-secure-installation

安装ppanel

1.配置MariaDB数据库

1. 登录到MariaDB

mariadb -u root -p

在MariaDB命令行界面中,执行以下命令来创建一个新的数据库 ppanel_db,并设置字符集为 utf8mb4_unicode_ci

CREATE DATABASE ppanel_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

接下来,创建一个本地数据库用户,并将该用户的权限限制为新创建的数据库,使用 ppanel 作为用户名,ppanel-password 作为用户密码。

CREATE USER 'ppanel'@'localhost';
GRANT ALL PRIVILEGES ON ppanel_db.* TO 'ppanel'@'localhost' IDENTIFIED BY 'ppanel-password';
FLUSH PRIVILEGES;

退出MariaDB

EXIT;

2.配置Nginx

/etc/nginx/nginx.conf 中的 user

user nginx;

修改为

user www-data;

添加 Nginx 虚拟主机配置文件

nano /etc/nginx/conf.d/website-domain-you-set.conf

然后写入以下配置,请注意更改网站域名和SSL证书文件(否则报错):

server {
    listen 443 ssl;
    server_name api.example.com *.example.com;   # 替换为你的域名
 
    ssl_certificate /path/your/certs/example.crt;  # 替换为你的证书路径
    ssl_certificate_key /path/your/private/example.key;  # 替换为你的私钥路径
 
    ssl_protocols TLSv1.2 TLSv1.3; # 推荐使用的协议
    ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384'; # 推荐的加密套件
    ssl_prefer_server_ciphers on;
 
    # cloudflare Start
    set_real_ip_from 0.0.0.0/0;  # 信任 Cloudflare 所有 IP 地址
    real_ip_header X-Forwarded-For;  # 使用 X-Forwarded-For 头获取真实 IP
    real_ip_recursive on;  # 递归解析 X-Forwarded-For 头中的多个 IP
    # cloudflare END
 
    # 默认代理设置
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header Upgrade $http_upgrade;
        proxy_http_version 1.1;
 
        add_header X-Cache $upstream_cache_status;
 
        # 配置代理到后端服务,如果后端服务在127.0.0.1:8080
        proxy_pass http://127.0.0.1:8080;
    }
 
    # 设置静态资源缓存
    location ~* \.(gif|png|jpg|css|js|woff|woff2)$ {
        expires 30d;
        add_header Cache-Control public;
    }
}
 
# HTTP 到 HTTPS 重定向
server {
    listen 80;
    server_name api.example.com *.example.com;  # 替换为你的域名
 
    location / {
        return 301 https://$host$request_uri;
    }
}

重启 Nginx

systemctl restart nginx

3.确定系统架构,并下载对应的二进制文件

下载地址:https://github.com/perfect-panel/ppanel/releases

示例说明:系统:Debian amd64,用户:root,当前目录:/root

  • 下载
wget https://github.com/perfect-panel/ppanel/releases/download/v0.1.0/ppanel-server-v0.1.0-linux-amd64.tar.gz
  • 解压
tar -zxvf ppanel-server-v0.1.0-linux-amd64.tar.gz
  • 移动
sudo mv ppanel-server /usr/local/bin/ppanel
sudo mkdir -p /usr/local/etc/ppanel
sudo mv ./etc/ppanel.yaml /usr/local/etc/ppanel/
  • 赋予二进制文件执行权限
sudo chmod +x /usr/local/bin/ppanel
  • 修改 ppanel.yaml 配置文件
nano /usr/local/etc/ppanel/ppanel.yaml
Host: 127.0.0.1 # 服务监听地址, 修改为:1270.0.1
Port: 8080 # 服务监听端口, 默认: 8080
Debug: false # 是否开启调试模式, 默认: false
JwtAuth: # JWT认证配置
  AccessSecret: d2a1b58958f13ab01shekdd123fcd12345xyz67890== # 访问令牌密钥, 请进行修改
  AccessExpire: 604800 # 访问令牌过期时间,单位秒, 默认: 604800
Logger: # 日志配置
  FilePath: ./ppanel.log # 日志文件路径, 默认: ./ppanel.log
  MaxSize: 50 # 日志文件最大大小, 单位MB, 默认: 50
  MaxBackup: 3 # 日志文件最大备份数, 默认: 3
  MaxAge: 30 # 日志文件最大保存时间,单位天, 默认: 30
  Compress: true # 是否压缩日志文件, 默认: true
  Level: info # 日志级别, 默认: info, 可选: debug, info, warn, error, panic, fatal
MySQL:
  Addr: 127.0.0.1:3306 # MySQL地址, 必填
  Username: ppanel # MySQL用户名, 必填
  Password: ppanel-password # MySQL密码, 必填
  Dbname: ppanel_db # MySQL数据库名, 必填
  Config: charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai # MySQL配置默认值
  MaxIdleConns: 10 # 最大空闲连接数, 默认: 10
  MaxOpenConns: 100 # 最大打开连接数, 默认: 100
  LogMode: info # 日志级别, 默认: info, 可选: debug, error, warn, info
  LogZap: true # 是否使用zap日志记录sql, 默认: true
  SlowThreshold: 1000 # 慢查询阈值,单位毫秒, 默认: 1000
Redis:
  Host: 127.0.0.1:6379 # Redis地址, 默认:localhost:6379
  Pass: '' # Redis密码, 默认: ""
  DB: 0 # Redis数据库, 默认: 0
 
Administrator:
  Email: [email protected] # 后台登录邮箱, 默认: [email protected]
  Password: password # 后台登录密码, 默认: password
  • 创建 systemd 服务文件
$ cat > /etc/systemd/system/ppanel.service <<EOF
[Unit]
Description=PPANEL Server
After=network.target
 
[Service]
ExecStart=/usr/local/bin/ppanel run --config /usr/local/etc/ppanel/ppanel.yaml
Restart=always
User=root
WorkingDirectory=/usr/local/bin
 
[Install]
WantedBy=multi-user.target
EOF
  • 重新加载 systemd 服务
systemctl daemon-reload
  • 启动服务
systemctl start ppanel
其他说明
  1. 安装路径:二进制文件最终移动到 /usr/local/bin 目录下

  2. systemd 服务:

    • 服务名称:ppanel
    • 服务配置文件:/etc/systemd/system/ppanel.service
    • 服务启动命令:systemctl start ppanel
    • 服务停止命令:systemctl stop ppanel
    • 服务重启命令:systemctl restart ppanel
    • 服务状态命令:systemctl status ppanel
    • 服务开机自启:systemctl enable ppanel
  3. 设置开机自启可通过以下命令开机自启

    systemctl enable ppanel
  4. 服务日志:服务日志默认输出到 /usr/local/bin/ppanel.log 文件中

  5. 可通过 journalctl -u ppanel -f 查看服务日志

  6. 当配置文件为空或者不存在的情况下,服务会使用默认配置启动,配置文件路径为:./etc/ppanel.yaml, 请通过http://服务器地址:8080/init 初始化系统配置