Uwsgi Nginx Apache select poll epoll

 

uWSGI is a Web server that implements the WSGI protocol, uwsgi, http and other protocols. Nginx role in HttpUwsgiModule uWSGI is exchanged with the server.
Pay attention to WSGI / uwsgi / uWSGI distinguish between these three concepts.
WSGI is a communication protocol.
uwsgi protocol is a line instead of the communication protocol used in this uWSGI server data communication with other network servers.
The uWSGI is achieved uwsgi and WSGI two protocols Web server.
uwsgi uWSGI server protocol is a proprietary protocol, which defines the type of transmitting information (type of information), before each uwsgi packet 4byte type described for the transmission of information, it is compared with WSGI are two things.

 

In the local virtual environment, the project root directory, execute the command to collect all the packages
pip freeze> plist.txt
via ftp upload software development project a good catalog to this server
installation and create a virtual environment, if there is jump this step through
sudo APT-GET-virtualenv install Python
Python -m Venv 11_venv [virtual environment name]

Work in a virtual environment, install all the required packages
Source / 11_venv / bin / the Active
PIP install -r plist.txt

Change settings.py file
DEBUG = False
ALLOW_HOSTS = [ '*',] represents the ip access to the server

Start the server, operating normally, but can not load static files
1: uWSGI
uWSGI implements all interfaces WSGI, is a fast, self-healing, developers and system administrators friendly server
installation uWSGI
PIP install uwsgi

Note (installation error encountered): pip install uwsgi uwsgi installation error
If you have previously modified version of python computer may fail to install, which is caused by the Python version,
terminal input python, using the computer to see which version of (I was python3 .5)
then install 3.5 python-dev, probably a few minutes
sudo apt-get install libpython3.5-dev

Executed again
pip install uwsgi

Successful installation
configuration uWSGI, uwsgi.ini new file in the project, write the following configuration
[uwsgi]
socket = 127.0.0.1: port (when using nginx connected using socket)
# = HTTP outside the network ip: port (do a web server directly, use HTTP)
chdir = project root directory
wsgi-file = project directory wsgi.py file, relative to the project root directory
Processes = 4
Threads 2 =
Master = True
the PidFile = uwsgi.pid
daemonize = uswgi.log

我的配置参考
[uwsgi]
socket=10.212.63.20:8000
#http=127.0.0.1:8000
chdir=/home/shihao/Desktop/bushulianxi/test7
wsgi-file=test7/wsgi.py
processes=4
threads=2
master=True
pidfile=uwsgi.pid
daemonize=uswgi.log

Start: uwsgi --ini uwsgi.ini (needs to be performed under the project directory, note ini front two -)
Stop: uwsgi --stop uwsgi.pid
restart: uwsgi --reload uwsgi.pid
Results: to view the site using the http protocol operation, operating normally, but static files can not load
2: use nginx
nginx role:
load balancing: multiple servers take turns processing the request
reflected proxy: hide the real server
implementing architecture: the client requests nginx, and then by nginx request uwsgi, run django python code in the framework
nginx + uwsgi python may also be used to code for other Web frame is not limited to django
to the official website to download a compressed file or command nginx mounting
sudo apt-get install nginx

Installed by default to / usr / local / nginx / sbin / directory (in my / usr / sbin under) ** Note: It is best to enter this directory execute the command **
View version: sudo nginx -v
start: sudo nginx
stop: sudo nginx -s stop
reboot: sudo nginx -s reload
to view the results through a browser running nginx

Some Note:
# If nginx is not installed in the default directory, you can search nginx installation directory
sudo ps -ajx | grep nginx

# Nginx.conf View profile directory (you must first enter the safe transfer directory)
sudo nginx -t

# 80 If the port is occupied, use the command to close port 80 occupied by the program
sudo fuser -k 80 / tcp

Pointing uwsgi Project: edit nginx.conf file (in my / etc / under nginx)
sudo vim nginx.conf

Added at the new location server entry point ip uwsgi the port
location / {
the include uwsgi_params; uwsgi all parameters to the
uwsgi_pass uwsgi the ip port;
}

