Ubuntu ServerにSharkeyをインストールする
お一人鯖作ってみてた際に横着してDockerでインストールしてたけど突如マニュアルインストールしてみようと思った
動機はマニュアルの方がDocker版よりパフォーマンスよかったりしないかな、程度SharkeyはMisskeyのフォーク
ノート編集などの機能拡張されてたりUIが弄ってあったりlistenbrainz連携が出来たりする
お金はなるべく書けない方向で行きたいので自宅で稼働しているミニPC(Ubuntu Server 22.04)とCloudflareで構築する
ドメインはCloudflareに移管済みなのでここでは割愛
Node.jsすら入れてなかったので入れる
sudo apt install -y nodejs npm
なんかやけに古いのが入ってくる
node -v
v12.22.9
n を入れる
sudo npm install n -g
n でstable(LTS?)を入れる
sudo n stable
installing : node-v20.12.1
mkdir : /usr/local/n/versions/node/20.12.1
fetch : https://nodejs.org/dist/v20.12.1/node-v20.12.1-linux-x64.tar.xz
copying : node/20.12.1
installed : v20.12.1 (with npm 10.5.0)
入れただけだと古い方が使われるまま
node -v
v12.22.9
そのままだと変わらんのでrehashする
hash -r
node -v
v20.12.1
うむ
最初に入れたnodeは消す
sudo apt purge -y nodejs npm
sudo apt autoremove -y
pnpm入れる
curl -fsSL https://get.pnpm.io/install.sh | sh -
==> Downloading pnpm binaries 8.15.6
WARN using --force I sure hope you know what you are doing
Copying pnpm CLI from /tmp/tmp.dFA5j4tbmm/pnpm to /home/***/.local/share/pnpm/pnpm
Appended new lines to /home/***/.bashrc
Next configuration changes were made:
export PNPM_HOME="/home/***/.local/share/pnpm"
case ":$PATH:" in
*":$PNPM_HOME:"*) ;;
*) export PATH="$PNPM_HOME:$PATH" ;;
esac
To start using pnpm, run:
source /home/***/.bashrc
ユーザ名伏せるのが面倒くさい
ちゃんと入ったか見ておく
pnpm -v
8.15.6
うむ
postgreSQLとredisが必要らしいので入れる
sudo apt install postgresql postgresql-contrib redis-server
redisの設定を変える
sudo vi /etc/redis/redis.conf
...
# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
# supervised no - no supervision interaction
# supervised upstart - signal upstart by putting Redis into SIGSTOP mode
# requires "expect stop" in your upstart job config
# supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
# supervised auto - detect upstart or systemd method based on
# UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
# They do not enable continuous pings back to your supervisor.
- supervised no
+ supervised systemd
...
redis再起動
sudo systemctl restart redis.service
sudo systemctl status redis
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2024-04-07 15:53:51 UTC; 11s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 1242240 (redis-server)
Status: "Ready to accept connections"
Tasks: 5 (limit: 9198)
Memory: 2.6M
CPU: 190ms
CGroup: /system.slice/redis-server.service
└─1242240 "/usr/bin/redis-server 127.0.0.1:6379" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">
Apr 07 15:53:51 **** systemd[1]: Starting Advanced key-value store...
Apr 07 15:53:51 **** systemd[1]: Started Advanced key-value store.
うむ
build-essential
は入れた記憶ないけどもう入ってた
sudo apt install build-essential
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
build-essential is already the newest version (12.9ubuntu3).
build-essential set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
corepack
を有効化しろとのこと
sudo corepack enable
これなんだ?と思ったらパッケージマネージャのマネージャらしい
n いらなかったのでは?misskey側のドキュメント参照すると色々入れ方がなんか違う
node.jsはもういいとしてそれ以外はmisskey側の手法でやり直す
sudo apt purge postgresql postgresql-contrib redis-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libjemalloc2 liblua5.1-0 liblzf1 lua-bitop lua-cjson redis-tools
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
postgresql* postgresql-contrib* redis-server*
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
After this operation, 339 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 116512 files and directories currently installed.)
Removing postgresql (14+238) ...
Removing postgresql-contrib (14+238) ...
Removing redis-server (5:6.0.16-1ubuntu1) ...
Processing triggers for man-db (2.10.2-1) ...
(Reading database ... 116495 files and directories currently installed.)
Purging configuration files for redis-server (5:6.0.16-1ubuntu1) ...
依存してたパッケージも消す
sudo apt autoremove
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
libjemalloc2 liblua5.1-0 liblzf1 lua-bitop lua-cjson redis-tools
0 upgraded, 0 newly installed, 6 to remove and 0 not upgraded.
After this operation, 5530 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 116490 files and directories currently installed.)
Removing redis-tools (5:6.0.16-1ubuntu1) ...
Removing libjemalloc2:amd64 (5.2.1-4ubuntu1) ...
Removing liblua5.1-0:amd64 (5.1.5-8.1build4) ...
Removing liblzf1:amd64 (3.6-3) ...
Removing lua-bitop:amd64 (1.0.2-5) ...
Removing lua-cjson:amd64 (2.1.0+dfsg-2.1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.6) ...
postgreSQL
入れる
sudo apt install -y postgresql-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
postgresql-common is already the newest version (238).
postgresql-common set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
あれ?なんかもういたらしい
ver15入れろってmisskeyには記載あったけど16が出ていたので16を入れる
料理初心者がよくやる勝手アレンジして後で死にそうなやつ
sudo sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -i -v 16;
active
だけどexited
なのはいいのか?まぁいいか
systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Sun 2024-04-07 15:53:01 UTC; 31min ago
Main PID: 1241092 (code=exited, status=0/SUCCESS)
CPU: 2ms
Apr 07 15:53:01 sakichan systemd[1]: Starting PostgreSQL RDBMS...
Apr 07 15:53:01 sakichan systemd[1]: Finished PostgreSQL RDBMS.
sharkeyの手順によると先にユーザを作るらしい
多分どっちでもいい気はするけど書いてあるとおりにする
sudo adduser --disabled-password --disabled-login sharkey
作ったユーザに切り替える
sudo -u sharkey -i
git cloneしてきてconfigファイル作るいつものやつ
git clone --recurse-submodules -b stable https://activitypub.software/TransFem-org/Sharkey.git
cd Sharkey
pnpm install --frozen-lockfile
cp .config/example.yml .config/default.yml
ここは各々の環境に合わせて変えろって言われるところ
URLはいつも通り一度サービス立ち上げたら二度と変えるなよって凄い念押しされる
DockerのときはDBは初期値のままでいいぞだったけど今回はちゃんと設定しろってことらしい
DB名sharkeyでなくていい気はするけど言われたとおりにしておく
url: https://{YOUR DOMAIN NAME}/
db:
host: localhost
port: 5432
db: sharkey
user: sharkey
pass: {YOUR PASSWORD}
ビルドしろとのこと
えっもう?
pnpm run build
> sharkey@2024.3.2 build /home/sharkey/Sharkey
> pnpm build-pre && pnpm -r build && pnpm build-assets
> sharkey@2024.3.2 build-pre /home/sharkey/Sharkey
> node ./scripts/build-pre.js
Scope: 8 of 9 workspace projects
packages/megalodon build$ tsc -p ./
└─ Done in 21.6s
packages/misskey-bubble-game build$ node ./build.js
└─ Done in 393ms
packages/misskey-js build$ npm run ts
│ > misskey-js@2024.3.1 ts
│ > npm run ts-esm && npm run ts-dts
│ > misskey-js@2024.3.1 ts-esm
│ > tsc --outDir built/esm
│ > misskey-js@2024.3.1 ts-dts
│ > tsc --outDir built/dts --declaration true --emitDeclarationOnly true --declarationMap true
└─ Done in 33.5s
packages/misskey-reversi build$ node ./build.js
└─ Done in 409ms
packages/backend build$ swc src -d built -D
│ Successfully compiled: 835 files, copied 27 files with swc (127.31ms)
└─ Done in 2.6s
packages/frontend build$ vite build
[897 lines collapsed]
│ ../../built/_vite_/U2AD61IU.js 169.59 kB
│ ../../built/_vite_/CsyrCbsw.js 170.83 kB
│ ../../built/_vite_/DC8MraHL.js 174.98 kB
│ ../../built/_vite_/B9E_xdxs.js 177.39 kB
│ ../../built/_vite_/Hx0vEw0N.js 261.10 kB
│ ../../built/_vite_/BICIrM8O.js 264.33 kB
│ ../../built/_vite_/DfzD-Ju7.js 301.56 kB
│ ../../built/_vite_/app-Ciznv2_q.js 466.69 kB
│ ../../built/_vite_/BOnd8D4O.js 628.28 kB
│ ✓ built in 1m 7s
└─ Done in 1m 10.8s
packages/sw build$ node build.js
│ (node:1293453) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
│ (Use `node --trace-warnings ...` to show where the warning was created)
│ Starting SW building...
│ done
└─ Done in 1.8s
> sharkey@2024.3.2 build-assets /home/sharkey/Sharkey
> node ./scripts/build-assets.mjs
(node:1294799) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
うちのぽんこつミニPCでも出来た
思ってたより全然早い
postgreSQL
のDB作れと言われる
sudo -u postgres psql
さっき作ったsharkey
のユーザはパスワード設定してなかったはずが一生聞かれて入れないので元のユーザに戻って仮パスワード作って再度実行
{YOUR_PASSWORD}
はさっきdefault.yml
で決めたやつ
CREATE DATABASE sharkey WITH ENCODING = 'UTF8';
CREATE USER sharkey WITH ENCRYPTED PASSWORD '{YOUR_PASSWORD}';
GRANT ALL PRIVILEGES ON DATABASE sharkey TO sharkey;
ALTER DATABASE sharkey OWNER TO sharkey;
\q
マイグレーション実行
pnpm run init
立ち上がるか確認
pnpm start
> sharkey@2024.3.2 start /home/sharkey/Sharkey
> pnpm check:connect && cd packages/backend && node ./built/boot/entry.js
> sharkey@2024.3.2 check:connect /home/sharkey/Sharkey
> cd packages/backend && pnpm check:connect
> backend@ check:connect /home/sharkey/Sharkey/packages/backend
> node ./check_connect.js
file:///home/sharkey/Sharkey/packages/backend/check_connect.js:14
throw e;
^
Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 6379
}
Node.js v20.12.1
ELIFECYCLE Command failed with exit code 1.
ELIFECYCLE Command failed with exit code 1.
ELIFECYCLE Command failed with exit code 1.
はいだめ
ポート6379が駄目ってことは何かってことで調べたらredis
らしい
動いてるか?
systemctl status redis-server
Unit redis-server.service could not be found.
そういやさっき消したわ
misskey側記載の方法で入れる
sudo snap install redis
redis 7.2.4 from Redis (redislabs) installed
動いてるか確認
systemctl status redis-server
Unit redis-server.service could not be found.
えぇ…
Ubuntu Server 22.04からは駄目みたい?
Ubuntu 22.04.4 LTS
なので駄目みたいですね
消してリポジトリ登録する方法で入れ直すことにする
下記で入れる
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
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-get update
sudo apt-get install redis
今度は大丈夫みたい?
systemctl status redis-server
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; disabled; vendor preset: enabled)
Active: active (running) since Sun 2024-04-07 17:17:33 UTC; 16s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 1317139 (redis-server)
Status: "Ready to accept connections"
Tasks: 6 (limit: 9198)
Memory: 3.0M
CPU: 168ms
CGroup: /system.slice/redis-server.service
└─1317139 "/usr/bin/redis-server 127.0.0.1:6379" "" "" "" "" "" "" ""
動かしてみる
pnpm start
> sharkey@2024.3.2 start /home/sharkey/Sharkey
> pnpm check:connect && cd packages/backend && node ./built/boot/entry.js
> sharkey@2024.3.2 check:connect /home/sharkey/Sharkey
> cd packages/backend && pnpm check:connect
> backend@ check:connect /home/sharkey/Sharkey/packages/backend
> node ./check_connect.js
_____ _ _
/ ___| | | |
`--.| |__ __ _ _ __| | _____ _ _
`--. '_ / _` | '__| |/ / _ | | |
/__/ / | | | (_| | | | < __/ |_| |
____/|_| |_|__,_|_| |_|____|__, |
__/ |
|___/
Sharkey is an open-source decentralized microblogging platform.
If you like Sharkey, please donate to support development. https://ko-fi.com/transfem
--- **** (PID: 1317606) ---
INFO * [core boot] Welcome to Sharkey!
INFO * [core boot] Sharkey v2024.3.2
INFO * [core boot env] NODE_ENV is not set
WARN * [core boot env] The environment is not in production mode.
WARN * [core boot env] DO NOT USE FOR PRODUCTION PURPOSE!
VERB * [core boot machine] Hostname: ****
VERB * [core boot machine] Platform: linux Arch: x64
VERB * [core boot machine] CPU: 4 core MEM: 7.6GB (available: 6.0GB)
INFO * [core boot nodejs] Version v20.12.1 detected.
DONE * [core boot config] Loaded
DONE * [core boot] Sharkey initialized
INFO * [core nest] NestFactory: Starting Nest application...
INFO * [core nest] InstanceLoader: MainModule dependencies initialized
INFO * [core nest] InstanceLoader: QueueModule dependencies initialized
INFO * [db sql] SELECT * FROM current_schema()
INFO * [db sql] info
INFO * [db sql] SELECT version();
INFO * [core nest] InstanceLoader: GlobalModule dependencies initialized
INFO * [core nest] InstanceLoader: RepositoryModule dependencies initialized
INFO * [core nest] InstanceLoader: DaemonModule dependencies initialized
INFO * [core nest] InstanceLoader: ServerModule dependencies initialized
INFO * [core nest] InstanceLoader: EndpointsModule dependencies initialized
INFO * [core nest] InstanceLoader: CoreModule dependencies initialized
INFO * [core boot] Starting 1 worker...
VERB * [core cluster] Process forked: [1]
INFO * [db sql] START TRANSACTION
INFO * [db sql] SELECT "MiMeta"."id" AS "MiMeta_id", "MiMeta"."name" AS "MiMeta_name",
VERB * [core cluster] Process is now online: [1]
INFO * [db sql] INSERT INTO "meta"("id", "name", "shortName", "description", "maintainerName", "
INFO * [db sql] SELECT "MiMeta"."id" AS "MiMeta_id", "MiMeta"."name" AS "MiMeta_name",
INFO * [db sql] COMMIT
INFO 1 [core nest] NestFactory: Starting Nest application...
INFO 1 [core nest] InstanceLoader: QueueModule dependencies initialized
INFO 1 [db sql] SELECT * FROM current_schema()
INFO 1 [db sql] info
INFO 1 [db sql] SELECT version();
INFO 1 [core nest] InstanceLoader: GlobalModule dependencies initialized
INFO 1 [core nest] InstanceLoader: RepositoryModule dependencies initialized
INFO 1 [core nest] InstanceLoader: CoreModule dependencies initialized
INFO 1 [core nest] InstanceLoader: QueueProcessorModule dependencies initialized
DONE * [core boot] All workers started
DONE * [core boot] Now listening on port 3000 on https://****
大丈夫そう
cloudflaredでtunnelはもう作ってあったのでこの時点で本番URLからはもう見れてたりする
外部から初期ユーザ作成画面が見れちゃってるということはさっさと管理者登録しないとやばいことに気づいて慌てて登録した
さっき立ち上げたのは一回落としてsystemd
登録する
sudo vi /etc/systemd/system/sharkey.service
[Unit]
Description=Sharkey daemon
[Service]
Type=simple
User=sharkey
ExecStart=/usr/bin/pnpm start
WorkingDirectory=/home/sharkey/Sharkey
Environment="NODE_OPTIONS=--max-old-space-size=8192"
Environment="NODE_ENV=production"
TimeoutSec=60
StandardOutput=journal
StandardError=journal
SyslogIdentifier=sharkey
Restart=always
[Install]
WantedBy=multi-user.target
再読み込み
sudo systemctl daemon-reload
サービス有効化
sudo systemctl enable sharkey
Created symlink /etc/systemd/system/multi-user.target.wants/sharkey.service → /etc/systemd/system/sharkey.service.
立ち上げる
systemctl status sharkey
× sharkey.service - Sharkey daemon
Loaded: loaded (/etc/systemd/system/sharkey.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2024-04-07 17:36:47 UTC; 6s ago
Process: 1318561 ExecStart=/usr/bin/pnpm start (code=exited, status=203/EXEC)
Main PID: 1318561 (code=exited, status=203/EXEC)
CPU: 3ms
why...?
pnpmのパスがサンプルと違ったらしい
which pnpm
/usr/local/bin/pnpm
サービス修正
[Unit]
Description=Sharkey daemon
[Service]
Type=simple
User=sharkey
- ExecStart=/usr/bin/pnpm start
+ ExecStart=/usr/local/bin/pnpm start
WorkingDirectory=/home/sharkey/Sharkey
Environment="NODE_OPTIONS=--max-old-space-size=8192"
Environment="NODE_ENV=production"
TimeoutSec=60
StandardOutput=journal
StandardError=journal
SyslogIdentifier=sharkey
Restart=always
[Install]
WantedBy=multi-user.target
再起動
sudo systemctl daemon-reload
sudo systemctl restart sharkey
systemctl status sharkey
● sharkey.service - Sharkey daemon
Loaded: loaded (/etc/systemd/system/sharkey.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2024-04-07 17:38:05 UTC; 4s ago
Main PID: 1318661 (node)
Tasks: 23 (limit: 9198)
Memory: 157.4M
CPU: 5.138s
CGroup: /system.slice/sharkey.service
├─1318661 node /usr/local/bin/pnpm start
├─1318676 sh -c "pnpm check:connect && cd packages/backend && node ./built/boot/entry.js"
└─1318715 node ./built/boot/entry.js
Apr 07 17:38:06 *** sharkey[1318661]: > sharkey@2024.3.2 start /home/sharkey/Sharkey
Apr 07 17:38:06 *** sharkey[1318661]: > pnpm check:connect && cd packages/backend && node ./built/boot/entry.js
Apr 07 17:38:07 *** sharkey[1318677]: > sharkey@2024.3.2 check:connect /home/sharkey/Sharkey
Apr 07 17:38:07 *** sharkey[1318677]: > cd packages/backend && pnpm check:connect
Apr 07 17:38:08 *** sharkey[1318689]: > backend@ check:connect /home/sharkey/Sharkey/packages/backend
Apr 07 17:38:08 *** sharkey[1318689]: > node ./check_connect.js
とりあえずこれで構築は良いみたい
パフォーマンスとかはしばらく様子見するとして構築はこれでおしまい