如何在CentOS 8上安装Wiki.js

时间:2020-02-23 14:30:55  来源:igfitidea点击:

本指南将讨论在CentOS 8 Linux机器上安装Wiki.js的理想步骤。
wiki.js是一个现代开源Wiki应用程序,内置于node.js,git和markdown。
Wiki.js可以安装在Linux,MacOS和Windows计算机上。
使用Wiki.js,我们可以使用内置的可视编辑器以广泛使用和简单的标记格式编写所有文档和Web内容。

我们写入的内容直接保存到Markdown(.md)文件中,并自动与远程GIT存储库同步。
我们可以从GIT存储库中读取所有内容。
下面我们可以找到wiki.js的主要功能。

Wiki.js的主要特征

它可以自由地使用和开放 - SourceBeautifly设计用于简单的Markdown Formathas集成访问控制 - 本地数据库或者外部认证提供商,如Microsoft帐户,Google ID,Facebook,Github,Slack或者LDAP(Active Directory).has直观资产管理灯宽重量和极其强大的威基.JS有一个内置的搜索引擎

系统设置要求

node.js 10.x或者lowerredis cachegit 2.x或者battra git符合符合的存储库(公共或者私人)(可选)

在CentOS 8上安装和配置Wiki.js

下一节将专注于在CentOS 8 Linux机器上安装Wiki.js。
我们首先安装所需的依赖项,然后继续安装和配置CentOS 8上的Wiki.js。

第1步:更新系统和设置时区

首先更新系统并设置正确的时区。

sudo yum -y update
sudo timedatectl list-timezones
sudo timedatectl set-timezone 'Africa/Nairobi'

第2步:为wiki.js创建专用用户

我们需要一个专用的系统用户来运行wiki.js应用程序。
让我们首先创建这个用户。

sudo groupadd --system wiki
sudo useradd -s /sbin/nologin --system -g wiki wiki

第3步:安装基本依赖包

让我们还安装在CentOS上运行Wiki.js所需的所有依赖性应用程序。
在Git,Unzip和Epel版本中

sudo yum install -y epel-release git vim wget curl unzip socat

安装node.js.

curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash 
sudo yum install -y nodejs nginx

安装MariaDB数据库服务器

sudo yum -y install @mariadb
sudo systemctl enable --now mariadb
sudo mysql_secure_installation

创建数据库用户和DB。

$mysql -u root -p
CREATE DATABASE wiki;
GRANT ALL PRIVILEGES ON wiki.* TO 'wikijs'@'localhost' IDENTIFIED BY 'Hyman@theitroad';
FLUSH PRIVILEGES;
QUIT;

安装Redis.

sudo yum -y install redis
sudo systemctl enable --now redis

确认所有服务状态

$systemctl status redis
● redis.service - Redis persistent key-value database
   Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis.service.d
           └─limit.conf
   Active: active (running) since Tue 2019-12-10 18:27:35 EAT; 20s ago
 Main PID: 661 (redis-server)
    Tasks: 4 (limit: 11512)
   Memory: 6.5M
   CGroup: /system.slice/redis.service
           └─661 /usr/bin/redis-server 127.0.0.1:6379
Dec 10 18:27:35 centos8.novalocal systemd[1]: Starting Redis persistent key-value database...
Dec 10 18:27:35 centos8.novalocal systemd[1]: Started Redis persistent key-value database.
$systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-12-08 10:50:05 EAT; 2 days ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 2581 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 11512)
   Memory: 78.0M
   CGroup: /system.slice/mariadb.service
           └─2581 /usr/libexec/mysqld --basedir=/usr
Dec 08 10:50:05 centos8.novalocal mysql-prepare-db-dir[2479]: Please report any problems at http://mariadb.org/jira
Dec 08 10:50:05 centos8.novalocal mysql-prepare-db-dir[2479]: The latest information about MariaDB is available at http://mariadb.org/.
Dec 08 10:50:05 centos8.novalocal mysql-prepare-db-dir[2479]: You can find additional information about the MySQL part at:
Dec 08 10:50:05 centos8.novalocal mysql-prepare-db-dir[2479]: http://dev.mysql.com
Dec 08 10:50:05 centos8.novalocal mysql-prepare-db-dir[2479]: Consider joining MariaDB's strong and vibrant community:
Dec 08 10:50:05 centos8.novalocal mysql-prepare-db-dir[2479]: https://mariadb.org/get-involved/
....

