nginx 安裝 (一)


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 nginx
root      4062     1  0 12:12 ?        00:00:00 nginx: master process nginx
nginx     4063  4062  0 12:12 ?        00:00:00 nginx: worker process
nginx     4064  4062  0 12:12 ?        00:00:00 nginx: worker process
nginx     4065  4062  0 12:12 ?        00:00:00 nginx: worker process
nginx     4066  4062  0 12:12 ?        00:00:00 nginx: worker process
root      4068  3898  0 12:12 pts/1    00:00:00 grep nginx

h. 重啓nginx
編寫restart.sh腳本
[root@x ~]# vi renginx.sh
#/bin/sh
kill -HUP `cat /var/run/nginx.pid`
[root@x ~]# chmod +x renginx.sh 
[root@x ~]# ps -ef|grep nginx
root      4062     1  0 12:12 ?        00:00:00 nginx: master process nginx
nginx     4063  4062  0 12:12 ?        00:00:00 nginx: worker process
nginx     4064  4062  0 12:12 ?        00:00:00 nginx: worker process
nginx     4065  4062  0 12:12 ?        00:00:00 nginx: worker process
nginx     4066  4062  0 12:12 ?        00:00:00 nginx: worker process
root      4083  3898  0 12:16 pts/1    00:00:00 grep nginx
[root@x ~]# ./renginx.sh
[root@x ~]# ps -ef|grep ngin
root      4062     1  0 12:12 ?        00:00:00 nginx: master process nginx
nginx     4087  4062  0 12:16 ?        00:00:00 nginx: worker process
nginx     4088  4062  0 12:16 ?        00:00:00 nginx: worker process
nginx     4089  4062  0 12:16 ?        00:00:00 nginx: worker process
nginx     4090  4062  0 12:16 ?        00:00:00 nginx: worker process
root      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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章