现有的Hexo架构已经用了三年年,随着Nodejs、hexo和theme-butterfly的大版本升级,现有的系统也该update一下了。基本情况是系统从RockyLinux9换成了Fedora,Nodejs由18升级到21,Butterfly主题由4.2升级到了5.2,Hexo也升级到了7.3。

2024.09.30 摄于内蒙古·呼和浩特市·泽成冰煮羊

基础软件

  1. 操作系统软件使用Fedora 40

    1
    2
    3
    4
    dnf update -y
    dnf install -y wget curl htop fail2ban rsyslog
    mkdir -p .config/htop
    touch .config/htop/htoprc
  2. 部署Nginx

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    dnf install -y wget curl nginx 
    dnf install -y netdata
    systemctl enable --now nginx
    systemctl enable --now netdata

    # 创建SSL目录
    mkdir /etc/nginx/ssl
    # 复制ssl证书

    # 创建通用SSL配置文件
    cat >/etc/nginx/ssl/ssl.conf <<EOF
    ssl_certificate /etc/nginx/ssl/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/certkey.pem;
    ssl_prefer_server_ciphers on;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;
    add_header X-Xss-Protection 1;
    EOF

    # 创建站点配置文件
    cat >/etc/nginx/conf.d/blog.conf<<EOF
    server {
    listen 80;
    server_name www.sujx.net;
    return 301 https://www.sujx.net$request_uri;
    }

    server {
    listen 443 ssl;
    gzip on;
    server_name www.sujx.net;
    charset utf-8;

    include /etc/nginx/ssl/ssl.conf;
    access_log /var/log/nginx/blog.access.log;
    error_log /var/log/nginx/blog.error.log;

    location / {
    root /opt/blog/public;
    index index.htm index.html;
    }

    location /netdata/ {
    proxy_pass http://127.0.0.1:19999/;
    }

    }
    EOF
  3. 配置Nginx

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    # 配置日志轮转
    dnf install -y logrotate
    touch /var/spool/cront/root

    echo "0 0 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx" >> /var/spool/cron/root

    # 配置站点日志分析
    dnf install -y goaccess

    # 添加地图显示
    wget https://download.db-ip.com/free/dbip-country-lite-2024-11.mmdb.gz
    gunzip dbip-country-lite-2024-11.mmdb.gz
    mv dbip-country-lite-2024-11.mmdb /usr/share/GeoIP/

    cat >> /etc/goaccess/goaccess.conf<<EOF
    geoip-database /usr/share/GeoIP/dbip-country-lite-2024-11.mmdb
    EOF

站点部署

  1. 部署Nodejs

    1
    2
    3
    4
    5
    6
    7
    8
    dnf install -y nodejs git
    node -v
    npm -v
    # 配置NPM使用淘宝镜像
    npm config set registry https://registry.npmmirror.com
    npm install -g npm-check
    # 全局升级检查
    npm-check -u -g
  2. 部署Hexo

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    npm install hexo-cli -g
    mkdir /opt/blog && cd /opt
    hexo init blog && cd ./blog

    # 安装博客文章排序插件
    npm install hexo-renderer-pug hexo-renderer-stylus --save
    # 安装字数统计插件
    npm install hexo-wordcount --save
    # 安装豆瓣插件
    npm install hexo-douban --save
    # 安装站点地图插件
    npm install hexo-generator-sitemap --save
    # 安装RSS插件
    npm install hexo-generator-feed --save
    # 安装本地搜索插件
    npm install hexo-generator-searchdb --save
    # 安装主题插件
    npm install hexo-theme-butterfly --save
    # 安装额外JS脚本插件
    npm install hexo-butterfly-extjs --save
    # 安装tag插件
    npm install hexo-butterfly-tag-plugins-plus --save
    # 安装PDF插件
    npm install hexo-pdf --save
    # 安装压缩静态资源插件
    npm install hexo-all-minifier --save
    # 安装Git上传插件
    npm install hexo-deployer-git --save
    # 安装阿里云OSS上传插件
    npm install hexo-deployer-ali-oss --save
    # 安装置顶插件
    npm uninstall hexo-generator-index --save
    npm install hexo-generator-index-pin-top --save

    # 测试
    hexo clean && hexo g
  3. 主题配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    # 字体设置,新版butterfly字体太小了
    # Global font settings
    # Don't modify the following settings unless you know how they work
    font:
    global_font_size: 15px
    code_font_size: 16px
    font_family: Noto Serif SC
    code_font_family: Roboto Mono

    # Font settings for the site title and site subtitle
    blog_title_font:
    font_link: https://fonts.googleapis.com/css?family=Titillium+Web&display=swap
    font-family: Roboto Mono

    # 需要调整默认的JS的CDN设置,要将默认的jsdelivr修改为cdnjs,或者local
    CDN:
    # The CDN provider for internal and third-party scripts
    # Options for both: local/jsdelivr/unpkg/cdnjs/custom
    # Note: Dev version can only use 'local' for internal scripts
    # Note: When setting third-party scripts to 'local', you need to install hexo-butterfly-extjs
    internal_provider: local
    third_party_provider: cdnjs

    # 配置监控页面显示
    # mkdir source/html
    # _config.yml 跳过页面渲染
    skip_render:
    - "html/**"
    # _config.butterfly.yml 创建监控页面
    menu:
    Home: / || fas fa-home
    Posts: /archives/ || fas fa-archive
    Categories: /categories/ || fas fa-folder-open
    Movies: /movies/ || fas fa-film
    Books: /books/ || fas fa-book
    Status: /html/access.html || fa fa-bar-chart
    About: /about/ || fas fa-heart


    # 其他需要对照旧版配置文件进行微调,旧版不能直接导入新版系统
  4. 定期生成

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    # 创建shell脚本
    mkdir /opt/scripts
    cat >/opt/scripts/blogUpdate.sh <<EOF
    #!/bin/bash
    source /etc/profile
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
    export LANG=zh_CN.UTF-8

    /usr/bin/goaccess -a -d -f /var/log/nginx/blog.access.log -p /etc/goaccess/goaccess.conf -o /opt/blog/source/html/access.html

    cd /opt/blog
    hexo clean
    hexo g
    EOF

    chmod +x /opt/scripts/blogUpdate.sh

    echo "55 23 * * * bash /opt/scripts/blogUpdate.sh" >> /var/spool/cron/root