Reminder: Please do not blindly expand horizontally, and give priority to the performance optimization of a single server. Only after the performance of a single server is optimized, the cluster will be maximized.
1. Architecture diagram :
Server preparation : 3 sets, ubuntu16.04 system
master: 192.168.1.190 nginx reverse proxy server
node1: 192.168.1.191 golang server
node2: 192.168.1.192 golang server
node3: 192.168.1.193 golang server
2. Simple 5-step installation (perform the following operations on the four servers respectively)
1. Download nginx_signing.key
wget http://nginx.org/keys/nginx_signing.key
2. Verify the signature through the nginx library
sudo apt-key add nginx_signing.key
3.vim /etc/apt/sources.list (add at the end of the file in sources.list):
deb http://nginx.org/packages/ubuntu/ codename nginx
deb-src http://nginx.org/packages/ubuntu/ codename nginx
4. apt-get update
5. apt-get install nginx
3. Master reverse proxy configuration (only need to be configured on 190)
vim /etc/nignx/nginx.conf Add the following to http{}: upstream www.demotest.com { server 192.168.1.191:20180 weight=1; server 192.168.1.192:20180 weight=1; server 192.168.1.193:20180 weight=1; weight; } server { listen 80; server_name www.demotest.com; location / { proxy_pass http://www.demotest.com; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
Closing remarks:
After completing the above configuration, you can enjoy the happiness brought by the distributed cluster, but this is not the optimal configuration, and there are many details that have not been considered, for example, what to do if the main server hangs up. . . But as a basic tutorial, the main purpose is to teach you to build a distributed cluster in the simplest way, and at the same time improve the performance at the minimum cost. Later, we will dig into the relevant details step by step, such as how to improve the performance of a single computer, how to allocate the resources of each computer in the cluster, how to build a distributed cluster with high disaster tolerance, etc.
https://www.cnblogs.com/qizexi/p/8994136.html