手动部署 - [OneinStack]

安装所需软件

apt update && apt install wget curl git vim -y

安装oneinstack

前往oneinstack官网选择合适的软件,再复制安装命令到SSH上执行

  • PHP >= 7.2.5

    • PHP缓存 Opcache (可选,推荐)

    • fileinfo

    • redis

  • MySQL 5.5+

  • Redis 无版本要求

安装时间视机器配置而定,vultr 2C2G 安装大概20分钟左右

安装完成后会输出nginx等软件的存放位置,安装后别忘记重启

Install.png

创建网站

SSH连接到VPS后输入下方命令,创建网站

/root/oneinstack/vhost.sh
  1. 三个选项分别是使用HTTP,使用自己的证书,以及申请免费证书

  2. 输入网站域名

  3. 网站目录,直接回车网站目录默认位于/data/wwwroot/网站域名

  4. 是否需要添加更多域名

  5. 是否需要HTTP重定向到HTTPS

  6. 申请证书使用的邮箱

creat-website5998a3999d9ff7b7.png

自动申请完证书后,还有几步

  1. 是否需要热链接保护

  2. 是否需要添加伪静态规则

  3. 添加哪种伪静态规则(这里直接回车,自带的laravel规则和proxypanel所需的不同)

  4. 是否允许记录访问日志

ssl.png

删除禁用函数

vim /usr/local/php/etc/php.ini

删除以下禁用函数:

  • proc_open

  • proc_get_status

  • symlink

phpDisableFunctions.png

删除后重启PHP

service php-fpm restart

修改网站运行目录

vim /usr/local/nginx/conf/vhost/网站域名.conf

在root开头那行末尾添加/public,别忘了末尾的分号

nginx48f87e1f222f1e13.png

添加伪静态

vim /usr/local/nginx/conf/rewrite/other.conf

添加以下伪静态规则

location / {  
    try_files $uri $uri/ /index.php$is_args$query_string;  
}

重启nginx

systemctl restart nginx

创建数据库与用户

登录并创建数据库

首先使用以下命令登录mysql,并输入密码(密码是啥?请看安装oneinstack小节)

mysql -u root -p

创建数据库,查看数据库是否创建成功

create database ProxyPanel default character set utf8mb4 collate utf8mb4_unicode_ci;
show databases;

创建数据库用户

创建名为ProxyPanel的用户,密码为ProxyPanel(自行更换密码),并给ProxyPanel用户ProxyPanel数据库的所有权限以及所有数据库的使用权限

grant usage on *.* to ProxyPanel@'localhost' identified by 'ProxyPanel';
grant  all  privileges  on  ProxyPanel.*  to  ProxyPanel@'localhost' identified by 'ProxyPanel';
flush privileges;

安装面板

cd /data/wwwroot/网站域名
git clone https://github.com/ProxyPanel/ProxyPanel.git .
cp .env.example .env

编辑.env

vim .env

参照下方含义进行编辑

| Key                          | Value              |        含义                             |
| ------------------------ |:----------------:| --------------------------:|
| DB_HOST               | localhost        | 数据库IP/域名 |
| DB_PORT               | 3306               | 数据库端口  |
| DB_DATABASE    | ProxyPanel     | 数据库名 |
| DB_USERNAME   | ProxyPanel    | 用户名 |
| DB_PASSWORD    | ProxyPanel    | 密码 |

安装依赖

输入下方命令安装PHP Composer,安装过程很简单,就不多赘述.

/root/oneinstack/addons.sh

再运行以下代码安装依赖

composer install --prefer-dist --optimize-autoloader --no-dev

导入数据库

php artisan migrate --seed

必要环境设置

php artisan key:generate
php artisan storage:link
chown -R www:www storage/ 
chmod -R 777 storage/

设置定时任务

mkdir /home/www && chown -R www:www /home/www && chmod -R 777 /home/www
crontab -e -u www
* * * * * php /data/wwwroot/网站域名/artisan schedule:run >> /dev/null 2>&1

设置队列管理 Horizon

cat > /etc/supervisor/conf.d/horizon.conf <<EOF
[program:horizon]
process_name=%(program_name)s
command=php $(pwd)/artisan horizon
autostart=true
autorestart=true
user=www
redirect_stderr=true
stdout_logfile=$(pwd)/storage/logs/horizon.log
stopwaitsecs=3600
EOF

supervisorctl reread
supervisorctl update
supervisorctl start horizon

设置广播 Reverb

【广播】 应用于内容的实时同步,目前用于用户支付结果查询,管理节点页面节点连通性,地理位置更新,重启结果等,需要内容实时在页面显示的场景。

大致步骤:

  1. 编辑目录下 .env 文件中 REVERB_ 开头参数;

  2. 清理缓存 php artisan optimize:clear && php artisan optimize

  3. 重新编译前端js和重启reverb,npm run build && supervisorctl restart reverb

  4. 添加/修改网站nginx配置文件

    server {
        ...
    
        location / {
            proxy_http_version 1.1;
            proxy_set_header Host $http_host;
            proxy_set_header Scheme $scheme;
            proxy_set_header SERVER_PORT $server_port;
            proxy_set_header REMOTE_ADDR $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
    
            proxy_pass http://0.0.0.0:8080;
        }
    
        ...
    }

通用修改/存在参数

env参数

BROADCAST_DRIVER

reverb

REVERB_APP_ID

随机数字id

REVERB_APP_KEY

随机字符串

REVERB_APP_SECRET

随机字符串

REVERB_SCHEME

可选,值为http/https

方案A 广播使用与面板同子域名

通知和面板都是使用:proxypanel.ddo.jp;← 域名是为了方便理解使用的案例

  • 配置env,REVERB_PATH, 用于分流正常访问和通知访问;

作用
备注

REVERB_PATH

Reverb 服务器期望接收连接的 URL 路径。在您的配置中为 REVERB_PATH=,表示没有路径前缀。

例如:/eventcastsing

REVERB_HOST

proxypanel.ddo.jp

REVERB_APP_ID=510141
REVERB_APP_KEY=ti12342lbcrgjzazvua6
REVERB_APP_SECRET=kvjczliy123hrylnh56z
REVERB_SCHEME=https
REVERB_HOST=proxypanel.ddo.jp
REVERB_PATH=/eventcastsing

VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"
VITE_REVERB_PATH="${REVERB_PATH}"
REVERB_SERVER_PATH="${REVERB_PATH}"

修改nginx配置中第4行需要按照REVERB_PATH值修改

server {
    ...

    location /eventcastsing/ {
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";

        proxy_pass http://0.0.0.0:8080;
    }

    ...
}

方案B 广播使用与面板使用不同子域名

  • 面板使用:proxypanel.ddo.jp;← 域名是为了方便理解使用的案例

    • 通知使用:b.ddo.jp 或者 proxypanel.work.gd

  • 配置env,REVERB_HOST;

作用
备注

REVERB_HOST

proxypanel.work.gd

REVERB_APP_ID=510141
REVERB_APP_KEY=ti12342lbcrgjzazvua6
REVERB_APP_SECRET=kvjczliy123hrylnh56z
REVERB_SCHEME=https
REVERB_HOST=proxypanel.work.gd
REVERB_PATH=

VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"
VITE_REVERB_PATH="${REVERB_PATH}"
REVERB_SERVER_PATH="${REVERB_PATH}"

优化

每次修改 .env 后,请运行以下代码,重新预加载必要文件

php artisan optimize

更新

面板

sh /www/wwwroot/demo.proxypanel.ml/update.sh

数据库

php artisan migrate

最后更新于

这有帮助吗?