Requisitos para instalação on-premises
- PostgreSQL 9.5 ou superior
- Node.JS 14.0 ou superior
- Proxy reverso para o apontamento DNS
Este manual considerará o sistema operacional Debian 10.
Primeiramente, atualize o sistema operacional
sudo apt update
sudo apt -y upgrade
Após a instalação das atualizações, reinicie o server
sudo reboot
Instale o GNU Privacy Guard (GnuPG) com o seguinte comando.
sudo apt -y install gnupg2
Importe a chave GPG utilizada para a assinatura dos pacotes
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Adicione o repositório do PostgreSQL
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
Verifique se o repositório foi adicionado corretamente usando o comando cat
$ cat /etc/apt/sources.list.d/pgdg.list
deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main
Atualize a lista de pacotes do sistema
sudo apt update
Instale o PostgreSQL
sudo apt -y install postgresql-13 postgresql-client-13
Inicie o servidor do BD
sudo pg_ctlcluster 13 main start
Confirme o status do serviço utilizando o comando systemctl
$ systemctl status postgresql@13-main.service
● postgresql@13-main.service - PostgreSQL Cluster 13-main
Loaded: loaded (/lib/systemd/system/postgresql@.service; enabled-runtime; vendor preset: enabled)
Active: active (running) since Fri 2020-10-30 11:27:01 CET; 2min 11s ago
Main PID: 4209 (postgres)
Tasks: 7 (limit: 4580)
Memory: 18.1M
CGroup: /system.slice/system-postgresql.slice/postgresql@13-main.service
├─4209 /usr/lib/postgresql/13/bin/postgres -D /var/lib/postgresql/13/main -c config_file=/etc/postgresql/13/main/postgresql.conf
├─4211 postgres: 13/main: checkpointer
├─4212 postgres: 13/main: background writer
├─4213 postgres: 13/main: walwriter
├─4214 postgres: 13/main: autovacuum launcher
├─4215 postgres: 13/main: stats collector
└─4216 postgres: 13/main: logical replication launcher
Oct 30 11:26:59 debian systemd[1]: Starting PostgreSQL Cluster 13-main...
Oct 30 11:27:01 debian systemd[1]: Started PostgreSQL Cluster 13-main.
Inicie o prompt do PostgreSQL
$ sudo su - postgres
postgres@debian:~$ psql
psql (13.0 (Debian 13.0-1.pgdg100+1))
Type "help" for help.
postgres=#
Altere a senha do usuário postgres
postgres=# alter user postgres with password 'S3nh4F0rt3';
Crie um usuário no BD para a wiki
postgres=# CREATE ROLE wikijs WITH SUPERUSER CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWORD 'S3nh4F0rt3';
Você pode conferir quais os usuários existentes com o comando \du
postgres-# \du
List of roles
Role name | Attributes | Member of
------------+------------------------------------------------------------+-----------
wikijs | Superuser, Create role, Create DB | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
Crie o banco de dados
postgres-# CREATE DATABASE wiki;
Dê privilégios de acesso ao banco recém-criado para o usuário criado anteriormente
postgres-# GRANT ALL PRIVILEGES ON DATABASE wiki TO wikijs;
Você pode conferir quais os bancos de dados existentes com o comando \l
postgres-# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
wiki | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres+
| | | | | navjot=CTc/postgres
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
Edite o arquivo pg_hba.conf, alterando o método de login para md5
vim /var/lib/pgsql/data/pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
Modelo para referência
# USER can be "all", a user name, a group name prefixed with "+", or a
# comma-separated list thereof. In both the DATABASE and USER fields
# you can also write a file name prefixed with "@" to include names
# from a separate file.
#
# ADDRESS specifies the set of hosts the record matches. It can be a
# host name, or it is made up of an IP address and a CIDR mask that is
# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
# specifies the number of significant bits in the mask. A host name
# that starts with a dot (.) matches a suffix of the actual host name.
# Alternatively, you can write an IP address and netmask in separate
# columns to specify the set of hosts. Instead of a CIDR-address, you
# can write "samehost" to match any of the server's own IP addresses,
# or "samenet" to match any address in any subnet that the server is
# directly connected to.
#
# METHOD can be "trust", "reject", "md5", "password", "scram-sha-256",
# "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert".
# Note that "password" sends passwords in clear text; "md5" or
# "scram-sha-256" are preferred since they send encrypted passwords.
#
# OPTIONS are a set of options for the authentication in the format
# NAME=VALUE. The available options depend on the different
# authentication methods -- refer to the "Client Authentication"
# section in the documentation for a list of which options are
# available for which authentication methods.
#
# Database and user names containing spaces, commas, quotes and other
# special characters must be quoted. Quoting one of the keywords
# "all", "sameuser", "samerole" or "replication" makes the name lose
# its special character, and just match a database or username with
# that name.
#
# This file is read on server startup and when the server receives a
# SIGHUP signal. If you edit the file on a running system, you have to
# SIGHUP the server for the changes to take effect, run "pg_ctl reload",
# or execute "SELECT pg_reload_conf()".
#
# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
Reinicie o serviço para que as configurações entrem em vigor
systemctl restart postgresql@13-main.service
Baixe o repositório do Node.js utilizando o curl
curl -sL https://deb.nodesource.com/setup_16.x | bash -
Instale o Node.js utilizando o apt
apt install nodejs
Confira a versão instalada com o comando:
$ node --version
v16.6.0
Faça download do release
wget https://github.com/Requarks/wiki/releases/download/2.5.201/wiki-js.tar.gz
Crie uma pasta e descompacte os arquivos
mkdir wiki
tar xzf wiki-js.tar.gz -C ./wiki
cd ./wiki
Renomeie o arquivo de configuração
mv config.sample.yml config.yml
Abra o arquivo de configuração para editá-lo
vim config.yml
Modelo para referência
#######################################################################
# 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: postgres
# PostgreSQL / MySQL / MariaDB / MS SQL Server only:
host: localhost
port: 5432
user: wikijs
pass: wikijsrocks
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
# 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: 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
# ++++++ 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
# ---------------------------------------------------------------------
# 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: ./data
Por razões de segurança, nós queremos que o serviço seja executado por um usuário sem privilégios. Para tal, criaremos um usuário e grupo respectivo.
groupadd -r wikijs
useradd -r -s /bin/false -g wikijs wikijs
chown -R wikijs:wikijs </var/wiki>
Crie o serviço
vim /etc/systemd/system/wiki.service
Modelo para referência
[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=/var/wiki
[Install]
WantedBy=multi-user.target
Antes de prosseguir, é necessário recarregar o systemd
systemctl daemon-reload
Ative e inicie o serviço
systemctl enable --now wiki
Para acompanhar o status de execução do serviço, use o journalctl
journalctl -u wiki