ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下載最新的 PCRE 源碼包,使用下面命令下載編譯和安裝 PCRE 包:html
cd /data/apps/ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gz tar -zxvf pcre-8.42.tar.gz cd pcre-8.42 ./configure make make install
查看是否安裝pcre java
rpm -qa pcre
安裝pcrenode
http://mirror.centos.org/centos/6/os/x86_64/Packages/pcre-7.8-7.el6.x86_64.rpm https://centos.pkgs.org/6/centos-x86_64/pcre-7.8-7.el6.x86_64.rpm.html rpm -ivh pcre-7.8-6.el6.x86_64.rpm
卸載pcrelinux
rpm -e --nodeps pcre
2 有網絡的狀況下 nginx
用yum安裝、更新開發工具"Development Tools"和"Server Platform Deveopment",而nginx會依賴openssl-devel和pcre-devel類庫,安裝以下:git
[root@node2 nginx]# yum groupinstall "Development Tools" "Server Platform Deveopment"
[root@node2 ~]# yum install openssl-devel pcre-devel
分別建立名爲"nginx"的用戶和組,用來運行nginx的worker進程,操做以下:github
[root@node2 nginx]# groupadd -r nginx
[root@node2 nginx]# useradd -r -g nginx nginx
Nginx 通常有兩個版本,分別是穩定版和開發版,您能夠根據您的目的來選擇這兩個版本的其中一個json
cd /data/apps wget http://nginx.org/download/nginx-1.14.1.tar.gz tar -zxvf nginx-1.14.1.tar.gz
cd nginx-1.14.1
先configure指定編譯選項,如安裝目錄、上面建立的運行用戶、須要的擴展模塊(SSL、FastCGI)等,選項及參數說明:http://nginx.org/en/docs/configure.html,操做以下:vim
[root@node2 nginx]# ./configure \ --prefix=/usr \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.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_stub_status_module \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/tmp/nginx/client/ \ --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ --http-scgi-temp-path=/var/tmp/nginx/scgi \ --with-pcre
Configure成功以下:centos
以後進行安裝
make && make install
先建立/etc/init.d/nginx服務腳本,這基於ngInx自身提供的命令實現的,腳本內容以下:
vim /etc/init.d/nginx
#!/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' -` 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 2 esac
併爲此腳本賦予執行權限,而後添加到系統服務管理列表,並讓其開機自動啓動,操做以下:
[root@node2 nginx]# vim /etc/init.d/nginx [root@node2 nginx]# chmod +x /etc/init.d/nginx [root@node2 nginx]# chkconfig --add nginx [root@node2 nginx]# chkconfig nginx on [root@node2 nginx]# chkconfig --list nginx
啓動nginx,查看網絡狀態,能夠看到nginx正在監聽80端口;用測試主機訪問nginx主機的IP,能夠看到nginx的歡迎頁面,過程以下:
[root@node2 nginx]# service nginx start [root@node2 nginx]# netstat -ntulp | grep nginx
若是啓動以後發現報錯,錯誤信息爲
[root@XXXXXXXX nginx-1.14.1]# service nginx start
Starting nginx: /usr/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
查詢 ll /usr/local/lib 看一看這個目錄 若是有就關聯上
若是是32位系統
[root@lee ~]# ln -s /usr/local/lib/libpcre.so.1 /lib
若是是64位系統
[root@lee ~]# ln -s /usr/local/lib/libpcre.so.1 /lib64
而後在啓動nginx就OK了
service nginx start
配置本地yum源或者第三方yum源
清理元數據緩存
yum clean all
從新創建元數據緩存
yum makecache
yum install -y unzip zip;
安裝監控軟件
nginx-module-vts
https://github.com/vozlt/nginx-module-vts
下載路徑 https://codeload.github.com/vozlt/nginx-module-vts/zip/master
unzip nginx-module-vts-master.zip
上傳之後 解壓之後 目錄爲
/data/apps/nginx-module-vts-master
移動到軟件目錄
mv /data/apps/nginx-module-vts-master /opt/soft/nginx-module-vts-master
進入ngnix目錄
執行命令
./configure \ --prefix=/usr \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.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_stub_status_module \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/tmp/nginx/client/ \ --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ --http-scgi-temp-path=/var/tmp/nginx/scgi \ --with-pcre \ --add-module=/opt/soft/nginx-module-vts-master
Configure成功以下:
以後進行安裝
make && make install
而後下載 nginx-vts-exporter
3、nginx-vts-exporter的使用
exporter會收集nginx性能指標的JSON格式數據,並彙總後暴露監控接口給Prometheus。
https://github.com/hnlq715/nginx-vts-exporter/releases/
下載連接爲
wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
啓動命令爲
/data/apps/nginx-vts-exporter-0.10.3.linux-amd64/nginx-vts-exporter -nginx.scrape_timeout 10 -nginx.scrape_uri http://127.0.0.1/status/format/json