如何在 Ubuntu 16.04 上设置和配置 Jekyll 开发站点


在这篇文章中,我们将学习如何设置和配置 Jekyll 开发站点。Jekyll 提供了内容管理系统 (CMS) 的优势,并具有数据库驱动站点中出现的性能和安全性。它也被称为博客感知,具有处理日期组织内容的功能。它特别适合离线工作的人员,它还提供了一个轻量级的编辑器和内容管理,具有版本控制功能,用于跟踪对其网站所做的更改。

先决条件

  • 安装了 Ubuntu 16.04 的机器。
  • 在机器上具有 Sudo 权限的用户。

在 Ubuntu 16.04 上安装 Jekyll 开发站点

在开始实际安装之前,我们首先将使用以下命令更新系统。

$ sudo apt-get update
Output:
Hit:1 http://in.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease [95.7 kB]
Hit:3 http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease
Fetched 95.7 kB in 1s (58.1 kB/s)
Reading package lists... Done

更新完成后,我们将安装 Jekyll 所需的依赖项,因为我们需要 Ruby 和开发库(如 Make 和 GCC)来编译和安装 Jekyll。

$ sudo apt-get install ruby ruby-dev make gcc

输出

Reading package lists... Done
Building dependency tree Reading state information... Done … …
Setting up libgmp-dev:amd64 (2:6.1.0+dfsg-2) ...
Setting up libjs-jquery (1.11.3+dfsg-4) ...
Setting up make (4.1-6) ...
Setting up manpages-dev (4.04-2) ...
Setting up rubygems-integration (1.10) ...
Setting up ruby-dev:amd64 (1:2.3.0+1) ...
Setting up ruby (1:2.3.0+1) ...
Setting up rake (10.5.0-2) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...

安装完成后,我们可以安装 Ruby 的 gem 包以及 Jekyll 作为一个捆绑包。

以下是使用 gem 安装程序安装 Jekyll 开发服务器的命令。

$ sudo gem install jekyll bundler
Fetching: liquid-3.0.6.gem (100%)
Successfully installed liquid-3.0.6
Fetching: kramdown-1.12.0.gem (100%)
Successfully installed kramdown-1.12.0
Fetching: mercenary-0.3.6.gem (100%)
Successfully installed mercenary-0.3.6
..
..
..
Installing ri documentation for rb-inotify-0.9.7
Parsing documentation for listen-3.0.8
Installing ri documentation for listen-3.0.8
Parsing documentation for jekyll-watch-1.5.0
Fetching: bundler-1.13.6.gem (100%)
Successfully installed bundler-1.13.6
Parsing documentation for bundler-1.13.6
Installing ri documentation for bundler-1.13.6
Done installing documentation for bundler after 5 seconds
19 gems installed

配置防火墙以允许 Jekyll

首先,我们将检查防火墙的状态,以便在 Web 浏览器上允许开发站点。以下是检查防火墙状态的命令 -

$ sudo ufw status
Output:
Status: active
To             Action             From
--             ------             ----
22             ALLOW             Anywhere
80             ALLOW             Anywhere
22 (v6)        ALLOW             Anywhere (v6)
80 (v6)        ALLOW             Anywhere (v6)

我们可以看到,只有 SSH 和 WWW 服务已启用,这意味着允许端口 22 和端口 80,我们需要为 Jekyll 打开端口 4000,这是 Jekyll 开发服务器的默认端口。

以下是启用防火墙上 4000 端口的命令 -

$ sudo ufw allow 4000
Output:
Rule added
Rule added (v6)

现在,我们将检查防火墙状态以交叉检查端口 4000 是否已启用。

$ sudo ufw status
Output:
Status: active
To          Action       From
--          ------       ----
22          ALLOW        Anywhere
80          ALLOW        Anywhere
4000        ALLOW        Anywhere
22 (v6)     ALLOW        Anywhere (v6)
80 (v6)     ALLOW        Anywhere (v6)
4000 (v6)   ALLOW        Anywhere (v6)

由于开发所需的端口已打开,我们将创建开发站点。

创建演示开发站点

在我们的主目录中,我们将在名为 www 的文件夹中为演示站点创建一个脚手架。

