Ghost是一个流行的开源博客平台,允许用户轻松创建和管理自己的博客。它是用JavaScript编写的,运行在Node.js库上,使其成为一个高度可扩展和灵活的平台。
在 Rocky Linux 9 上安装 Ghost(英语:Install Ghost)
第 1 步。第一步是将系统更新到最新版本的软件包列表。为此,请运行以下命令:
<span class="pln">sudo dnf check</span><span class="pun">-</span><span class="pln">update sudo dnf install dnf</span><span class="pun">-</span><span class="pln">utils</span>
第 2 步。安装 Nginx Web 服务器。
默认情况下,Nginx 在 Rocky Linux 9 基础存储库中不可用。现在运行以下命令将 Nginx 稳定存储库添加到您的系统中:
<span class="pln">sudo tee </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">yum</span><span class="pun">.</span><span class="pln">repos</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">-</span><span class="pln">stable</span><span class="pun">.</span><span class="pln">repo</span><span class="pun"><<</span><span class="pln">EOF </span><span class="pun">[</span><span class="pln">nginx</span><span class="pun">-</span><span class="pln">stable</span><span class="pun">]</span><span class="pln"> name</span><span class="pun">=</span><span class="pln">nginx stable repo baseurl</span><span class="pun">=</span><span class="pln">http</span><span class="pun">:</span><span class="com">//nginx.org/packages/centos/9/x86_64/</span><span class="pln"> gpgcheck</span><span class="pun">=</span><span class="lit">1</span><span class="pln"> enabled</span><span class="pun">=</span><span class="lit">1</span><span class="pln"> gpgkey</span><span class="pun">=</span><span class="pln">https</span><span class="pun">:</span><span class="com">//nginx.org/keys/nginx_signing.key</span><span class="pln"> module_hotfixes</span><span class="pun">=</span><span class="kwd">true</span><span class="pln"> EOF</span>
现在,运行以下命令将 Nginx 的最新稳定版本安装到您的服务器上:
<span class="pln">sudo dnf update sudo dnf install nginx</span>
安装完成后,启动 Nginx 服务并使其能够在重新启动时自动启动,一次性完成:
<span class="pln">sudo systemctl enable </span><span class="pun">--</span><span class="pln">now nginx</span>
要验证是否已安装最新版本的 Nginx,请运行:
<span class="pln">nginx </span><span class="pun">-</span><span class="pln">v</span>
默认情况下,Nginx 侦听端口 80 和 443。如果您的服务器上安装并配置了任何防火墙,则需要通过 firewalld 允许这两个端口。您可以使用以下命令允许它们:
<span class="pln">sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">permanent </span><span class="pun">--</span><span class="pln">zone</span><span class="pun">=</span><span class="kwd">public</span> <span class="pun">--</span><span class="kwd">add</span><span class="pun">-</span><span class="pln">service</span><span class="pun">=</span><span class="pln">http sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">permanent </span><span class="pun">--</span><span class="pln">zone</span><span class="pun">=</span><span class="kwd">public</span> <span class="pun">--</span><span class="kwd">add</span><span class="pun">-</span><span class="pln">service</span><span class="pun">=</span><span class="pln">https sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">reload</span>
您可以通过列出当前防火墙设置进行验证:
<span class="pln">sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">permanent </span><span class="pun">--</span><span class="pln">list</span><span class="pun">-</span><span class="pln">all</span>
此外,我们设置的SELinux现在允许Nginx连接到网络:
<span class="pln">sudo setsebool </span><span class="pun">-</span><span class="pln">P httpd_can_network_connect </span><span class="lit">1</span>
有关安装 Nginx 的其他资源,请阅读下面的帖子:
- 如何在 Rocky Linux √ 上安装 Nginx
第 3 步。在 Rocky Linux 9 上安装 Node.js。
默认情况下,Node.js 在 Rocky Linux 9 基础存储库中不可用。现在运行以下命令将 NodeSource 存储库添加到您的系统:
<span class="pln">curl </span><span class="pun">-</span><span class="pln">sL https</span><span class="pun">:</span><span class="com">//rpm.nodesource.com/setup_16.x | bash -</span>
接下来,使用以下命令安装最新的 Node.js 版本:
<span class="pln">sudo dnf install nodejs</span>
使用以下命令验证已安装的 Node.js 版本:
<span class="pln">node </span><span class="pun">-</span><span class="pln">v</span>
若要验证 NPM 版本,请运行以下命令:
<span class="pln">npm </span><span class="pun">-</span><span class="pln">v</span>
有关安装 Node.js 的其他资源,请阅读下面的帖子:
- 如何在 Rocky Linux √ 上安装 Node.js
第 4 步。安装 MariaDB 数据库。
默认情况下,MariaDB 在 Rocky Linux 9 基础存储库中可用。现在运行以下命令将最新的稳定版本的 MariaDB 安装到您的系统中:
<span class="pln">sudo dnf install mariadb</span><span class="pun">-</span><span class="pln">server mariadb</span>
安装完成后,启动 MariaDB 服务并通过运行以下命令使其在启动时自动启动:
<span class="pln">sudo systemctl enable mariadb </span><span class="pun">--</span><span class="pln">now sudo systemctl start mariadb sudo systemctl status mariadb</span>
要检查安装的 MariaDB 版本,请运行以下命令:
<span class="pln">mariadb </span><span class="pun">--</span><span class="pln">version</span>
默认情况下,MariaDB 未强化。您可以使用脚本保护 MariaDB。您应该仔细阅读并在每个步骤下方仔细阅读,这将设置root密码,删除匿名用户,禁止远程root登录,并删除测试数据库和对安全MariaDB的访问权限:mysql_secure_installation
<span class="pln">mysql_secure_installation</span>
像这样配置它:
<span class="pun">-</span> <span class="typ">Set</span><span class="pln"> root password</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Remove</span><span class="pln"> anonymous users</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Disallow</span><span class="pln"> root login remotely</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Remove</span><span class="pln"> test database </span><span class="kwd">and</span><span class="pln"> access to it</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Reload</span><span class="pln"> privilege tables now</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y</span>
现在,您可以尝试使用设置的根用户密码访问数据库:
<span class="pln">mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>
现在创建一个数据库用户,数据库,并将对所创建数据库的控制权分配给用户:
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE DATABASE ghostdb</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE USER </span><span class="str">'ghostuser'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'your-strong-password'</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> GRANT ALL ON ghostdb</span><span class="pun">.*</span><span class="pln"> TO </span><span class="str">'ghostuser'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> FLUSH PRIVILEGES</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> EXIT</span><span class="pun">;</span>
有关安装 MariaDB 的其他资源,请阅读以下帖子:
- 如何在 Rocky Linux √ 上安装 MariaDB
第5步。在 Rocky Linux 9 上安装 Ghost。
运行以下命令以安装 Ghost-CLI 工具。忽略在此过程中收到的任何警告:
<span class="pln">sudo npm install ghost</span><span class="pun">-</span><span class="pln">cli@latest </span><span class="pun">-</span><span class="pln">g</span>
接下来,创建 Ghost 根目录:
<span class="pln">sudo mkdir </span><span class="pun">-</span><span class="pln">p </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">ghost</span>
设置所有权和目录权限:
<span class="pln">sudo chown $USER</span><span class="pun">:</span><span class="pln">$USER </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">ghost sudo chmod </span><span class="lit">755</span> <span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">ghost</span>
在终端中,导航到目录并使用以下命令运行它:
<span class="pln">cd </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">ghost ghost install</span>
在安装过程中,CLI 工具将询问许多问题进行配置:
- 在编写本教程时,Ghost-CLI 不支持除 Ubuntu 之外的任何其他操作系统。它会询问您是否仍要继续安装。按 Y 继续。
- 博客网址:输入完整的博客网址以及 HTTPS 协议。(
https://ghost.your-domain.com
) - MySQL 主机名:按 Enter 键使用默认值,因为我们的 Ghost 安装和 MySQL 位于同一台服务器上。
localhost
- MySQL 用户名:输入您的 MySQL 用户名。
root
- MySQL 密码:输入之前创建的根密码。
- 幽灵数据库名称:为幻影数据库命名。(
ghostdb
) - 须藤密码:输入系统密码以执行提升的命令。
sudo
- 设置一个幽灵MySQL用户?:安装程序会询问你是否要为Ghost创建一个单独的MySQL用户。按 Y 继续。
- 设置Nginx?:通常,Ghost-CLI会检测到您的Nginx安装并自动为您的博客配置它。但截至目前,它无法检测到我们的Nginx安装。因此,安装程序将自动跳过此步骤。我们将手动配置 Nginx。
- 设置 SSL?:由于它跳过了 Nginx 配置,CLI 工具也将跳过设置 SSL。
- 设置 systemd?:Ghost 会询问您是否要为 Ghost 设置系统服务。按 Y 继续。
- 启动幽灵?:按 Y 开始安装幽灵。该服务将启动,但我们需要配置 Nginx 和 SSL 才能使其正常工作。
第 6 步。安装Certbot。
我们通过运行以下命令手动从Let’s Encrypt生成SSL证书:
<span class="pln">sudo dnf install certbot python3</span><span class="pun">-</span><span class="pln">certbot</span><span class="pun">-</span><span class="pln">nginx</span>
然后,运行以下命令以使用 Nginx 生成证书:
<span class="pln">sudo certbot </span><span class="pun">--</span><span class="pln">nginx</span>
步骤 7.访问幽灵网页界面。
成功安装后,打开您的 Web 浏览器并使用 URL 访问 Ghost 管理界面。您应该看到以下页面:https://ghost.your-domain.com
感谢您使用本教程在您的 Rocky Linux 9 系统上安装 Ghost Content 管理系统。有关其他帮助或有用信息,我们建议您查看Ghost官方网站。