Вы находитесь на странице: 1из 4

Installation of Nginx

Step 1: Add the nginx user useradd -s /bin/false nginx . Step 2: Install the following, use yum install gcc openssl-devel pcre-devel zlib-devel GeoIP* Step 3: Download the stable version . Step 4: Extract the tar.gz file. Step 5: Configuration, ./configure \ --prefix=/usr \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/conf/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_gzip_static_module \ --with-http_geoip_module \ --with-http_realip_module \ --with-http_stub_status_module \ --http-log-path=/var/log/nginx/access.log \ --http-client-body-temp-path=/var/www/nginx/client/ \ --http-proxy-temp-path=/var/www/nginx/proxy/ \ --http-fastcgi-temp-path=/var/www/nginx/fcgi/ Copy and past. Step 6: And run the make and make install command. Step 7: We need to create a directory called virtuosol in /etc/conf/nginx. Step 8: Need to cerate a directory called sitesdisable sitesenabled ssl.crt ssl.key . Step 9: Configuring the sites, Enter into the directory /etc/conf/nginx/virtuosol/sitesenabled and create a conf file for the site. Ex: demo.hogaming.info.conf , idoo.lifeisu.com.conf. Step 10: For example i have attached the conf file.Make sure your conf file as same as this. Step 11: Inclued that conf file in nginx.conf /etc/conf/nginx/nginx.conf .For example: include virtuosol/sitesenabled/idoo.lifeisu.com .conf; .

Step 12: /etc/init.d/nginx configtest this command is used to check the conf file. Step 13: It said OK, then start the service. /etc/init.d/nginx start. Step 14: /etc/init.d/nginx {start|stop|status|restart|condrestart|try-restart|reload|force-reload| configtest} Monitoring Nginx server status with stub module :http { server { listen ip.addresss; locatation /nginx_status { stub_status on; access_log off; allow ip.address; deny all; } } } testing nginx status: GET http://your-domain.com/nginx_status

perl script save it as ngnix-status.pl


Change settings in ngnix-status.pl to let script know where it will save rrd-base and images #!/usr/bin/perl use RRDs; use LWP::UserAgent; # define location of rrdtool databases my $rrd = '/opt/rrd'; # define location of images my $img = '/opt/rrd/html'; # define your nginx stats URL my $URL = "http://your-domain.com/nginx_status"; Last step is to insert following string to /etc/crontab file and to restart crondaemon: * * * * * root /some/path/rrd_nginx.pl

...

#!/usr/bin/perl use RRDs; use LWP::UserAgent; # define location of rrdtool databases my $rrd = '/opt/rrd';

# define location of images my $img = '/opt/rrd'; # define your nginx stats URL my $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 it if (! -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 database RRDs::update "$rrd/nginx.rrd", "-t", "requests:total:reading:writing:waiting", "N:$requests:$total:$reading:$writing:$waiting"; # Generate graphs CreateGraphs("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"; } }

Вам также может понравиться