Deploy the library management system project

 

Deploy the library management system project

 

 

Deployment preparation

You will use the following software to deploy the book management project

  • nginx
  • uWSGI
  • CentOS7
  • Deploy library management project files
  • virtualenv
  • supervisor

WEDNESDAY

Python web server development uses WSGI protocol (Web Server Gateway Interface)

The python web project will generate a wsgi.py file by default, and determine the application module.

The production environment uses uWSGI, which implements all WSGI interfaces, is written in C language, and is a highly efficient web server.

uWSGI is a full-featured HTTP server, which implements WSGI protocol, uwsgi protocol, http protocol, etc. What it has to do is to convert the HTTP protocol into a language-supported network protocol. For example, the HTTP protocol is converted to the WSGI protocol so that Python can be used directly.

Nginx

Nginx is used for its reverse proxy function. The project will be deployed on the server through Django+uWSGI+Nginx.

CentOS

1. Pack the project CRM folder, compressed file

2. Upload files to Centos server via xftp, scp, lrzsz, etc.

Linux usage skills

1. Operate your linxu with multiple terminals through software such as xshell or iTerm, so that when debugging uwsgi, nginx, and project code, you can avoid switching directories back and forth and improve work efficiency.

2. Note that if you modify the configuration file of the linux software, you must restart the service to take effect.

Virtualenv

It is recommended to build a clean and isolated python interpreter environment to prevent software dependencies and conflicts.

Supervisor

Supervisor (http://supervisord.org/) is a client/server service developed in Python. It is a process management tool under Linux/Unix systems and does not support Windows systems. It can easily monitor, start, stop, and restart one or more processes. When a process is managed by Supervisor, when a process is accidentally killed, supervisort will automatically re-pull it after it detects that the process has died. It is very convenient to achieve the function of automatic process recovery, no longer need to write a shell script to control it.

 

Start deployment

1. Familiar with Linux operation

linux basic command operation, omit...

 

2. Installation of python3 interpreter

Reference blog: https://www.cnblogs.com/tiger666/articles/10312522.html

 

3. Configure the virtualenvwrapper tool to solve virtual environment problems

# Confirm ~ / .bashrc virtualenvwrapper arranged inside the profile 
WORKON_HOME = ~ / Envs that
VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
VIRTUALENVWRAPPER_PYTHON=/opt/python36/bin/python3
source /opt/python36/bin/virtualenvwrapper.sh

# Create and activate a virtual environment for library management system project 
mkvirtualenv book_manage_env

 

4. Install and configure MariaDB database, create database data, and migrate data imported into the library management system

(1) Install and start MariaDB database

Under CentOS7, MariaDB is the mysql database, but the package name is different

# Use yum to download and install MariaDB 
yum install MariaDB MariaDB-Client-Server - the y-

# Start mariadb server 
systemctl start mysql

(2) Connect and authorize root user remote access

# Use the client to link mysql server 
mysql-uroot-- the p-landing mariadb on linux

# Note 1, linux database, you need to set up a remote link to the root user privileges, password is qishi3q 
Grant All privileges ON * * to root @. ' % ' IDENTIFIED by ' qishi3q ' ;
 # authorize all rights, in all the libraries, All tables for the root user on all hosts, set permissions password is qishi3q 
# refresh authorization form 
flush privileges;

Note 2: The firewall and selinux of linux should be closed, otherwise the 3306 port of windows to connect to linux may be rejected

(3) Import the data of the book management project

 

Import the data of the library management system on the linux server, mysql

# 1. mysql data export, and import 
This command is typed in linux/ windows
mysqldump -u root -p --all-databases >  book_manage.dump  

# 2. Upload this data file to the linux database

# 3. In mysql of linux, import this data file (you need to specify the database in the dump file: use szday58) 
mysql -u root -p </opt/ book_manage.dump
 # or enter mysql to enter the database, use the command: 
source / opt/book_manage.dump

 

5. Enter the virtual environment and run the project

The test uses the linux python interpreter to run the project and switch to the project to run (note that the module problem of the interpreter must be solved to run the project normally)

# 127.0.0.1 does not work, it can only be accessed 
locally , if you want everyone to access, you must use 0.0.0.0 python3 manage.py runserver 0.0.0.0:8000

Then you can access through the IP plus port. If this IP is my cloud server IP, then when we go to the interview, we can take this project to the interviewer and show it on the computer. It's so compelling~

 

Easter egg : Now there is a problem. We can only access the project through 10.0.0.7:8000, but the public website is not like this . For example, Luffy School City is accessed through the domain name, and we can also resolve the Luffy School City. The IP of the website server can be accessed through the address, but there is no port added because the default port is 80

Although we can directly change the port to 80 and there is no problem, then the problem is here: 

1 Django runs the web interface by default using the wsgiref stand-alone module, the performance will be relatively low, what should I do?

uwsgi + django + nginx

2 If we want to run another project to provide external services, what should we do? The server has only one port 80, how to solve it

nginx + uwsgi + django + supervisor

 

 




-Complete the installation and configuration of nginx, understand how to configure nginx.conf -Complete the uWSGI command learning, use uWSGI to start the knight project, support multi-process -Complete

nginx to process the static files of the book management project

-The final effect

can be found by visiting port 80 of nginx Book management page, and ensure that the static file page is normal

 

Guess you like

Origin blog.csdn.net/qq_45533926/article/details/111808714