zoukankan      html  css  js  c++  java
  • centos6.8下LNMP (nginx1.8.0+php5.6.10+mysql5.6.12)

    在平时运维工作中,经常需要用到LNMP应用框架。
    以下对LNMP环境部署记录下:

    1)前期准备:为了安装顺利,建议先使用yum安装依赖库
    [root@opd ~]#yum install -y make cmake gcc gcc-c++ autoconf automake libpng-devel libjpeg-devel zlib libxml2-devel ncurses-devel bison libtool-ltdl-devel libiconv libmcrypt mhash mcrypt libmcrypt-devel pcre-devel openssl-devel freetype-devel libcurl-devel

    2)安装nginx
    [root@opd ~]#cd /opt/src
    [root@src ~]#wget http://nginx.org/download/nginx-1.8.0.tar.gz
    [root@src ~]#tar -zxvf nginx-1.8.0.tar.gz
    [root@src ~]#cd nginx-1.8.0
    添加www用户,其中-M参数表示不添加用户家目录,-s参数表示指定shell类型
    [root@nginx-1.8.0 ~]#useradd www -M -s /sbin/nologin
    [root@nginx-1.8.0 ~]#vim auto/cc/gcc
    将这句注释掉取消Debug编译模式 大概在179行
    #CFLAGS="$CFLAGS -g"

    我们再配置下nginx编译参数
    [root@nginx-1.8.0 ~]#./configure --prefix=/opt/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
    [root@nginx-1.8.0 ~]#make
    [root@nginx-1.8.0 ~]#make install clean
    添加开机自启动
    [root@nginx-1.8.0 ~]#vim /etc/rc.local
    在这个文件里面添加:/opt/nginx/sbin/nginx
    [root@nginx-1.8.0 ~]#/opt/nginx/sbin/nginx

                                                                   Centos7采用yum方式安装nginx                                                            
    centos7系统库中默认是没有nginx的rpm包的,所以我们自己需要先更新下rpm依赖库
    1)使用yum安装nginx需要包括Nginx的库,安装Nginx的库
    # rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

    2)使用下面命令安装nginx
    # yum install nginx

    3)启动Nginx
    # service nginx start

    # systemctl start nginx.service
                                                                                                                                                                               

    3)安装PHP
    由于PHP需要这些类库的支撑
    先下载PHP
    [root@opd ~]#cd /opt/src/
    [root@src ~]#wget http://cn2.php.net/distributions/php-5.6.10.tar.gz
    [root@src ~]#tar -zxvf php-5.6.10.tar.gz
    [root@src ~]#cd php-5.6.10
    我们先配置下PHP的编译参数
    [root@php-5.6.10 ~]#./configure --prefix=/opt/php --with-mysql --with-mysqli --with-iconv-dir --with-zlib --with-libxml-dir --enable-xml --with-curl --enable-fpm --enable-mbstring --with-gd --with-openssl --with-mhash --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-libdir=/usr/lib64 --with-jpeg-dir=/usr/lib64 --with-freetype-dir=/usr/lib64 --with-png-dir=/usr/lib64
    [root@php-5.6.10 ~]#make
    [root@php-5.6.10 ~]#make install clean
    复制php.ini
    [root@php-5.6.10 ~]#cp php.ini-development /opt/php/lib/php.ini
    [root@php-5.6.10 ~]#cd /opt/php/etc/
    [root@php-5.6.10 ~]#cp php-fpm.conf.default php-fpm.conf        //在php-fpm.conf文件中可以定义php的服务端口、进程启动的用户和组权限(最好和nginx服务启动权限一直)等。
    使用PHP-FPM管理脚本,在编译包里面已经配置好了,只需要复制到/etc/init.d/中即可
    [root@php-5.6.10 ~]#cd /opt/src/php-5.6.10/sapi/fpm/
    [root@php-5.6.10 ~]#cp init.d.php-fpm /etc/init.d/php-fpm
    [root@php-5.6.10 ~]#chmod +x /etc/init.d/php-fpm
    启动php-fpm
    [root@php-5.6.10 ~]#service php-fpm start
    加入开机启动策略
    [root@php-5.6.10 ~]#chkconfig --add php-fpm
    [root@php-5.6.10 ~]#chkconfig php-fpm on

    4)安装MySQL (可参考:centos 6x系统下源码安装mysql操作记录
    MySQL5.7.x以上的版本不支持本安装新增了boost引擎,后续我会更新……
    先下载MySQL
    [root@opd ~]#cd /opt/src/
    [root@src ~]#wget http://cdn.mysql.com//archives/mysql-5.6/mysql-5.6.21.tar.gz
    [root@src ~]#tar -zxvf mysql-5.6.12.tar.gz
    [root@src ~]#cd mysql-5.6.12
    我们先配置下MySQL的编译参数 一般我们就配置下安装路径就可以了 如你有特殊配置也可以在安装之后修改参数也可以的
    [root@mysql-5.6.12 ~]#cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DCOMPILATION_COMMENT='production environment' -DWITH_READLINE=ON -DSYSCONFDIR=/opt/mysql -DMYSQL_UNIX_ADDR=/opt/mysql/mysql.sock -DMYSQL_DATADIR=/opt/data

    -------------------------------------------------------------------------------------------------------------------------------------
    注意:mysql5.5以上的编译就用cmake了,而不是使用./configure了。
    cmake编译的优化参数说明如下:
    -------------------------------------
    -DCMAKE_INSTALL_PREFIX=dir_name       安装的主目录
    -DDEFAULT_CHARSET          字符集,默认字符集是latin1
    -DDEFAULT_COLLATION=collation_name       服务校对,默认的是latin1_swedish_ci,可以通过SHOW COLLATION语句查看哪个校对匹配的字符集
    -DENABLED_LOCAL_INFILE       是否打开LOAD DATA INFILE的LOCAL参数
    -DWITH_INNOBASE_STORAGE_ENGINE=1       将INNODB存储引擎编译进去
    -DWITH_FEDERATED_STORAGE_ENGINE=1       将FEDERATED存储引擎编译进去
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1       将BLACKHOLE存储引擎编译进去
    -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1      不编译EXAMPLE存储引擎
    -DWITH_PARTITION_STORAGE_ENGINE=1          将分区存储引擎编译进去
    -DWITH_PERFSCHEMA_STORAGE_ENGINE=1       将Performance Schema(性能视图)存储引擎编译进去
    -DCOMPILATION_COMMENT=string       编译环境描述
    -DWITH_READLINE=bool       是否使用readline库
    -DSYSCONFDIR=dir_name my.cnf       参数文件的路径
    -DMYSQL_UNIX_ADDR=file_name Unix socket        文件的路径,socket文件用于服务器监听连接,这个参数必须是绝对路径
    -DENABLED_PROFILING=bool       是否开启profiling代码的查询(用于SHOW PROFILE and SHOW PROFILES语句)
    -DMYSQL_DATADIR=dir_name MySQL       文件目录的路径,这个参数也可以在启动MySQL的时候带上--datadir参数进行设置
    -DWITH_EXTRA_CHARSETS=name       指定额外的字符集,默认是all,包含所有的字符集。
    -DINSTALL_BINDIR=dir_name      安装用户程序的路径,默认路径是DCMAKE_INSTALL_PREFIX/bin
    -DINSTALL_DOCDIR=dir_name      安装文档的路径,默认路径是DCMAKE_INSTALL_PREFIX/doc
    -DINSTALL_INCLUDEDIR=dir_name      安装头文件的路径,默认路径是DCMAKE_INSTALL_PREFIX/include
    -DINSTALL_LIBDIR=dir_name       安装库文件的路径,默认路径是DCMAKE_INSTALL_PREFIX/lib
    -DINSTALL_MANDIR=dir_name      安装帮助手册的路径,默认路径是DCMAKE_INSTALL_PREFIX/man
    -DINSTALL_PLUGINDIR=dir_name      安装插件的路径,默认路径是DCMAKE_INSTALL_PREFIX/lib/plugin
    -DINSTALL_SBINDIR=dir_name      安装mysqld服务端启动脚本的路径,默认路径是DCMAKE_INSTALL_PREFIX/bin
    -DINSTALL_SCRIPTDIR=dir_name      初始化MySQL数据库的数据文件路径的mysql_install_db脚本路径,默认路径是DCMAKE_INSTALL_PREFIX/scripts
    -DINSTALL_SQLBENCHDIR=dir_name      安装sql-bench的路径,默认路径是DCMAKE_INSTALL_PREFIX
    -DINSTALL_SUPPORTFILESDIR=dir_name      安装支持文件的路径,默认路径是DCMAKE_INSTALL_PREFIX/support-files
    -DMYSQL_TCP_PORT=port_num     服务器监听TCP/IP连接的端口,默认是3306

    如若要编译进其它功能,如SSL等,则可使用类似如下选项来实现编译时使用某库或不使用某库:
    -DWITH_READLINE=1
    -DWITH_SSL=system
    -DWITH_ZLIB=system
    -DWITH_LIBWRAP=0
    -------------------------------------------------------------------------------------------------------------------------------------

    编译需要较长的时间
    [root@mysql-5.6.12 ~]#make
    [root@mysql-5.6.12 ~]#make install clean
    添加mysql用户,设置mysql目录权限
    [root@mysql-5.6.12 ~]# useradd mysql -M -s /sbin/nologin
    [root@mysql-5.6.12 ~]# chown -R mysql:mysql /opt/mysql
    [root@mysql-5.6.12 ~]# chown -R mysql:mysql /opt/data
    安装数据库
    [root@mysql-5.6.12 ~]# cd /opt/mysql/scripts
    [root@scripts ~]#./mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
    [root@scripts ~]#cd /opt/mysql/support-files
    复制mysql管理脚本
    [root@support-files ~]#cp mysql.server /etc/rc.d/init.d/mysql
    复制mysql配置文件
    [root@support-files ~]#cp my-default.cnf /etc/my.cnf
    添加mysql服务
    [root@support-files ~]#chkconfig --add mysql
    加入开机启动策略
    [root@support-files ~]#chkconfig mysql on
    [root@support-files ~]#service mysql start

    4)nginx+php配置

    server {
            listen       80;
            server_name  www.wangshibo.com;
    
            #charset koi8-r;
    
            access_log  /Data/logs/nginx/www.wangshibo.com/access.log main;
            error_log  /Data/logs/nginx/www.wangshibo.com/error.log;
    
            ## maintence
            if ($remote_addr !~ ^(100.110.15.16|100.110.15.17|100.110.15.18|127.0.0.1)) {             //nginx访问的白名单限制
              rewrite ^.*$ /maintence.php last;
            }
    
            location / {
                root   /var/www/vhosts/www.wangshibo.com/main;
            try_files $uri $uri/ @router;
                index  index.php;
            }
    
            location /nginx_status {
               stub_status on;
               access_log off;
            }
    
    
            #error_page  404              /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        
            location @router {
            rewrite ^.*$ /index.php last;
            }
    
            location ~ .php$ {
                root       /var/www/vhosts/www.wangshibo.com/main;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_read_timeout 30;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;               //这一行最好将/scripts换成$document_root,否则可能出现白面
                #include        fastcgi_params;
                include        fastcgi.conf;
            }
        
            location ~ ^/(status|ping)$
            {
               include fastcgi_params;
               fastcgi_pass 127.0.0.1:9000;
               fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
            }
    
            } 
  • 相关阅读:
    SpringMVC详解
    会话控制cookie和session
    jsp详解
    Jquery Enter事件
    JS获取request字符串
    net 2.0使用ajax
    C#通过WebClient/HttpWebRequest实现http的post/get方法
    WCF Rest:不使用UriTemplate使用post方式传参解决HTTP400问题以及参数映射问题
    关于ASP.NET 中站点地图sitemap 的使用
    Web.config自定义节点configSections
  • 原文地址:https://www.cnblogs.com/kevingrace/p/5761338.html
Copyright © 2011-2022 走看看