1. Install PCRE:
cd /usr/local/srcwget http://downloads.sourceforge.net/project/pcre/pcre/8.34/pcre-8.34.tar.gz
tar zxvf pcre-8.34.tar.gzcd pcre-8.34./configure --prefix=/usr/local/pcremakemake install
Ii. Download The proxy_cache plug-in
cd /usr/local/srcwget http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz
tar zxvf ngx_cache_purge-2.1.tar.gz
3. Install tengine
Yum install OpenSSL-devel-y
cd /usr/local/srcwget http://tengine.taobao.org/download/tengine-2.0.0.tar.gztar zxvf tengine-2.0.0.tar.gzcd tengine-2.0.0./configure --add-module=/usr/local/src/ngx_cache_purge-2.1 --prefix=/usr/local/nginx --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.34
make
make install
/Usr/local/nginx/sbin/nginx # Start nginxchown Nobody. Nobody-r/usr/local/nginx/htmlchmod 700-r/usr/local/nginx/html
If there is a compilation problem, check whether the cause is as follows:
. /Configure: error: the http ssl module requires OpenSSL library cause: to install the http_ssl_module, OpenSSL library is required. Solution: Yum install OpenSSL-devel. /configure: error: the HTTP rewrite module requires the PCRE Library. cause: to install the http_rewrite_module, install the PCRE development kit first. Solution: Yum install PCRE-devel
Note:
-- With-PCRE =/usr/local/src/pcre-8.21 pointingIt is the path to extract the source code package, not the installation path.Otherwise, an error is reported.
-- Add-module =/usr/local/src/ngx_cache_purge-2.1 is the plug-in module that loads the cache
4. Set tengine to start
VI/etc/rc. d/init. d/nginx # edit the Startup File and add the following content
#!/bin/bash# Tengine Startup script# processname: nginx# chkconfig: - 85 15# description: nginx is a World Wide Web server. It is used to serve# pidfile: /var/run/nginx.pid# config: /usr/local/nginx/conf/nginx.confnginxd=/usr/local/nginx/sbin/nginxnginx_config=/usr/local/nginx/conf/nginx.confnginx_pid=/usr/local/nginx/logs/nginx.pidRETVAL=0prog="nginx"# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ ${NETWORKING} = "no" ] && exit 0[ -x $nginxd ] || exit 0# Start nginx daemons functions.start() {if [ -e $nginx_pid ];thenecho "tengine already running...."exit 1fiecho -n $"Starting $prog: "daemon $nginxd -c ${nginx_config}RETVAL=$?echo[ $RETVAL = 0 ] && touch /var/lock/subsys/nginxreturn $RETVAL}# Stop nginx daemons functions.stop() {echo -n $"Stopping $prog: "killproc $nginxdRETVAL=$?echo[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid}reload() {echo -n $"Reloading $prog: "#kill -HUP `cat ${nginx_pid}`killproc $nginxd -HUPRETVAL=$?echo}# See how we were called.case "$1" instart)start;;stop)stop;;reload)reload;;restart)stopstart;;status)status $progRETVAL=$?;;*)echo $"Usage: $prog {start|stop|restart|reload|status|help}"exit 1esacexit $RETVAL
Save and exit
Chmod 775/etc/rc. d/init. d/nginx # grant the File Execution permission chkconfig -- level 012345 nginx on # Set startup/etc/rc. d/init. d/nginx restart
4. Configure tengine
Back up the nginx initial configuration file. We need to recreate the configuration file.
MV/usr/local/nginx/CONF/nginx. CONF/usr/local/nginx/CONF/nginx. conf. Bak
Create nginx user WWW
Groupadd WWW
Useradd-G WWW
Edit the main configuration file:
vi /usr/local/nginx/conf/nginx.conf
The content is as follows:
User WWW; worker_processes 4; # Number of worker processes, which is the number of CPU cores or twice error_log logs/error. log crit; # debug | info | notice | warn | error | crit PID logs/nginx. PID;
# Specifies the value for maximum file descriptors that can be opened by this process.
Worker_rlimit_nofile 65535;
Events {use epoll; # worker_connections 65535;} HTTP {include mime. types; # sets the MIME type, which is determined by mime. the type file defines default_type application/octet-stream;
Charset UTF-8;
Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request" ''$ Status $ response" $ http_referer "'' "$ http_user_agent" "$ http_x_forwarded_for "'; access_log logs/access. log main; # Set the Request Buffer server_names_hash_bucket_size 256; # increase, originally 128 client_header_buffer_size 256 K; # increase, originally 32 K large_client_header_buffers 4 256 K; # increase, originally 32 K # size limits bytes 50 m; # maximum number of individual file bytes allowed for client requests client_header_timeout 3 m; client_body_timeout 3 m; send_timeout 3 m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; server_tokens on; # Do Not Display nginx version information limit_conn_zone $ binary_remote_addr zone = perip: 10 m; # Add limit_zone to limit the concurrency of the same IP address # limit on; # enable the error page to jump to include gzip. conf; # compress the configuration file include proxy. conf; # proxy_cache parameter configuration file include vhost /*. conf; # nginx virtual host contains the file directory include mysvrhost. conf; # Back-end web server list file}
Edit the proxy configuration file:
cd /usr/local/nginx/conf/mkdir vhostvi /usr/local/nginx/conf/proxy.conf
The content is as follows:
# Note: The paths specified by proxy_temp_path and proxy_cache_path must be in the same partition.
Proxy_temp_path/tmp/proxy_temp;
# Set the name of the Web cache area to cache_one. The size of the memory cache space is 500 mb. The content not accessed within one day is automatically cleared. The size of the hard disk cache space is 30 GB. Proxy_cache_path/tmp/proxy_cache levels = keys_zone = cache_one: 500 m inactive = 1D max_size = 30g;
Listen 512 K; # original 512 K proxy_connect_timeout 50; # proxy connection timeout proxy_read_timeout 600; # proxy sending timeout proxy_send_timeout 600; # proxy receiving timeout proxy_buffer_size 128 K; # proxy buffer size, originally 32 K proxy_buffers 16 256 K; # Proxy Buffer, originally 4 64 K proxy_busy_buffers_size 512 K; # buffer size under high load, originally 128 K proxy_temp_file_write_size 1024 m; # The size of the temporary proxy cache file is 128 K # proxy_ignore_client_abort on; # The proxy is not allowed to actively close the connection to proxy_next_upstream error timeout invalid_header http_500 http_503 http_404 http_502;
Edit the host configuration file:
vi /usr/local/nginx/conf/mysvrhost.conf
The content is as follows:
Upstream cn100 {ip_hash; # session persistence server 127.0.0.1: 8080 max_fails = 1 fail_timeout = 60 s; server 127.0.0.1: 9080 max_fails = 1 fail_timeout = 60 s ;}
Edit the compressed configuration file:
vi /usr/local/nginx/conf/gzip.conf
The content is as follows:
# Gzip compression settings #2012.4.2 # Use http://tool.chinaz.com/gzips/to check the compression status # Start the pre-compression function, which is effective for all types of files # gzip_static on; # enable nginx_static, find the corresponding GZ file for any file # do not find the pre-compressed file and perform dynamic compression gzip on; gzip_min_length 1 K; # set the minimum compression value, in bytes. if the value of min_length exceeds the set value, it will be compressed, and smaller than the value will not be compressed. gzip_comp_level 3; # Set the compression level. values 1-9 and 1 indicate the minimum compression speed and the fastest compression speed. Values 9 indicate that the maximum compression speed is the slowest, the CPU resources consumed are also gzip_buffers 16 64 K; # set the system cache size to store the data stream of gzip compression results, it can avoid nginx frequent requests to the system for compressing the space size gzip_types text/plain application/X-JavaScript text/CSS text/JavaScript; # About gzip_types, if you want to enable gzip compression for images, use the following section: # gzip_types text/plain application/X-JavaScript text/CSS text/JavaScript Application/X-httpd-PHP image/JPEG image/GIF image/PNG; # gzip public configuration gzip_http_version 1.1; # identify the HTTP protocol version (1.0/1.1) gzip_proxied any; # Set whether to perform compression when using a proxy. The default value is off gzip_vary on; # It is related to the HTTP header, add a vary header and the agent determines whether to compress gzip_disable "MSIE [1-6]. "; # disable gzip compression for IE6
Edit the configuration file:
vi /usr/local/nginx/conf/vhost/cn100.conf
The content is as follows:
Server {
Listen 80;
SERVER_NAME localhost;
# Default Startup File
Index index.html index.htm;
# Configure the publishing directory as/usr/local/tomcat1/webapps/root
Root/usr/local/tomcat1/webapps/root;
Location/
{
# If the backend server returns errors such as 502, 504, and execution timeout, the request is automatically forwarded to another server in the upstream Server Load balancer pool for failover.
Proxy_next_upstream http_502 http_504 error timeout invalid_header;
Proxy_cache cache_one;
# Set different cache times for different HTTP Status Codes
Proxy_cache_valid 200 304 12 h;
# Combine domain names, Uris, and parameters into the key values of the Web cache. nginx hashes the cached content to the second-level cache directory based on the key values.
Proxy_cache_key $ host $ URI $ is_args $ ARGs;
Proxy_set_header host $ host;
Proxy_set_header X-real-IP $ remote_addr;
Proxy_set_header X-forwarded-for $ proxy_add_x_forwarded_for;
Proxy_pass http: // cn100;
Proxy_pass_header set-cookie;
# Transmit the set-Cookie HTTP header to the user. Otherwise, some applications that contain cookies, such as my typecho
# Expiration time 3 days
Expires 3D;
}
# It is used to clear the cache. If a URL is http: // 192.168.8.42/test.txt, you can clear the cache of the URL by accessing http: // 192.168.8.42/purge/test.txt.
Location ~ /Purge (/.*)
{
# Only the specified IP address or IP segment is allowed to clear the URL cache.
Allow 127.0.0.1;
Allow 192.168.0.0/16;
Deny all;
Proxy_cache_purge cache_one $ host $1 $ is_args $ ARGs;
}
# View the nginx concurrent connection count Configuration
Location/nginxstatus
{
Stub_status on;
Access_log off;
Auth_basic "nginxstatus ";
}
# Define the path of nginx output logs
# Access_log/data/logs/nginx_wugk/access. Log main;
# Error_log/data/logs/nginx_wugk/error. Log crit;
# Access_log off; # select whether to enable access logs based on your own needs. If you comment out this parameter, it indicates that access logs are enabled.
Error_page 404/404 .html;
Error_page 500 502 503 504/404 .html;
Location =/404.html {
Root HTML;
}
Limit_conn perip 50; # if the number of concurrent IP addresses exceeds 50, 503 is returned.
}
Configure tcp settings for tengine and optimize the settings:
vi /etc/sysctl.conf
The content is as follows:
Net. ipv4.ip _ forward = 0 net. ipv4.conf. default. rp_filter = 1 net. ipv4.conf. default. accept_source_route = 0 kernel. sysrq = 0 kernel. core_uses_pid = 1 net. ipv4.tcp _ syncookies = 1 kernel. msgmnb = 65536 kernel. msgmax = 65536 kernel. shmmax = 68719476736 kernel. shmall = 4294967296. net. ipv4.tcp _ max_tw_buckets = 6000. net. ipv4.tcp _ sack = 1 net. ipv4.tcp _ window_scaling = 1 net. ipv4.tcp _ rmem = 4096 87380 4194304 net. ipv4.tcp _ WMEM = 4096 16384 4194304 net. core. wmem_default = 8388608. net. core. rmem_default = 8388608. net. core. rmem_max = 16777216. net. core. wmem_max = 16777216. net. core. netdev_max_backlog = 262144. net. core. somaxconn = 262144 net. ipv4.tcp _ max_orphans = 3276800. net. ipv4.tcp _ max_syn_backlog = 262144 net. ipv4.tcp _ timestamps = 0 net. ipv4.tcp _ synack_retries = 1 net. ipv4.tcp _ syn_retries = 1 net. ipv4.tcp _ tw_recycle = 1 net. ipv4.tcp _ tw_reuse = 1 net. ipv4.tcp _ mem = 94500000 915000000 927000000 net. ipv4.tcp _ fin_timeout = 1 net. ipv4.tcp _ keepalive_time = 30 net. ipv4.ip _ local_port_range = 1024 65000 # port range that allows the system to open
Make the configuration take effect immediately
/sbin/sysctl -p
Create a script to restart all
VI/root/restartall
#! /Bin/sh # restart memcached process service memcached restart # clear the log Rm-F/usr/local/tomcat1/logs/* Rm-F/usr/local/tomcat2/logs/ *
# Clear Cache
Rm-RF/tmp/proxy_cache # restart tomcat/usr/local/cmdat1/bin/shutdown. Sh
/usr/local/tomcat2/bin/shutdown.sh
/usr/local/tomcat1/bin/startup.sh
/usr/local/tomcat2/bin/startup.sh
# Restart nginx
Service nginx restart
Grant operation permission
Chmod 777/root/restartall
To restart the service later, you only need:
/Root/restartall
Http://www.cnblogs.com/littlehb/archive/2013/04/02/2994686.html
CentOS-6.5 installation configuration tengine