Hexo 是使用的比較多的博客框架了,我也嘗試本身搭一下,作一些基礎功能的測試。之因此沒有使用 GitHub 而選擇了碼雲,一是我有本身的 VPS 不須要使用 GitHub Pages ,因此本文也沒有關於如何使用 GitHub Pages 的教程;二是 GitHub 上私有倉庫是收費的,碼雲上面能建立免費的私有倉庫。也有人選擇使用 Docker 來建立博客環境,作鏡像備份,這裏沒有使用此方案,各有所好吧!node
主服務器系統版本與內核版本:linux
[root@dbn-japan ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@dbn-japan ~]# uname -r 3.10.0-862.3.2.el7.x86_64
測試服務器系統版本與內核版本:git
[root@host ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [root@host ~]# uname -r 4.10.4-1.el7.elrepo.x86_64
yum install -y wget
# 下載nodejs最新的bin包 wget https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-x64.tar.xz # 解壓 xz -d node-v10.13.0-linux-x64.tar.xz tar -xf node-v10.13.0-linux-x64.tar # 移動目錄 mv node-v10.13.0-linux-x64 /usr/local/nodejs # 部署文件 ln -s /usr/local/nodejs/bin/node /usr/bin/node ln -s /usr/local/nodejs/bin/npm /usr/bin/npm
能夠去官方網站下載,我這裏使用的類型爲:Linux Binaries (x64)web
[root@dbn-japan packages]# node -v v10.13.0 [root@dbn-japan packages]# npm -v 6.4.1
若是輸出了版本號,說明安裝成功。npm
yum install -y git
初始化設置:json
git config --global user.email "dbnuo@foxmail.com" git config --global user.name "BNDong"
npm install -g hexo-cli
安裝後嘗試執行命令: hexo vim
若是出現下面的輸出,按我下面的方法解決,沒有則跳過。bash
[root@dbn-japan packages]# hexo -bash: hexo: command not found
編輯環境變量文件: vim /etc/profile ,在文件末尾增長下面設置:服務器
export PATH=$PATH:/usr/local/nodejs/lib/node_modules/hexo-cli/bin
刷新環境變量: source /etc/profile ,這時再運行命令 hexo 就會有正確的輸出了。hexo
建立新的分支:sources
運行下面的命令建立 SSH Key,郵箱部分改爲你建立帳戶時候的郵箱:
[root@dbn-japan blog.dbnuo.org]# ssh-keygen -t rsa -C "dbnuo@foxmail.com" Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): # 目錄 Enter passphrase (empty for no passphrase): # 輸入密碼,可回車跳過 Enter same passphrase again: # 再次輸入密碼
查看公開密鑰:
cat ~/.ssh/id_rsa.pub
將公開密鑰添加至碼雲。
跳轉至網站根目錄,克隆項目至本地:
git clone https://gitee.com/dbnuo/bnd-hexo.git
跳轉至拉取的項目目錄:
# 建立 hexo 目錄 mkdir hexo # 進入 hexo 目錄 cd hexo/ # 初始化 hexo 目錄 hexo init npm install # 安裝插件 npm install hexo-generator-index --save npm install hexo-generator-archive --save npm install hexo-generator-category --save npm install hexo-generator-tag --save npm install hexo-server --save npm install hexo-deployer-git --save npm install hexo-deployer-heroku --save npm install hexo-deployer-rsync --save npm install hexo-deployer-openshift --save npm install hexo-renderer-marked --save npm install hexo-renderer-stylus --save npm install hexo-generator-feed --save npm install hexo-generator-sitemap --save
先看文件夾裏都有什麼:
[root@dbn-japan hexo]# ls -a . .. _config.yml .gitignore node_modules package.json package-lock.json scaffolds source themes
基礎配置能夠參考官方文檔的配置說明。這裏須要在末尾添加 Git 的配置:
...
deploy: type: git repo: https://gitee.com/dbnuo/bnd-hexo.git branch: master message: 'web updata: {{now("YYYY-MM-DD HH/mm/ss")}}'
運行命令: hexo cl && hexo g -d 輸入用戶名和密碼後,頁面代碼就會提交至碼雲項目中。
將網站目錄指定至 hexo 的 public 文件夾中,訪問網站:
跳轉至項目目錄 bnd-hexo:
git checkout -b sources # 建立切換分支 git push origin sources # 提交代碼至分支
提交至碼雲項目分支:
至此搭建完畢,代碼也備份到項目中了。爲了測試備份恢復,我新建了個文章 test 並提交進行測試。
切換至測試服務器,基礎的安裝和設置能夠參考上面的流程。
跳轉至網站的根目錄:
# 拉取項目至本地 git clone https://gitee.com/dbnuo/bnd-hexo.git # 跳轉至目錄 cd bnd-hexo # 建立分支並拉取 git checkout -b sources origin/sources # 跳轉至源文件目錄 cd hexo # 初始安裝 npm install npm install hexo-generator-index --save npm install hexo-generator-archive --save npm install hexo-generator-category --save npm install hexo-generator-tag --save npm install hexo-server --save npm install hexo-deployer-git --save npm install hexo-deployer-heroku --save npm install hexo-deployer-rsync --save npm install hexo-deployer-openshift --save npm install hexo-renderer-marked --save npm install hexo-renderer-stylus --save npm install hexo-generator-feed --save npm install hexo-generator-sitemap --save
執行完畢,hexo 就恢復了,能夠正常操做了。
至此兩臺服務器都對一個項目庫進行操做,能夠說是多終端了,我在測試服務器新建了個文章: hexo new post "test2"
建立成功後提交上傳。
切換回主服務器:
# 跳轉至項目目錄 cd bnd-hexo # 拉取項目 git pull origin sources # 跳轉至源文件目錄 cd hexo/ # 從新編譯 hexo cl && hexo g -d
再訪問網站:
看到這裏出現了文章 test2 ,至此多終端編輯操做成功。
這裏簡單介紹了一些必要的流程操做,建議你們將一些基本操做封裝成腳原本操做,至於主題和優化你們能夠參考一些網上的資源教程,感謝閱讀,拜謝!