banner
NEWS LETTER

使用GitHub/Gitee搭建个人博客(一)

Scroll down

本章介绍了搭建个人博客需要安装的环境(node、git、hexo的安装)
本案例使用环境:CentOS:7.4,node:12.13.1,hexo-cli:4.2

一、下载环境

1、下载node

官网地址:http://nodejs.cn/推荐版本:

1
wget https://npm.taobao.org/mirrors/node/v12.13.1/node-v12.13.1-linux-x64.tar.xz
  • node版本不是越高越好,服务器会出现各种不兼容

2、解压node

命令为:

1
tar -zxvf node-v12.13.1-linux-x64.tar.xz
  • 若出现错误:
    1
    2
    3
    gzip: stdin: not in gzip format
    tar: Child returned status 1
    tar: Error is not recoverable: exiting now
  • 将解压参数修改为’-xvf’:
    1
    tar -xvf node-v12.13.1-linux-x64.tar.xz

3、修改文件名:

1
mv node-v12.13.1-linux-x64 nodejs

4、设置软连接

设置 node 和 npm 的软连接

1
2
ln -s /opt/software/nodejs/bin/node /usr/local/bin/node
ln -s /opt/software/nodejs/bin/npm /usr/local/bin/npm
  • 由于node下载第三方依赖包是从国外服务器下载,可能会出现下载速度缓慢问题
  • 为了提高效率,把npm的镜像源替换为淘宝的镜像源
    1
    npm config set registry https://registry.npm.taobao.org
    检测是否修改成功
    1
    2
    npm config get registry
    // 或 npm info express
  • 若需要还原npm仓库地址,则把镜像源修改回来就行
    1
    npm config set registry https://registry.npmjs.org/

5、查看版本

查看 node 和 npm 的版本:

1
2
node -v
npm -v

最终显示结局为:

1
2
3
4
[root@localhost ~]# node -v
v12.13.1
[root@localhost ~]# npm -v
6.12.1

6、安装git

1
2
3
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum -y install git-core
git --version # 查看git版本

7、安装hexo

设置软连接:

1
2
npm install hexo-cli -g
ln -s /opt/software/nodejs/lib/node_modules/hexo-cli/bin/hexo /usr/local/bin/hexo

8、查看hexo版本

1
hexo -v
  • 出现以下信息,安装成功
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    hexo-cli: 4.2.0
    os: Linux 3.10.0-693.el7.x86_64 linux x64
    node: 12.13.1
    v8: 7.7.299.13-node.16
    uv: 1.33.1
    zlib: 1.2.11
    brotli: 1.0.7
    ares: 1.15.0
    modules: 72
    nghttp2: 1.39.2
    napi: 5
    llhttp: 1.1.4
    http_parser: 2.8.0
    openssl: 1.1.1d
    cldr: 35.1
    icu: 64.2
    tz: 2019c
    unicode: 12.1

二、部署环境

1、初始化hexo:

1
2
3
mkdir hexo  # 创建目录
cd hexo # 进入目录
hexo init # 初始化(等待片刻)

hexo 常用命令:

1
2
3
4
hexo clean
hexo generate # (简写:hexo g)生成静态文件到项目根目录的public文件夹中
hexo server # (简写:hexo s)运行本地服务
hexo deploy # (简写:hexo d)一键部署
  • 执行相关命令可能会出现错误:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    [root@localhost hexo]# hexo g
    INFO Validating config
    INFO =======================================
    ██╗ ██████╗ █████╗ ██████╗ ██╗ ██╗███████╗
    ██║██╔════╝██╔══██╗██╔══██╗██║ ██║██╔════╝
    ██║██║ ███████║██████╔╝██║ ██║███████╗
    ██║██║ ██╔══██║██╔══██╗██║ ██║╚════██║
    ██║╚██████╗██║ ██║██║ ██║╚██████╔╝███████║
    ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝
    =============================================
    INFO === Checking package dependencies ===
    ERROR Package bulma-stylus is not installed.
    ERROR Package hexo-renderer-inferno is not installed.
    ERROR Package hexo-component-inferno is not installed.
    ERROR Package inferno is not installed.
    ERROR Package inferno-create-element is not installed.
    ERROR Please install the missing dependencies your Hexo site root directory:
    ERROR npm install --save bulma-stylus@0.8.0 hexo-renderer-inferno@^0.1.3 hexo-component-inferno@^0.10.0 inferno@^7.3.3 inferno-create-element@^7.3.3
    ERROR or:
    ERROR yarn add bulma-stylus@0.8.0 hexo-renderer-inferno@^0.1.3 hexo-component-inferno@^0.10.0 inferno@^7.3.3 inferno-create-element@^7.3.3
  • 按照提示安装相关依赖:
    npm install --save bulma-stylus@0.8.0 hexo-component-inferno@^0.10.0 hexo-renderer-inferno@^0.1.3 inferno@^7.3.3 inferno-create-element@^7.3.3

2、安装deploy git插件

1
npm install hexo-deployer-git --save
  • 若不安装此插件,使用’hexo deploy’部署代码会出现报错
    报错信息
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    [root@localhost hexo]# hexo d
    INFO Validating config
    Inferno is in development mode.
    INFO =======================================
    ██╗ ██████╗ █████╗ ██████╗ ██╗ ██╗███████╗
    ██║██╔════╝██╔══██╗██╔══██╗██║ ██║██╔════╝
    ██║██║ ███████║██████╔╝██║ ██║███████╗
    ██║██║ ██╔══██║██╔══██╗██║ ██║╚════██║
    ██║╚██████╗██║ ██║██║ ██║╚██████╔╝███████║
    ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝
    =============================================
    INFO === Checking package dependencies ===
    INFO === Checking theme configurations ===
    INFO === Registering Hexo extensions ===
    ERROR Deployer not found: git

3、本地运行测试:

1
2
hexo g
hexo s
  • 运行控制台输出:
    1
    2
    3
    4
    [root@localhost hexo]# hexo s
    INFO Validating config
    INFO Start processing
    INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
  • 浏览器访问地址:http://localhost:4000

请随意打赏

评论