TandoorRecipes项目手动安装与配置指南

TandoorRecipes项目手动安装与配置指南

recipes Application for managing recipes, planning meals, building shopping lists and much much more! recipes 项目地址: https://gitcode.com/gh_mirrors/re/recipes

前言

TandoorRecipes是一个基于Django框架开发的现代化食谱管理系统,它提供了完整的食谱管理、食材跟踪和菜单规划功能。本文将详细介绍如何在Linux系统上手动安装和配置TandoorRecipes项目,包括后端服务、数据库和前端构建的完整流程。

系统要求

在开始安装前,请确保您的系统满足以下最低要求:

  • 操作系统:Ubuntu/Debian或兼容的Linux发行版
  • Python版本:3.10或更高(推荐3.12)
  • 内存:至少2GB(前端构建过程需要较多内存)
  • 磁盘空间:建议预留至少1GB可用空间

准备工作

1. 创建专用用户

为安全考虑,我们首先创建一个专用用户来运行应用:

sudo useradd recipes

2. 系统更新与基础软件安装

更新系统并安装必要的软件包:

sudo apt update && sudo apt upgrade -y
sudo apt install -y git curl python3 python3-pip python3-venv nginx

3. 获取项目代码

将项目代码克隆到系统目录:

git clone https://github.com/vabene1111/recipes.git -b master
sudo mv recipes /var/www
cd /var/www/recipes
sudo chown -R recipes:www-data /var/www/recipes

4. 创建Python虚拟环境

python3 -m venv /var/www/recipes
source /var/www/recipes/bin/activate

依赖安装

1. Node.js和Yarn安装

前端构建需要Node.js环境:

# 对于Ubuntu系统
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
sudo npm install --global yarn

2. 数据库支持包

安装PostgreSQL开发库:

sudo apt install -y libpq-dev postgresql

3. LDAP支持(可选)

如需LDAP集成,安装以下包:

sudo apt install -y libsasl2-dev python3-dev libldap2-dev libssl-dev

4. Python依赖安装

/var/www/recipes/bin/pip3 install -r requirements.txt

5. 前端构建

cd ./vue
yarn install
yarn build

数据库配置

1. PostgreSQL设置

sudo -u postgres psql

在PostgreSQL控制台中执行:

CREATE DATABASE djangodb;
CREATE USER djangouser WITH PASSWORD 'your_secure_password';
GRANT ALL PRIVILEGES ON DATABASE djangodb TO djangouser;
ALTER DATABASE djangodb OWNER TO djangouser;

-- 优化设置
ALTER ROLE djangouser SET client_encoding TO 'utf8';
ALTER ROLE djangouser SET default_transaction_isolation TO 'read committed';
ALTER ROLE djangouser SET timezone TO 'UTC';

-- 临时授予超级用户权限(后续会移除)
ALTER USER djangouser WITH SUPERUSER;

2. 环境变量配置

下载模板配置文件:

wget https://raw.githubusercontent.com/vabene1111/recipes/develop/.env.template -O /var/www/recipes/.env

编辑.env文件,重点关注以下配置项:

  • SECRET_KEY:使用base64 /dev/urandom | head -c50生成安全密钥
  • POSTGRES_HOST:通常为127.0.0.1
  • POSTGRES_PASSWORD:与数据库设置一致
  • STATIC_URLMEDIA_URL:指向/var/www/recipes下的相应目录

应用初始化

1. 加载环境变量并迁移数据库

export $(cat /var/www/recipes/.env |grep "^[^#]" | xargs)
/var/www/recipes/bin/python3 manage.py migrate

2. 移除数据库超级用户权限

sudo -u postgres psql
ALTER USER djangouser WITH NOSUPERUSER;
exit

3. 收集静态文件

/var/www/recipes/bin/python3 manage.py collectstatic --no-input
/var/www/recipes/bin/python3 manage.py collectstatic_js_reverse

服务配置

1. Gunicorn服务

创建服务文件/etc/systemd/system/gunicorn_recipes.service

[Unit]
Description=gunicorn daemon for recipes
After=network.target

[Service]
Type=simple
Restart=always
RestartSec=3
User=recipes
Group=www-data
WorkingDirectory=/var/www/recipes
EnvironmentFile=/var/www/recipes/.env
ExecStart=/var/www/recipes/bin/gunicorn --error-logfile /tmp/gunicorn_err.log --log-level debug --capture-output --bind unix:/var/www/recipes/recipes.sock recipes.wsgi:application

[Install]
WantedBy=multi-user.target

启用并启动服务:

sudo systemctl enable --now gunicorn_recipes
sudo systemctl status gunicorn_recipes  # 验证服务状态

2. Nginx配置

创建配置文件/etc/nginx/conf.d/recipes.conf

server {
    listen 8002;
    
    location /static/ {
        alias /var/www/recipes/staticfiles;
    }
    
    location /media/ {
        alias /var/www/recipes/mediafiles;
    }

    location / {
        proxy_set_header Host $http_host;
        proxy_pass http://unix:/var/www/recipes/recipes.sock;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

重新加载Nginx配置:

sudo systemctl reload nginx

更新流程

当需要更新应用时,执行以下步骤:

cd /var/www/recipes
git pull
export $(cat /var/www/recipes/.env |grep "^[^#]" | xargs)
bin/pip3 install -r requirements.txt
bin/python3 manage.py migrate
bin/python3 manage.py collectstatic --no-input
bin/python3 manage.py collectstatic_js_reverse
cd vue
yarn install
yarn build
sudo systemctl restart gunicorn_recipes

常见问题解决

  1. 前端构建内存不足

    • 确保系统有足够内存(至少2GB)
    • 可尝试设置Node.js内存限制:export NODE_OPTIONS=--max_old_space_size=4096
  2. 数据库连接问题

    • 检查.env中的数据库配置
    • 验证PostgreSQL服务是否运行
  3. 权限问题

    • 确保/var/www/recipes目录权限正确
    • 检查Gunicorn服务使用的用户权限

通过以上步骤,您应该已经成功安装并配置了TandoorRecipes项目。现在可以通过浏览器访问服务器IP和配置的端口(如8002)来使用您的食谱管理系统了。

recipes Application for managing recipes, planning meals, building shopping lists and much much more! recipes 项目地址: https://gitcode.com/gh_mirrors/re/recipes

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陆可鹃Joey

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值