If this article helps you, please click a star on shfshanyue/op-note for me

If you are new, you can click the link to buy it

The front-end research

At the beginning of the research server rendering to write a demo, just interested in poetry, so I made a site about poetry, the more I write, the demo turned into a demo, in general is very simple. It just hung off the server.

Technology stack 👉 Next. Js + React + ApolloClient + Docker + Docker Compose

The website is at 👉 poetry string song

Later, I hung up my own blog 👉 mountain moon’s blog

The backend support

With the front-end, we naturally need server-side support. Following the principle of simplicity and convenience, we made a direct choice between Parse-Server and GraphQL, and finally chose GraphQL. And made a half-finished scaffold. Supports the following functions

Semi-finished scaffolding hanging at Github github.com/shfshanyue/…

  • N+1 query
  • On-demand loading of database fields
  • Middleware for a specific field cache
  • Access to the Sentry
  • Access Consul KEv/Value Store
  • JWT does identification
  • Structure error messages and use sentry alerts
  • Structured log information for ELK analysis
  • The Docker and Docker Compose
  • Traefik does load balancing (and does not) with reverse proxies

Here the scaffold has a living example of todos. Xiange. Tech/playground you need to use shanyue/shanyue do account password, login is createUserToken mutation

At that time wrote a front-end half-finished scaffolding, Shfshanyu/react-Apollo-starter, do not know now can run up……

👉 Graphql + ApolloServer + Sequelize + Docker + JWT + (Traefik + Sentry + Consul)

Docker

Docker + docker-compose is used for deployment. I also do a lot of Docker tests on it

The database

The backend relies on data, so Redis and Postgres are deployed with Docker

When you plug in the monitor, you’ll notice that Postgres is taking up more and more memory from the beginning to the end, because some of the data is moving from disk to memory.

VPN

It is a little dangerous to access the database on the public network, so I built a VPN with Docker to develop access locally. The following images are used

Github.com/kylemanna/d…

Although it is set up, it is still confused, so far it only controls a certain CIDR segment through VPN

Configure the service

The back-end needed to configure the service, docker deployed Consul with only its key-value store, and its service discovery functionality was wasted

Directly install and download bare-metal devices

Consul agent-data-dir =/consul/ data-config-dir =/consul/ config-server-data-dir =/consul/ data-advertise 172.17.68.39 -bootstrap-expect= 1-node = yony-server-bind =0.0.0.0 -client=0.0.0.0 - UICopy the code

Error collection system

An error collection system was needed on both the front and back ends, so Sentry was deployed with Docker

Sentry relies on Redis, Postgres, and I direct my dependencies to redis and Postgres, which are common to my site. Later migration is a problem, and error logging is so heavy that it can even crash the database. But no matter, my site is also me a user, no one with no error, no error, no problem.

The reverse proxy

The front and back end need to do a reverse proxy, the accidental choice of Traefik, at least than nginx more beautiful interface, more convenient service configuration, but also can do service discovery, the disadvantage is less documentation

Traefik is also installed directly on bare – metal devices. Docker is directly configured with label and proxy port number file. I wrote an article about it

Traefik start and simple configuration

As for why there are so many requests on the graph, it is because the Gitlab Runner requests a Gitlab every second.

Logging system

Set up elK. However, in view of the fact that the three most visited partners are Google Spider, Baidu spider and myself, I have not used it since it was built

Reference building: github.com/deviantony/…

There may bea need for a file beats, but I haven’t had one yet

Code warehouse

Some personal codes, learning records, and some of my notes about landscape and flowers need a place to put, so I set up a GitLab, but the GitLab ate more than two GIGABytes of memory.

Be careful to turn off gitLab’s Prometheus dependencies, otherwise it will eat a lot of memory

CI

After setting up gITLab, in order to support GITLab, I set up GitLab-Runner to make CI/CD.

But at present, only the blog has access to CI, because only the blog is built after CI, I feel that the front and back end projects that started first will be scrapped…

DNS server

There are so many services available, but some things can’t be put on the public network, such as Consul, Redis, Postgres and GitLab, and they can’t remember the port number, so they built a DNS server for local access

yum install dnsmasq
Copy the code

File editing and window management

Vim and TMUx are standard on Linux to improve server productivity. It is recommended to use source code to compile and install vim and TMUx. Yum, even with EPEL, comes in too low a package version and lacks many features. For example, vim opens a file directory. Here are my own viM and TMUX configurations

  • Github.com/shfshanyue/…
  • Github.com/shfshanyue/…

Automated operation and maintenance

At the beginning, I often had to reinstall the system when I was tossing servers, and since I had two servers, automatic operation and maintenance was essential. I usually use Ansible to do some server pre-configuration, some necessary tools such as Docker, Git, vim, TMUx, JQ, auto-jump installation.

Because my server is all centos, playbook is a little bad.

  • Github.com/shfshanyue/…

Docker-compose is composed for the majority of servers, and ansible-playbook is composed for the majority of servers.

When you have a new server, you can follow these steps

  1. Use ansible-role to preconfigure the environment
  2. If you do not have ansible-role, write ansible-playbook yourself
  3. Use Docker for installation for some services
  4. If none of the above problems can be solved, install them manually

monitoring

Monitor hosts and containers using Prometheus + Node – Exporter + CAdvisor, and visualize them using Grafana

When you need to monitor hosts, containers, or databases, follow these steps

  1. Find a star-studded Dashboard in Grafana
  2. Tweak it as needed

Since switching to the sequential database, my disk space has been shrinking

conclusion

In short, the server is still more about testing, learning and practice, and k8S should be added later.


Pay attention to the public number shanyuexixing, record my technical growth, welcome to exchange