[Image and Text] describes how to use Tengine dynamic module loading on taobao web server

Source: Internet
Author: User
Tags ini versions

Tengine is a Web server project launched by Taobao. Based on Nginx, it adds many advanced functions and features to meet the needs of high-traffic websites. It is currently open-source. It is developed and maintained by the Tengine team. Core members of the Tengine team are from Internet companies such as Taobao and Sogou. Tengine inherits all Nginx features and is 100% compatible with Nginx configurations. This article describes how to use "dynamic module loading (DSO.

What is "dynamic module loading? Make a simple comparison:

Nginx does not have the echo function by default. Traditionally, we will download the echo module, recompile Nginx, and then use the newly compiled Nginx. If you need to use many modules, there are two situations: either there are many Nginx versions, different versions have different functions, and there are various modules in the arrangement and combination; or there is a omnipotent Nginx, all modules are available (like OpenResty ).

Is there a way to be flexible and not so bloated? The answer is "dynamic module loading" (similar to Windows dynamic link library and DLL files. In Linux, the suffix is generally SO ).

If you only install Tengine, you can only use its basic functions. If you need the echo module, you only need to install Tengine-echo, and you can use the echo module with a slight configuration. Tengine does not need to be re-compiled, and various modules are combined as needed.

Tengine supports DSO by default, unless the "-- without-dso" option is specified. At present, our software warehouse has integrated some common Tengine modules. Use "yum search tengine" to see:

 

I will use the echo module and realtime_request module for demonstration below. If you do not know how to use these two modules, you can first "yum info tengine-echo tengine-realtime_request" one:

 

The package information provided by YUM contains the basic information of the module, simple descriptions, and URLs.

The Tengine in the repository uses jemalloc for memory allocation acceleration, so jemalloc is automatically installed. By default, LUA is supported and luajit acceleration is used. During the installation process, luajit is automatically installed:

 

We can see which modules "tengine-m" have been integrated by default. Static indicates the Static compilation module, which is directly written in the binary of Tengine. Shared is a dynamic module that can be dynamically loaded or detached.

The main configuration file of Tengine is (/etc/tengine. conf ):

 

The dso {} is used to control the dynamic module, which is similar to the PHP module. Let's take a look at (/etc/tengine/conf. d/tengine-standard-dso.ini ):

 

Here is the packaged standard module. It is installed and enabled with Tengine by default. We can use or uninstall it as needed.

Install a third-party module, simply "sudo yum-y install tengine-echo tengine-realtime_request, after the installation is complete, the "/usr/lib64/tengine/modules/ngx_http_echo_module.so" and "/usr/lib64/tengine/modules/ngx_http_realtime_request_module.so" dynamic library files are generated. To facilitate management, we put a third-party library in the corresponding configuration file "/etc/tengine/conf. d/tengine-3rdparty-dso.ini ":

 

Check the Tengine module and the supported command "tengine-l ":

 

Then we first verify the correctness of the realtime_request module, add the configuration file (/etc/tengine/vhost. d/realtime_request-demo.conf ):

The code is as follows: Copy code
Realtime_zonesize 16 m;
Server {
Listen 9081 backlog = 8192;
Server_name realtime. request. demo;
Charset UTF-8;
 
Location /{
Realtime_request on;
Access_log off;
Log_not_found off;
    }
}

Access the corresponding page to view the access statistics of each vhost:

 

Then verify the correctness of the echo module. The configuration file (/etc/tengine/vhost. d/echo. tengine. conf ):

The code is as follows: Copy code
Server {
Listen9082 default_server;
Server_name echo.tengine.org;
Charset UTF-8;
 
Location /{
Echo "hello, world! ";
Access_log off;
Log_not_found off;
    }
}

Open the corresponding page and you will see the echo printed information:

 

Is it flexible and easy to use?

Taobao is indeed at the forefront in the Chinese IT industry. Tengine is becoming more and more powerful with the development and maintenance of Taobao's team.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.