Installation notes for Centos-6.3-x86_64minimal Mini Edition-Nginx

Source: Internet
Author: User
Tags rrd rrdtool install perl
Install Nginx1261, download Nginxwgethttp: nginxorgdownloadnginx-126targz2, unzip tar-vzxfnginx-126targz3, compile configure -- prefix = usrlocalnginx -- pid-pat
Install Nginx 1.2.61 and download Nginx # wget http://nginx.org/download/nginx-1.2.6.tar.gz2 Decompress # tar-vzxf nginx-1.2.6.tar.gz3, compile #. /configure -- prefix =/usr/local/nginx -- pid-path =/var/run/nginx. pid -- error-log-path =/var/logs/nginx/error. log -- http-log-path =/var/logs/nginx/access. log -- with-http_stub_status_moduleConfiguration summary + using system PCRE library + OpenSSL library is not used + md5: using system crypto library + sha1: using system crypto library + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx. conf "nginx pid file:"/var/run/nginx. pid "nginx error log file:"/var/logs/nginx/error. log "nginx http access log file:"/var/logs/nginx/access. log "nginx http client request body temporary files:" client_body_temp "nginx http proxy temporary files:" proxy_temp "nginx http fastcgi temporary files:" fastcgi_temp "nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp" # make # sudo make install4. modify the configuration # sudo vim/usr/local/nginx/conf/nginx. conf5, start, restart, and close
Run prefix/sbin/nginx to start # sudo/usr/local/nginx/sbin/nginx to restart the configuration (the configuration takes effect after modification) # sudo kill-HUP 'cat/var/run/nginx. pid 'or # sudo/usr/local/nginx/sbin/nginx-s reload restart Nginx # sudo/usr/local/nginx/sbin/nginx-s reopen close # sudo kill' cat/var/run/nginx. pid 'or # sudo/usr/local/nginx/sbin/nginx-s quit check version #/usr/local/nginx/sbin/nginx-v do not run, only test the configuration file. Nginx check the correct syntax configuration and open the specified file in the configuration # sudo/usr/local/nginx/sbin/nginx-t view the version number, compilation version, and configuration parameters #/usr/ local/nginx/sbin/nginx-V send stop, quit, reopen, and reload signals to the main process (version> = 0.7.53) # sudo/usr/local/nginx/sbin/nginx-s stop # sudo/usr/local/nginx/sbin/nginx-s quit # sudo/usr/local/nginx/sbin /nginx-s reopen # sudo/usr/local/nginx/sbin/nginx-s reload6. install the self-starting program: http://wiki.nginx.org/InitScriptsRed Hat Nginx Init Script: http://wiki.nginx.org/redhatnginxinitscriptthe downloaded file is: nginx, as shown below:
#!/bin/sh## nginx - this script starts and stops the nginx daemon## chkconfig:   - 85 15 # description:  Nginx is an HTTP(S) server, HTTP(S) reverse \#               proxy and IMAP/POP3 proxy server# processname: nginx# config:      /etc/nginx/nginx.conf# config:      /etc/sysconfig/nginx# pidfile:     /var/run/nginx.pid # Source function library.. /etc/rc.d/init.d/functions # Source networking configuration.. /etc/sysconfig/network # Check that networking is up.[ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/sbin/nginx"prog=$(basename $nginx) NGINX_CONF_FILE="/etc/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() {   # make required directories   user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`   if [ -z "`grep $user /etc/passwd`" ]; then       useradd -M -s /bin/nologin $user   fi   options=`$nginx -V 2>&1 | grep 'configure arguments:'`   for opt in $options; do       if [ `echo $opt | grep '.*-temp-path'` ]; then           value=`echo $opt | cut -d "=" -f 2`           if [ ! -d "$value" ]; then               # echo "creating" $value               mkdir -p $value && chown -R $user $value           fi       fi   done} start() {    [ -x $nginx ] || exit 5    [ -f $NGINX_CONF_FILE ] || exit 6    make_dirs    echo -n $"Starting $prog: "    daemon $nginx -c $NGINX_CONF_FILE    retval=$?    echo    [ $retval -eq 0 ] && touch $lockfile    return $retval} stop() {    echo -n $"Stopping $prog: "    killproc $prog -QUIT    retval=$?    echo    [ $retval -eq 0 ] && rm -f $lockfile    return $retval} restart() {    configtest || return $?    stop    sleep 1    start} reload() {    configtest || return $?    echo -n $"Reloading $prog: "    killproc $nginx -HUP    RETVAL=$?    echo} force_reload() {    restart} configtest() {  $nginx -t -c $NGINX_CONF_FILE} rh_status() {    status $prog} rh_status_q() {    rh_status >/dev/null 2>&1} case "$1" in    start)        rh_status_q && exit 0        $1        ;;    stop)        rh_status_q || exit 0        $1        ;;    restart|configtest)        $1        ;;    reload)        rh_status_q || exit 7        $1        ;;    force-reload)        force_reload        ;;    status)        rh_status        ;;    condrestart|try-restart)        rh_status_q || exit 0            ;;    *)        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"        exit 2esac


