Bench 是用于管理基于 Frappe 框架的站点部署的命令行工具。以下是在生产环境中部署 Frappe 站点的步骤。
安装 Bench
部署 Frappe 站点与在本地系统上搭建并没有太大区别。如果你的服务器是受支持的 Linux 发行版(Debian、Ubuntu、CentOS),可以使用 Easy Install 脚本安装 Bench。请确保向脚本传递 --production 标志。
sudo python install.py --production --user [frappe-user]
设置站点和应用
# change directory to frappe-bench
cd frappe-bench
# create a new site
bench new-site example.com
# download frappe apps or your custom-apps
bench get-app erpnext
bench get-app https://github.com/yourremote/yourapp.git
# install apps onto your site
bench --site example.com install-app erpnext yourapp
检查 supervisor
如果一切设置正确,你应该能在 supervisor 状态输出中看到 Frappe 进程。
$ sudo supervisorctl status
frappe-bench-redis:frappe-bench-redis-cache RUNNING pid 6467, uptime 10 days, 8:12:09
frappe-bench-redis:frappe-bench-redis-queue RUNNING pid 6466, uptime 10 days, 8:12:09
frappe-bench-redis:frappe-bench-redis-socketio RUNNING pid 6468, uptime 10 days, 8:12:09
frappe-bench-web:frappe-bench-frappe-web RUNNING pid 8856, uptime 10 days, 4:32:18
frappe-bench-web:frappe-bench-node-socketio RUNNING pid 8858, uptime 10 days, 4:32:18
frappe-bench-workers:frappe-bench-frappe-default-worker-0 RUNNING pid 8823, uptime 10 days, 4:32:19
frappe-bench-workers:frappe-bench-frappe-long-worker-0 RUNNING pid 8824, uptime 10 days, 4:32:19
frappe-bench-workers:frappe-bench-frappe-schedule RUNNING pid 8822, uptime 10 days, 4:32:19
frappe-bench-workers:frappe-bench-frappe-short-worker-0 RUNNING pid 8825, uptime 10 days, 4:32:19
如果你拥有 example.com 并且它已映射到服务器的 IP 地址,你的站点应该可以通过 example.com 访问。
更新
要更新你的站点,只需运行以下命令。它会更新你所有的应用(git pull),在所有站点上运行补丁,构建 JS 和 CSS 资源,并重启 supervisor。
# update everything
bench update
# update apps
bench update --pull
# run patches only
bench update --patch
# build assets only
bench update --build
# update bench (the cli)
bench update --bench
# update python packages and node_modules
bench update --requirements
Redis 命名空间
命名空间有助于保护用户数据。多个 Bench 可以共用同一个 Redis 实例,而无需担心命名空间冲突。你可以按照以下设置步骤在 Frappe 中启用 Redis 命名空间(目前 Frappe 在 Bench 级别支持 Redis 队列的命名空间)。
你可以使用 bench create-rq-users 命令行工具创建 Redis 用户,并使用凭据配置 Frappe。
bench create-rq-users
# Optional flags
# --use-rq-auth Enable Redis authentication for all bench sites
# --set-admin-password sets default user admin password
上述命令会在 Bench 配置目录中生成一个 ACL 文件。请确保 Redis_queue.conf 文件已配置为使用 ACL 文件(如果尚未配置的话)(或者,使用最新版本的 Bench CLI 运行 bench setup redis)。
aclfile [frappe-bench-absolute-path]/config/redis_queue.acl