网址展示:我的个人博客
此文章总结不易,参考各个文章总结,如有问题请留言…
一台轻量应用服务器点以下链接购买享专属优惠,买一台2核2G的足够。
https://curl.qcloud.com/YrzHcTR9
win11 64位;
node.js:v14.15.3 64位;
git:2.29.2.windows.2 64位
编写代码使用VSCode
自主安装(修改安装路径,一路next)
cmd 查看版本
C:\Users\hong>node -v
v14.15.3
C:\Users\hong>npm -v
6.14.9
命令提示行打入:
npm config set prefix "E:\environment\nodejs\node_global"
npm config set cache "E:\environment\nodejs\node_cache"
自主安装(修改安装路径,一路next)
cmd 查看版本
C:\Users\hong>git --version
git version 2.33.1
设置Github的名字和邮箱
git config --global user.name "你的名字"
git config --global user.email“你的邮箱"
生成ssh
ssh-keygen -t rsa -C "你的名字/你的邮箱"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
/c/Users/Administrator/.ssh/id_rsa already exists.
Overwrite (y/n)? y(输入y)
Enter passphrase (empty for no passphrase):(回车)
Enter same passphrase again:(回车)
系统会自动在.ssh文件夹(.SSH在C:\Users\Windows用户名目录下)下生成两个文件,id_rsa和id_rsa.pub
# 选择存放博客文件的位置,鼠标右键,选择Git Bash Here
# 依次执行完成以下操作
# 1.hexo框架的全局安装
npm install -g hexo-cli
# 2.新建一个网站,[folder]改自定义博客文件夹名称
hexo init [folder]
# 3.进入博客文件夹
cd 上一步博客文件夹名称
# 4.安装博客所需要的依赖文件
npm install
生成静态文件并启动服务
hexo g && hexo s
1
运行成功最后一行出现
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
浏览器中打开 http://localhost:4000 或127.0.0.1:4000,看到网页,则运行成功
在hexo根目录执行
git clone -b master [https://gitee.com/immyw/hexo-theme-butterfly.git](https://gitee.com/immyw/hexo-theme-butterfly.git) themes/butterfly
修改hexo根目录下的_config.yml,修改主题
theme: butterfly
npm install hexo-renderer-pug hexo-renderer-stylus --save
为减少升级主题带来的不便,采用以下方法
hexo根目录下创建config.butterfly.yml,主题(磁盘:\博客跟目录\themes\butterfly)下的config.yml內容复制到刚刚创建的config.butterfly.yml
注:
详情配置信息可前往一下主题配置首页调试。有问题也可以访问文章开头我的博客进行评论联系
Butterfly - A Simple and Card UI Design theme for Hexo
# 用户名就是git,若不存在用户目录,则会创建
adduser -d /home/git -m git
# 输入设置git用户的密码,此步骤在此不展示,建议密码设置复杂点,毕竟是放在网上的
passwd git
# 编辑/etc/sudoers文件,在root ALL=(ALL) ALL之后回车追加以下内容
git ALL=(ALL) ALL
chmod 755 /home/git
# 切换用户并进入当前用户目录
su git
cd /home/git
# 创建文件并给予权限
mkdir .ssh && chmod 700 .ssh
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
linux新开一个终端
# root用户下执行
cd ~/.ssh/
# 此步将id_rsa.pub上传当前目录再执行查看
ls ./id_rsa.pub
# cp到git用户目录下
scp ./id_rsa.pub root@114.xxx.xxx.xxx:/home/git
切换用户
# 切换到git用户
su git
# 进入git用户的家目录
cd /home/git
#将id_rsa.pub文件内容追加到authorized_keys中
cat ./id_rsa.pub >> .ssh/authorized_keys
# 连接
ssh git@服务器IP
# 新仓库要建立在哪个文件夹自己选,我直接放在git用户的目录下
cd /home/git
# 创建一个新仓库目录
mkdir hexoblog.git
# 进入新仓库目录
cd hexoblog.git
# 初始化该新仓库
git init --bare
# 出现以下内容表示成功
Initialized empty Git repository in /home/git/hexoblog.git/
如连接时报错:
ECDSA host key for [ip address] has changed and you have requested strict checking
解决:修改本地.ssh下的host文件即可,删除与服务器连接信息
至此,服务器上的git仓库搭建完毕,地址为:
git@服务器IP:/home/git/hexoblog.git
# 新建部署后文件位置
sudo mkdir -p /home/web/hexo
仓库下新建/hooks/post-update文件,新增内容
#!/bin/bash
git --work-tree=/home/web/hexo --git-dir=/home/git/hexoblog.git checkout -f
给post-update权限
cd /home/git/hexoblog.git/hooks/
sudo chown -R git:git /home/web/hexo
# 赋予其可执行权限
sudo chmod +x post-update
修改根目录下config.yml文件
deploy:
type: git
repository:
repo: git@服务器IP:/home/git/hexoblog.git
branch: master #把博客推送至主分支
至此,在根目录Git Bash Here执行
hexo clean && hexo g && hexo d
1
查看服务器/home/web/hexo目录下生成静态文件,至此完成!!
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。