The short video system has the same characteristics as the live broadcast system, which is oriented to a large number of user groups and focuses on the aggregation point. Such as lunch time, leisure time in the evening. Therefore, it is particularly important to load the system well, not only to improve the stability and availability of the system, but also to improve user experience and retention from the side.

The descriptive explanation of load balancing is no longer explained, just Google or Baidu. This section describes two load balancing schemes. Scheme 1: Use mature schemes of operators, such as SLB of Ali Cloud and CLB of Tencent Cloud. These mature solutions have high stability and low operation and maintenance costs. You just need to maintain the back-end services, but unless you're a large customer of a certain magnitude, you can't customize. Solution 2: Self-built load balancer, which requires basic o&M capabilities. Operation and maintenance personnel need to continue to track, you can freely expand customization. If the early order of magnitude is small, it is recommended to go to this scheme. If the latter order of magnitude is large, it is safer to go to plan one. This section describes the self-built load balancing method of Solution 2. As an example, the minimum scenario uses a server with 1 core and 1G5M bandwidth. Note: You need to expand the configuration based on your own service conditions. Here is an example to illustrate the minimum configuration. First, we need to prepare relevant materials as follows:Copy the code

1. System domain name

2. 1 Nginx load server (used for foreground distribution).

3. Two Web back-end servers (configure PHP environment, place management background and interface)

4. One Mysql database server (configuring the database)

5. One Redis cache server (configure cache)

6.Session One shared server (data sharing Session)

7. The above servers must be in an internal network, so that the experience of response speed is better.

Second, each server is set up in turn according to the way of building the original system. Nginx load server and Session cache server setup and configuration. 1.Nginx load server setup, assuming the entry domain name is yunbaozhibo.com

1.1 Installing a PCRE

Get the pcRE build installation package, which is currently available at pcre.org/.

Decompress the pcre-xx.tar.gz package. Go to the decompressed directory and run the./configure command to install make & make install

1.2 Installing OpenSSL Obtain the openSSL compilation and installation package. You can obtain the latest version from openssl.org/source/. Gz package. Go to the decompressed directory and run the./config command to install make & make install

1.3 Installing the ZLib

Zlib.net/zlib.net/zlib.net/zlib.net/zlib.net/zlib.net/

Decompress the zlibxxx.zip package. Note: the tar package here should be a problem, can not command decompression, can only change the zip package

Go to the decompression directory and run./configure

Execute make & make install

1.4 install Nginx

Get nginx, on nginx.org/en/download.html can get the newest version

Gz. Go to the directory and run the./configure command to automatically associate the three components

Execute make & make install

1.5 Configuring Related Information After the installation is complete, nginx is in /usr/local/nginx and nginx.conf is in the conf of this file. Nginx is started in sbin.

Configure the nginx.conf file

Add it before server{} in HTTP {}

upstream    yunbaozhibo.com{

ip_hash; Session replication server 192.168.7.11:80 The internal IP address of the web server is 192.168.7.22:80. Here is the Intranet IP address of the Web server. Here it is best to add a simple backup server. After the web is suspended, jump to it. } is added to location /{} in server{} in HTTP {}

proxy_pass yunbaozhibo.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;

After the configuration, start the nginx/usr/local/nginx/sbin/nginx

2. Configure the Session server. Assume that the IP address of the Session server is 192.168.7.2. The Redis port is 1122

The Session server uses Redis to cache shared sessions.

2.1 Install and start the Redis service

2.2 Find the php.ini file on the Web server and modify it as follows

Find; session.save_handler = files

Session.save_habdler = redis

Find; The session. Save_path = “/ TMP”

Session. save_path = “TCP ://192.168.7.2:1122”