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
- Original Address: When I have a server what I've done
- Series: When I have a server what I've done
Overview
Last year, the server has two, one 2C4G, a 1C2G
This year there are three servers, with the following names as hostname
the following configuration
dev
: 1C2G, less than a hundred dollars. For everyday coding, simple reverse proxy and project deploymentshanyue
: 2C4G,k8s master nodeshuifeng
: 4C16G,k8s work node
Because dev
the 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:
- 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 rsync
copied 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 remote
the job done
In vscode plug-in keyword search, install it wants to download up to three plug-ins
Development and debugging
如果调试前端页面需要在浏览器中打开地址,比如 IP:8000
,一般采用两种方案
nginx
镜像 +volume
挂载 +docker-compose
+traefik
服务发现。略微麻烦npm run dev
+openvpn
。在本地环境中的浏览器通过openvpn
连接局域网
如果调试后端接口,需要打断点直接使用 vscode remote
对外服务
有几个在公网下可访问的服务,如
- 公众号开发: 主要用以给我的公众号导流 -> 如果想知道流程是什么,请转到这篇文章 两年前端头条面试记,从中的隐藏部分你便能知道大概。过几天,我将写一篇文章作为总结。
- https://whoami.shanyue.tech/: 用以测试
traefik
的负载均衡及服务发现 - 若干
reveal.js
页面
对内服务
主要以数据库为主,使用 local DNS
+ traefik
+ openvpn
暴露在本地环境,使用禁掉公网端口以及仅在内网访问的IP白名单保证安全
postgres
,主要是一个关于诗词的数据库redis
traefik dashboard
,管理流量
另外,这些对内对外的服务均是通过 docker
以及 docker-compose
部署
博客去了哪里?
以下是我博客的历程
- 个人服务器,后来服务器部署了
k8s
就把博客挪出了 netlify
,但是网络不好alioss
+github actions
,速度挺好,但是对http rewrite
支持的不是很好
以后将会考虑 serverless
你可以发现,我现在更多的转向了一些免费的云服务,如
serverless
可以写后端服务,我将把我的公众号的服务迁移过来。国内可用阿里云以及腾讯云,国外 awsdynomodb
与tablestore
免费的数据存储oss
很便宜的对象存储服务netlify
免费的静态网站托管托管服务github actions
免费的CICD及构建服务器sentry
免费的错误日志收集系统github
免费的私有仓库服务prerender.io
免费的预渲染服务
嗯,有了这些都可以做一个自由开发者了 (自惭形秽中...)
openVPN
数据库放在公网访问有点危险,用docker建了vpn在本地开发访问。使用了以下镜像
traefik
前后端需要做一个反向代理,选择了 traefik,更方便的服务配置以及服务发现,只需要配置容器的 labels
就可以部署成功
另外 traefik
可以很方便的自动生成 ssl/tls 证书,为你提供 https 服务
DNS server
有了这么多的服务,但有的东西不好放在公网,如 redis
,postgres
一些私有服务以及开发待调试的服务,又记不住端口号,所以又搭了一个 dns server
,方便在本地访问
自动化运维
初期折腾服务器的时候经常需要重装系统,并且我有三台服务器,自动化运维是必不可少的了。
必备工具如 docker
,git
,vim
,tmux
,jq
都是通过 ansible
进行的安装
可以参考我的配置
当你有了一台新服务器时,你可以遵循以下步骤
- 使用 ansible-role 预配置环境
- 如果没有 ansible-role,则自己写 role
- 对于一些服务使用 docker 进行安装
- 如果以上都无法解决,手动安装
监控
没有像去年那样使用 prometheus
一套,只简单了使用了两个命令以及阿里云自带的监控
ctop
: 监控容器htop
: 监控进程
对比
如果说与去年有对比的话,体现在两方面
- 更彻底的容器化
- 更加拥抱云服务,如
github actions
,serverless,netlify 等
另外,还有一方面是自建了 k8s 集群 (真是烧钱),将会在另一个仓库中介绍它的体系。但是如果你对 k8s 没有什么兴趣的话,这一台1C2G的服务器完全满足你的要求