wiki.js部署指南

1、环境准备

1.1 安装nodejs

1
2
3
4
5
6
7
8
9
tar -xvf node-v16.15.0-linux-x64.tar.gz
mv node-v16.15.0-linux-x64/ nodejs_16.15
cd nodejs_16.15/

# 设置环境变量
vim /etc/profile
export NODE_HOME=/opt/nodejs_16.15
export PATH=$NODE_HOME/bin:$PATH:$NODE_HOME/data/node_global/bin

1.2 安装PostgreSQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
rpm -Uvh https://mirrors.aliyun.com/postgresql/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

sed -i "s@https://download.postgresql.org/pub@https://mirrors.aliyun.com/postgresql@g" /etc/yum.repos.d/pgdg-redhat-all.repo

# 安装最新版本
yum install -y postgresql

# 安装PostgreSQL 13
yum install -y postgresql13-server

# 初始化PostgreSQL
sudo -u postgres /usr/pgsql-13/bin/initdb

# 启动服务
systemctl start postgresql-13

# 设置服务开机自启
systemctl enable postgresql-13

# 查看服务状态
systemctl status postgresql-13

1.3 创建数据库及用户

1
2
3
4
5
6
7
8
9
10
sudo -u postgres psql

# 创建用户
CREATE USER wiki WITH PASSWORD 'wikijs';

# 创建数据库
CREATE DATABASE wiki OWNER wiki;

# 授权
GRANT ALL PRIVILEGES ON DATABASE wiki TO wiki;

2、下载wiki.js包

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

3、解压

1
2
3
mkdir wiki
tar xzf wiki-js.tar.gz -C ./wiki
cd ./wiki

4、修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
mv config.sample.yml config.yml
vim config.yml

#######################################################################
# Wiki.js - CONFIGURATION #
#######################################################################
# Full documentation + examples:
# https://docs.requarks.io/install

# ---------------------------------------------------------------------
# Port the server should listen to
# ---------------------------------------------------------------------

port: 3001

# ---------------------------------------------------------------------
# Database
# ---------------------------------------------------------------------
# Supported Database Engines:
# - postgres = PostgreSQL 9.5 or later
# - mysql = MySQL 8.0 or later (5.7.8 partially supported, refer to docs)
# - mariadb = MariaDB 10.2.7 or later
# - mssql = MS SQL Server 2012 or later
# - sqlite = SQLite 3.9 or later

db:
type: postgres

# PostgreSQL / MySQL / MariaDB / MS SQL Server only:
host: localhost
port: 5432
user: wiki
pass: wikijs
db: wiki
ssl: false

# Optional - PostgreSQL / MySQL / MariaDB only:
# -> Uncomment lines you need below and set `auto` to false
# -> Full list of accepted options: https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
sslOptions:
auto: true
# rejectUnauthorized: false
# ca: path/to/ca.crt
# cert: path/to/cert.crt
# key: path/to/key.pem
# pfx: path/to/cert.pfx
# passphrase: xyz123

# Optional - PostgreSQL only:
schema: public

# SQLite only:
# storage: path/to/database.sqlite

#######################################################################
# ADVANCED OPTIONS #
#######################################################################
# Do not change unless you know what you are doing!

# ---------------------------------------------------------------------
# SSL/TLS Settings
# ---------------------------------------------------------------------
# Consider using a reverse proxy (e.g. nginx) if you require more
# advanced options than those provided below.

ssl:
enabled: false
port: 3443

# Provider to use, possible values: custom, letsencrypt
provider: custom

# ++++++ For custom only ++++++
# Certificate format, either 'pem' or 'pfx':
format: pem
# Using PEM format:
key: /opt/certs/wiki.zhoumx.net/wiki.zhoumx.net.key
cert: /opt/certs/wiki.zhoumx.net/fullchain.cer
# Using PFX format:
pfx: path/to/cert.pfx
# Passphrase when using encrypted PEM / PFX keys (default: null):
passphrase: null
# Diffie Hellman parameters, with key length being greater or equal
# to 1024 bits (default: null):
dhparam: null

# ++++++ For letsencrypt only ++++++
domain: wiki.yourdomain.com
subscriberEmail: admin@example.com

# ---------------------------------------------------------------------
# Database Pool Options
# ---------------------------------------------------------------------
# Refer to https://github.com/vincit/tarn.js for all possible options

pool:
# min: 2
# max: 10

# ---------------------------------------------------------------------
# IP address the server should listen to
# ---------------------------------------------------------------------
# Leave 0.0.0.0 for all interfaces

bindIP: 0.0.0.0

# ---------------------------------------------------------------------
# Log Level
# ---------------------------------------------------------------------
# Possible values: error, warn, info (default), verbose, debug, silly

logLevel: info

# ---------------------------------------------------------------------
# Log Format
# ---------------------------------------------------------------------
# Output format for logging, possible values: default, json

logFormat: default

# ---------------------------------------------------------------------
# Offline Mode
# ---------------------------------------------------------------------
# If your server cannot access the internet. Set to true and manually
# download the offline files for sideloading.

offline: false

# ---------------------------------------------------------------------
# High-Availability
# ---------------------------------------------------------------------
# Set to true if you have multiple concurrent instances running off the
# same DB (e.g. Kubernetes pods / load balanced instances). Leave false
# otherwise. You MUST be using PostgreSQL to use this feature.

ha: false

# ---------------------------------------------------------------------
# Data Path
# ---------------------------------------------------------------------
# Writeable data path used for cache and temporary user uploads.
dataPath: /opt/wiki

# ---------------------------------------------------------------------
# Body Parser Limit
# ---------------------------------------------------------------------
# Maximum size of API requests body that can be parsed. Does not affect
# file uploads.

bodyParserLimit: 5mb

5、运行wiki.js

1
node server

6、配置nginx反向代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
server
{
listen 80;
listen [::]:80;
server_name 域名;
return 301 https://域名$request_uri;
access_log /home/wwwlogs/wiki.log;
}

server
{
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name 域名;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/wiki;

ssl_certificate 证书;
ssl_certificate_key 私钥;
ssl_session_timeout 5m;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_session_cache builtin:1000 shared:SSL:10m;
# openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

include rewrite/other.conf;
#error_page 404 /404.html;

# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

include enable-php.conf;

location / {
proxy_pass http://127.0.0.1:3001;
}

access_log /home/wwwlogs/wiki.log;
}

7、作为服务运行,加入systemd

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
vim /etc/systemd/system/wiki.service

[Unit]
Description=Wiki.js
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/node server
Restart=always
# Consider creating a dedicated user for Wiki.js here:
User=nobody
Environment=NODE_ENV=production
WorkingDirectory=/home/wwwroot/wiki

[Install]
WantedBy=multi-user.target

运行服务

1
systemctl start wiki

在系统启动时启用该服务

1
systemctl enable wiki

8、wiki迁移

备份数据库

1
/usr/pgsql-13/bin/pg_dump  -h 127.0.0.1 -p 5432 -U wiki -F c > wikibackup.dump

还原数据库

1
/usr/pgsql-13/bin/pg_restore -h 127.0.0.1 -p 5432 -U wiki -d wiki -v wikibackup.dump

9、查看日志

1
journalctl -u wiki

wiki.js部署指南
https://www.zhoumx.net/2022/10/16/wiki.js_install/
作者
阿星
发布于
2022年10月16日
许可协议