linux服务器下LNMP安装与配置方法

2019-10-14 22:24:08丽君

      Unix group of processes
      <value name="group">nginx</value>                        取消注释

 <value name="max_children">128</value>
#最大子进程数128,如果内存小于2G,则64个最佳
<value name="rlimit_files">65535</value>
# Set open file desc rlimit,同时打开的文件数,linux系统允许同时打开的文件数为1024,修改linux系统中允许同时打开的文件,ulimit -SHn 65535,而且这个参数重启后还能生效,加到 /etc/profile全局配置文件的最后,开机就会生效,ulimit -a查看open files 65535
       ulimit  用户控制shell启动进程所占用的资源
              -H   设定硬性资源限制,也就是管理员设定的限制
              -S    设定软性资源限制,弹性限制
              -n    设定可同时打开的最大文件个数
              -f     设定单个文件最大大小
              -a    查看目前的限制
<value name="max_requests">1024</value>
#最大请求数, How much requests each process should execute before respawn.一个子进程能够回应1042个请求

11. 启动php-cgi(fastcgi)进程,监听127.0.0.1的9000端口,进程数为128(如果服务器内存小于3GB,可以只开启64个进程),用户为nginx:


/usr/local/php/sbin/php-fpm start
#启动php-cgi
/usr/local/php/sbin/php-fpm reload
#重新加载配置文件
/usr/local/php/sbin/php-fpm stop
#关闭php-fpm,此时nginx肯定连不上php

12. 安装Nginx所需的pcre库


tar zxvf pcre-8.10.tar.gz
cd pcre-8.10/
./configure
make && make install
cd ../

13. 安装Nginx


tar zxvf nginx-0.8.46.tar.gz
cd nginx-0.8.46/
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../

14. 修改Nginx配置文件


vi /usr/local/nginx/conf/nginx.conf
user  nginx nginx;
worker_processes 1;
#相当于cpu个数
error_log  logs/nginx_error.log;
#错误日志
pid        /usr/local/nginx/nginx.pid;
#主进程PID保存文件
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
#文件描述符数量