安装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虚拟用户
1 [root@Web-lnmp02 ~]# useradd nginx -s /sbin/nologin -M ##禁止用户用于ssh登录,且不创建家目录 2 [root@Web-lnmp02 ~]# id nginx 3 uid=501(nginx) gid=501(nginx) groups=501(nginx) 4 [root@Web-lnmp02 ~]#
1.1.2 在安装Nginx之前安装配套的pcre
1 [root@Web-lnmp02 tools]# rpm -qa pcre pcre-devel 2 pcre-7.8-7.el6.x86_64 3 [root@Web-lnmp02 tools]# yum install -y pcre pcre-devel 4 Loaded plugins: fastestmirror, security 5 Setting up Install Process 6 Loading mirror speeds from cached hostfile 7 * base: mirrors.sina.cn 8 * extras: mirrors.opencas.cn 9 * updates: centos.ustc.edu.cn 10 Package pcre-7.8-7.el6.x86_64 already installed and latest version 11 Resolving Dependencies 12 --> Running transaction check 13 ---> Package pcre-devel.x86_64 0:7.8-7.el6 will be installed 14 --> Finished Dependency Resolution 15 16 Dependencies Resolved 17 18 ================================================================================ 19 Package Arch Version Repository Size 20 ================================================================================ 21 Installing: 22 pcre-devel x86_64 7.8-7.el6 base 320 k 23 24 Transaction Summary 25 ================================================================================ 26 Install 1 Package(s) 27 28 Total download size: 320 k 29 Installed size: 957 k 30 Downloading Packages: 31 pcre-devel-7.8-7.el6.x86_64.rpm | 320 kB 00:00 32 Running rpm_check_debug 33 Running Transaction Test 34 Transaction Test Succeeded 35 Running Transaction 36 Installing : pcre-devel-7.8-7.el6.x86_64 1/1 37 Verifying : pcre-devel-7.8-7.el6.x86_64 1/1 38 39 Installed: 40 pcre-devel.x86_64 0:7.8-7.el6 41 [root@Web-lnmp02 tools]# rpm -qa pcre pcre-devel 42 pcre-7.8-7.el6.x86_64 43 pcre-devel-7.8-7.el6.x86_64
1.1.3 安装SSL Modules跟OpenSSL library
1 [root@Web-lnmp02 ~]# yum install -y openssl-devel 2 [root@Web-lnmp02 ~]# rpm -qa|grep openssl 3 openssl-1.0.1e-42.el6_7.2.x86_64 4 openssl-devel-1.0.1e-42.el6_7.2.x86_64 5 openssl098e-0.9.8e-18.el6_5.2.x86_64
1.1.4 下载Nginx,并且编译安装
1 [root@Web-lnmp02 tools]# wget http://nginx.org/download/nginx-1.6.3.tar.gz 2 --2015-11-28 20:50:36-- http://nginx.org/download/nginx-1.6.3.tar.gz 3 4 [root@Web-lnmp02 tools]# ll 5 total 788 6 -rw-r--r--. 1 root root 805253 Apr 8 2015 nginx-1.6.3.tar.gz 7 [root@Web-lnmp02 tools]# tar xf nginx-1.6.3.tar.gz ##解压 8 [root@Web-lnmp02 tools]# ll 9 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.3 2 [root@Web-lnmp02 nginx-1.6.3]# ls -lk 3 total 624 4 drwxr-xr-x. 6 1001 1001 4 Nov 28 20:52 auto 5 -rw-r--r--. 1 1001 1001 232 Apr 7 2015 CHANGES 6 -rw-r--r--. 1 1001 1001 353 Apr 7 2015 CHANGES.ru 7 drwxr-xr-x. 2 1001 1001 4 Nov 28 20:52 conf 8 -rwxr-xr-x. 1 1001 1001 3 Apr 7 2015 configure 9 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/nginx 2 [root@Web-lnmp02 nginx-1.6.3]# ls -l /application/ 3 total 4 4 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.3 6 [root@Web-lnmp02 nginx-1.6.3]# cd nginx 7 -bash: cd: nginx: No such file or directory 8 [root@Web-lnmp02 nginx-1.6.3]# cd /application/nginx 9 [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.1.5 启动Nginx服务
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 测试
服务器地址:
浏览器访问:
########## 今天的苦逼是为了不这样一直苦逼下去!##########