4
Service:ezBookkeeping
Jeffery edited this page 2026-06-11 10:03:47 +08:00

簡介

ezBookkeeping 是一套自架的個人記帳服務。本文記錄在 Ubuntu 上以二進位檔搭配 systemd 部署,並使用 PostgreSQL 作為資料庫的步驟。

下載 ezBookkeeping

從官方下載指定版本的壓縮檔並解壓縮,以下提供兩個版本,擇一執行即可。

wget https://github.com/mayswind/ezbookkeeping/releases/download/v1.4.0/ezbookkeeping-v1.4.0-linux-amd64.tar.gz && tar zxvf ezbookkeeping-v1.4.0-linux-amd64.tar.gz
wget https://github.com/mayswind/ezbookkeeping/releases/download/v1.5.1/ezbookkeeping-v1.5.1-linux-amd64.tar.gz && tar zxvf ezbookkeeping-v1.5.1-linux-amd64.tar.gz

建立 ezBookkeeping 服務

以 systemd 管理服務,可開機自動啟動、崩潰時自動重啟。先建立服務設定檔。

nano /etc/systemd/system/ezbookkeeping.service

服務檔內容如下:

[Unit]
Description=ezBookkeeping

[Service]
Environment=HOME=/root
Type=simple
WorkingDirectory=/root
ExecStart=/root/ezbookkeeping server run
Restart=always
User=root

[Install]
WantedBy=multi-user.target

啟動服務

重新載入 systemd 設定、設為開機自動啟動、啟動服務並檢視狀態。

systemctl daemon-reload && systemctl enable ezbookkeeping.service && systemctl start ezbookkeeping.service && systemctl status ezbookkeeping.service

設定資料庫

以 postgres 系統帳號進入 PostgreSQL 互動介面。

sudo -u postgres psql

新建專屬使用者與資料庫。

CREATE USER ezbookkeeping WITH PASSWORD 'ezbookkeeping';

CREATE DATABASE ezbookkeeping;

設定資料庫權限(Postgres 15 以後,schema 權限需另外授予,否則應用程式無法建立資料表)。

-- 1. Give ownership of the database to the app user
ALTER DATABASE ezbookkeeping OWNER TO ezbookkeeping;

-- 2. Give ownership of the public schema to the app user
ALTER SCHEMA public OWNER TO ezbookkeeping;

-- 3. Ensure the user has create permissions (Crucial for Postgres 15+)
GRANT USAGE, CREATE ON SCHEMA public TO ezbookkeeping;