带你安装Nginx服务

时间: 2023-08-15 admin 互联网

带你安装Nginx服务

带你安装Nginx服务

Nginx最大特点:

静态小文件(1M),支持高并发,同时占用系统资源很少。3W并发,10个进程,内存150M。

Nginx特点:

1、配置简单,灵活,轻量。

2、高并发(静态小文件),静态几万的并发。

3、占用资源少。2W并发 开10个线程服务,内存消耗几百M。

4、功能种类较多(Web,cache,proxy),每一个功能都不是特别强。

5、支持epoll模型,使得Nginx可以支持高并发!apache(select模型)。

6、Nginx可以配合动态服务(FASTCGI接口)

7、利用nginx可以对IP限速,可以限制连接数。

1.1 Nginx安装

1.1.1 创建Nginx虚拟用户

 [root@Web-lnmp02 ~]# useradd nginx -s /sbin/nologin -M   ##禁止用户用于ssh登录,且不创建家目录[root@Web-lnmp02 ~]# id nginxuid=501(nginx) gid=501(nginx) groups=501(nginx)[root@Web-lnmp02 ~]# 

1.1.2 在安装Nginx之前安装配套的pcre


--------------------------------------------------------------------
注:如果你对python感兴趣,我这有个学习Python基地,里面有很多学习资料,感兴趣的+Q群:895 797 751,--------------------------------------------------------------------[root@Web-lnmp02 tools]# rpm -qa pcre pcre-devel                  pcre-7.8-7.el6.x86_64[root@Web-lnmp02 tools]# yum install -y pcre pcre-develLoaded plugins: fastestmirror, securitySetting up Install ProcessLoading mirror speeds from cached hostfile* base: mirrors.sina.cn* extras: mirrors.opencas.cn* updates: centos.ustc.edu.cnPackage pcre-7.8-7.el6.x86_64 already installed and latest versionResolving Dependencies--> Running transaction check---> Package pcre-devel.x86_64 0:7.8-7.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================Package              Arch             Version             Repository      Size================================================================================Installing:pcre-devel           x86_64           7.8-7.el6           base           320 kTransaction Summary================================================================================Install       1 Package(s)Total download size: 320 kInstalled size: 957 kDownloading Packages:pcre-devel-7.8-7.el6.x86_64.rpm                          | 320 kB     00:00     Running rpm_check_debugRunning Transaction TestTransaction Test Succeeded
Running TransactionInstalling : pcre-devel-7.8-7.el6.x86_64                                  Verifying  : pcre-devel-7.8-7.el6.x86_64                                 Installed:pcre-devel.x86_64 0:7.8-7.el6                                             [root@Web-lnmp02 tools]# rpm -qa pcre pcre-devel      pcre-7.8-7.el6.x86_64pcre-devel-7.8-7.el6.x86_64

1.1.3 安装SSL Modules跟OpenSSL library

[root@Web-lnmp02 ~]# yum install -y openssl-devel[root@Web-lnmp02 ~]# rpm -qa|grep openssl        openssl-1.0.1e-42.el6_7.2.x86_64openssl-devel-1.0.1e-42.el6_7.2.x86_64openssl098e-0.9.8e-18.el6_5.2.x86_64

1.1.4 下载Nginx,并且编译安装

 1 [root@Web-lnmp02 tools]# wget .6.3.tar.gz2 --2015-11-28 20:50:36--  .6.3.tar.gz3 4 [root@Web-lnmp02 tools]# ll5 total 7886 -rw-r--r--. 1 root root 805253 Apr  8  2015 nginx-1.6.3.tar.gz7 [root@Web-lnmp02 tools]# tar xf nginx-1.6.3.tar.gz  ##解压8 [root@Web-lnmp02 tools]# ll9 total 792
10 drwxr-xr-x. 8 1001 1001   4096 Apr  7  2015 nginx-1.6.3
11 -rw-r--r--. 1 root root 805253 Apr  8  2015 nginx-1.6.3.tar.gz
12 [root@Web-lnmp02 tools]# 

编译安装Nginx

1 [root@Web-lnmp02 tools]# cd nginx-1.6.32 [root@Web-lnmp02 nginx-1.6.3]# ls -lk3 total 6244 drwxr-xr-x. 6 1001 1001   4 Nov 28 20:52 auto5 -rw-r--r--. 1 1001 1001 232 Apr  7  2015 CHANGES6 -rw-r--r--. 1 1001 1001 353 Apr  7  2015 CHANGES.ru7 drwxr-xr-x. 2 1001 1001   4 Nov 28 20:52 conf8 -rwxr-xr-x. 1 1001 1001   3 Apr  7  2015 configure9 drwxr-xr-x. 4 1001 1001   4 Nov 28 20:52 contrib
10 drwxr-xr-x. 2 1001 1001   4 Nov 28 20:52 html
11 -rw-r--r--. 1 1001 1001   2 Apr  7  2015 LICENSE
12 drwxr-xr-x. 2 1001 1001   4 Nov 28 20:52 man
13 -rw-r--r--. 1 1001 1001   1 Apr  7  2015 README
14 drwxr-xr-x. 8 1001 1001   4 Nov 28 20:52 src
15 [root@Web-lnmp02 nginx-1.6.3]# ./configure --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
16 [root@Web-lnmp02 nginx-1.6.3]# make && make install ##编译

备注:

参数简单说明:

–prefix=PATH 设置安装路径

–user=USER 进程用户权限

–group=GROUP 进程用户组权限

–with-http_ssl_module 激活ssl功能

–with-http_stub_status_module 激活状态信息

接着创建软链接:

 1 [root@Web-lnmp02 nginx-1.6.3]# ln -s /application/nginx-1.6.3/  /application/nginx2 [root@Web-lnmp02 nginx-1.6.3]# ls -l /application/3 total 44 lrwxrwxrwx. 1 root root   25 Nov 28 21:18 nginx -> /application/nginx-1.6.3/5 drwxr-xr-x. 6 root root 4096 Nov 28 21:09 nginx-1.6.36 [root@Web-lnmp02 nginx-1.6.3]# cd nginx7 -bash: cd: nginx: No such file or directory8 [root@Web-lnmp02 nginx-1.6.3]# cd /application/nginx9 [root@Web-lnmp02 nginx]# ll
10 total 16
11 drwxr-xr-x. 2 root root 4096 Nov 28 21:09 conf
12 drwxr-xr-x. 2 root root 4096 Nov 28 21:09 html
13 drwxr-xr-x. 2 root root 4096 Nov 28 21:09 logs
14 drwxr-xr-x. 2 root root 4096 Nov 28 21:09 sbin
1 [root@Web-lnmp02 nginx]# /application/nginx/sbin/nginx   ##启动Nginx服务
2 [root@Web-lnmp02 nginx]# lsof -i :80
3 COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
4 nginx   5027  root    6u  IPv4  23623      0t0  TCP *:http (LISTEN)
5 nginx   5028 nginx    6u  IPv4  23623      0t0  TCP *:http (LISTEN)
6 [root@Web-lnmp02 nginx]# netstat -lntup|grep nginx|grep -v grep
7 tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      5027/nginx 

1.1.6 测试