基于wikijs搭建局域网下的内部知识库

工作中会遇到许多值得总结的案例,一般我会注意收集相关文件保存起来,但是具体的值得注意的点都记录在独立的zim笔记中,两者不关联。这种方式也几乎无法内部交流。遂萌生了搭建局域网知识库的想法,一番比较之后,决定使用 wikijs 搭建。

本文的方式是在个人服务器上通过apt包管理器分别安装,没有使用 docker 容器,这并非不想,而是尝试之后而放弃的。实际上,我最初就是照着 wikijs 官网的 docker 教程安装的,但是安装完毕,在网页输入管理员邮箱等信息后,会遇到报 Unknown authentication strategy "jwt" 错误且在日志文件中报Fetching latest updates from Graph endpoint failed的错误,网页联网异常,而且语言文件加载失败。我尝试了 troubleshoting 以及网络上其他的处理方式(设置 offline)等均无法解决。因此只能尝试基于 linux 包管理器独立安装。

该笔记也不是对安装过程的原始记录,而是在顺利安装后对安装过程的回顾与整理,以资备忘。里面不排除存在细节错误的问题,不过应该都可以在网络检索后轻松解决。

该安装记录基于ubuntu 22.04 jammy 的服务器版本,无图形用户界面。

安装 postgreSQL

# search to confirm postgres version in package repo
apt list postgresql
# >14+258

# install postgresql
sudo apt-get install postgresql postgresql-contrib

# during installation, a linux user named `postgres` will created. it seems its password is null, i am not really sure.

配置 postgreSQL

# all the operation is under user postgres
# change current user
sudo su - postgres

# you can type `exit` after all job finished to back to your origin login user on linux

# I want craeate all the data in my ext disk, so create database folder `postgres` on it
mkdir /mnt/filedisk/postgres

# change folder owner to postgres, optional
sudo chown postgres:postgres /mnt/filedisk/postgres

# after above, you need enter postgres cli to finish database operation
# enter db cli
psql

#all the db cli command will lead by `postgres~#`
CREATE TABLESPACE wikispace LOCATION '/mnt/filedisk/postgres';
# that will crate a tablespace in /mnt/filedisk/postgres to store database we desired, all sql sentence need semicolon at end.

CREATE DATABASE wikidb TABLESPACE wikispace;
#that create a wikidb database in /mnt/.../postgres/

CREATE ROLE wikijs WITH LOGIN;
\password wikijs;
# that create a database role for wikijs app and set its password

GRANT ALL PRIVILEGES ON DATABASE wikidb TO wikijs;
# make wikijs as the wikidb owner

\q
#exit postgres cli

# you can use \l to list database, \db to list tablespace and \? to get command help

安装 nodejs

apt list nodejs
#> 12

sudo apt-get install nodejs

# you can test installation with `nodejs -v`

安装 wikijs

# create a special user for wikijs app in linus OS
sudo adduser wikijs

# create app directory
mkdir /mnt/filedisk/www
mkdir /mnt/filedisk/WWW/wikijs

chown wikijs:wikijs /mnt/filedisk/www
chown wikijs:wikijs /mnt/filedisk/www/wikijs

For better speed experience, you may install v2ray and its frontend, also if installed you need correctly config it and get avialable vpn subscribtion.

sudo su - wikijs

cd /mnt/filedisk/www/wikijs

wget https://github.com/Requarks/wiki/releases/latest/download/wiki-js.tar.gz

tar xzf wiki-js.tar.gz

配置 wikijs

# still in /mnt/filedisk/www/wikijs
cp config.sample.yml config.yml

In config.yml.just change the username and user password to connect to postgreaql.

I mean for simple setting, just change db:wikidb and pass:**** , the other are default.

also change port:3000 to port:80.

#in folder wikijs
node server
#run the app,use ip addrss to access wiki site. blocked by ufw. may need sudo node server
# allow in connection in firewall
sudo ufw allow 80

# apply above rule
sudo ufw enable

# check your firewall rule
sudo ufw status

until now , you can access 192.168.0.100:80 to get the init site, or simply 192.168.0.100

配置 wikijs 服务

in order to run wikijs as service for autorestart and autorun while booting, you need create a wikijs service.

sudo vim /etc/systemd/system/wikijs.service
# create and edit wikijs service config
[Unit]
Description=Wiki.js
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/node server
Restart=always

User=root
Environment=NODE_ENV=production
WorkingDirectory=/mnt/filedisk/wikijs

[Install]
WantedBy=multi-user.target

note: you must set User=root in service config, for all port less than 1000 on linux will need root authority.

sudo systemctl daemon-reload
# reload config setting in systemctl process


sudo systemctl start wikijs.service
# start service

sudo systemctl enable wikijs.service
# set autorun when boot
参考链接

sql-createdatabase

sql-createtablespace

Install Wiki.js with Node.js, PostgreSQL, and Nginx on Ubuntu 20.04 LTS

wikijs official doc