4 Introduction to Linux website architecture service

Linux

1 integrated architecture components and service planning

Website architecture is generally considered from two aspects:

  1. User visits website
  2. Site manager visits the site

1.1 user access to website

1.1.1 static cluster architecture
  1. When the user visits the website, first resolve the website through the DNS server, and then send a request to the resolved address;
  2. When the request is sent to the website device, it usually needs to go through the firewall device. The firewall device will filter all requests, prevent illegal requests, map legal requests and send them to the server inside the architecture;
  3. First arrive at the load balancing server, which is mainly used to solve the problem of high concurrency and distribute all requests to different web servers according to certain policies.
    To solve the problem of high concurrency, the idea of cluster is generally adopted. Multiple web servers are built into a static cluster architecture, which can realize rapid response in the face of a large number of user access, and greatly improve the amount of concurrent access;
  4. If only one load balancing server is provided, a single point of failure may occur. In order to improve the redundancy of the architecture, an additional standby load balancing server will be provided in the architecture;
    In order to share the access pressure of the primary load balancing server, the resources of the primary and standby load balancing servers are generally adjusted to realize the dual primary configuration in load balancing. (similar to the dual speaker system in the society)
  5. The pictures, audio, video, attachments and other resources provided by general websites are not directly stored in the web server, but in the storage server;
    The traditional storage server is called local storage server. The web server stores the mount point directory of resources. When users need to access resources, they access the resources in the local storage server through the mount point in the web server, which is convenient for unified data management;
    If you need to access a large amount of data, the local storage server will generate a large number of disk IO operations, which will reduce the access speed. In order to solve this problem, the mainstream storage solution is distributed storage. There are many storage nodes in distributed storage to connect multiple storage servers, and the data will be stored in different servers. The access from the web server will reach the management node. The management node integrates the data in different servers through each management node to achieve efficient data access.
1.1.2 dynamic cluster architecture

Dynamic cluster architecture can provide dynamic request services. Dynamic requests in different types of languages correspond to different service deployments.

php => php-fpm
java => tomcat
python => uwsgi

The storage server in the dynamic cluster architecture is the database server. The database server includes the master database server and the slave database server. The slave database server will synchronize the data in the master database server in real time. The slave server generally processes the request of reading data, and the master database server generally processes the request of writing data, so as to realize the architecture of reading and writing separation.

1.1.3 cache server

Cache servers generally exist between web servers and storage servers, which are mainly used to reduce the pressure of storage servers. The storage server will store some popular resource data in the cache server.
Read operation, that is, read the data in the cache server - redis
The write operation is generally written to the cache in the cache server - queue server

1.1.4 backup server

The backup server is generally used to back up important data in the architecture regularly or in real time.
The architecture idea of backup server is mainly two places and three centers, in order to further ensure data security.

1.2 website manager visits the website

  1. VPN server
    Website managers usually manage the server remotely through the network and use the VPN server to establish a virtual private path between the external network host and the website server.
  2. Springboard / fortress server
    The VPN server is generally equipped with a springboard machine / fortress machine server, which is mainly used to manage and control the access rights of the website manager, record the operation behavior of the manager and locate the responsibility.
  3. Monitoring server
    The monitoring server is mainly used to monitor the operation status of each server, so that the manager can make adjustments in time.
  4. Batch management server
    Batch management of multiple servers in the architecture.
  5. Log audit server
    The operation department needs to collect data for analysis and processing. The log audit server provides functions such as log collection, filtering and data display.
  6. Business distribution service
    It is used to assign tasks to staff (mainly operation and maintenance personnel) and record work status and results.
  7. Resource sharing server
    It is used for staff to share information resources.

2 architecture website service application

2.1 website nginx service deployment process

The official source is used for deployment here.

  1. yum source files need to be configured
vim /etc/yum.repos.d/nginx.repo 

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
  1. Install software program
yum install -y nginx
  1. Start the software program
systemctl start nginx 
systemctl enable nginx
  1. test
    Use the browser to access the server address and check whether you can see the nginx service welcome page.

2.2 website nginx service directory structure

rpm -ql nginx
/etc/nginx				--- nginx Service profile information
/etc/nginx/conf.d 		--- nginx Service extension profile information
/usr/share/nginx/html/	--- nginx Service default site directory
/var/log/nginx			--- nginx Service default log piece information

/usr/sbin/nginx			--- nginx Service management command file
	-t: test configuration and exit 
		Syntax check of configuration file
	-s signal: send signal to a master process: stop, quit, reopen, reload
		Receive signal information, including stop-stop it, reload-restart

2.3 description of website nginx service configuration

cat /etc/nginx/nginx.conf
user  www;										 --- User information. The default is system information worker Process user information 
ps -ef|grep nginx
	master process: The service running state is the main process to ensure that the service is running
	worker process: Service operation is mainly used to process requests to visit websites

worker_processes  1;							 --- definition worker Number of processes, 1 by default worker The process can only carry 30000 concurrent traffic
                                                     Can adjust worker Number of processes to improve the concurrency of the website
error_log  /var/log/nginx/error.log notice;		 --- Record service error log information
pid        /var/run/nginx.pid;					 --- Record service operation pid file
events {
    worker_connections  1024;					 --- definition worker Number of concurrent connections established by a single process
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" "$http_x_real_ip"'; 
												 --- set up nginx Log format information log4j
    access_log  /var/log/nginx/access.log  main;
												 --- Define access log file path
    keepalive_timeout  65;						 --- definition TCP Long link timeout		
    include /etc/nginx/conf.d/*.conf;			 --- Other file information will be added by default

# cat /etc/nginx/conf.d/bbs.conf 
server {
  listen  80;									 --- Specify listening network port information
  server_name bbs.oldboy.com;					 --- Define website domain name information
  client_max_body_size 10m;						 --- Define that the client can upload more than 10 on the specified page m data
  location / {
      root /html/bbs;							 --- Specify site directory information
      index index.php index.html index.htm; 	 --- Specify the first page file information
  }
  location ~ \.php$ {
      root /html/bbs;
      fastcgi_pass  127.0.0.1:9000;				 --- If it is python Code program needs to use uwsgi Realize dynamic request processing
      include fastcgi_params;
  }
  location = /status {
      stub_status;
  }
}

2.4 website nginx service enterprise application

2.4.1 construction process of static resource website
  1. Get static code information
  2. Configuration file preparation information
vim /etc/nginx/conf.d/www.conf

server {
	listen     80;
	server_name www.oldboy.com;
	location / {
	    root /html/www;
	    index index.html index.htm;
	}
}
  1. Upload code information
mkdir  /html/www
mv game/*  /html/www/
  1. Restart nginx service
systemct restart nginx
2.4.2 construction process of dynamic resource website
  1. Get code information github / code cloud
  2. The python dependency package needs to be installed
yum Installation dependency required:
(1) yum install -y python-pip git mysql-devel redis python-devel 
(2) Manual upgrade required python program  centos7 Default 2.7 => 3.7

pip Installation dependency required:
Install dependent modules according to your own code
  1. Installation and configuration uwsgi information
pip install uwsgi
pip3 install uwsgi

vim uwsgi
 start-up uwsgi service
  1. Write nginx service configuration file
server {
    listen     80;
    server_name www.oldboy.com;
    location / {
        root /html/www;
        index index.html index.htm;
    }
	location /dynamic/ {
	    root /html/www;
		include uwsgi_params;
		uwsgi_pass 127.0.0.1:8000;
	}
  }

Tags: Linux Nginx

Posted by cypr on Mon, 23 May 2022 14:43:28 +0300