如何在Debian 9上安装wiki js
杨和超
・13 分钟阅读
使用不同的系统?
Wiki.js是一个免费的开源应用程序,它构建在node.js,MongoDB,git和Markdown之上,Wiki.js源代码是公共托管在gitHub ,本指南将向你展示,如何使用Nodejs MongoDB, PM2, nginx, git和Acme.sh在新的Debian 9实例上安装Wiki.js。
要求
- Node.js 6.9.0或更高版本
- MongoDB 3.2或更高版本
- Nginx
- Git 2.7.4或更高版本
- 一个符合git的存储库(公用或私有)(可选)
- 最小768MB内存
- 设置了
A
/AAAA
记录的域名
查看Debian版本。
lsb_release -ds
# Debian GNU/Linux 9.4 (stretch)
确保你的系统是最新的。
apt update && apt upgrade -y
安装必要的软件包。
apt install -y build-essential apt-transport-https sudo curl wget dirmngr sudo
使用sudo
访问创建一个新的non-root
用户帐户,并且切换到它。
adduser johndoe --gecos\\\"John Doe\\\"
usermod -aG sudo johndoe
su - johndoe
注:将johndoe
替换为你的用户名。
设置时区。
sudo dpkg-reconfigure tzdata
安装Git
在Debian上安装Git 。
sudo apt install -y git
验证Git版本。
git --version
# git version 2.11.0
安装Node.js
通过使用Node.js安装NodeSource来安装node.js 。
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt install -y nodejs
检查Node.js和npm版本。
node -v && npm -v
# v8.11.2
# 5.6.0
安装MongoDB
Wiki.js使用MongoDB作为数据库引擎,因此,我们需要在服务器上安装MongoDB ,我们将使用官方mongoDB个存储库进行安装。
安装MongoDB社区版。
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
echo\\\"deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/3.6 main\\\" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
sudo apt update
sudo apt install -y mongodb-org
检查版本。
mongo --version | head -n 1 && mongod --version | head -n 1
# MongoDB shell version v3.6.5
# db version v3.6.5
启用和启动MongoDB 。
sudo systemctl enable mongod.service
sudo systemctl start mongod.service
安装和配置Nginx
强烈建议在Wiki.js前面放置一个标准的web服务器,这样可以确保你可以使用SSL,多个网站,缓存和更多功能,我们将在本教程中使用Nginx,但是,任何其他服务器都可以,你只需要正确配置它。
安装Nginx 。
wget https://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
rm nginx_signing.key
sudo -s
printf\\\"deb https://nginx.org/packages/mainline/debian/ $(lsb_release -sc) nginxndeb-src https://nginx.org/packages/mainline/debian/ $(lsb_release -sc) nginxn\\\" >> /etc/apt/sources.list.d/nginx_mainline.list
exit
sudo apt update
sudo apt install -y nginx
检查版本。
sudo nginx -v
# nginx version: nginx/1.15.0
启用和启动Nginx 。
sudo systemctl enable nginx.service
sudo systemctl start nginx.service
将Nginx配置为Wiki.js应用程序的HTTP
或HTTPS
(如果你使用SSL )反向代理。
运行sudo vim /etc/nginx/conf.d/wiki.js.conf
然后用下面的基本反向代理配置填充它。
server {
listen [::]:80;
listen 80;
server_name wiki.example.com;
root /usr/share/nginx/html;
charset utf-8;
client_max_body_size 50M;
location /.well-known/acme-challenge/ {
allow all;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection\\\"upgrade\\\";
proxy_next_upstream error timeout http_502 http_503 http_504;
}
}
在上面的配置中你需要改变的唯一的东西是server_name
指令,如果你决定配置除3000
之外的其他端口,可能还有proxy_pass
指令,Wiki.js默认使用端口3000
。
检查配置。
sudo nginx -t
重新加载Nginx 。
sudo systemctl reload nginx.service
安装Acme.sh,并且获取let\\\'s Encrypt证书(可选)
不需要使用HTTPS保护你的wiki,但是,保护你的网站流量是一种很好的做法。为了从let\\\'s Encrypt获得一个SSL证书,我们将使用Acme.sh客户端,Acme.sh是一个纯unix shell软件,用于从let\\\'s Encrypt获得SSL证书,
下载并安装Acme.sh 。
sudo mkdir /etc/letsencrypt
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh
sudo ./acme.sh --install --home /etc/letsencrypt --accountemail your_email@example.com
cd ~
检查版本。
/etc/letsencrypt/acme.sh --version
# v2.7.9
获取wiki.example.com
的RSA和ECDSA证书。
# RSA 2048
sudo /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt -d wiki.example.com --webroot /usr/share/nginx/html --reloadcmd\\\"sudo systemctl reload nginx.service\\\" --accountemail your_email@example.com --ocsp-must-staple --keylength 2048
# ECDSA/ECC P-256
sudo /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt -d wiki.example.com --webroot /usr/share/nginx/html --reloadcmd\\\"sudo systemctl reload nginx.service\\\" --accountemail your_email@example.com --ocsp-must-staple --keylength ec-256
注意:不要忘记将wiki.example.com
替换为你的域名。
运行上述命令后,证书和密钥将在下列目录中。
- 用于RSA :
/etc/letsencrypt/wiki.example.com
目录, - 对于ecc/ecdsa :
/etc/letsencrypt/wiki.example.com_ecc
目录,
从let\\\'s Encrypt获得证书之后,我们需要配置Nginx以利用它们。
运行sudo vim /etc/nginx/conf.d/wiki.js.conf
再次将Nginx配置为HTTPS
反向代理。
server {
listen [::]$1 ssl http2;
listen 443 ssl http2;
listen [::]$2;
listen 80;
server_name wiki.example.com;
root /usr/share/nginx/html;
charset utf-8;
client_max_body_size 50M;
location /.well-known/acme-challenge/ {
allow all;
}
# RSA
ssl_certificate /etc/letsencrypt/wiki.example.com/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/wiki.example.com/example.com.key;
# ECDSA
ssl_certificate /etc/letsencrypt/wiki.example.com_ecc/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/wiki.example.com_ecc/example.com.key;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection\\\"upgrade\\\";
proxy_next_upstream error timeout http_502 http_503 http_504;
}
}
检查配置。
sudo nginx -t
重新加载Nginx 。
sudo systemctl reload nginx.service
安装Wiki.js
创建Wiki.js应该安装的空文档根目录。
sudo mkdir -p /var/www/wiki.example.com
导航到文档根目录。
cd /var/www/wiki.example.com
将/var/www/wiki.example.com
文件夹的所有权更改为用户johndoe
。
sudo chown -R johndoe:johndoe /var/www/wiki.example.com
从/var/www/wiki.example.com
文件夹中运行以下命令下载和安装Wiki.js 。
curl -sSo- https://wiki.js.org/install.sh | bash
你可以运行以下命令来查看当前安装的Wiki.js版本。
node wiki --version
# 1.0.78
安装完成后,系统会提示你运行配置向导。
运行以下命令启动配置向导。
node wiki configure
这将通知你导航到http://localhost:3000
以配置Wiki.js ,如果你在Wiki.js面前有Nginx,那么,这意味着你可以打开你的域名(例如。http://wiki.example.com
),而不是去localhost
。
使用浏览器,导航到http://wiki.example.com
,并且按照屏幕指示操作,在配置向导中输入的所有设置都保存在config.yml
文件中,配置向导将自动为你启动Wiki.js 。
设置PM2
默认情况下,在系统重新启动后,wiki不会自动启动,为了使它在开机时启动,我们需要设置PM2流程管理器,PM2作为本地NPM模块捆绑在Wiki.js中,因此我们不需要在全局上安装PM2.
告诉PM2将自身配置为启动服务。
/var/www/wiki.example.com/node_modules/pm2/bin/pm2 startup
最后,保存当前的PM2配置。
/var/www/wiki.example.com/node_modules/pm2/bin/pm2 save
使用PM2作为流程管理器,你的Wiki.js实例作为后台进程运行,你可以使用sudo reboot重新启动你的操作系统,并检查Wiki.js在重新引导后是否启动。