wiki.js 部署
1 前言
找了许久的个人知识库系统,迟迟没有动作。经过了解后感觉wiki.js还不错,这个系列文章详细描述一下全过程。
wifi.js可以满足我的以下要求:
- 支持文档在线编辑
- 支持二进制文件上传和下载
- 支持历史记录和回滚
- 支持用户账号分权
- 支持数据和nas同步
这个系列打算用三个篇章来描述,分别是部署和使用以及迁移。
本篇文章是wifi.js系列的第一篇,wifi.js部署
参考:
1. Wiki.js | Wiki.js (requarks.io)
2. Wiki.js 本地部署 - 我的全新 Hugo 网站 (xja.github.io)
3.Install Wiki.js with Node.js, PostgreSQL, and Nginx on Ubuntu 20.04 LTS | Vultr Docs
2 部署
wiki.js可以部署在众多操作系统中,可以说只要支持node.js就可以实现部署了。这个讲的是wifi.js部署再ubuntu-22.04操作系统上的。
2.1目标机器
- Docker
- Kubernetes
- Linux
- macOS
- Windows
我们选择安装在原生的ubuntu上面
2.2wifi.js依赖
wiki.js的运行依赖以下几个条件:
- node.js环境
- PostgreSQL 15
本篇介绍的安装都是基于源码的安装方法:简单,直接,明了。
2.3 nodejs
为了后面便于追溯问题,我们选一个固定的release版本而不是最新的版本
2.3.1 nodejs下载
Index of /dist/latest-v16.x/ (nodejs.org)
$ mkdir nodejs
$ cd nodejs
$ wget https://nodejs.org/dist/latest-v16.x/node-v16.20.2.tar.xz
$ tar xf node-v16.20.2.tar.xz
$ cd node-v16.20.2/
$ ./configure --prefix=$(pwd)/local
$ make
$ make install
$ node -v
2.3.2 使用nvm下载&安装比源码安装好很多
# sudo adduser nodejs
[sudo] password for bl616:
Adding user `nodejs' ...
Adding new group `nodejs' (1002) ...
Adding new user `nodejs' (1002) with group `nodejs' ...
Creating home directory `/home/nodejs' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for nodejs
Enter the new value, or press ENTER for the defaultFull Name []:Room Number []:Work Phone []:Home Phone []:Other []:
Is the information correct? [Y/n]$ su - nodejs
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
$ nvm install 16.15.1
$ node --version
2.4 PostgreSQL
Ubuntu源码安装配置PostgreSQL_postgres:x:1001:-CSDN博客
2.4.1 PostgreSQL下载
$ sudo apt-get install libicu-dev
$ mkdir postgresql
$ cd postgresql/
$ wget https://ftp.postgresql.org/pub/source/v16.2/postgresql-16.2.tar.bz2
$ tar xf postgresql-16.2.tar.bz2
$ cd postgresql-16.2/
$ mkdir local
$ ./configure --prefix=$(pwd)/local
$ make
$ make install
2.4.2 PostgreSQL安装
2.4.3 PostgreSQL配置
2.4.3.1添加postgres用户和用户组
$sudo adduser postgres
Adding user `postgres' ...
Adding new group `postgres' (1001) ...
Adding new user `postgres' (1001) with group `postgres' ...
Creating home directory `/home/postgres' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for postgres
Enter the new value, or press ENTER for the defaultFull Name []:Room Number []:Work Phone []:Home Phone []:Other []:
Is the information correct? [Y/n] y
2.4.3.2创建数据目录
创建postgresql数据库的数据主目录并修改文件所有者
$ su - postgres
$ mkdir ~/data
2.4.3.3 配置环境
为了方便,可以将该bin路径添加到PATH变量中。
$ sudo vi /etc/profile
在末尾添加如下配置,PGHOME为pg的安装目录路径,PGDATA为pg的数据目录路径。
# PostsQL
export PGHOME=/opt/pgsql/pgsql-16.1
export PGDATA=/opt/pgsql/data
export PATH=$PATH:$PGHOME/bin
2.4.3.4 重新加载系统环境变量
source /etc/profile
2.4.3.5 初始化数据库
切换到postgre用户,并使用initdb初始化数据库
su - postgres
initdb
返回root用户,可以看到data目录下已经被初始化
cd /opt/pgsql/data/
ls
>base pg_hba.conf pg_notify pg_stat pg_twophase postgresql.auto.conf
global pg_ident.conf pg_replslot pg_stat_tmp PG_VERSION postgresql.conf
pg_commit_ts pg_logical pg_serial pg_subtrans pg_wal
pg_dynshmem pg_multixact pg_snapshots pg_tblspc pg_xact
2.4.3.6 启动postgresql
update-rc.d: error: postgresql Default-Start contains no runlevels, aborting.
这个报错的原因是:编辑/etc/init.d下的你的服务,头部#!/usr/bin/env bash 下添加如下内容:
### BEGIN INIT INFO
# Provides: XXX
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start XXX daemon at boot time
# Description: Start XXX daemon at boot time
### END INIT INFO
2.4.3.7 开机自启动
PostgreSQL的开机自启动脚本位于PostgreSQL源码目录的contrib/start-scripts路径下。linux文件即为linux系统上的启动脚本
$ ls postgresql-16.2/contrib/start-scripts/ -l
total 12
-rw-r--r-- 1 postgres postgres 1441 2月 6 2024 freebsd
-rw-r--r-- 1 postgres postgres 3526 2月 6 2024 linux
drwxrwxr-x 2 postgres postgres 4096 2月 6 2024 macos# 切换为root用户
$ su - bl616# 复制Linux文件到/etc/init.d目录下,更名为postgresql
$ sudo cp /home/postgres/pgsql/postgresql-16.2/contrib/start-scripts/linux /etc/init.d/postgresql# 修改postgresql文件属性,添加X属性
$ sudo chmod a+x /etc/init.d/postgresql# 修改/etc/init.d/postgresql文件的两个变量
prefix设置为postgresql的安装路径:/home/postgres/pgsql/postgresql-16.2/local
PGDATA设置为postgresql的数据目录路径:"/home/postgres/pgsql/data"# 设置postgresql服务开启自启动
sudo systemctl enable postgresql
2.4.3.8 确保postgres已经启动
$ psql
psql (16.2)
Type "help" for help.postgres=# help
You are using psql, the command-line interface to PostgreSQL.
Type: \copyright for distribution terms\h for help with SQL commands\? for help with psql commands\g or terminate with semicolon to execute query\q to quit
postgres-# quit
2.4.3.9 在数据中创建一个wikijs用户
postgres@ubuntu:~$ createuser --interactive
Enter name of role to add: wikijs
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
2.4.3.10在数据库中为wikijs设置密码
postgres@bl616-virtual-machine:~$ psql
psql (16.2)
Type "help" for help.postgres=# \password wikijs
Enter new password for user "wikijs":
Enter it again:
postgres=# CREATE DATABASE wikijs;
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE wikijs TO wikijs;
GRANT
postgres=# \q
2.5 wiki.js
2.5.1 wiki.js下载
$$ sudo adduser wikijs
[sudo] password for bl616:
Adding user `wikijs' ...
Adding new group `wikijs' (1003) ...
Adding new user `wikijs' (1003) with group `wikijs' ...
Creating home directory `/home/wikijs' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for wikijs
Enter the new value, or press ENTER for the defaultFull Name []:Room Number []:Work Phone []:Home Phone []:Other []:
Is the information correct? [Y/n]$ sudo usermod -aG nodejs wikijs
$ sudo mkdir -p /var/www/wikijs
$ sudo chown wikijs:wikijs /var/www/wikijs
$ su - wikijs
$ cd /var/www/wikijs
$ git clone https://github.com/requarks/wiki.git
$ git checkout v2.5.302
$ git checkout v2.5.302//这里迁出的分支名字为'HEAD detached at v2.5.302'
$ git checkout -b v2.5.302
2.5.2 使用
$ cp config.sample.yml config.yml