nocoBASE を AlmaLinux 9 にインストールする手順メモ
nocoBASE はノーコードでデータベースアプリを作れるオープンソースツールです。自前のサーバーにインストールして使う場合の手順を、 AlmaLinux 9 を例にまとめました。
全体の流れはこんな感じです。
- Node.js と Yarn のセットアップ
- MariaDB のインストールとデータベース作成
- nocoBASE のインストールと初期設定
- systemd サービス化
- Nginx でリバースプロキシ(SSL)
前提環境
- AlmaLinux 9(dnf 使用)
- ドメインは各自の環境に置き換えてください
基本パッケージのインストール
まずはシステム全体を更新して、必要なパッケージを入れます。
dnf update -y
dnf install -y curl ca-certificates git
dnf groupinstall -y "Development Tools"
dnf install -y python3 python3-devel
Node.js のセットアップ
nocoBASE は Node.js で動くので、20.x をインストールします。
curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
dnf install -y nodejs
Yarn を有効にします。
corepack enable
corepack prepare yarn@1.22.22 --activate
バージョンを確認しておきます。
node -v
yarn -v
MariaDB のインストール
nocoBASE はデータベースに MariaDB を使います。10.11 をインストールします。
curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=10.11
dnf install -y MariaDB-server MariaDB-client
サービスを起動してセキュリティ設定を実行します。
systemctl enable --now mariadb
mariadb-secure-installation
データベースとユーザーの作成
MariaDB にログインして、nocoBASE 用のデータベースとユーザーを作成します。
mariadb -uroot
CREATE DATABASE nocobase CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'nocobase'@'localhost' IDENTIFIED BY 'RepYh314';
GRANT ALL PRIVILEGES ON nocobase.* TO 'nocobase'@'localhost';
FLUSH PRIVILEGES;
パスワードは環境に合わせて変更してください。
nocoBASE のインストール
/srv/ 以下にインストールします。
cd /srv/
yarn create nocobase-app my-nocobase-app -d mariadb \
-e DB_HOST=localhost \
-e DB_PORT=3306 \
-e DB_DATABASE=nocobase \
-e DB_USER=nocobase \
-e DB_PASSWORD=RepYh314 \
-e TZ=JST
環境変数の設定
.env ファイルを編集します。
cd my-nocobase-app
vi .env
以下の設定を変更・追加してください。
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=nocobase
DB_USER=nocobase
DB_PASSWORD=RepYh314
TZ=JST
INIT_ROOT_EMAIL=system-info@renbird.jp
INIT_ROOT_PASSWORD=RepYh314
INIT_ROOT_NICKNAME=Super Admin
INIT_ROOT_USERNAME=nocoadmin
依存パッケージのインストール
yarn install
パッチ適用(バグ修正)
@nocobase/plugin-action-export に既知のバグがあり、ロールのエクスポート時にエラーになる場合があります。パッチを当てて回避します。
パッチファイルを作成します。
mkdir -p patches/@nocobase+plugin-action-export+1.8.27
vi patches/@nocobase+plugin-action-export+1.8.27/fix-role-actions.patch
パッチの内容はこんな感じです。
--- a/dist/server/index.js
+++ b/dist/server/index.js
@@ -56,7 +56,9 @@
const roles = await db.getRepository('roles').find();
for (const role of roles) {
- for (const action of role.strategy.actions) {
+ const actions = role?.strategy?.actions || [];
+ for (const action of actions) {
...
}
}
パッチを適用します。
npx patch-package @nocobase/plugin-action-export
初期インストールと起動確認
yarn nocobase install --lang=ja-JP
開発モードで起動して動作を確認します。
yarn dev
yarn start
ブラウザでアクセスして初期設定画面が表示されれば OK です。
systemd サービス化
本番運用にするには、systemd でサービスとして登録します。
専用ユーザーを作成します。
useradd -r -M -d /srv/my-nocobase-app -s /usr/sbin/nologin nocobase
chown -R nocobase:nocobase /srv/my-nocobase-app
ユニットファイルを作成します。
vi /etc/systemd/system/nocobase.service
[Unit]
Description=nocoBase
After=network.target
[Service]
Type=simple
User=nocobase
Group=nocobase
WorkingDirectory=/srv/my-nocobase-app
EnvironmentFile=/srv/my-nocobase-app/.env
ExecStart=/usr/bin/env NODE_ENV=production /usr/bin/yarn start
Restart=on-failure
RestartSec=5
LimitNOFILE=10000
[Install]
WantedBy=multi-user.target
サービスを有効化して起動します。
chmod +x /etc/systemd/system/nocobase.service
systemctl daemon-reload
systemctl enable --now nocobase
ログの確認はこちらです。
journalctl -u nocobase -f
Nginx リバースプロキシ設定
外部から HTTPS でアクセスできるように、Nginx でリバースプロキシを設定します。
dnf install -y nginx
SSL 証明書の作成
自己-signed 証明書を作成します。本番環境では Let’s Encrypt を使うのがおすすめです。
cd /etc/nginx/
mkdir ssl
cd ssl
openssl genrsa 2048 > server.key
openssl req -new -key server.key > server.csr
openssl x509 -days 3650 -req -sha256 -signkey server.key < server.csr > server.crt
Nginx の設定ファイル
cd /etc/nginx/conf.d/
vi nocobase.conf
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name example.com;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
location / {
proxy_pass http://127.0.0.1:13000;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/12;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2a06:98c0::/29;
set_real_ip_from 2c0f:f248::/32;
real_ip_header CF-Connecting-IP;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
set_real_ip_from は Cloudflare の IP 範囲です。Cloudflare を通さない場合は削除しても大丈夫です。
Nginx を再起動します。
systemctl restart nginx
systemctl enable nginx
まとめ
以上で nocoBASE のインストールと設定は完了です。https://example.com にアクセスして動作を確認してください。
途中でハマりやすいポイントとしては、以下の点が挙げられます。
- パッチの適用: エクスポート関連のバグはパッチなしではエラーになることがある
- .env の設定:
INIT_ROOT_*を忘れると管理者アカウントが作成されない - Cloudflare の real_ip: 設定しないとアクセスログの IP が全部 Cloudflare のものになる
公式ドキュメントも合わせて確認すると良いと思います。