You can use monitoring programs such as cacti and nagios to monitor nginx servers, but sometimes it is not that complicated. You can use nginx-rrd to monitor connections and requests.
First, compile and install nginx. Pay attention to loading the stub_status module. The stub_status module in Nginx is mainly used to view some Nginx status information.
This module is not compiled into Nginx by default. If you want to use this module, you must specify
- tarxzvfnginx-1.2.0.tar.gz
- cdnginx-1.2.0
- ./configure--prefix=/usr/local/nginx--with-http_stub_status_module
- make&&makeinstall
Install the relevant perl and rrdtool rpm packages in yum
- yuminstallperlrrdtoolperl-libwww-perllibwww-perlperl-rrdtool
After confirming that rrdtool and corresponding perl are installed, start to install nginx-rrd
- Tarzxvfnginx-rrd-0.1.4.tgz
- Cdnginx-rrd-0.1.4
- Cp-pusr/sbin/*/usr/sbin // copy the master program file to/usr/sbin.
- Cp-petc/nginx-rrd.conf/etc // copy the configuration file to/etc
- Create nginx-rrd directory
- Mkdir/usr/local/nginx/html/rrd
- Cphtml/index. php/usr/local/nginx/html
Here, we recommend you change the default access password WCO in the index. php file.
Edit/etc/nginx-rrd.conf
- vim/etc/nginx-rrd.conf
- #####################################################
- #
- #dirwhererrddatabasesarestored
- RRD_DIR="/usr/local/nginx/html/rrd";
- #dirwherepngimagesarepresented
- WWW_DIR="/usr/local/nginx/html";
- #processnicelevel
- NICE_LEVEL="-19";
- #bindir
- BIN_DIR="/usr/sbin";
- #serverstotest
- #server_utl;server_name
- SERVERS_URL="http://www.linuxom.com/nginx_status;www.linuxom.com"
Multiple virtual hosts can be separated by spaces in SERVERS_URL. The front part is the address of nginx_status, followed by the Domain Name of the monitored host.
Check whether the installed nginx contains the stub_status module.
- /usr/local/nginx/sbin/nginx-V
- nginxversion:Nginx/1.2.0
- configurearguments:--with-http_stub_status_module
Confirm that the stub_status module is supported and edit and modify nginx. conf.
- Vim/usr/local/nginx/conf/nginx. conf
- // Add the following content to server {}:
- Location /{
- Roothtml;
- Indexindex.phpindex.htmlindex.htm;
- Location/nginx_status {
- Stub_statuson; // This option parameter is supported by the stub_status module during compilation. If it is not compiled, a warning will be generated when nginx is started.
- Access_logoff;
- }
- }
- # Error_page404/404.html;
- # Redirectservererrorpagestothestaticpage/50x.html
- #
- Error_page500502503504/50x.html;
- Location =/50x.html {
- Roothtml;
- }
- # ProxythePHPscriptstoApachelisteningon127.0.0.1: 80
- #
- # Location ~ \. Php $ {
- # Proxy_passhttp: // 127.0.0.1;
- #}
- # PassthePHPscriptstoFastCGIserverlisteningon127.0.0.1: 9000
- #
- // Remove the annotation of the following content, which is supported by php. Note the file path.
- Location ~ \. Php $ {
- Roothtml;
- Fastcgi_pass127.0.0.1: 9000;
- Fastcgi_indexindex.php;
- Fastcgi_paramSCRIPT_FILENAME/usr/local/nginx/html $ fastcgi_script_name;
- Includefagi_params;
- }
Restart Nginx Server
- /usr/local/nginx/sbin/nginx-sreload
Set timed data collection
- crontab-e
- *****root/usr/sbin/nginx-collect
- */10****root/usr/sbin/nginx-graph
Access page http: // domain name/index. php, the number of nginx connections such
The number of nginx requests is as follows: