centos7.6部署安装Wikijs

Posted Aihao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7.6部署安装Wikijs相关的知识,希望对你有一定的参考价值。

写在前面

环境

wiki安装路径:/var/wiki

node安装路径:/usr/local/node

安装软件前,先看看官网的说明文档,养成良好的习惯,总归是有好处的。

https://www.postgresql.org/download/linux/redhat/

1.安装postgresql

# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Install PostgreSQL:
sudo yum install -y postgresql13-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13

# start postgresql13
sudo systemctl start postgresql-13

# run status
sudo systemctl status postgresql-13

# 查看进程信息
ps -ef | grep postgres

# 查看 5432端口是否打开
netstat -tpnl | grep 5432

# 开放端口
firewall-cmd --zone=public --add-port=5432/tcp --permanent

# 配置生效
firewall-cmd --reload  

# 切换用户
su postgres

# 连接pgsql server
psql -U postgres

# 添加密码
alter user postgres with password 'root';

select * from pg_shadow;

# 退出
\q

# 进入data目录
cd /var/lib/pgsql/13/data

vi postgresql.conf

去掉listen_addresses注释,将listen_addresses = 'localhost' 改成 listen_addresses = '*'

vi pg_hba.conf

修改postgresql服务连接文件,local下的 peer 改成 md5,本地就可以连接了。

# 增加一行允许所有连接
host   all         all        0.0.0.0/0         md5


# 重启postgresql-13
service postgresql-13 restart

最后云服务器防火墙开放5432端口就可以使用Navicat工具连接啦!

2.安装node

# downloade
wget https://nodejs.org/dist/v14.15.4/node-v14.15.4-linux-x64.tar.xz

# 剪切至 /usr/local 目录下
mv node-v14.15.4-linux-x64.tar.xz /usr/local

# 解压
tar -xvf node-v14.15.4-linux-x64.tar.xz

# 重命名为 node
mv node-v14.15.4-linux-x64 node

# 为node、npm建立软连接
ln -s /usr/local/node/bin/node /usr/bin/node

ln -s /usr/local/node/bin/npm /usr/bin/npm

环境变量配置,使用vi编辑器配置环境变量

# vim 编辑profile
vim /etc/profile

打开后添加下面三行环境变量即可。

# node environment
export NODE_HOME=/usr/local/node
export NODE_PATH=$NODE_HOME/lib/node_modules
export PATH=$NODE_HOME/bin:$PATH
# 刷新profile文件,使其生效
source /etc/profile

测试node

# test node
[root@10-23-202-173 local]# node -v
v14.15.4
[root@10-23-202-173 local]# npm -v
6.14.10
[root@10-23-202-173 local]#

3.安装Wiki

cd /var

# 下载wiki
wget https://github.com/Requarks/wiki/releases/download/2.5.170/wiki-js.tar.gz

# 创建wiki文件夹
mkdir wiki

# 解压至wiki文件夹
tar xzf wiki-js.tar.gz -C wiki

# 进入wiki目录
cd wiki

# Rename the sample config file to config.yml
mv config.sample.yml config.yml

# Edit the config file and fill in your database and port settings
vi config.yml


PostgreSQL is the recommended engine for best performance, features and future compatibility.

db:
type: postgres
host: localhost
port: 5432
user: wikijs
pass: wikijsrocks
db: wiki
 
注意db:wiki数据库必须自己手动创建,wikijs不会自动创建数据库!

详细配置参见 https://docs.requarks.io/install/config

# Run Wiki.js
cd /var/wiki

node server

# 开放3000端口,默认3000端口
firewall-cmd --zone=public --add-port=3000/tcp --permanent

# 配置生效
firewall-cmd --reload

最后,浏览器访问ip:port 即可!

4.Run as service

There are several solutions to run Wiki.js as a background service. We'll focus on systemd in this guide as it's available in nearly all linux distributions.

1.Create a new file named wiki.service inside directory /etc/systemd/system.

vi /etc/systemd/system/wiki.service

2.Paste the following contents (assuming your wiki is installed at /usr/src/wiki):

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

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

[Install]
WantedBy=multi-user.target

3.Save the service file (CTRL+X, followed by Y).

4.Reload systemd

systemctl daemon-reload

5.Run the service

systemctl start wiki

systemctl status wiki

这时可能会出现wiki.service启动不成功的情况,参见 https://github.com/Requarks/wiki/issues/2296

6.Enable the service on system boot.

systemctl enable wiki

Note: You can see the logs of the service using journalctl -u wiki


以上是关于centos7.6部署安装Wikijs的主要内容,如果未能解决你的问题,请参考以下文章

wikijs-一款wiki系统

.Net Core部署Linux系统(CentOS7.6)

wikijs:一款基于NodeJS的轻量级wiki

Centos7.6手工编译安装PHP7.2+nginx1.19.1并部署禅道

Centos7.6下Mysql5.7部署

干货分享:Centos7.6使用rpm安装mysql数据库