部署 Blotter 博客系统

由于换小号嫖腾讯云 618 活动,因此要把服务器上的博客迁移一下,顺便做一下部署笔记

环境配置

Blotter 需要的内容有:Python、Go、Java、Node.JS、Yarn、MongoDB、GraphViz、PlantUML、Git

sudo apt update
sudo apt install python3.8 python3-pip nodejs npm graphviz plantuml git nginx screen -y
sudo npm -g install n
sudo n stable
sudo npm -g install yarn

wget https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz
sudo tar -xzvf go1.14.4.linux-amd64.tar.gz -C /usr/local
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
export PATH=$PATH:/usr/local/go/bin

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4B7C549A058F8B6B
sudo apt-get update
sudo apt-get install -y mongodb-org

python3.8 -m pip install pymongo feedparser bs4 lxml --user

安装 Blotter

git clone https://gitee.com/OhYee/blotter.git
git clone https://gitee.com/OhYee/blotter_page.git -b gh-pages
cd blotter && go build && cd ..
cd blotter_page && yarn && cd ..

配置 Nginx

在这里可能还需要配置nginx.conf的启动用户为static文件的用户,如User ubuntu

如果需要配置 WASM,则还需要在mime.types中添加application/wasm wasm;

server {
    listen       80;
    server_name www.oyohyee.com;
    rewrite ^(.*)$ https://$host$1 permanent;
}

map $http_upgrade $connection_upgrade{
        default upgrade;
        '' close;
}

server {
    listen       443 ssl http2 default_server;
    server_name www.oyohyee.com;

    client_max_body_size 20m;

    ssl_certificate "/etc/nginx/ssl/1_www.oyohyee.com_bundle.crt";
    ssl_certificate_key "/etc/nginx/ssl/2_www.oyohyee.com.key";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    proxy_max_temp_file_size 0;


    location ^~ / {
        #root   /usr/share/nginx/html;
        #index  index.html index.htm;
        proxy_pass  http://127.0.0.1:50002;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Scheme $scheme;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Host $server_name;
    }
    location ^~/static/ {
        root /home/ubuntu/blog/;
    }
    location ^~/api/ {
        proxy_pass http://127.0.0.1:50000;
        proxy_set_header nginx true;
                proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
    location = /ads.txt {
        root /home/ubuntu/blog;
    }
    rewrite /sitemap.txt /api/sitemap.txt;
    rewrite /sitemap.xml /api/sitemap.xml;
    rewrite /rss.xml /api/rss.xml;
    rewrite /robots.txt /api/robots.txt;
}

配置定时任务

0 * * * * bash /home/ubuntu/blog/autopush
30 3 * * * bash /home/ubuntu/blog/autobackup
0 3 * * * bash /home/ubuntu/blog/spider

百度主动推送

#!/bin/bash
curl https://www.oyohyee.com/sitemap.txt > /home/ubuntu/blog/urls.txt
curl -H 'Content-Type:text/plain' --data-binary @/home/ubuntu/blog/urls.txt "http://data.zz.baidu.com/urls?site=www.oyohyee.com&token=Ah36uCNcnwq2q7LX"

每日备份

#!/bin/bash
mongodump -o /home/ubuntu/blog/backup/`date '+%Y_%m_%d'`

爬虫更新

#!/bin/bash
python3.8 /home/ubuntu/blog/blotter/spider/main.py >> spider.txt

开放 25 端口

控制台开放对应服务器的端口用于发送邮件

参考文章