After deploying our own static blog page, we can publish articles to the blog system, but each time we need to compile and package files and upload them to the cloud server. The same process can be completed with the best tool. Next, we will combine git version management tool to realize automatic deployment process. In the future, we only upload MD files and the blog page can be automatically updated

1. Select the version management tool

Here we directly use the code cloud, relatively fast, you know, directly create the code repository to push our blog code to the remote side, but need to pay attention to the need to ignore the file, if you use IDEA can download.

.idea
*.iml
node_modules
out
db.json
Copy the code

Out is the package output path, which can be adjusted from the project root directory _config.yml. Db. json should be ignored to avoid conflicts during deployment

2. Cloud server installation and running environment

  • The git downloadDownload and install, or install through yum
    The first option: yum install git the second option: Decompress the downloaded binary file package, set environment variables, and download it from Baidu to view the git-version versionCopy the code
  • The node to downloadDownload the Linux binary file (X64)
    Decompress the package tar -xvf node-v14.16.1-linux-x64.tar.xz rename the file mv node-v14.16.1-linux-x64 node14 Create a soft connection. Set the environment variable ln -s node14/bin/node /usr/bin/node View the version node -v NPM -vCopy the code

3. Pull the code and install Hexo

  • Pull the code and deploy it manually
    Git clone https://gitee.com/ install CNPM NPM install -g CNPM - registry=https://registry.npm.taobao.org by CNPM installation hexo CNPM install - g hexo - cli create hexo soft chain, Run the global environment variable ln -s /export/app/kayla-blog/node_modules/hexo-cli/bin/hexo /usr/bin/hexo to compile the static file hexo gCopy the code
  • Set the user name and password

Directly modify the project directory. Git /config and add the following information

[credential]
      helper = store
Copy the code

4. Create automated scripts

If the above steps work, then it is relatively easy to use The Linux cron to periodically execute script tasks to trigger pulling the latest blog content and compiling static files

  • Create a CRon task
    Crontab -e (hexo-g. Sh) hexo.out (hexo.out) You must add 2>&1 */3 * * * */ export/app/hexo-g.sh >> /export/app/hexo.out 2>&1Copy the code
  • Script content hexo-g.sh
    #! /bin/bash source /etc/profile source ~/. Bashrc echo $(date "+%Y-%m-%d %H:% m :%S")" CD /export/app/blog echo "git pull echo G echo "done"Copy the code
  • The test results

    There may be some difficulties in the deployment process, students who have difficulties can put them in the comments section, and we can solve them together and learn from each other
    Start automatically compile, the current time: 2021-05-04 07:51:01 began to pull gitee code From https://gitee.com/xxx/blog 1 ecc028.. 980f12b master -> origin/master Updating 1ecc028.. 980f12b Fast-forward ... 215\232\345\256\242\347\275\221\347\253\231.md" | 66 +++++++++++++--------- 1 file changed, 38 insertions(+), ->out INFO valconfig INFO Start processing INFO Files loaded in 270 ms INFO Generated: 2021/05/03/ build my blog website /index.html INFO 1 files Generated in 76 ms completedCopy the code