当前位置:网站首页>Openresty chapter 01 introduction and installation configuration
Openresty chapter 01 introduction and installation configuration
2022-06-26 00:38:00 【tinychen777】
This paper mainly focuses on openresty Make an introduction to the installation and configuration of initialization .
1、OpenResty brief introduction
Read about web The server students must be right nginx No stranger ,nginx As the No. 1 market share at present web The server , Itself as static web The server 、 Reverse proxy service and four layers 、 The seven layer load balancer has excellent performance . But for web For servers ,nginx Many of the features of are static web application , That is to say, its dynamic processing capability is somewhat lacking . Let's take the simplest example ,nginx It is not possible to make more than one logical judgment in the configuration , This is inconvenient for some architecture design .OpenResty Was born to solve this problem .
The government is concerned about OpenResty The introduction of :
OpenResty It's based on Nginx And Lua A high performance Web platform , It has a lot of sophisticated integration inside Lua library 、 Third party modules and most of the dependencies . Easy to construct to handle ultra-high concurrency 、 Highly scalable dynamics Web application 、Web Services and dynamic gateways .
OpenResty By bringing together a variety of well-designed Nginx modular ( Mainly by OpenResty Team independent development ), So that Nginx Effectively become a powerful gm Web Application platform . such ,Web Developers and systems engineers can use it Lua Scripting language mobilization Nginx Various supported C as well as Lua modular , Build up quickly enough to be competent 10K Even 1000K High performance of the above single-machine concurrent connections Web Application system .
OpenResty The goal is to let you Web The service runs directly in Nginx Services within , make the best of Nginx The non-blocking I/O Model , Not just to HTTP Client request , Even for the remote backend MySQL、PostgreSQL、Memcached as well as Redis And so on for consistent high performance response .
My simple understanding is OpenResty=nginx+lua+ Third party Library , in fact nginx It can also be added by compiling lua Support for , meanwhile nginx You can also add third-party library support through compilation ,OpenResty It is directly packed together . Let's not talk about OpenResty As omnipotent web Whether the server can meet all the business requirements , Its outstanding dynamic processing capability can bring great flexibility and additional diversified processing capability to our system architecture .
2、yum install
2.1 To configure yum Source
openresty The official website provides various mainstream services Linux Distribution Precompiled translation package , If there is no special need , Generally, you can directly use the official installation package for installation .
Now let's centos
As an example :
# add the yum repo:
wget https://openresty.org/package/centos/openresty.repo
sudo mv openresty.repo /etc/yum.repos.d/
# update the yum index:
sudo yum check-update
2.2 rpm Package introduction
openresty Of yum Source except openresty Beyond itself , There are other toolkits and dependent packages , We can view all the available rpm package , For these rpm For detailed explanation of the package, please refer to the official website file .
sudo yum --disablerepo="*" --enablerepo="openresty" list available
The following is a brief introduction to some key rpm package .
2.2.1 openresty
This is for the core OpenResty Production version of the service . That is the whole openresty The core function file that provides the main services in . In the use of rpm Package installation , In the system openresty The instruction will be linked to /usr/bin/openresty
, and /usr/bin/openresty
It's actually /usr/local/openresty/nginx/sbin/nginx
The soft links
actually /usr/local/openresty/nginx/sbin/nginx
It's the whole thing openresty Of nginx The body of the executable , We add -V Parameter to view its details including the compiled module . The reason why you want to soft link it to /usr/bin/openresty
, The official explanation is to avoid contact with what is already on the machine nginx conflict .
From the above compilation parameters, we can see openresty Using their own maintenance openssl library 、zlib library 、pcre Kuhe LuaJIT library , In this way, it can better control the version, function update and synchronization coordination among various libraries .
2.2.2 openresty-resty
This bag has resty
Command line program , This toolkit mainly relies on resty-cli This project , This package relies on Standards Of perl
Package and the above mentioned openresty
The package can work properly . By default, it points to /usr/bin/resty
An environment variable of the directory , And the source file is in /usr/local/openresty/bin/resty
Personally, I think the main function of this toolkit is to facilitate us to debug some simple commands
$ resty -e 'ngx.say("hello")'
hello
2.2.3 openresty-doc
As the name suggests, this rpm The most important function of the package is to provide document query , Generally speaking, attention should be paid to the use of UTF-8 Coded Terminal that will do . and man The command is somewhat similar , If we want to inquire openresty Documents related to a module in , Just use restydoc
Command is enough .
# We can directly enter the corresponding module name to view the corresponding document
restydoc ngx_lua
restydoc ngx_lua_upstream
restydoc ngx_http_v2_module
restydoc luajit
# You can also join -s Parameter to view the document of an instruction or part
restydoc -s content_by_lua
restydoc -s proxy_pass
2.2.4 openresty-openssl
This is a openresty Officially maintained OpenSSL library . To save money , This version disables multithreading support in the build . Besides , The most important thing about this version is OpenResty Officials have added some of their own patches to support some openssl The latest features of , At the same time, some optimizations have been made to make the older system support the latest version openssl. Empathy , Not only is openssl,openresty Self maintained pcre and zlib Libraries also have this purpose .
and nginx default rpm The version is still older / The stability of the openssl Version comparison ,openresty about openssl The support of version is undoubtedly more radical .
2.2.5 other
For more detailed package introduction, please check the official English document , The introduction is quite comprehensive , Generally speaking, it is the main tool software such as openresty、openssl、pcre、zlib And so on 、debug edition 、asan edition 、valgrind Version, etc , I won't elaborate here .
2.3 rpm Package installation openresty
Although the above introduces many openresty Related to the package , But in fact, you only need to install openresty, Other dependencies are determined by yum Automatic processing . Be careful openresty-doc、openresty-resty And so on are optional packages .
# add the yum repo:
wget https://openresty.org/package/centos/openresty.repo
sudo mv openresty.repo /etc/yum.repos.d/
# update the yum index:
sudo yum check-update
# use yum to install
yum install openresty
After installation, the default directory path will be displayed /usr/local/openresty/nginx
The following generates the corresponding configuration file directory , And we will yum Installed nginx And compile and install nginx The comparison shows almost the same .
# Use yum Installed nginx
[[email protected] nginx]# pwd
/etc/nginx
[[email protected] nginx]# ls
conf.d fastcgi_params koi-utf koi-win mime.types modules nginx.conf scgi_params uwsgi_params win-utf
# Source code compiler installed nginx
[[email protected] nginx]# pwd
/home/nginx
[[email protected] nginx]# ls
client_body_temp conf fastcgi_temp html logs sbin scgi_temp uwsgi_temp
# Use yum Installed openresty In the catalog nginx
[[email protected] nginx]# pwd
/usr/local/openresty/nginx
[[email protected] nginx]# ls
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
Let's write a simple nginx.conf The configuration file can be used for testing , The file uses the default path /usr/local/openresty/nginx/conf/nginx.conf
.
[[email protected] conf]# openresty -T
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
# configuration file /usr/local/openresty/nginx/conf/nginx.conf:
user root;
worker_processes 1;
error_log logs/error.log;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main
'$remote_addr | [$time_local] | $status | $scheme | '
'$server_name | request= $request | request_uri= $request_uri | http_referer= $http_referer | '
'UA= $http_user_agent | $request_time | $ssl_protocol | $ssl_cipher | '
'remote_port= $remote_port | $request_id';
access_log logs/access.log main;
server {
listen 8080;
location / {
default_type text/html;
content_by_lua_block {
ngx.say("<p>hello, world</p>")
}
}
}
}
Separate use curl And browser tests are normal
[[email protected] conf]# curl 10.224.192.144:8080
<p>hello, world</p>
Corresponding operations can also be seen in the log
[[email protected] conf]# tail -f ../logs/access.log
10.224.192.144 | [12/Mar/2021:14:42:25 +0800] | 200 | http | | request= GET / HTTP/1.1 | request_uri= / | http_referer= - | UA= curl/7.29.0 | 0.000 | - | - | remote_port= 34626 | 602882ad9b5cf910bea2f6d13ce4bf5e
10.228.18.249 | [12/Mar/2021:14:42:51 +0800] | 200 | http | | request= GET / HTTP/1.1 | request_uri= / | http_referer= - | UA= Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36 | 0.000 | - | - | remote_port= 7148 | 5a91256294bf307ed62f48a06905dbc0
10.228.18.249 | [12/Mar/2021:14:42:51 +0800] | 200 | http | | request= GET /favicon.ico HTTP/1.1 | request_uri= /favicon.ico | http_referer= http://10.224.192.144:8080/ | UA= Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36 | 0.000 | - | - | remote_port= 7148 | 372e7402db9f396950dae48b66a7e1ce
Check that the port listening and service processes are normal
Then you can basically judge that the installation is successful .
3、 Source code compilation and installation
If customization is required , It is our best choice to compile and install from the source code . Let's go first Official website Download the latest version of openresty Source package and extract .
cd /home
wget https://openresty.org/download/openresty-1.19.3.1.tar.gz
tar -zxvf openresty-1.19.3.1.tar.gz
3.1 Compile environment
[[email protected] home]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.9.2009 (Core)
Release: 7.9.2009
Codename: Core
At the same time, we also need to prepare tools for compilation, such as compilers , about CentOS7, We can simply install the entire development kit Development Tools
.
yum grouplist
yum groupinstall "Development Tools" -y
3.2 Get ready openssl、pcre and zlib
and nginx equally , We manually download the latest version of openssl、pcre and zlib, Note the three libraries Just download and unzip , There is no need to install in advance .
# download
wget https://www.openssl.org/source/openssl-1.1.1j.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
wget https://zlib.net/zlib-1.2.11.tar.gz
# decompression
tar -zxvf openssl-1.1.1j.tar.gz
tar -zxvf pcre-8.44.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
3.3 Compilation and installation
and nginx Compilation and installation of , We can customize the modules that are compiled and installed , Here you can see openresty Modular Official statement .
cd /home/openresty-1.19.3.1/
./configure --prefix=/home/openresty --with-openssl=/home/openssl-1.1.1j --with-pcre=/home/pcre-8.44 --with-zlib=/home/zlib-1.2.11 --with-http_realip_module --with-http_stub_status_module --with-debug --with-http_ssl_module --with-http_v2_module
gmake -j8
gmake install
Finally, when the installation is completed, we can see that the openresty In the catalog /home/openresty/nginx/sbin/nginx
Soft links to /home/openresty/bin/openresty
, Logic and yum Installed openresty equally
If you want to facilitate global operations , You can create a soft link .
ln -s /home/openresty/bin/openresty /usr/local/bin/openresty
Of course, if you feel that this kind of directory is not easy to operate , We can also add more parameters during compilation , Manually specify all commonly used directories , The operation is similar to nginx There's almost no difference , Here is a simple example :
./configure \
--prefix=/home/openresty \
--sbin-path=/home/openresty/bin/nginx \
--conf-path=/home/openresty/conf/nginx.conf \
--http-log-path=/home/openresty/logs/access.log \
--error-log-path=/home/openresty/logs/error.log \
--pid-path=/home/openresty/logs/nginx.pid \
--lock-path=/home/openresty/logs/nginx.lock \
--http-client-body-temp-path=/home/openresty/client_body_temp/ \
--http-proxy-temp-path=/home/openresty/proxy_temp/ \
--http-fastcgi-temp-path=/home/openresty/fastcgi_temp/ \
--http-uwsgi-temp-path=/home/openresty/uwsgi_temp/ \
--http-scgi-temp-path=/home/openresty/scgi_temp/ \
--with-openssl=/home/openssl-1.1.1k \
--with-pcre=/home/pcre-8.44 \
--with-zlib=/home/zlib-1.2.11 \
--with-http_realip_module \
--with-http_stub_status_module \
--with-debug \
--with-http_ssl_module \
--with-http_v2_module \
--build=tinychen-build \
--dry-run
4、OpenResty operation
openresty Operation instructions and nginx It's exactly the same . As follows :
[[email protected] home]# nginx -h
nginx version: nginx/1.19.8
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix]
[-e filename] [-c filename] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /etc/nginx/)
-e filename : set error log file (default: /var/log/nginx/error.log)
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file
[[email protected] home]# openresty -h
nginx version: openresty/1.19.3.1
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/openresty/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
-h
Print help menu-v
Lowercase v Yes print version and exit-V
uppercase V Is to print the compilation parameters and version information and exit-t
Lowercase t Is to test the configuration file for errors and exit-T
uppercase T Is to test whether the configuration file is incorrect, print out the effective configuration file and exit , If nginx.conf It uses include Command adds additional configuration files , It will also be spliced and printed together-q
Do not print non error messages during the test , fit debug Use-s
Send a signal to control master process , Respectivelystop
( The violence stopped ),quit
( Elegant stop ),reopen
( Reopen the log file ),reload
( Elegant restart )-p
adopt -p Parameter to specify the actual working directory , For example, we have two different test projects , You can use theopenresty -p /path/to/app
Specify a different working directory at startup , This allows multiple different OpenResty Applications share the same OpenResty The effect of the service program-c
adopt -c Parameter to specify a different configuration file instead of just the configuration file under the default path-g
Set the global instructions outside the configuration file at startup , for exampleopenresty -g "pid /var/run/nginx.pid; worker_processes 8;"
边栏推荐
- 在同一台机器上部署OGG并测试
- Frequently asked questions about redis
- linux安装redis
- Atlas200dk brush machine
- Core ideas of SQL optimization
- 1-10vmware builds customized network architecture
- 1-11Vmware虚拟机常见的问题解决
- 1-11solutions to common problems of VMware virtual machine
- 11.1.1 overview of Flink_ Flink overview
- How ASA configures port mapping and pat
猜你喜欢
EBS R12.2.0升级到R12.2.6
About Simple Data Visualization
The problem of low video memory in yolov5 accelerated multi GPU training
How to deliver a shelter hospital within 48 hours?
1-9Vmware中网络配置
idea设置mapper映射文件的模板
Introduction to anchor free decision
"Method not allowed", 405 problem analysis and solution
Drag the mouse to rotate the display around an object
性能领跑云原生数据库市场!英特尔携腾讯共建云上技术生态
随机推荐
论文中英文大小写、数字与标点的正确撰写方式
What are AOI, X-ray and ICT in SMT industry? What does it do?
Installing redis on Linux
机器视觉:照亮“智”造新“视”界
1-11Vmware虚拟机常见的问题解决
Multi-Instance Redo Apply
Methods to realize asynchrony
dbca静默安装及建库
Frequently asked questions about redis
EBS r12.2.0 to r12.2.6
SQL中只要用到聚合函数就一定要用到group by 吗?
事物/现象/事情/东西/情况/表象
Reentrant functions must be used within signal processing functions
CaMKIIa和GCaMP6f是一样的嘛?
Redis memory elimination mechanism
Idea set the template of mapper mapping file
Apache foundation officially announced Apache inlong as a top-level project
Why do we need to make panels and edges in PCB production
原型和原型链的理解
MySQL master-slave replication