$ cd ~
$ jekyll new www
OutPut:
New jekyll site installed in /home/ubuntu/www.
Running bundle install in /home/ubuntu/www...
Fetching gem metadata from https://rubygems.org.cn/...........
Fetching version metadata from https://rubygems.org.cn/..
Fetching dependency metadata from https://rubygems.org.cn/.
Resolving dependencies...
Using public_suffix 2.0.4
Using colorator 1.1.0
Using ffi 1.9.14
Using forwardable-extended 2.6.0
Using sass 3.4.22
Using rb-fsevent 0.9.8
Using kramdown 1.12.0
Using liquid 3.0.6
Using mercenary 0.3.6
Using rouge 1.11.1
Using safe_yaml 1.0.4
Installing minima 2.0.0
Using bundler 1.13.6
Using addressable 2.5.0
Using rb-inotify 0.9.7
Using pathutil 0.14.0
Using jekyll-sass-converter 1.5.0
Using listen 3.0.8
Using jekyll-watch 1.5.0
Using jekyll 3.3.1
Installing jekyll-feed 0.8.0
Bundle complete! 3 Gemfile dependencies, 21 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
Post-install message from minima:
----------------------------------------------
Thank you for installing minima 2.0!
Minima 2.0 comes with a breaking change that
renders '<your-site>/css/main.scss' redundant.
That file is now bundled with this gem as
'<minima>/assets/main.scss'.
More Information:
https://github.com/jekyll/minima#customization
----------------------------------------------

这将使用其 Gemfiles 指定默认主题,我们现在将运行 bundle 来安装主题。

$ cd www
$ bundle install
Output:
Using public_suffix 2.0.4
Using colorator 1.1.0
Using ffi 1.9.14
Using forwardable-extended 2.6.0
…
…
Using jekyll-watch 1.5.0
Using jekyll 3.3.1
Using jekyll-feed 0.8.0
Bundle complete! 3 Gemfile dependencies, 21 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

www 的树结构如下所示 -

.
├── about.md
├── _config.yml
├── Gemfile
├── Gemfile.lock
├── index.md
└── _posts
└── 2016-11-15-welcome-to-jekyll.markdown
1 directory, 6 files

在继续执行下一步之前,我们需要在 _config.yml 文件中进行一些配置更改。

$ vi ~/www/_config.yml
Output:
The configuration file will be looks like this
title: Your awesome title
email: your-email@domain.com
description: > # this means to ignore newlines until "baseurl:"
Write an awesome description for your new site here. You can edit this
line in _config.yml. It will appear in your document head meta (for
Google search results) and in your feed.xml site description.
baseurl: "" # the subpath of your site, e.g. /blog
url: "ubuntu-16" # the base hostname & protocol for your site, e.g. http://example.com
twitter_username: jekyllrb
github_username: jekyll
# Build settings
markdown: kramdown
theme: minima
gems:
- jekyll-feed
exclude:
- Gemfile
- Gemfile.lock

我们需要找到以下行,并需要将示例替换为您站点的域名

url: "http://example.com" # the base hostname & protocol for your site, e.g. http://example.com

配置完成后,我们现在启动 Jekyll 的 Web 服务器。

启动 Jekyll 的服务器

我们需要启动 Jekyll 的 Web 服务器,它将通过监视目录中的文件来支持站点开发,这还将生成静态网站,并且每次保存更改时。

$ jekyll serve --host=192.168.2.117
Output:
Configuration file: /home/ubuntu/www/_config.yml
Configuration file: /home/ubuntu/www/_config.yml
Source: /home/ubuntu/www
Destination: /home/ubuntu/www/_site
Incremental build: disabled. Enable with --incremental
Generating...
done in 0.372 seconds.
Auto-regeneration: enabled for '/home/ubuntu/www'
Configuration file: /home/ubuntu/www/_config.yml
Server address: http://192.168.2.117:4000/
Server running... press ctrl-c to stop.

服务器运行后,网站正在运行并可以使用 IP 地址或域名访问,因为这是一个演示站点,我们将从本地 IP 地址访问它,https://192.168.2.197。在本文中,我们将学习如何设置和配置 Jekyll 并安装依赖项,以及配置 Jekyll 以设置演示网站,我们还将学习如何启动 Jekyll Web 服务器。

更新于: 2020 年 1 月 20 日

83 次查看

开启你的 职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.