1安装PCRE库

  ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包:

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    

 rpm    -qa   pcre

安装pcre

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

卸载pcre

 rpm   -e  --nodeps    pcre

2 有网络的情况下

2-2、安装编译开发工具类库

用yum安装、更新开发工具"Development Tools"和"Server Platform Deveopment",而nginx会依赖openssl-devel和pcre-devel类库,安装如下:

[root@node2 nginx]# yum groupinstall "Development Tools" "Server Platform Deveopment"
[root@node2 ~]# yum install openssl-devel pcre-devel

2-3、创建用户和用户组

分别创建名为"nginx"的用户和组,用来运行nginx的worker进程,操作如下:

[root@node2 nginx]# groupadd -r nginx
[root@node2 nginx]# useradd -r -g nginx nginx

2-4、编译并安装

      安装nginx

  Nginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个

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,操作如下:

    [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成功如下:

之后进行安装

make && make install

  

2-5、为nginx提供SysV init服务脚本

先创建/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

2-6、启动并访问测试

启动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

三、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

  

ngnix 安装的更多相关文章

  1. Ngnix 安装、信号量、虚拟主机配置

    ngnix的安装很简单 1.先从ngnix官网下载ngnix压缩包 wget http://nginx.org/download/nginx-1.6.2.tar.gz 2.解压并进入其目录 tar - ...

  2. Ngnix 安装与使用

    高性能web服务器-ngnix MySQL读写分离技术 sphinx和mongodb 课程内容简介 一般都是拿nginx作为负载均衡器使用.Apache还是web市场老大.全球的市场份额大概在(60% ...

  3. Ngnix安装

    一.pcre安装 yum install pcre 或 https://sourceforge.net/projects/pcre/files/pcre/8.37/ 手动下载后上传至linux 1.y ...

  4. Ngnix 安装常见错误的处理

    错误:   解决方案:(联网下) 出现上面的问题是由于没有c++编译器造成 # yum -y install gcc-c++   使用上面的命令即可安装c++解决问题 如果确实c编译器,使用如下命令解 ...

  5. 基础篇四:Ngnix安装

    然后直接 yum  install nginx 安装nginx

  6. Linux下的ngnix安装与启动

     Linux安装Nginx 1.安装gcc gcc-c++(如新环境,未安装请先安装)$ yum install -y gcc gcc-c++2.安装wget$ yum -y install wget ...

  7. ubuntu14.04下安装ngnix,mediawiki,nodebb,everything,gitlab

    本周折腾了以下几个东西,mediawiki(维基),nodebb(论坛),gitlab(私有git服务器). 本来的目的是搭建一个wiki,选用了mediawiki后,使用apache搭建好了. 搭论 ...

  8. Ngnix负载均衡安装及配置

    1.ngnix概念 Nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.由俄罗斯的程序设计师Igor Sysoev所开发,官方测试nginx能够支支撑5 ...

  9. 003.安装nginx(lnmp)

    一.下载nginx 下载nginx源码包,解压: [root@huh ~]# cd /usr/local/src/ [root@huh src]# wget http://nginx.org/down ...

随机推荐

  1. R 语言文件读写

    1. working directory:工作目录 > getwd() > setwd("C:/data") # 设定当前工作目录 2. 读取格式化的 table &g ...

  2. 【PHP Manager for IIS】让IIS支持PHP

    本文安装环境: 操作系统:Win7 64位 PHP版本:PHP 5.5.15(VC11 x64 Thread Safe)    下载地址:http://windows.php.net/download ...

  3. Azure Messaging-ServiceBus Messaging

    Azure Messaging-ServiceBus Messaging 上篇博文中我们介绍了Azure Messaging的重复消息机制.At most once 和At least once. A ...

  4. 矿Java开发学习之旅------>Java排序算法经典的二分法插入排序

    一.折半插入排序(二分插入排序) 将直接插入排序中寻找A[i]的插入位置的方法改为採用折半比較,就可以得到折半插入排序算法.在处理A[i]时,A[0]--A[i-1]已经按关键码值排好序.所谓折半比較 ...

  5. QImage学习学习

    QImage这个类之前用过,无外乎是加载一个图片文件显示出来,并没有做过多的研究,目前工作中用到了灰度图以及图片的像素操作,重新学习了下,记录记录. 一些基本操作方法 获取图像的首地址: const ...

  6. Android开发中如何加载API源码帮助开发

    在eclipse中添加android源码既可以帮助我们的开发,又能使我们边开发边学习. android环境的搭建:http://blog.csdn.net/dawanganban/article/de ...

  7. Project Euler:Problem 28 Number spiral diagonals

    Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is forme ...

  8. Entity Framework加载数据的三种方式。

    MSDN文章Loading Related Entities 有 Eagerly Loading Lazy Loading Explicitly Loading 三种方式. 而看到查询中包含Inclu ...

  9. 将枚举转成SelectListItem

    代码如下: /// <summary> /// 将一个枚举转化成一个List<SelectListItem> /// </summary> /// <type ...

  10. i/o多路复用笔记

    1.用户空间和内核空间 操作系统的核心是内核,独立于普通的应用程序,可以访问受保护的内存空间,也可以访问底层硬件设备.为了保护用户进程不能直接操作内核,保证内核的安全,操作系统将虚拟空间划分为两部分, ...