美文网首页
安装nginx

安装nginx

作者: 心疼你萌萌哒 | 来源:发表于2018-05-12 09:38 被阅读0次

安装nginx所需环境:

1.yum install gcc
  yum install pcre-devel
  yum install zlib zlib-devel
  yum install openssl openssl-devel
  或者一键安装:yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2.下载nginx压缩包:
wget http://nginx.org/download/nginx-1.10.2.tar.gz
下载在当前目录
3.解压缩:tar -zxvf nginx-1.10.2.tar.gz
4.进入nginx-1.10.2目录:cd nginx-1.10.2
5.  执行  ./configure
6.  执行make
7.  执行make install
8. 查找nginx安装目录:whereis nginx
9.进入niginx安装目录,默认在 cd /usr/local/nginx/
10. cd sbin
11. 执行 ./nginx   ## 注意80端口占用情况 如果被占用执行失败

12.打开浏览器,输入ip地址,看到welcome to nginx!即安装成功
## 0\. 环境和参考文档

centos-6.5 
[Tengine 官网](http://tengine.taobao.org/)

## 1\. 安装依赖

```
yum -y groupinstall "Development tools"
yum -y groupinstall "Server Platform Development"
yum -y install pcre-devel

## 编译时候提示安装的依赖
yum install -y libxslt-devel
yum install -y gd-devel
yum install -y lua-devel

## GeoIP  用户访问来源
cd /usr/local/src
wget http://pkgs.repoforge.org/geoip/geoip-devel-1.4.6-1.el6.rf.x86_64.rpm
wget http://pkgs.repoforge.org/geoip/geoip-1.4.6-1.el6.rf.x86_64.rpm

rpm -ivh geoip-devel-1.4.6-1.el6.rf.x86_64.rpm
rpm -ivh geoip-1.4.6-1.el6.rf.x86_64.rpm

```

## 添加Tengine的运行时用户

`useradd -r tengine`

## 编译安装

```
./configure \
--prefix=/usr/local/tengine \
--sbin-path=/usr/local/tengine/sbin/tengine \
--conf-path=/usr/local/tengine/conf/tengine.conf \
--error-log-path=/usr/local/tengine/logs/error.log \
--http-log-path=/usr/local/tengine/logs/access.log \
--pid-path=/var/run/tengine/tengine.pid \
--lock-path=/var/lock/tengine.lock \
--user=tengine \
--group=tengine \
--with-http_ssl_module \
--enable-mods-shared=all \
--dso-path=/usr/local/tengine/dso \
--without_ngx_http_lua_module
```

## 将启动脚本引入环境变量

```
vim /etc/profile.d/tengine.sh

export PATH=/usr/local/tengine/sbin:$PATH

reboot
```

## 配置

```
vim /usr/local/tengine/conf/tengine.conf
## 设置开启的worker数量为auto  (global context)  `cat /proc/cpuinfo`
worker_processes auto;
## 绑定cpu亲缘   (global context)
worker_cpu_afinity auto;
## 定义每个worker进程可以打开的文件句柄参数  (global context)
worker_rlimit_nofile 51200
## 设置每个worker的最大连接数 (events context)
worker_connections 51200
```

## 启动 | 停止tengine

```
tengine -c /usr/local/tengine/conf/tengine.conf
tengine -s stop
```

## 做个压力测试

### 碰到 apr_socket_recv: Connection reset bu peer (104) 错误的解决

`ulimit -n 51200`

> 开始测试 
> `/usr/local/apache-2.2.27/bin/ab -c 2000 -n 20000 http://192.168.1.101/index.html` 
> 在被测机器使用 `top` `htop` `vmstat` 查看cpu负载和`wa`值 
> `vmstat 1 看cpu wa 数值`

## 开启Tengine的健康监测

> 需要动态的加载`sysguard`模块 
> 这样当cpu负载到达`1.1`之后, Tengine停止服务,并将请求转发至`loadlimit`action

```
## server http context

dso {
    ngx_http_sysguard_module.so;
}

http {
    sysguard on;
    sysguard_load load=1.1 action=/loadlimit;

    server {
        location /loadlimit {
            return 503;
        }
    }
}
```

## 集群中upstream 的健康状态监测配置

```
http {
    upstream cluster1 {
        # simple round-robin
        consistent_hash $request_uri;

        server 192.168.0.1:80 id=1001;
        server 192.168.0.2:80 id=1002;

        check interval=3000 rise=2 fall=5 timeout=1000 type=http;
        check_http_send "HEAD / HTTP/1.0\r\n\r\n";
        check_http_expect_alive http_2xx http_3xx;
    }

    server {
        listen 80;

        location /1 {
            proxy_pass http://cluster1;
        }
        location /status {
            check_status;
            access_log   off;
        }
    }
}
```

## 查看集群状态信息

`http://127.0.0.1/status` 
![检查失败的图片](https://img.haomeiwen.com/i11415933/c7af2404c73cdcf2?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

相关文章

网友评论

      本文标题:安装nginx

      本文链接:https://www.haomeiwen.com/subject/qxecdftx.html