nginx 安装 (一)

来源:互联网 发布:时间戳java显示gmt时间 编辑:程序博客网 时间:2024/05/16 14:49

1. 环境

     硬件:CORE I5 4核 + 4G DDR3 + 1Gb网卡 + 100Mb交换机

    OS:centos 5.6
2. 安装步骤
  a. 安装nginx-release-centos-5-0.el5.ngx.noarch.rpm,安装后可以通过yum来安装nginx
  [root@x ~]# wget http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm  [root@x ~]# rpm -ivh nginx-release-centos-5-0.el5.ngx.noarch.rpm
  b. 安装nginx

  [root@x ~]# yum install nginx

  c. 配置nginx.conf
 [root@x nginx]# pwd /etc/nginx [root@x nginx]# vi nginx.conf  user  nginx;  worker_processes  4;  error_log  /var/log/nginx/error.log warn;  pid        /var/run/nginx.pid;  events {     use epoll;     worker_connections  65535;  }  http {   include       /etc/nginx/mime.types;   default_type  application/octet-stream;   log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                     '$status $body_bytes_sent "$http_referer" '                     '"$http_user_agent" "$http_x_forwarded_for"';   access_log  /var/log/nginx/access.log  main;   sendfile        on;   #tcp_nopush     on;   keepalive_timeout  15;   #gzip  on;   include /etc/nginx/conf.d/*.conf;  }
d. 测试配置文件格式是否正确
 [root@x nginx]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: [warn] 65535 worker_connections are more than open file resource limit: 1024 nginx: configuration file /etc/nginx/nginx.conf test is successful
e. 修改OS参数
  
[root@x conf.d]# vi /etc/security/limits.conf   # /etc/security/limits.conf#
#Each line describes a limit for a user in the form:##<domain>        <type>  <item>  <value>##Where:#<domain> can be:#        - an user name#        - a group name, with @group syntax#        - the wildcard *, for default entry#        - the wildcard %, can be also used with %group syntax,#                 for maxlogin limit##<type> can have the two values:#        - "soft" for enforcing the soft limits#        - "hard" for enforcing hard limits##<item> can be one of the following:#        - core - limits the core file size (KB)#        - data - max data size (KB)#        - fsize - maximum filesize (KB)#        - memlock - max locked-in-memory address space (KB)#        - nofile - max number of open files#        - rss - max resident set size (KB)#        - stack - max stack size (KB)#        - cpu - max CPU time (MIN)#        - nproc - max number of processes#        - as - address space limit#        - maxlogins - max number of logins for this user#        - maxsyslogins - max number of logins on the system#        - priority - the priority to run user process with#        - locks - max number of file locks the user can hold#        - sigpending - max number of pending signals#        - msgqueue - max memory used by POSIX message queues (bytes)#        - nice - max nice priority allowed to raise to#        - rtprio - max realtime priority##<domain>      <type>  <item>         <value>##*               soft    core            0#*               hard    rss             10000#@student        hard    nproc           20#@faculty        soft    nproc           20#@faculty        hard    nproc           50#ftp             hard    nproc           0#@student        -       maxlogins       4*                -        nofile     65535# End of file
  修改配置后,重启主机使配置生效。
  
  f. 再次测试nginx配置
  [root@x ~]# nginx -t  nginx: the configuration file /etc/nginx/nginx.conf syntax is ok  nginx: configuration file /etc/nginx/nginx.conf test is successful
g. 启动nginx
[root@x ~]# nginx[root@x ~]# ps -ef|grep nginxroot      4062     1  0 12:12 ?        00:00:00 nginx: master process nginxnginx     4063  4062  0 12:12 ?        00:00:00 nginx: worker processnginx     4064  4062  0 12:12 ?        00:00:00 nginx: worker processnginx     4065  4062  0 12:12 ?        00:00:00 nginx: worker processnginx     4066  4062  0 12:12 ?        00:00:00 nginx: worker processroot      4068  3898  0 12:12 pts/1    00:00:00 grep nginx

h. 重启nginx
编写restart.sh脚本
[root@x ~]# vi renginx.sh#/bin/shkill -HUP `cat /var/run/nginx.pid`[root@x ~]# chmod +x renginx.sh [root@x ~]# ps -ef|grep nginxroot      4062     1  0 12:12 ?        00:00:00 nginx: master process nginxnginx     4063  4062  0 12:12 ?        00:00:00 nginx: worker processnginx     4064  4062  0 12:12 ?        00:00:00 nginx: worker processnginx     4065  4062  0 12:12 ?        00:00:00 nginx: worker processnginx     4066  4062  0 12:12 ?        00:00:00 nginx: worker processroot      4083  3898  0 12:16 pts/1    00:00:00 grep nginx[root@x ~]# ./renginx.sh[root@x ~]# ps -ef|grep nginroot      4062     1  0 12:12 ?        00:00:00 nginx: master process nginxnginx     4087  4062  0 12:16 ?        00:00:00 nginx: worker processnginx     4088  4062  0 12:16 ?        00:00:00 nginx: worker processnginx     4089  4062  0 12:16 ?        00:00:00 nginx: worker processnginx     4090  4062  0 12:16 ?        00:00:00 nginx: worker processroot      4099  3898  0 12:17 pts/1    00:00:00 grep ngin
i. 关闭nginx
 [root@x ~]# nginx -s stop [root@x ~]# ps -ef|grep nginx  root      4104  3898  0 12:18 pts/1    00:00:00 grep nginx