When I have a server what I've done

When the eighteen year-end, I wrote an article when I have a server what I've done

Is the end, my server architecture has also undergone some changes, therefore summarize some

Overview

Last year, the server has two, one 2C4G, a 1C2G

This year there are three servers, with the following names as hostnamethe following configuration

  • dev: 1C2G, less than a hundred dollars. For everyday coding, simple reverse proxy and project deployment
  • shanyue: 2C4G,k8s master node
  • shuifeng: 4C16G,k8s work node

Because devthe machines last enumerated things like, next only presented here on this 1C2G server did what

Simply draw an architectural view of this server (less likely to draw, so to build a warehouse shfshanyue / graph to learn a variety of architectural drawing method)

Blog and coding

Basically your own personal blog and coding are on the server to complete this test, as to why you want to develop in the server:

  1. In the company of my own laptop and Mac synchronization blog is too painful, while using the server as an intermediary is a lot easier

Since writing blog as well as some personal code in the server, so I bought a new MBP has become a display

Development environment

zsh+ tmux+ vim, The following theme

Most of the time in this mode, if the process of writing blog need shots, then downloaded to a random directory, and then use the rsynccopied to the target path

$ rsync ~/Documents/tmux.png dev:/path/Documents/blog/op/assets/dev-env.png

vscode remote

If you need to debug code, or in writing typescript, using vscode remotethe job done

In vscode plug-in keyword search, install it wants to download up to three plug-ins

Development and debugging

如果调试前端页面需要在浏览器中打开地址,比如 IP:8000,一般采用两种方案

  1. nginx镜像 + volume挂载 + docker-compose + traefik服务发现。略微麻烦
  2. npm run dev + openvpn。在本地环境中的浏览器通过 openvpn 连接局域网

如果调试后端接口,需要打断点直接使用 vscode remote

对外服务

有几个在公网下可访问的服务,如

对内服务

主要以数据库为主,使用 local DNS + traefik + openvpn 暴露在本地环境,使用禁掉公网端口以及仅在内网访问的IP白名单保证安全

  • postgres,主要是一个关于诗词的数据库
  • redis
  • traefik dashboard,管理流量

另外,这些对内对外的服务均是通过 docker 以及 docker-compose 部署

博客去了哪里?

以下是我博客的历程

  1. 个人服务器,后来服务器部署了 k8s 就把博客挪出了
  2. netlify,但是网络不好
  3. alioss + github actions,速度挺好,但是对 http rewrite 支持的不是很好

以后将会考虑 serverless

你可以发现,我现在更多的转向了一些免费的云服务,如

  1. serverless 可以写后端服务,我将把我的公众号的服务迁移过来。国内可用阿里云以及腾讯云,国外 aws
  2. dynomodbtablestore 免费的数据存储
  3. oss 很便宜的对象存储服务
  4. netlify 免费的静态网站托管托管服务
  5. github actions 免费的CICD及构建服务器
  6. sentry 免费的错误日志收集系统
  7. github 免费的私有仓库服务
  8. prerender.io 免费的预渲染服务

嗯,有了这些都可以做一个自由开发者了 (自惭形秽中...)

openVPN

数据库放在公网访问有点危险,用docker建了vpn在本地开发访问。使用了以下镜像

docker-openvpn

traefik

前后端需要做一个反向代理,选择了 traefik,更方便的服务配置以及服务发现,只需要配置容器的 labels 就可以部署成功

另外 traefik 可以很方便的自动生成 ssl/tls 证书,为你提供 https 服务

DNS server

有了这么多的服务,但有的东西不好放在公网,如 redispostgres 一些私有服务以及开发待调试的服务,又记不住端口号,所以又搭了一个 dns server,方便在本地访问

自动化运维

初期折腾服务器的时候经常需要重装系统,并且我有三台服务器,自动化运维是必不可少的了。

必备工具如 dockergitvimtmuxjq 都是通过 ansible 进行的安装

可以参考我的配置

当你有了一台新服务器时,你可以遵循以下步骤

  1. 使用 ansible-role 预配置环境
  2. 如果没有 ansible-role,则自己写 role
  3. 对于一些服务使用 docker 进行安装
  4. 如果以上都无法解决,手动安装

监控

没有像去年那样使用 prometheus 一套,只简单了使用了两个命令以及阿里云自带的监控

  • ctop: 监控容器
  • htop: 监控进程

对比

如果说与去年有对比的话,体现在两方面

  1. 更彻底的容器化
  2. 更加拥抱云服务,如 github actions,serverless,netlify 等

另外,还有一方面是自建了 k8s 集群 (真是烧钱),将会在另一个仓库中介绍它的体系。但是如果你对 k8s 没有什么兴趣的话,这一台1C2G的服务器完全满足你的要求

Guess you like

Origin www.cnblogs.com/xianwang/p/12099871.html