【Linux专题】RockyLinux 8.6 部署 wiki.js 开源文档库

系统预配置

更新系统

1、yum update -y

设置正确时间

1、yum -y install chrony
2、systemctl enable --now chronyd

创建wiki用户用于启动程序

1、groupadd --system wiki
2、adduser -s /sbin/nologin --system -g wiki wiki

关闭SELinux

1、sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
2、reboot

安装软件包

需要安装的软件包有:nodejs、nginx、mariadb 和 redis

安装epel-release

1、yum -y install epel-release
2、yum makecache

安装nodejs和nginx

1、curl -sL https://rpm.nodesource.com/setup_14.x | bash -
2、yum -y install nodejs nginx

安装mariadb

1、yum -y install @mariadb

安装redis

1、yum -y install redis

下载wiki压缩包

1、wget -c https://github.com/Requarks/wiki/releases/download/2.5.201/wiki-js.tar.gz

配置数据库

启动数据库服务并配置 root 用户登录

1、systemctl enable --now mariadb
2、mysql_secure_installation # 安全初始化
3、mysql -uroot -p # 登录数据库

创建数据库和表

1、CREATE DATABASE wikijs;
2、GRANT ALL PRIVILEGES ON wikijs.* TO 'wikijs'@'localhost' IDENTIFIED BY 'PASSWORD';
3、FLUSH PRIVILEGES;
4、QUIT;

启动redis服务,但无需配置

1、systemctl enable --now redis

配置wiki . js程序

创建工作目录

1、mkdir -p /var/www/wikijs
2、chown -R wiki:wiki /var/www/wikijs

解压源码到工作目录

1、tar -xvf wiki-js.tar.gz -C /var/www/wikijs

附件: wiki-js.tar.gz

创建 wiki.js 配置文件

1、cd /var/www/wikijs
2、cp config.sample.yml config.yml
3、vim config.yml
4、    # 修改以下部分
5、  db:
6、  type: mariadb
7、  host: localhost
8、  port: 3306
9、  user: wikijs
10、  pass: '数据库用户 wikijs 的密码'
11、  db: wikijs
12、  ssl: false
13、  # 结束

测试 node.js 是否工作

1、[root@localhost ~]# cd /var/www/wikijs
2、[root@localhost wikijs]# node server
3、Loading configuration from /var/www/wikijs/config.yml... OK
4、2022-09-11T09:17:37.526Z [MASTER] info: =======================================
5、2022-09-11T09:17:37.528Z [MASTER] info: = Wiki.js 2.5.287 =====================
6、2022-09-11T09:17:37.528Z [MASTER] info: =======================================
7、2022-09-11T09:17:37.528Z [MASTER] info: Initializing...
8、2022-09-11T09:17:38.017Z [MASTER] info: Using database driver mysql2 for mariadb [ OK ]
9、2022-09-11T09:17:38.020Z [MASTER] info: Connecting to database...
10、2022-09-11T09:17:38.045Z [MASTER] info: Database Connection Successful [ OK ]
11、2022-09-11T09:17:38.523Z [MASTER] warn: DB Configuration is empty or incomplete. Switching to Setup mode...
12、2022-09-11T09:17:38.523Z [MASTER] info: Starting setup wizard...
13、2022-09-11T09:17:38.633Z [MASTER] info: Starting HTTP server on port 3000...
14、2022-09-11T09:17:38.633Z [MASTER] info: HTTP Server on port: [ 3000 ]
15、2022-09-11T09:17:38.637Z [MASTER] info: HTTP Server: [ RUNNING ]
16、2022-09-11T09:17:38.637Z [MASTER] info:
17、????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
18、2022-09-11T09:17:38.637Z [MASTER] info:
19、2022-09-11T09:17:38.637Z [MASTER] info: Browse to http://YOUR-SERVER-IP:3000/ to complete setup!
20、2022-09-11T09:17:38.637Z [MASTER] info:
21、2022-09-11T09:17:38.638Z [MASTER] info:
22、????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
23、看到以上输出说明正常,按 CTRL-C 退出即可

配置 systemd 服务

创建文件 /etc/systemd/system/wiki.service 并添加以下内容

 1、[Unit] Description=Wiki.js
 2、After=network.target
 3、[Service]
 4、Type=simple
 5、ExecStart=/usr/bin/node server
 6、Restart=always
 7、User=wiki
 8、Environment=NODE_ENV=production
 9、WorkingDirectory=/var/www/wikijs
10、[Install] WantedBy=multi-user.target

启动服务并验证

1、systemctl daemon-reload
2、systemctl enable --now wiki.service
3、ss -tlnp | grep 3000
4、LISTEN 0     128     0.0.0.0:3000     0.0.0.0:*   users:(("node",pid=49082,fd=19))

此时浏览器访问 3000 端口就能访问了,如果公网部署的话最好申请个证书,配置反向代理

配置Nginx反向代理

防火墙放行 https 服务

1、firewall-cmd --add-service=https --permanent
2、firewall-cmd --reload

创建 nginx 配置文件

/etc/nginx/conf.d/wikijs.conf 内容如下

1、server {
2、  listen 443;server_name 公网ip地址/或域名;
3、  /** 证书部分配置
4、  ssl_certificate "/etc/pki/nginx/server.crt";
5、  ssl_certificate_key "/etc/pki/nginx/private/server.key";
6、  ssl_session_cache shared:SSL:1m;
7、  ssl_session_timeout 10m;
8、  ssl_ciphers PROFILE=SYSTEM;
9、  ssl_prefer_server_ciphers on;
10、  **/
11、  location / {
12、  proxy_set_header Host $http_host;
13、  proxy_set_header X-Real-IP $remote_addr;
14、  proxy_pass http://127.0.0.1:3000;
15、  proxy_http_version 1.1;
16、  proxy_set_header Upgrade $http_upgrade;
17、  proxy_set_header Connection "upgrade";
18、  proxy_next_upstream error timeout http_502 http_503 http_504;
19、  }
20、}

重启nginx

1、nginx -t
2、systemctl enable --now nginx
3、systemctl restart nginx

浏览器访问即可看到安装界面

自行设置管理员邮箱,可以随意设置,只要符合邮箱格式即可,如:[email protected]

安装过程截图略

使用podman安装ElasticSearch实现全文搜素

默认情况下,wiki.js 仅支持搜索标题,需要配合 ES 来实现全文搜索。
并且 wiki.js 仅支持 ES 16.X/17.X 版本

安装 podman

1、yum -y install podman

使用无根容器

1、[admin@localhost ~]$ podman pull docker.io/library/elasticsearch:7.17.2

启动无根容器

1、[admin@localhost ~]$ podman run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.io/library/elasticsearch:7.17.2

使用 systemd 管理无根容器自启动

1、[admin@localhost ~]$ ssh admin@localhost  # 重要
2、[admin@localhost ~]$ loginctl enable-linger
3、[admin@localhost ~]$ mkdir -p .config/systemd/user
4、[admin@localhost ~]$ cd ~/.config/systemd/user
5、[admin@localhost user]$ podman generate systemd -n es -f
6、[admin@localhost user]$ systemctl --user daemon-reload
7、[admin@localhost user]$ podman stop es
8、[admin@localhost user]$ systemctl --user enable container-es.service --now

配置全文搜索

资源下载: