加入收藏 | 设为首页 | 会员中心 | 我要投稿 甘南站长网 (https://www.0941zz.com/)- 科技、行业物联网、开发、云计算、云管理!
当前位置: 首页 > 运营中心 > LNMP > 正文

LNMP系统服务搭建过程详解

发布时间:2023-02-17 14:03:06 所属栏目:LNMP 来源:互联网
导读:图文解释 和LAMP不同的是LNMP中的N指的是Nginx(类似于Apache的一种web服务软件)其他都一样。目前这种环境应用的也是非常之多。Nginx设计的初衷是提供一种快速高效多并发的web服务软件。在静态页面的处理上Nginx的确胜Apache一筹,然而在动态页面的处理上Ng
  图文解释
      和LAMP不同的是LNMP中的N指的是Nginx(类似于Apache的一种web服务软件)其他都一样。目前这种环境应用的也是非常之多。Nginx设计的初衷是提供一种快速高效多并发的web服务软件。在静态页面的处理上Nginx的确胜Apache一筹,然而在动态页面的处理上Nginx并不比Apache有多少优势。但是,目前还是有很多爱好者对Nginx比较热衷,随着Nginx的技术逐渐成熟,它在web服务软件领域的地位越来越高。下边记录一下LNMP架构搭建的详细过程。
 
  一、MysqL数据库的安装
  1. 系统环境
 
  CentOS 6.4 x86_64 Mini 版本安装
 
  2. 基础软件包安装
 
  [root@vip ~]# yum install gcc vim make wget -y
  3. 下载
 
  # 进入源码存放目录[root@vip ~]# cd /usr/local/src# 下载MysqL安装包[root@vip src]# wget downloads.MysqL.com/archives/get/file/MysqL-5.5.40-linux2.6-x86_64.tar.gz
  4. 解压安装
 
  # 拷贝启动脚本[root@vip MysqL]# /bin/cp support-files/MysqL.server /etc/init.d/MysqLd# 赋予可执行权限[root@vip MysqL]# chmod 755 /etc/init.d/MysqLd
  10. 修改启动脚本
 
  [root@vip MysqL]# vim /etc/init.d/MysqLd# 修改设置内容如下basedir=/usr/local/MysqL
  datadir=/var/lib/MysqL
  11. 把MysqL添加到服务
 
  makemake install
  5、修改配置文件
 
  cp /usr/local/src/PHP-5.3.27/sapi/fpm/init.d.PHP-fpm /etc/init.d/PHP-fpm
  给它更改权限为755
 
  Nginx.org/download/Nginx-1.8.0.tar.gztar zxvf Nginx-1.8.0.grep Nginx
  四、测试PHP解析
  首先配置 Nginx 配置文件,使其能够支持PHP。
 
  vim /usr/local/Nginx/conf/Nginx.conf
  找到:
 
  location = /50x.html {
      root html;
  }
  在其后面增加如下配置:
 
  location ~ .PHP$ {
      root html;
      fastcgi_pass ;
      fastcgi_index index.PHP;
      fastcgi_param SCRIPT_FILENAME /usr/local/Nginx/html$fastcgi_script_name;
      include fastcgi_params;
  }
  重新加载:
 
  /usr/local/Nginx/sbin/Nginx -s reload
  创建测试文件:
 
  vim /usr/local/Nginx/html/2.PHP<?PHPecho test PHP scripts.;?>
  测试<span style=font-size: 10pt; color: rgba(128,courier'>curl localhost/.PHP test PHP scripts.
 
  显示成这样,才说明 PHP 解析正常。
 
  五、Nginx启动脚本和配置文件
  1、编写启动脚本并加入系统服务
 
  vim /etc/init.d/Nginx
  写入如下内容:
 
  #!/bin/bash
  # chkconfig: - 30 21# description: http service.
  # Source Function Library
  . /etc/init.d/functions
  # Nginx Settings
  
  Nginx_SBIN=/usr/local/Nginx/sbin/NginxNginx_CONF=/usr/local/Nginx/conf/Nginx.confNginx_PID=/usr/local/Nginx/logs/Nginx.pidRETVAL=prog=Nginxstart() {echo -n $starting $prog: mkdir -p /dev/shm/Nginx_temp
          daemon $Nginx_SBIN -c $Nginx_CONF
          RETVAL=$?echoreturn $RETVAL
  }
  
  stop() {Stopping $prog: killproc -p $Nginx_PID $Nginx_SBIN -TERMrm -rf /dev/shm/Nginx_temp
          RETVAL=$?return $RETVAL
  }
  
  reload(){Reloading $prog: HUP
          RETVAL=$?return $RETVAL
  }
  
  restart(){
          stop
          start
  }
  
  configtest(){
      $Nginx_SBIN -c $Nginx_CONF -t
      return }case $1 in
    start)
          start
          ;;
    stop)
          stop
          ;;
    reload)
          reload
          ;;
    restart)
          restart
          ;;
    configtest)
          configtest
          ;;  *)echo $Usage: $0 {start|stop|reload|restart|configtest}RETVAL=1esacexit $RETVAL
  保存后,更改权限:
 
  <span style='font-family: courier new,1)>755 /etc/init.d/Nginx
  chkconfig --add Nginx
  chkconfig Nginx on
  2、更改整理Nginx配置
 
  首先清空原来的配置文件:
 
  > /usr/local/Nginx/conf/Nginx.conf快速清空文档。
  编辑文件写入如下内容:
 
  # vim /usr/local/Nginx/conf/Nginx.confuser nobody nobody;
  worker_processes ;
  error_log /usr/local/Nginx/logs/Nginx_error.log crit;
  pid /usr/local/Nginx/logs/Nginx.pid;
  worker_rlimit_nofile 51200;
  
  events
  {   
      use epoll;
      worker_connections 6000;
  }
  
  http
  {
      include mime.types;
      default_type application/octet-stream;
      server_names_hash_bucket_size 3526;
      server_names_hash_max_size 4096;
      log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'$host $request_uri $status$http_referer $http_user_agent';
      sendfile on;
      tcp_nopush on;
      keepalive_timeout 30;
      client_header_timeout 3m;
      client_body_timeout 3m;
      send_timeout 3m;
      connection_pool_size 256;
      client_header_buffer_size 1k;
      large_client_header_buffers 8 4k;
      request_pool_size 4k;
      output_buffers 4 32k;
      postpone_output 1460;
      client_max_body_size 10m;
      client_body_buffer_size 256k;
      client_body_temp_path /usr/local/Nginx/client_body_temp;
      proxy_temp_path /usr/local/Nginx/proxy_temp;
      fastcgi_temp_path /usr/local/Nginx/fastcgi_temp;
      fastcgi_intercept_errors on;
      tcp_nodelay on;gzip on;
      gzip_min_length 1k;
      gzip_buffers  8k;
      gzip_comp_level ;
      gzip_http_version 1.1;
      gzip_types text/plain application/x-javascript text/css text/htm application/xml;
  
      include vhosts/*.conf;
  }
  继续如下操作:
 
  cd /usr/local/Nginx/confmkdir vhosts
  cd vhosts
  vim default.conf
  写入如下内容:
 
  fpm
  listen.owner = nobody
  listen.group = nobody
  pm = pm.max_spare_servers =  rlimit_files = 1024
  配置说明:
 
  global部分是全局配置,指定pid文件路径以及error_log路径。
  [www]是一个pool,其实还可以再写第二个pool,第二个pool和第一个不一样的地方,首先pool的name,比如叫做[www2]。然后listen肯定就不能一样了,比如可以listen=/tmp/PHP-fcgi2.sock。而user,group也可以和[www]中定义的不一样。listen.owner这个是定义/tmp/PHP-fcgi.sock这个文件的所有者是谁,在PHP5.4版本之后监听的socket文件权限默认变成了 rw-------,如果不定义listen.owner那么Nginx调用这个socket的时候就没有权限了,故在这里我们定义listen.owner为Nginx的子进程监听用户。

(编辑:甘南站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读