Note: The original nginx.conf there are two lines must be commented out.
/etc/nginx/conf.d/*.conf the include;
the include / etc / Nginx / sites-Enabled / *;

Uwsgi.ini modify files, start socket, disable http
restart nginx, uwsgi
results: View project in a browser, you can find that file does not load properly, then solve the problem of static files
3: static files
still can not find the file has been now finally resolved
all of the static files are from the nginx, and do not go to the request uwsgi
static entry configured nginx, open the conf / nginx.conf file, locate the server, add a new LOCATION
LOCATION / static {
Alias / var / www / test5 / static /; # Note: the address is given their casual
}

Create a directory structure on the server "/ var / the WWW / test5 /"
cd / var / the WWW
mkdir test5
cd test5
mkdir static
sudo chmod 777 static

Modify settings.py file
STATIC_ROOT = '/ var / WWW / Test5 / static /'
STATIC_URL = '/ static /'

Collect all the static files to a specified directory static_root: python manage.py collectstatic
At this point there can be found a static file / var / www / test5 / static folder
restart nginx, uwsgi

 

 

 

 

Senior transit in select Linux IO multiplexing, the advantages and disadvantages poll epoll of, select, and epoll and poll shortcomings of.

一、select的缺点:

1、编写难度大

2、同时处理的文件描述符是有上限的

3、每次需要重新设定fd集合

4、性能会随用户的增多而效率降低

5、输入输出参数在一起
select的几大缺点:
(1)每次调用select,都需要把fd集合从用户态拷贝到内核态,这个开销在fd很多时会很大
(2)同时每次调用select都需要在内核遍历传递进来的所有fd,这个开销在fd很多时也很大
(3)select支持的文件描述符数量太小了,默认是1024

二、poll的缺点

poll是对select的一种改良,最突出的改良有两点:

1、文件描述符数量没有上限

2、将输入输出参数进行分离,不用每次设定

那么poll的缺点是:

poll中监听的文件描述符数目增多时:

1、和select一样,poll返回后,需要轮询pollfd来获取就绪的描述符

2、每次调用poll都需要大把大量客户端在一时刻可能只有很少的处于就绪状态,因此随着监视的描述符数量的增长,其效率也会线性下降。

三、epoll的优点:

1、文件描述符数目没有上限:通过epoll_ctl()来注册一个文件描述符,内核中使用红黑树的数据结构来管理所有需要监控的文件描述符。

2、基于事件就绪通知方式:一旦被监听的某个文件描述符就绪,内核会采用类似于callback的回调机制,迅速激活这个文件描述符,这样随着文件描述符数量的增加,也不会影响判定就绪的性能。

3、维护就绪队列:当文件描述符就绪,就会被放到内核中的一个就绪队列中,这样调用epoll_weit获取就绪文件描述符的时候,只要取队列中的元素即可,操作的时间复杂度恒为O(1)。

4、关于有些地方说:epoll还有内存映射机制,即内核将就绪队列通过mmap的方式映射到用户态,避免了拷贝内存这样的额外性能开销。关于这一点,我并不认为这是epoll的优点,因为他和epoll底层工作方式相悖。mmap是一种共享内存,但是我们都知道共享内存中一旦有数据,用户就能直接看到,并且使用,但是epoll_wait在取数据时传入了一块缓存区这是和贡献内存相悖的其一;其二是操作系统并不相信任何人,尤其是用户,它不会让用户直接去取内核中的数据。

 


文件系统是操作系统用于明确存储设备(常见的是磁盘,也有基于NAND Flash的固态硬盘)或分区上的文件的方法和数据结构;即在存储设备上组织文件的方法。操作系统中负责管理和存储文件信息的软件机构称为文件管理系统,简称文件系统。文件系统由三部分组成:文件系统的接口,对对象操纵和管理的软件集合,对象及属性。从系统角度来看,文件系统是对文件存储设备的空间进行组织和分配,负责文件存储并对存入的文件进行保护和检索的系统。具体地说,它负责为用户建立文件,存入、读出、修改、转储文件,控制文件的存取,当用户不再使用时撤销文件等。


UTF-8 国际组织 3字节
GBK 防本土 2字节

哈希密码:密钥 加颜 不可逆算法

put 修改全部
patch 指定修改
get
post
head

 

Guess you like

Origin www.cnblogs.com/wyf2019/p/10959657.html