十月Vercel被墙的临时解决方案:GitHub Actions 与 Rsync 自动部署
Vercel暂时被墙 十月初Vercel被墙的临时解决方案,先用自己的服务器部署博客。
要求:不手动部署,希望像之前在Vercel一样,在提交git后能够自动生成并部署。
需要使用 Github Actions 来生成,Rsync 来部署。
创建部署用户 1 2 3 4 5 6 7 8 sudo adduser deploy sudo usermod -s /bin/bash -d /home/deploy deploy sudo mkdir -p /www/blog sudo chown -R deploy:deploy /www/blog sudo chmod -R 775 /www/blog
生成SSH登录秘钥 1 2 3 4 5 6 7 su deploy ssh-keygen -t ed25519 -C "your_email@example.com" cat id_ed25519.pub >> authorized_keyscat id_ed25519.pub
出于安全考虑,建议禁用该用户的密码登录,仅允许使用密钥登录。
配置Github Actions 在仓库中创建文件/.github/workflows/deploy-to-server.yml
,并写入以下内容:
/.github/workflows/deploy-to-server.yml 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 name: Deploy to Server on: push: branches: - main workflow_dispatch: jobs: deploy: name: Deploy to Server runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v3 with: node-version: 18 - name: Install Dependencies run: npm install - name: Build Hexo Application run: npm run build - name: Deploy to server uses: burnett01/rsync-deployments@6.0.0 with: switches: -avzr --delete path: public/ remote_host: ${{ secrets.DEPLOY_SERVER }} remote_port: ${{ secrets.DEPLOY_PORT }} remote_user: ${{ secrets.REMOTE_USER }} remote_key: ${{ secrets.SSH_KEY }} remote_path: ${{ secrets.DEPLOY_PATH }}
然后进入你的Github仓库,选择 Settings > Secrets and Variables > Actions > New Repository Secret 添加上面用到的环境变量。
DEPLOY_SERVER
服务器IP
DEPLOY_PORT
SSH端口,一般为22
REMOTE_USER
登录用户名
SSH_KEY
私钥
DEPLOY_PATH
服务器上的部署路径,例如/www/blog/
如果不想在本次提交中触发自动部署,请在提交信息的最后添加[skip actions]
,详见Skipping workflow runs 。
可能遇到的问题 bash: line 1: rsync: command not found 1 2 3 Warning: Permanently added '***' (ED25519) to the list of known hosts. bash: line 1: rsync: command not found rsync: connection unexpectedly closed (0 bytes received so far) [sender]
请在你的目标服务器上安装 rsync
1 2 sudo apt-get update sudo apt-get -y install rsync