前置系统要求
- Debian 12
安装前的准备
# 更新系统
apt update && apt upgrade -y
# 安装基础工具
apt install -y curl wget git unzip software-properties-common \
apt-transport-https ca-certificates gnupg lsb-release
# 设置时区
timedatectl set-timezone Asia/Shanghai
# 禁用防火墙(如果启用)
ufw disable
步骤 1:安装 Nginx
# 添加 Nginx 官方仓库
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/debian bookworm nginx" \
| tee /etc/apt/sources.list.d/nginx.list
# 设置仓库优先级
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
| tee /etc/apt/preferences.d/99nginx
# 安装 Nginx
apt update && apt install -y nginx
# 修改用户为 www-data
sed -i 's/^user.*/user www-data;/' /etc/nginx/nginx.conf
# 启动服务
systemctl start nginx && systemctl enable nginx
步骤 2:安装 Redis
# 添加 Redis 仓库
curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] \
https://packages.redis.io/deb bookworm main" | tee /etc/apt/sources.list.d/redis.list
# 安装 Redis
apt update && apt install -y redis
# 配置 Redis
sed -i 's/^# bind 127.0.0.1 ::1/bind 127.0.0.1 ::1/' /etc/redis/redis.conf
sed -i 's/^# maxmemory <bytes>/maxmemory 256mb/' /etc/redis/redis.conf
sed -i 's/^# maxmemory-policy noeviction/maxmemory-policy allkeys-lru/' /etc/redis/redis.conf
# 启动服务
systemctl restart redis-server && systemctl enable redis-server
步骤 3:安装 MariaDB
# 添加 MariaDB 仓库
mkdir -p /etc/apt/keyrings
curl -o /etc/apt/keyrings/mariadb-keyring.pgp \
'https://mariadb.org/mariadb_release_signing_key.pgp'
cat > /etc/apt/sources.list.d/mariadb.sources <<EOF
X-RepoLib-Name: MariaDB
Types: deb
URIs: https://deb.mariadb.org/11.8/debian
Suites: bookworm
Components: main
Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
EOF
# 安装 MariaDB
apt update && apt install -y mariadb-server mariadb-client
# 启动服务
systemctl start mariadb && systemctl enable mariadb
# 安全初始化
mariadb-secure-installation
创建数据库
# 生成安全密码
DB_PASSWORD=$(openssl rand -base64 16)
echo "请牢记数据库密码!!! 数据库密码:$DB_PASSWORD"
# 创建数据库和用户(使用 mariadb 命令,避免弃用警告)
mariadb -u root -p <<EOF
CREATE DATABASE ppanel CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'ppanel'@'localhost' IDENTIFIED BY '$DB_PASSWORD';
GRANT ALL PRIVILEGES ON ppanel.* TO 'ppanel'@'localhost';
FLUSH PRIVILEGES;
EOF
步骤 4:配置 Nginx
# 创建配置目录
mkdir -p /etc/nginx/conf.d
# 创建站点配置
cat > /etc/nginx/conf.d/sspanel.conf <<'EOF'
server {
listen 80;
listen [::]:80;
server_name your-domain.com; # 修改为你的域名
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;
# 配置代理到后端服务
proxy_pass http://127.0.0.1:8080;
}
# 设置静态资源缓存
location ~* \.(gif|png|jpg|css|js|woff|woff2)$ {
expires 30d;
add_header Cache-Control public;
}
}
EOF
# 测试配置
nginx -t
# 重载 Nginx
systemctl reload nginx
为了保护用户数据安全,强烈建议配置 HTTPS:
# 安装 Certbot
apt install -y certbot python3-certbot-nginx
# 获取证书
certbot --nginx -d your-domain.com
步骤 5:安装ppanel-server
确定系统架构,并下载对应的二进制文件
下载地址:https://github.com/perfect-panel/server/releases
示例说明:系统:Debian amd64,用户:root,当前目录:/root
- 下载
wget -O ppanel-server-linux-amd64.tar.gz \
https://github.com/perfect-panel/server/releases/latest/download/ppanel-server-linux-amd64.tar.gz
- 解压
tar -zxvf ppanel-server-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 配置文件
cat > /usr/local/etc/ppanel/ppanel.yaml <<'EOF'
Host: 127.0.0.1 # 服务监听地址
Port: 8080 # 服务监听端口, 默认: 8080
Debug: false # 是否开启调试模式, 默认: false
JwtAuth: # JWT认证配置
AccessSecret: CHANGE_ME_TO_A_RANDOM_SECRET # 访问令牌密钥, 请修改为随机字符串
AccessExpire: 604800 # 访问令牌过期时间,单位秒, 默认: 604800 (7天)
Logger: # 日志配置
FilePath: /var/log/ppanel/ppanel.log # 日志文件路径
MaxSize: 50 # 日志文件最大大小, 单位MB
MaxBackup: 3 # 日志文件最大备份数
MaxAge: 30 # 日志文件最大保存时间,单位天
Compress: true # 是否压缩日志文件
Level: info # 日志级别: debug, info, warn, error, panic, fatal
MySQL:
Addr: 127.0.0.1:3306 # MySQL地址
Username: ppanel # MySQL用户名 (与创建的用户一致)
Password: CHANGE_ME_TO_DB_PASSWORD # MySQL密码 (换成之前生成的随机密码)
Dbname: ppanel # MySQL数据库名 (与脚本创建的数据库一致)
Config: charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai
MaxIdleConns: 10
MaxOpenConns: 100
LogMode: info
LogZap: true
SlowThreshold: 1000
Redis:
Host: 127.0.0.1:6379
Pass: '' # 如果Redis设置了密码,在这里填写
DB: 0
Administrator:
Email: [email protected] # 后台登录邮箱,请修改
Password: CHANGE_ME_TO_STRONG_PASSWORD # 后台登录密码,请修改为强密码
EOF
- 创建 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
其他说明
-
安装路径:二进制文件最终移动到 /usr/local/bin 目录下
-
systemd 服务:
- 服务名称:ppanel
- 服务配置文件:/etc/systemd/system/ppanel.service
- 服务启动命令:systemctl start ppanel
- 服务停止命令:systemctl stop ppanel
- 服务重启命令:systemctl restart ppanel
- 服务状态命令:systemctl status ppanel
- 服务开机自启:systemctl enable ppanel
-
设置开机自启可通过以下命令开机自启
systemctl enable ppanel
-
服务日志:服务日志默认输出到 /usr/local/bin/ppanel.log 文件中
-
可通过
journalctl -u ppanel -f
查看服务日志 -
当配置文件为空或者不存在的情况下,服务会使用默认配置启动,配置文件路径为:
./etc/ppanel.yaml
, 请通过http://服务器地址:8080/init
初始化系统配置