Save to/etc/init. d/nginx
# Cp nginx/etc/init. d
# Sudo vim/etc/init. d/nginx (modify the nginx main program path)
**************************************** **********************
......
# Nginx = "/usr/sbin/nginx"
Nginx = "/usr/local/nginx/sbin/nginx"
Prog = $ (basename $ nginx)


# NGINX_CONF_FILE = "/etc/nginx. conf"
NGINX_CONF_FILE = "/usr/local/nginx/conf/nginx. conf"
......
**************************************** **********************


Add execution permission
# Sudo chmod + x/etc/init. d/nginx


Configure to nginx service
# Sudo chkconfig nginx on


View configuration results
# Sudo chkconfig -- list nginx
Nginx 0: disable 1: disable 2: Enable 3: Enable 4: enable 5: Enable 6: disable
7. monitor Nginx concurrent statistics need to be compiled with -- with-http_stub_status_module
Modify the nginx configuration file as follows:
# Sudo vi/usr/local/nginx/conf/nginx. conf
http {    ...    server {        listen SOME.IP.ADD.RESS;        ...        location /nginx_status {            stub_status on;            access_log   off;            #allow SOME.IP.ADD.RESS;            #deny all;        }        ...    }    ...}
# Sudo yum install perl-rrdtool perl-libwww-perl.noarch
# Wget http://kovyrin.net/files/mrtg/rrd_nginx.pl.txt
#!/usr/bin/perluse RRDs;use LWP::UserAgent;# define location of rrdtool databasesmy $rrd = '/opt/rrd';# define location of imagesmy $img = '/opt/rrd';# define your nginx stats URLmy $URL = "http://moviewer.com/nginx_status";my $ua = LWP::UserAgent->new(timeout => 30);my $response = $ua->request(HTTP::Request->new('GET', $URL));my $requests = 0;my $total =  0;my $reading = 0;my $writing = 0;my $waiting = 0;foreach (split(/\n/, $response->content)) {  $total = $1 if (/^Active connections:\s+(\d+)/);  if (/^Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/) {    $reading = $1;    $writing = $2;    $waiting = $3;  }  $requests = $3 if (/^\s+(\d+)\s+(\d+)\s+(\d+)/);}#print "RQ:$requests; TT:$total; RD:$reading; WR:$writing; WA:$waiting\n";# if rrdtool database doesn't exist, create itif (! -e "$rrd/nginx.rrd") {  RRDs::create "$rrd/nginx.rrd",        "-s 60","DS:requests:COUNTER:120:0:100000000","DS:total:ABSOLUTE:120:0:60000","DS:reading:ABSOLUTE:120:0:60000","DS:writing:ABSOLUTE:120:0:60000","DS:waiting:ABSOLUTE:120:0:60000","RRA:AVERAGE:0.5:1:2880","RRA:AVERAGE:0.5:30:672","RRA:AVERAGE:0.5:120:732","RRA:AVERAGE:0.5:720:1460";}# insert values into rrd databaseRRDs::update "$rrd/nginx.rrd",  "-t", "requests:total:reading:writing:waiting",  "N:$requests:$total:$reading:$writing:$waiting";# Generate graphsCreateGraphs("day");CreateGraphs("week");CreateGraphs("month");CreateGraphs("year");#------------------------------------------------------------------------------sub CreateGraphs($){  my $period = shift;    RRDs::graph "$img/requests-$period.png","-s -1$period","-t Requests on nginx","--lazy","-h", "150", "-w", "700","-l 0","-a", "PNG","-v requests/sec","DEF:requests=$rrd/nginx.rrd:requests:AVERAGE","LINE2:requests#336600:Requests","GPRINT:requests:MAX:  Max\\: %5.1lf %S","GPRINT:requests:AVERAGE: Avg\\: %5.1lf %S","GPRINT:requests:LAST: Current\\: %5.1lf %Sreq/sec","HRULE:0#000000";  if ($ERROR = RRDs::error) {     print "$0: unable to generate $period graph: $ERROR\n";   }  RRDs::graph "$img/connections-$period.png","-s -1$period","-t Requests on nginx","--lazy","-h", "150", "-w", "700","-l 0","-a", "PNG","-v requests/sec","DEF:total=$rrd/nginx.rrd:total:AVERAGE","DEF:reading=$rrd/nginx.rrd:reading:AVERAGE","DEF:writing=$rrd/nginx.rrd:writing:AVERAGE","DEF:waiting=$rrd/nginx.rrd:waiting:AVERAGE","LINE2:total#22FF22:Total","GPRINT:total:LAST:   Current\\: %5.1lf %S","GPRINT:total:MIN:  Min\\: %5.1lf %S","GPRINT:total:AVERAGE: Avg\\: %5.1lf %S","GPRINT:total:MAX:  Max\\: %5.1lf %S\\n","LINE2:reading#0022FF:Reading","GPRINT:reading:LAST: Current\\: %5.1lf %S","GPRINT:reading:MIN:  Min\\: %5.1lf %S","GPRINT:reading:AVERAGE: Avg\\: %5.1lf %S","GPRINT:reading:MAX:  Max\\: %5.1lf %S\\n","LINE2:writing#FF0000:Writing","GPRINT:writing:LAST: Current\\: %5.1lf %S","GPRINT:writing:MIN:  Min\\: %5.1lf %S","GPRINT:writing:AVERAGE: Avg\\: %5.1lf %S","GPRINT:writing:MAX:  Max\\: %5.1lf %S\\n","LINE2:waiting#00AAAA:Waiting","GPRINT:waiting:LAST: Current\\: %5.1lf %S","GPRINT:waiting:MIN:  Min\\: %5.1lf %S","GPRINT:waiting:AVERAGE: Avg\\: %5.1lf %S","GPRINT:waiting:MAX:  Max\\: %5.1lf %S\\n","HRULE:0#000000";  if ($ERROR = RRDs::error) {     print "$0: unable to generate $period graph: $ERROR\n";   }}


The script generates a statistical table image based on the number of connections per year, month, day, and week, and the number of requests.


# Mv rrd_nginx.pl.txt rrd_nginx.pl
Add execution permission
# Chmod + x rrd_nginx.pl
# Sudo vim/etc/crontab
New
* *** Root/home/web/download/rrd_nginx.pl
Or crontab-e
Add the preceding row.
# Sudo service crond restart


Reference address: Workshop
#!/bin/bash#function:cut nginx log files for lnmp v0.5 and v0.6#author: http://lnmp.org#set the path to nginx log fileslog_files_path="/var/logs/nginx"#set nginx log files you want to cutproject_name=unknownlog_files_name=accesslog_files_dir=${log_files_path}/bck/${project_name}/$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")set the path to nginx.nginx_sbin="/etc/init.d/nginx"#############################################Please do not modify the following script #############################################mkdir -p $log_files_dir#log_files_num=${#log_files_name[@]}#cut nginx log files#for((i=0;i<$log_files_num;i++));domv ${log_files_path}/${log_files_name}.log ${log_files_dir}/${log_files_name}_$(date -d "yesterday" +"%Y%m%d")_$(date +"%Y%m%d%H%M%S").log#donekill -USR1 $(cat /var/run/nginx.pid)$nginx_sbin  force-reload

# Sudo chmod + x cut_nginx_logs.sh
# Crontab-e
5 0 *** root/home/web/cron/cut_nginx_logs.sh
That is, run the separation script at 00:05 every day.

The following files are automatically generated in the log directory every day:
/Var/logs/nginx/bck/unknown/2013/02/access_20130222_20130224262711.log

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.