CentOS7上部署Hexo博客

Hexo博客搭建部署

Hexo是一款非常简洁明快,不用写代码就能搭建运行起来的静态博客框架,而且支持MarkDown文本编辑,如果你精通前端研发,那么恭喜你了,Hexo就是完全给你预备的,你可以随意的自建主题和风格样式,如果你不懂前端也没关系,Hexo也为你提供的大量的预制主题可以供你选择。我之前折腾过几回Hexo博客,现在把折腾的步骤分享给大家。

文章目录

      • Hexo博客搭建部署
        • 1. 安装Git
        • 2. 安装Node.js
        • 3. 安装Hexo
        • 4. 安装Next主题
        • 5. 配置阿里云安全组
        • 6. 安装Nginx
        • 7. 部署到Github和Coding
        • 8. 绑定域名
        • 9. 配置和发布博客
        • 10. Hexo缩写指令
        • 11. Hexo常用命令
        • 12.官方文档

1. 安装Git

# 1.先更新系统
yum update
# 2.安装依赖的包
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
# 3.下载git源码并解压
# 下载地址:https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.19.2.tar.gz
tar zxvf git-2.17.1.tar.gz
cd git-2.17.1
# 4.编译安装
# 将其安装在“/usr/local/git”目录下。
make prefix=/usr/local/git all
make prefix=/usr/local/git install
# 5.配置环境变化
vim /etc/profile
# 然后在文件的最后一行,添加下面的内容,然后保存退出。
export PATH=$PATH:/usr/local/git/bin
# 使用source命令生效。
source /etc/profile
# 6.验证是否安装成功。
git --version

配置git账户信息:

git config --global user.name "yourname"
git config --global user.email "youremail"
git config user.name
git config user.email
# 生成免密key
ssh-keygen -t rsa -C "youremail"
    

2. 安装Node.js

yum -y update gcc
yum -y install gcc+ gcc-c++
wget https://npm.taobao.org/mirrors/node/v10.13.0/node-v10.13.0.tar.gz
tar xvf node-v10.13.0.tar.gz
cd node-v10.13.0/
./configure
make   #这个操作可能会很久
make install
node -v
npm -v

3. 安装Hexo

npm install -g hexo-cli
hexo init myblog
cd myblog //进入这个myblog文件夹
npm install
hexo g
hexo server

打开hexo的服务,在浏览器输入localhost:4000就可以看到你生成的博客了

4. 安装Next主题

# 进入你的hexo项目根目录
cd your-hexo-site
git clone https://github.com/theme-next/hexo-theme-next themes/next

# 修改站点配置文件中的主题配置
theme: next
scheme: Gemini
# 修改语言选项
language: zh-Hans     next5版本
language: zh-CN       next6版本

5. 配置阿里云安全组

如果你在阿里云服务等云服务器上搭建的,就要开启安全组的端口,类似于开启防火墙端口,添加入站出站规则。 入口方向:80和4000端口

6. 安装Nginx

# 安装:
yum install nginx
# 启动:
systemctl start nginx
systemctl enable nginx

配置 Nginx配置文件

vim /etc/nginx/nginx.conf

user root;
.......
......
server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /home/hexo/myblog/public;
        
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {
        }
        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

输入url即可显示博客首页。

7. 部署到Github和Coding

  • 进入GitHub,新建一个Repository
  • 仓库的名字,必须是自己的Github账户的用户名.github.io
  • 进入Coding (https://dev.tencent.com/user),新建一个Repository,跟建github页一样建Coding页
  • 用Nodepad++打开hexo文件夹下面的_config.yml文件,添加项目地址
deploy:
  type: git
  repo: 
    github: [email protected]:xxx/xxx.github.io.git
    coding: [email protected]:xxx/xxx.git
  branch: master
  • 执行安装发布插件命令
    npm install hexo-deployer-git --save
  • 在GitHub的setting中,找到SSH keys的设置选项,点击New SSH key把id_rsa.pub里面的信息复制进去
  • 执行 ssh -T [email protected] 验证连接
  • 同理,在Coding的设置中,也配置好SSH免密码安全设置
  • 执行 ssh -T [email protected] 验证连接

过一会儿就可以在http://yourname.github.io 和http://yourname.coding.me 这两个网站看到你的博客了。

8. 绑定域名

如有你有自己的域名,就可以配置一下自己的域名了。

  1. 打开终端,输入ping 用户名.github.io
  2. 修改域名解析 A:IP地址 CNAME:xxxx.github.io
  3. 在D:\blog\source中新建CNAME记事本,内容输入www.xxxxx.cn,保存关闭。然后重命名,删除后缀.txt
  4. GitHub中菜单填写域名,步骤:Setting-Repositories-Settings-Custom domain

9. 配置和发布博客

# 新建标签页面
cd you-site
sudo hexo new page tags
# 创建完成后,打开you-site/source/tags的index.md,修改如下
---
title: 标签
date: 2019-05-26 18:16:05
type: "tags"
comments: false
---

# 新建类别页面
cd you-site
hexo new page categories
# 创建完成后,打开you-site/source/categories的index.md,修改如下
---
title: 分类
date: 2019-05-26 18:18:12
type: "categories"
comments: false
---

# 新建自我介绍页面
hexo new page about
# 创建完成后,打开you-site/source/about的index.md,修改如下
---
title: 关于我
date: 2019-05-28 21:09:56
type: "about"
comments: false
---

# 配置博客生成模板
# 设置your site/scaffolds/post.md文件
---
title: {{ title }}
date: {{ date }}
tags:
categories:
copyright: true
---

# 生成新的文章,newpapername就是文件名
hexo new newpapername
# 打开newpapername.md编辑文章
=======================================================================================
---
title: aiomultiprocess及aiohttp的简单使用
date: 2019-06-18 20:01:14
categories:
	- Python
tags:
	- aiomultiprocess
	- aiohttp
	- python
---

>xxxxxx
<!-- more -->
=====================================================================================
# 清理
hexo clean
# 生成静态页
hexo g
# 发布
hexo d

10. Hexo缩写指令

  • hexo g # 完整命令为hexo generate,用于生成静态文件
  • hexo s # 完整命令为hexo server,用于启动服务器,主要用来本地预览
  • hexo d # 完整命令为hexo deploy,用于将本地文件发布到github上
  • hexo n # 完整命令为hexo new,用于新建一篇文章

11. Hexo常用命令

  • hexo new “postName” # 新建文章
  • hexo new page “pageName” # 新建页面
  • hexo generate # 生成静态页面至public目录
  • hexo server # 开启预览访问端口(默认端口4000,'ctrl + c’关闭server)
  • hexo deploy # 部署到GitHub
  • hexo help # 查看帮助
  • hexo version # 查看Hexo的版本
  • hexo s -g # 生成并本地预览
  • hexo d -g # 生成并上传

12.官方文档

  • Hexo官方文档 https://hexo.io/zh-cn/docs/
  • Hexo主题合集 https://hexo.io/themes/)

你可能感兴趣的:(Linux,nginx,linux,node.js,前端,centos)