如何在 Ubuntu 22.04 上安装类似 Reddit 的 Fediverse 内容聚合器 Kbin
Kbin 是一个类似 Reddit 的开源内容聚合器和联邦微博平台。它允许您创建和管理社区,并可以与其他 ActivityPub 服务(包括 Mastodon、Pleroma 和 Peertube)进行通信。
虽然您可以加入和使用一些流行的 Kbin 实例,但您也可以为您的朋友和家人运行您自己的 Kbin 实例。在本教程中,您将学习如何在 Ubuntu 22.04 服务器上安装 Kbin。
先决条件
运行 Ubuntu 22.04 的服务器。
非 root sudo 用户。
完全限定域名 (FQDN),例如 example.com
。
确保一切都已更新。
$ sudo apt update
$ sudo apt upgrade
您的系统需要的软件包很少。
$ sudo apt install wget curl nano ufw software-properties-common dirmngr apt-transport-https gnupg2 ca-certificates lsb-release ubuntu-keyring unzip -y
其中一些软件包可能已经安装在您的系统上。
我们的安装还需要访问控制列表(ACL)才能工作。安装它。
$ sudo apt install acl
第 1 步 - 配置防火墙
第一步是配置防火墙。 Ubuntu 默认带有 ufw(简单防火墙)。
检查防火墙是否正在运行。
$ sudo ufw status
您将得到以下输出。
Status: inactive
允许 SSH 端口,以便防火墙在启用它时不会中断当前连接。
$ sudo ufw allow OpenSSH
还允许 HTTP 和 HTTPS 端口。
$ sudo ufw allow http
$ sudo ufw allow https
启用防火墙
$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
再次检查防火墙的状态。
$ sudo ufw status
您应该看到类似的输出。
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
80/tcp ALLOW Anywhere
443 ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
443 (v6) ALLOW Anywhere (v6)
第 2 步 - 安装 Git
Git 通常随 Ubuntu 服务器一起安装,但如果没有安装,则应使用以下命令进行安装。
$ sudo apt install git
验证安装。
$ git --version
git version 2.34.1
使用基本信息配置 Git。
$ git config --global user.name "Your Name"
$ git config --global user.email "[email "
第 3 步 - 安装 Nginx
Ubuntu 附带了旧版本的 Nginx。要安装最新版本,您需要下载官方 Nginx 存储库。
导入 Nginx 的签名密钥。
$ curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
添加 Nginx 稳定版本的存储库。
$ echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg arch=amd64] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
更新系统存储库。
$ sudo apt update
安装 Nginx。
$ sudo apt install nginx
验证安装。
$ nginx -v
nginx version: nginx/1.24.0
启动 Nginx 服务器。
$ sudo systemctl start nginx
第 4 步 - 安装 PHP 并配置 PHP
Ubuntu 22.04 附带 PHP 8.1.2 版本,该版本有点过时。我们将使用 Ondrej 的 PHP 存储库安装最新的 PHP 8.2 版本。
$ sudo add-apt-repository ppa:ondrej/php
接下来,安装 Kbin 所需的 PHP 及其扩展。
$ sudo apt install php8.2-common php8.2-fpm php8.2-cli php8.2-amqp php8.2-pgsql php8.2-gd php8.2-curl php8.2-simplexml php8.2-dom php8.2-xml php8.2-redis php8.2-mbstring php8.2-intl unzip
验证安装。
$ php --version
PHP 8.2.7 (cli) (built: Jun 8 2023 15:27:40) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies
打开文件 /etc/php/8.2/fpm/pool.d/www.conf
。
$ sudo nano /etc/php/8.2/fpm/pool.d/www.conf
我们需要将 PHP 进程的 Unix 用户/组设置为 nginx。在文件中找到 user=www-data
和 group=www-data
行,并将其更改为 nginx
。
...
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
...
在文件中找到 listen.owner=www-data
和 listen.group=www-data
行,并将其更改为 nginx
。
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions. The owner
; and group can be specified either by name or by their numeric IDs.
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = nginx
listen.group = nginx
按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
将 PHP-FPM 的内存限制从 128 MB 增加到 512 MB。
$ sudo sed -i 's/memory_limit = 128M/memory_limit = 512M/' /etc/php/8.2/fpm/php.ini
将文件上传大小增加到 8 MB。
$ sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 8M/' /etc/php/8.2/fpm/php.ini
重新启动 PHP-FPM 服务。
$ sudo systemctl restart php8.2-fpm
将 PHP 会话目录的组更改为 Nginx。
$ sudo chgrp -R nginx /var/lib/php/sessions
第 5 步 - 安装 Composer
Composer 是 PHP 的依赖管理工具,是 Kbin 安装所必需的。获取作曲家设置文件。
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
运行安装程序以生成 Composer 二进制文件。
$ php composer-setup.php
删除安装文件。
$ php -r "unlink('composer-setup.php');"
将 composer.phar
二进制文件移至 /usr/local/bin
目录。
$ sudo mv composer.phar /usr/local/bin/composer
验证 Composer 安装。
$ composer --version
Composer version 2.5.8 2023-06-09 17:13:21
第 6 步 - 安装和配置 PostgreSQL
Ubuntu 22.04 默认附带 PostgreSQL 14。我们将改用 PostgreSQL 15。
运行以下命令添加 PostgreSQL GPG 密钥。
$ curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /usr/share/keyrings/postgresql-key.gpg >/dev/null
将 APT 存储库添加到您的源列表中。
$ sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/postgresql-key.gpg arch=amd64] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
更新系统存储库。
$ sudo apt update
现在,您可以使用以下命令安装 PostgreSQL。
$ sudo apt install postgresql postgresql-contrib
postgresql-contrib 包包含一些额外的实用程序。
检查 PostgreSQL 服务的状态。
$ sudo systemctl status postgresql
? postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Sat 2023-06-17 09:15:50 UTC; 3h 40min ago
Main PID: 26989 (code=exited, status=0/SUCCESS)
CPU: 1ms
Jun 17 09:15:50 nspeaks systemd[1]: Starting PostgreSQL RDBMS...
Jun 17 09:15:50 nspeaks systemd[1]: Finished PostgreSQL RDBMS.
您可以看到该服务默认已启用并正在运行。
启动 PostgreSQL shell。
$ sudo -i -u postgres psql
创建 Kbin 数据库。
postgres=# CREATE DATABASE kbin;
创建 Kbin 用户并选择一个强密码。
postgres-# CREATE USER kbinuser WITH PASSWORD 'Your_Password';
将数据库所有者更改为 Kbin 用户。
postgres-# ALTER DATABASE kbin OWNER TO kbinuser;
退出外壳。
postgres-# \q
验证您的凭据是否有效。
$ psql --username kbinuser --password --host localhost kbin
Password:
psql (15.3 (Ubuntu 15.3-1.pgdg22.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.
kbin=>
输入 \q
退出 shell。
第 7 步 - 安装 Nodejs 和 Yarn
Ubuntu 22.04 附带了已过时的 Node v12。我们将安装 Node 的最新 LTS 版本,在编写本教程时为 v18。
从 NodeSource 获取 Node v18 安装程序。
$ curl -sL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
运行安装程序脚本。
$ sudo bash nodesource_setup.sh
安装 Node.js。
$ sudo apt install nodejs
验证 Node.js 版本。
$ node -v
v18.16.1
删除安装程序文件。
$ rm nodesource_setup.sh
第 8 步 - 安装 Yarn
导入 Yarn 的 GPG 密钥。
$ curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
将 Yarn 源添加到系统存储库列表中。
$ echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
更新您的系统存储库列表。
$ sudo apt update
安装纱线
$ sudo apt install yarn
验证安装。
$ yarn --version
1.22.19
第 8 步 - 安装 Redis
Magento 使用 Redis 进行会话和缓存存储。它完全是可选的,您可以使用数据库进行会话存储。但 Redis 做得更好。最新版本的 Magento 可与 Redis 7.0 配合使用。 Ubuntu 附带 Redis 6.0,因此我们将使用 Redis 存储库进行安装。
导入官方 Redis GPG 密钥。
$ curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
将 APT 存储库添加到您的源列表中。
$ 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
更新系统存储库列表。
$ sudo apt update
发出以下命令来安装 Redis 服务器。
$ sudo apt install redis
确认Redis版本。
$ redis-server -v
Redis server v=7.0.11 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=3af367a78d5e21e9
让我们使用以下命令验证服务连接。
$ redis-cli
您将切换到 Redis shell。
第一步是设置 Redis 默认用户的密码。将 Your_Redis_Password
替换为您选择的强密码。确保在密码前添加 >
字符。
127.0.0.1:6379> acl setuser default >Your_Redis_Password
测试 Redis 身份验证。
127.0.0.1:6379> AUTH Your_Redis_Password
OK
对服务执行 Ping 操作。
127.0.0.1:6379> ping
PONG
输入 exit
退出服务。
如果需要,可以使用以下命令生成 Redis 密码。
$ openssl rand 60 | openssl base64 -A
OaYOuq6J9HhxMV0sGCeZbaGecphCl4GBfVkCOPkNjkQE1FX9DKpGSCJcDb8UV+AuFKA8tR1PgjGequn1
步骤 9 - 安装和配置 RabbitMQ
Kbin 需要 RabbitMQ 来进行消息队列。我们将从 Ubuntu 存储库安装它。
$ sudo apt install rabbitmq-server
创建一个兔子用户。选择一个强密码。
$ sudo rabbitmqctl add_user kbin StrongPassword
将用户设置为管理员。
$ sudo rabbitmqctl set_user_tags kbin administrator
第 10 步 - 下载 Kbin
在下载Kbin之前,我们需要创建一个Kbin用户帐户。
$ adduser kbin
将 kbin
用户添加到 sudo 组。
$ sudo usermod -aG sudo kbin
以 kbin
用户身份登录。
$ su - kbin
创建 /var/www/html/kbin
目录。
$ sudo mkdir /var/wwww/html/kbin -p
切换到目录。
$ cd /var/www/html/kbin
为该文件夹授予适当的权限,以便当前登录的用户可以执行任务。
$ sudo chown $USER:$USER kbin
将 Kbin Git 存储库克隆到当前文件夹中。确保在命令末尾添加句点(.)以引用当前文件夹。
$ git clone https://codeberg.org/Kbin/kbin-core.git .
创建 public/media
目录。
$ mkdir public/media
给予其完全许可。
$ chmod 777 public/media
步骤11 - 配置环境文件
生成 Mercure JWT 密钥。
$ node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
再次使用相同的命令生成应用程序密钥。
$ node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
在 Kbin 目录中创建并打开 .env
文件进行编辑。
$ nano .env
将以下代码粘贴到其中。在以下文件中使用上面生成的密钥。
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
# kbin variables
SERVER_NAME="nspeaks.xyz" # production
KBIN_DOMAIN=nspeaks.xyz
KBIN_TITLE=Howtoforge
KBIN_DEFAULT_LANG=en
KBIN_FEDERATION_ENABLED=true
[email
[email
KBIN_JS_ENABLED=true
KBIN_REGISTRATIONS_ENABLED=true
KBIN_API_ITEMS_PER_PAGE=25
#KBIN_STORAGE_URL=/media
KBIN_META_TITLE="Kbin Lab"
KBIN_META_DESCRIPTION="content aggregator and micro-blogging platform for the fediverse"
KBIN_META_KEYWORDS="kbin, content agregator, open source, fediverse"
KBIN_HEADER_LOGO=false
KBIN_CAPTCHA_ENABLED=false
# Redis
REDIS_PASSWORD=YourRedisPassword
REDIS_DNS=redis://default:${REDIS_PASSWORD}@localhost:6379
###> symfony/framework-bundle ###
APP_ENV=prod
APP_SECRET=427f5e2940e5b2472c1b44b2d06e0525
###< symfony/framework-bundle ###
###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
POSTGRES_DB=kbin
POSTGRES_USER=kbin
POSTGRES_PASSWORD=Your_Password
POSTGRES_VERSION=15
DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@127.0.0.1:5432/${POSTGRES_DB}?serverVersion=${POSTGRES_VERSION}&charset=utf8"
###< doctrine/doctrine-bundle ###
###> symfony/messenger ###
# Choose one of the transports below
RABBITMQ_PASSWORD=RabbitMQPassword
MESSENGER_TRANSPORT_DSN=amqp://kbin:${RABBITMQ_PASSWORD}@rabbitmq:5672/%2f/messages
#MESSENGER_TRANSPORT_DSN=doctrine://default
#MESSENGER_TRANSPORT_DSN=redis://${REDIS_PASSWORD}@redis:6379/messages
###< symfony/messenger ###
###> symfony/mailgun-mailer ###
#MAILER_DSN=mailgun+smtp://[email :key@default?region=us
MAILER_DSN=smtp://AKIA3FIG4NVFH4TXXEXY:BJQvNI9U6JqSuUFQ9Ffd22Dvom/8KNwk7EIrFTRai02/@email-smtp.us-west-2.amazonaws.com:465
###< symfony/mailgun-mailer ###
###> symfony/mercure-bundle ###
# See https://symfony.com/doc/current/mercure.html#configuration
# The URL of the Mercure hub, used by the app to publish updates (can be a local URL)
MERCURE_URL=https://example.com/.well-known/mercure
# The public URL of the Mercure hub, used by the browser to connect
MERCURE_PUBLIC_URL=https://example.com/.well-known/mercure
# The secret used to sign the JWTs
MERCURE_JWT_SECRET="!ChangeThisMercureHubJWTSecretKey!"
###< symfony/mercure-bundle ###
###> symfony/lock ###
LOCK_DSN=flock
###< symfony/lock ###
按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
步骤 12 - 安装 Kbin
使用 Composer 安装 Kbin 所需的软件包。
$ composer install --prefer-dist --no-dev
$ composer dump-env prod
清除缓存。
$ APP_ENV=prod APP_DEBUG=0 php bin/console cache:clear
$ composer clear-cache
为媒体文件夹授予适当的权限。
$ sudo chown kbin:nginx public/media
使用 setfacl
命令设置正确的文件和目录权限。以下命令检测当前使用的 Web 服务器 (Nginx) 并设置现有和未来文件和文件夹的权限。
$ HTTPDUSER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1)
$ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
$ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
创建并迁移 PostgreSQL 数据库。
$ php bin/console doctrine:database:create
$ php bin/console doctrine:migrations:migrate
系统会提示您是否要继续数据迁移。输入 yes
继续。
WARNING! You are about to execute a migration in database "kbin" that could result in schema changes and data loss. Are you sure you wish to continue? (yes/no) [yes]:
> yes
[notice] Migrating up to DoctrineMigrations\Version20230615203020
[notice] finished in 1373.9ms, used 24M memory, 79 migrations executed, 667 sql queries
[OK] Successfully migrated to version : DoctrineMigrations\Version20230615203020
安装并构建 Kbin 站点的公共前端。
$ yarn install
$ yarn build
为 Kbin 创建一个新的管理员用户。
$ php bin/console kbin:user:create username [email password
向用户授予管理权限。
$ php bin/console kbin:user:admin username
更新密钥。
$ php bin/console kbin:ap:keys:update
第 13 步 - 安装 SSL
我们需要安装 Certbot 来生成 SSL 证书。您可以使用 Ubuntu 的存储库安装 Certbot,也可以使用 Snapd 工具获取最新版本。我们将使用 Snapd 版本。
Ubuntu 22.04 默认安装了 Snapd。运行以下命令以确保您的 Snapd 版本是最新的。
$ sudo snap install core && sudo snap refresh core
安装证书机器人。
$ sudo snap install --classic certbot
使用以下命令确保可以通过创建到 /usr/bin
目录的符号链接来运行 Certbot 命令。
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot
运行以下命令生成 SSL 证书。
$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m [email -d example.com
上述命令会将证书下载到服务器上的 /etc/letsencrypt/live/example.com
目录中。
生成 Diffie-Hellman 组证书。
$ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096
检查 Certbot 续订调度程序服务。
$ sudo systemctl list-timers
您会发现 snap.certbot.renew.service
是计划运行的服务之一。
NEXT LEFT LAST PASSED UNIT ACTIVATES
Wed 2023-06-28 10:09:00 UTC 20min left Wed 2023-06-28 09:39:00 UTC 9min ago phpsessionclean.timer phpsessionclean.service
Wed 2023-06-28 11:13:02 UTC 1h 24min left Wed 2023-06-28 04:41:28 UTC 5h 7min ago ua-timer.timer ua-timer.service
Wed 2023-06-28 12:11:00 UTC 2h 22min left n/a n/a snap.certbot.renew.timer snap.certbot.renew.service
对该过程进行一次演练,以检查 SSL 续订是否正常工作。
$ sudo certbot renew --dry-run
如果没有看到任何错误,则一切都已准备就绪。您的证书将自动更新。
第 14 步 - 配置 Nginx
创建并打开文件 /etc/nginx/conf.d/kbin.conf
进行编辑。
$ sudo nano /etc/nginx/conf.d/kbin.conf
将以下代码粘贴到其中。
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
access_log /var/log/nginx/kbin.access.log;
error_log /var/log/nginx/kbin.error.log;
# SSL
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
ssl_stapling on;
ssl_stapling_verify on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
# use https://blog.cloudflare.com/announcing-1111 Cloudfare+Apnic labs, It is free and secure
resolver 1.1.1.1 1.0.0.1 [2606:4700:4700::1111] [2606:4700:4700::1001] valid=300s;
root /var/www/html/kbin/public;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
# Pass PHP Scripts To FastCGI Server
location ~* \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/run/php-fpm/www.sock; # Depends On The PHP Version
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
include fastcgi_params;
}
# deny access to writable files/directories
location ~* ^/sites/*/(documents|edi|era) {
deny all;
return 404;
}
# deny access to certain directories
location ~* ^/(contrib|tests) {
deny all;
return 404;
}
# Alternatively all access to these files can be denied
location ~* ^/(admin|setup|acl_setup|acl_upgrade|sl_convert|sql_upgrade|gacl/setup|ippf_upgrade|sql_patch)\.php {
deny all;
return 404;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
}
}
# enforce HTTPS
server {
listen 80;
listen [::]:80;
server_name example.com;
return 301 https://$host$request_uri;
}
请注意,Nginx 配置中使用的根目录是 /var/www/html/kbin/public/。
完成后按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
打开文件 /etc/nginx/nginx.conf
进行编辑。
$ sudo nano /etc/nginx/nginx.conf
在 include /etc/nginx/conf.d/*.conf;
行之前添加以下行。
server_names_hash_bucket_size 64;
按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
验证 Nginx 配置文件语法。
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
重新启动 Nginx 服务。
$ sudo systemctl restart nginx
第 15 步 - 安装和配置 Supervisor
Supervisor 是一个进程管理器,我们将使用它作为 Kbin 的消息工作器 (RabbitMQ) 的进程监视器。第一步是安装 Supervisor。
$ sudo apt install supervisor
创建 /etc/supervisor/conf.d/messenger-worker.conf
文件并打开它进行编辑。
$ sudo nano /etc/supervisor/conf.d/messenger-worker.conf
将以下代码粘贴到其中。
[program:messenger-kbin]
command=php /var/www/html/kbin/bin/console messenger:consume async --time-limit=3600
user=kbin
numprocs=2
startsecs=0
autostart=true
autorestart=true
startretries=10
process_name=%(program_name)s_%(process_num)02d
stderr_logfile=/var/log/supervisor/%(program_name)s_stderr.log
stderr_logfile_maxbytes=10MB
stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log
stdout_logfile_maxbytes=10MB
[program:messenger-ap]
command=php /var/www/html/kbin/bin/console messenger:consume async_ap --time-limit=3600
user=kbin
numprocs=2
startsecs=0
autostart=true
autorestart=true
startretries=10
process_name=%(program_name)s_%(process_num)02d
stderr_logfile=/var/log/supervisor/%(program_name)s_stderr.log
stderr_logfile_maxbytes=10MB
stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log
stdout_logfile_maxbytes=10MB
按 Ctrl + X 并在出现提示时输入 Y 来保存文件。
执行以下命令重新读取并更新新的配置文件。
$ sudo supervisorctl reread
$ sudo supervisorctl update
启动所有 Supervisor 服务。
$ sudo supervisorctl start all
步骤 16 - 访问 Kbin
打开 URL https://example.com
,您将看到以下 Kbin 主页。
单击顶部的登录链接以显示登录页面。
输入在步骤 12 中创建的凭据,然后单击登录按钮继续。您将返回到 Kbin 主页。您可以从这里开始使用 Kbin。
结论
我们关于在 Ubuntu 22.04 服务器上安装类似 Reddit 的内容聚合器 Kbin 的教程到此结束。如果您有任何疑问,请在下面的评论中发表。