本文讲解在CentOS 8操作系统上安装和配置Wiki.js服务的方法,我们将从安装必需的依赖项开始,然后继续在CentOS 8上安装和配置Wiki.js。系统设置要求:Node.js 10.x或更高版本、Redis缓存、Git 2.x或更高版本、符合Git的存储库(公共或私有,可选)。
一、更新系统并设定时区 首先更新系统并设置正确的时区: sudo yum -y update sudo timedatectl list-timezones sudo timedatectl set-timezone 'Africa/Nairobi' 如果你在中国,请设置为Asia/Shanghai,参考用timedatectl在Linux中检查当前时区及更改时区(创建符号链接来更改时区)。
二、为Wiki.js创建专用用户 我们需要一个专用的系统用户来运行Wiki.js应用程序,首先创建该用户: sudo groupadd --system wiki sudo useradd -s /sbin/nologin --system -g wiki wiki
三、安装基本的依赖包 我们还要安装在CentOS 8上运行Wiki.js所需的所有依赖项应用程序: 1、安装git,unzip和epel-release sudo yum install -y epel-release git vim wget curl unzip socat 2、安装Node.js curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash - sudo yum install -y nodejs nginx gcc-c++ make 3、安装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 'Str0ngWikiP@s5'; FLUSH PRIVILEGES; QUIT; 4、安装Redis sudo yum -y install redis sudo systemctl enable --now redis 确认所有服务状态: $ systemctl status redis $ systemctl status mariadb
四、下载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 tar zxf wiki-js.tar.gz -C /srv/wiki 从提供的模板创建配置文件: sudo mkdir /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: 'Str0ngWikiP@s5' 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 输出信息如下所示:
五、配置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 输出信息如下图所示:
该服务应绑定到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反向代理,以完成Wiki.js的安装 安装并启动Nginx Web服务: sudo yum -y install nginx sudo systemctl enable --now nginx 如果你正在运行防火墙服务,请允许该服务: sudo firewall-cmd --add-service=http --permanent sudo firewall-cmd --reload 参考:在CentOS 8系统上配置和管理防火墙(Firewall)的方法。 配置Nginx: 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的安装:
填写所需的管理员详细信息,然后单击“Install”按钮:
等待安装完成:
使用安装期间提供的帐户信息登录:
同意在第一个屏幕中创建主页:
至此,配置Wiki.js服务完成。
相关主题 |