如何在Ubuntu 18.04上安装Ghost
Ghost是建立在Node.js平台之上的现代源代码发布平台。
它是完全可定制的,并且易于使用,使我们可以以几乎零的学习曲线发布内容。
在本教程中,我们将向我们展示如何使用Nginx作为代理在Ubuntu 18.04服务器上部署安全的Ghost教程 ,免费的Let's Encrypt SSL证书,Node.js的最新LTS版本以及MySQL/MariaDB作为数据库后端。
准备工作
作为遵循本教程的前提条件,我们将需要:
- 根据官方的Ghost系统要求,我们至少需要1G的内存。如果服务器的内存小于1GB,则可以创建交换文件。
- 指向公共服务器IP的域名。在本教程中,我们将使用'example.com'。
- 通过遵循如何在Ubuntu 18.04上安装Nginx来安装Nginx。
- 遵循如何在Ubuntu 18.04上使用UFW设置防火墙来配置防火墙。
确保端口“ 80”和“ 443”处于打开状态。
在继续本教程之前,请确保我们以具有sudo特权的用户身份登录。
安装Node.js和Yarn
在撰写本文时,推荐的Ghost Node.js版本是v8 carbon LTS。
我们将从NodeSource存储库中安装Node.js。
使用以下“ curl”命令为Node.js v8启用NodeSource存储库:
curl -sL https://deb.nodesource.com/setup_8.x | sudo bash
通过键入以下命令安装Node.js:
sudo apt install nodejs
有关其他安装方法,请参阅我们的《如何在Ubuntu 18.04上安装Node.js》教程。
要安装yarn,请使用以下命令在系统上启用Yarn存储库:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -echo "deb https://dl.yarnpkg.com/debian/stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
启用存储库后,请使用以下命令安装yarn:
sudo apt updatesudo apt-get -o Dpkg::Options::="--force-overwrite" install yarn
安装MySQL
Ghost支持MySQL,MariaDB和SQLite数据库。
在本教程中,当我们在生产模式下运行Ghost时,我们将使用MySQL(推荐的数据库)。
使用以下命令安装MySQL软件包:
sudo apt install mysql-server
运行“ mysql_secure_installation”命令以提高MySQL安装的安全性:
sudo mysql_secure_installation
系统将要求我们配置“ VALIDATE PASSWORD PLUGIN”,该密码用于测试MySQL用户密码的强度。
密码验证策略分为三个级别:低,中和强。
如果我们不想设置验证密码插件,请按“ ENTER”。
在下一个提示符下,将要求我们设置MySQL root用户的密码。
一旦设置了root密码,脚本还将要求我们删除匿名用户,限制root用户对本地计算机的访问并删除测试数据库。
我们应该对所有问题回答“是”(是)。
接下来,我们需要将身份验证方法从'auth_socket'更改为'mysql_native_password',以便Ghost安装程序可以访问我们的MySQL服务器。
为此,请以root用户身份登录到MySQL服务器:
sudo mysql
并运行以下查询,该查询将在使用“ mysql_native_password”方法时为MySQL root用户设置密码:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_pasword';FLUSH PRIVILEGES;
确保使用强密码更改“ very_strong_pasword”。
安装Ghost-CLI
我们将使用官方的Ghost CLI实用程序安装Ghost。
使用该实用程序,我们可以在单个命令中安装或者更新Ghost。
Ghost CLI作为npm软件包提供。
以下命令将在Ubuntu系统上全局安装Ghost CLI:
sudo yarn global add ghost-cli
创建Ghost安装位置
我们将在建议的安装位置“/var/www/ghost”目录中下载并安装Ghost。
要创建目录类型:
sudo mkdir -p /var/www/ghost
将目录的所有权更改为用户:
sudo chown $USER:$USER /var/www/ghost
'$USER'是一个环境变量,用于保存用户名。
设置正确的目录权限:
sudo chmod 775 /var/www/ghost
安装Ghost
现在,我们已经安装了Ghost CLI,并且所有准备工作已经完成,我们可以从安装开始。
转到“/var/www/ghost”目录。
cd /var/www/ghost
要开始安装,请运行“ ghost install”,它将安装和配置Ghost,将Nginx配置为反向代理,并通过免费的SSL证书加密来保护。
ghost install
✔ Checking system Node.js version ✔ Checking logged in user ✔ Checking current folder permissions System checks failed with message: 'Linux version is not Ubuntu 16' Some features of Ghost-CLI Jan not work without additional configuration. For local installs we recommend using `ghost install local` instead. ? Continue anyway? (y/N) y
安装程序将检查系统并打印一些警告,如上所示。
输入“ y”继续,安装程序将下载并安装Ghost:
ℹ Checking operating system compatibility [skipped] ✔ Checking for a MySQL installation ✔ Checking memory availability ✔ Checking for latest Ghost version ✔ Setting up install directory ✔ Downloading and installing Ghost v1.24.9 ✔ Finishing install process
接下来,将提示我们设置教程 URL和MySQL信息。
提供我们在“安装MySQL”部分中设置的根用户名和密码,并使用默认的数据库名称“ ghost_prod”。
? Enter your blog URL: https://example.com ? Enter your MySQL hostname: localhost ? Enter your MySQL username: root ? Enter your MySQL password: [hidden] ? Enter your Ghost database name: ghost_prod
安装程序将创建一个名为'ghost'的系统用户,并询问我们是否要创建一个幽灵MySQL用户,请键入'Yes'。
✔ Configuring Ghost ✔ Setting up instance Running sudo command: chown -R ghost:ghost /var/www/ghost/content ✔ Setting up "ghost" system user ? Do you wish to set up "ghost" mysql user? Yes ✔ Setting up "ghost" mysql user
接下来,安装程序将询问我们是否要设置Nginx。
输入“是”进行确认。
? Do you wish to set up Nginx? Yes ✔ Creating nginx config file at /var/www/ghost/system/files/example.com.conf Running sudo command: ln -sf /var/www/ghost/system/files/example.com.conf /etc/nginx/sites-available/example.com.conf Running sudo command: ln -sf /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/example.com.conf Running sudo command: nginx -s reload ✔ Setting up Nginx
设置好Nginx之后,安装程序将询问我们是否要设置SSL。
输入“是”进行确认,配置向导将要求我们输入电子邮件地址,然后它将为域生成一个免费的“加密SSL”证书并配置Nginx。
? Do you wish to set up SSL? Yes ? Enter your email (used for Let's Encrypt notifications) [email protected] Running sudo command: mkdir -p /etc/letsencrypt Running sudo command: ./acme.sh --install --home /etc/letsencrypt Running sudo command: /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt --domain example.com --webroot /var/www/ghost/system/nginx-root --reloadcmd "nginx -s reload" --accountemail [email protected] Running sudo command: openssl dhparam -out /etc/nginx/snippets/dhparam.pem 2048 Running sudo command: mv /tmp/ssl-params.conf /etc/nginx/snippets/ssl-params.conf ✔ Creating ssl config file at /var/www/ghost/system/files/example.com-ssl.conf Running sudo command: ln -sf /var/www/ghost/system/files/example.com-ssl.conf /etc/nginx/sites-available/example.com-ssl.conf Running sudo command: ln -sf /etc/nginx/sites-available/example.com-ssl.conf /etc/nginx/sites-enabled/example.com-ssl.conf Running sudo command: nginx -s reload ✔ Setting up SSL
接下来,安装程序将询问我们是否要设置systemd服务。
输入“ Y”以接受,安装程序将创建一个名为ghost_example-com的新系统服务,并使其在启动时启动:
? Do you wish to set up Systemd? Yes ✔ Creating systemd service file at /var/www/ghost/system/files/ghost_example-com.service Running sudo command: ln -sf /var/www/ghost/system/files/ghost_example-com.service /lib/systemd/system/ghost_example-com.service Running sudo command: systemctl daemon-reload ✔ Setting up Systemd
最后,安装程序将设置数据库并询问我们是否要启动Ghost,键入“是”。
Running sudo command: /var/www/ghost/current/node_modules/.bin/knex-migrator-migrate --init --mgpath /var/www/ghost/current ✔ Running database migrations ? Do you want to start Ghost? Yes Running sudo command: systemctl is-active ghost_example-com ✔ Ensuring user is not logged in as ghost user ✔ Checking if logged in user is directory owner ✔ Checking current folder permissions Running sudo command: systemctl is-active ghost_example-com ✔ Validating config ✔ Checking folder permissions ✔ Checking file permissions ✔ Checking content folder ownership ✔ Checking memory availability Running sudo command: systemctl start ghost_example-com ✔ Starting Ghost Running sudo command: systemctl is-enabled ghost_example-com Running sudo command: systemctl enable ghost_example-com --quiet ✔ Starting Ghost You can access your publication at https://example.com Next, go to your admin interface at https://example.com/ghost/to complete the setup of your publication Ghost uses direct mail by default To set up an alternative email method read our docs at https://docs.ghost.org/docs/mail-config
完成Ghost设置
打开浏览器,转到“ https://example.com/ghost/”上的Ghost管理界面,将显示以下屏幕:
要开始使用,请点击“创建帐户”按钮。
我们将被重定向到“创建帐户”屏幕,我们需要其中输入Blog标题以及帐户全名,电子邮件地址和密码:
填写详细信息后,点击“邀请团队”按钮。
在此屏幕上,系统将要求我们输入合作者的电子邮件地址。
我们只需单击“我稍后再做,带我到我的教程 !”链接,我们将被重定向到Ghost仪表板:
其中我们可以创建新帖子,添加用户并更改Ghosts配置。