第4步:下载wiki.js

下载Wiki.js的最新版本

curl -s https://api.github.com/repos/Requarks/wiki/releases/latest \
  | grep browser_download_url \
  | grep -v windows \
  | cut -d '"' -f 4 \
  | wget -qi 

将包提取到我们选择的目录

sudo mkdir /srv/wiki
sudo tar zxf wiki-js.tar.gz -C /srv/wiki

从提供的模板创建配置文件。

cd /srv/wiki
sudo cp config.sample.yml config.yml

修改配置文件并填写数据库,redis和端口设置:

$vim config.yml
#######################################################################
# Wiki.js - CONFIGURATION                                             #
#######################################################################
# Full documentation + examples:
# https://docs.requarks.io/install
# --------------------------------------------------------------------
# Port the server should listen to
# --------------------------------------------------------------------
port: 3000
# --------------------------------------------------------------------
# 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: mariadb
  # PostgreSQL/MySQL/MariaDB/MS SQL Server only:
  host: localhost
  port: 3306
  user: wikijs
  pass: 'Hyman@theitroad'
  db: wiki
  ssl: false
  # 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
  # Certificate format, either 'pem' or 'pfx':
  format: pem
  # Using PEM format:
  key: path/to/key.pem
  cert: path/to/cert.pem
  # 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
  # Listen on this HTTP port and redirect all requests to HTTPS.
  # Set to false to disable (default: 80):
  redirectNonSSLPort: 80
# --------------------------------------------------------------------
# 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
# --------------------------------------------------------------------
# Upload Limits
# --------------------------------------------------------------------
# If you're using a reverse-proxy in front of Wiki.js, you must also
# change your proxy upload limits!
uploads:
  # Maximum upload size in bytes per file (default: 5242880 (5 MB))
  maxFileSize: 5242880
  # Maximum file uploads per request (default: 20)
  maxFiles: 10
# --------------------------------------------------------------------
# Offline Mode
# --------------------------------------------------------------------
# If your server cannot access the internet. Set to true and manually
# download the offline files for sideloading.
offline: false
# --------------------------------------------------------------------
# Data Path
# --------------------------------------------------------------------
# Writeable data path for Wiki.js, mainly for cache and user uploads.
dataPath: ./data

通过运行wiki.js来测试配置:

sudo node server

我们应该获得类似于下面的输出。

第4步:配置wiki.js服务

现在配置Wiki.js应用程序以作为服务运行。

sudo vim /etc/systemd/system/wiki.service

添加:

[Unit]
Description=Wiki.js
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/node server
Restart=always
User=wiki
Environment=NODE_ENV=production
WorkingDirectory=/srv/wiki
[Install]
WantedBy=multi-user.target

提供目录的用户权限。

sudo chown -R wiki:wiki /srv/wiki

重新加载系统和启动服务。

sudo systemctl daemon-reload
sudo systemctl enable --now wiki.service

确认服务状态

$systemctl status wiki

我们应该获得类似于下面的输出。

该服务应绑定到TCP端口3000:

$ss -tunelp | grep 3000
tcp   LISTEN  0       128                  0.0.0.0:3000           0.0.0.0:*      uid:977 ino:283510 sk:e <->

安装和配置nginx反向代理

安装并启动nginx Web服务。

sudo yum -y install nginx
sudo systemctl enable --now nginx

如果我们有防火墙服务运行,请允许服务。

sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload

配置selinux:

sudo semanage port -a -t http_port_t -p tcp 3000
sudo setsebool -P httpd_can_network_connect 1

为wiki.js创建nginx配置文件

$sudo vim /etc/nginx/conf.d/wikijs.conf

修改和粘贴以下数据

server {
    listen      80;
    server_name wiki.example.com;
    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;
    }
}

确认nginx配置并重新启动服务。

$sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
$sudo systemctl restart nginx

在CentOS 8上打开Web浏览器上的URL以完成Wiki.js安装。

填写所需的管理员详细信息,然后单击"安装"按钮。

等待安装完成。

使用安装期间提供的凭据登录。

同意在第一个屏幕中创建主页。