如何在CentOS 8上安装Wiki.js

本指南描述了在CentOS 8 Linux机器上安装Wiki.js的理想步骤。 Wiki.js是基于Node.js,Git和Markdown构建的现代开源Wiki应用程序。 Wiki.js可以安装在Linux,macOS和Windows计算机上。使用Wiki.js,您可以使用内置的可视化编辑器以简单且广泛使用的Markdown格式创建所有文档和Web内容。

您编写的内容直接存储在Markdown中 (.Md创建一个文件并自动将其与远程Git存储库同步。您可以从Git存储库中读取所有内容。以下是Wiki.js的主要功能。

Wiki.js的主要功能

  • 免费使用和开源
  • 专为现代网络设计
  • 以简单的降价格式编辑内容
  • 具有集成的访问控制本地数据库或外部身份验证提供程序,例如Microsoft帐户,Google ID,Facebook,GitHub,Slack,LDAP(活动目录)。
  • 具有直观的资产管理
  • 轻巧而结实
  • Wiki.js具有内置的搜索引擎

系统配置要求

  • Node.js 10.x或更高版本
  • Redis缓存
  • Git 2.x或更高版本
  • 兼容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 8上运行Wiki.js所需的所有依赖项应用程序。

  • 安装git,解压缩,epel-release
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

创建一个数据库用户和数据库。

$ mysql -u root -p

CREATE DATABASE wiki;
GRANT ALL PRIVILEGES ON wiki.* TO 'wikijs'@'localhost' IDENTIFIED BY '[email protected]';
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: '[email protected]'
  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

重新加载systemd并启动服务。

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

检查服务状态

$ systemctl status wiki

您应该获得以下输出:

如何在CentOS 8上安装Wiki.js

该服务必须绑定到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

如果您正在运行firewalld服务,请允许该服务。

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

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

如何在CentOS 8上安装Wiki.js

输入所需的管理员详细信息,然后输入安装按钮

如何在CentOS 8上安装Wiki.js

等待安装完成。

如何在CentOS 8上安装Wiki.js

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

如何在CentOS 8上安装Wiki.js

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

如何在CentOS 8上安装Wiki.js

请访问Wiki.js官方文档,以了解如何构建Wiki和添加页面。

Sidebar