• CentOS6.6x86_64 部署 Nginx1.62+MySQL5.6.20+PHP5.6.4


    准备工作

    1. 切换到管理员身份

      su -
      
    2. 安装编译扩展

      yum install -y gcc-c++
      
    3. 创建数据库目录、代码目录

      mkdir /mnt/data /mnt/www
      

    安装Nginx 1.6.2

    1. 进入应用下载目录

      cd /usr/local/src
      
    2. 下载Nginx软件包及依赖包

      yum install -y openssl-devel pcre-devel zlib-devel
      wget http://nginx.org/download/nginx-1.6.2.tar.gz
      
    3. 添加用户及用户组

      useradd www
      
    4. 编译安装Nginx

      ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_flv_module --user=www --group=www --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
      
      make -j5 install
      
    5. 创建启动脚本

      vi /etc/init.d/nginx

      #!/bin/sh
      #
      # nginx        Startup script for nginx
      #
      # chkconfig: - 85 15
      # processname: nginx
      # config: /etc/nginx/nginx.conf
      # config: /etc/sysconfig/nginx
      # pidfile: /var/run/nginx.pid
      # description: nginx is an HTTP and reverse proxy server
      #
      ### BEGIN INIT INFO
      # Provides: nginx
      # Required-Start: $local_fs $remote_fs $network
      # Required-Stop: $local_fs $remote_fs $network
      # Default-Start: 2 3 4 5
      # Default-Stop: 0 1 6
      # Short-Description: start and stop nginx
      ### END INIT INFO
      
      # Source function library.
      . /etc/rc.d/init.d/functions
      
      if [ -L $0 ]; then
          initscript=`/bin/readlink -f $0`
      else
          initscript=$0
      fi
      
      sysconfig=`/bin/basename $initscript`
      
      if [ -f /etc/sysconfig/$sysconfig ]; then
          . /etc/sysconfig/$sysconfig
      fi
      
      nginx=${NGINX-/usr/sbin/nginx}
      prog=`/bin/basename $nginx`
      conffile=${CONFFILE-/etc/nginx/nginx.conf}
      lockfile=${LOCKFILE-/var/lock/subsys/nginx}
      pidfile=${PIDFILE-/var/run/nginx.pid}
      SLEEPMSEC=${SLEEPMSEC-200000}
      UPGRADEWAITLOOPS=${UPGRADEWAITLOOPS-5}
      RETVAL=0
      
      start() {
          echo -n $"Starting $prog: "
      
          daemon --pidfile=${pidfile} ${nginx} -c ${conffile}
          RETVAL=$?
          echo
          [ $RETVAL = 0 ] && touch ${lockfile}
          return $RETVAL
      }
      
      stop() {
          echo -n $"Stopping $prog: "
          killproc -p ${pidfile} ${prog}
          RETVAL=$?
          echo
          [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
      }
      
      reload() {
          echo -n $"Reloading $prog: "
          killproc -p ${pidfile} ${prog} -HUP
          RETVAL=$?
          echo
      }
      
      upgrade() {
          oldbinpidfile=${pidfile}.oldbin
      
          configtest -q || return
          echo -n $"Starting new master $prog: "
          killproc -p ${pidfile} ${prog} -USR2
          echo
      
          for i in `/usr/bin/seq $UPGRADEWAITLOOPS`; do
              /bin/usleep $SLEEPMSEC
              if [ -f ${oldbinpidfile} -a -f ${pidfile} ]; then
                  echo -n $"Graceful shutdown of old $prog: "
                  killproc -p ${oldbinpidfile} ${prog} -QUIT
                  RETVAL=$?
                  echo
                  return
              fi
          done
      
          echo $"Upgrade failed!"
          RETVAL=1
      }
      
      configtest() {
          if [ "$#" -ne 0 ] ; then
              case "$1" in
                  -q)
                      FLAG=$1
                      ;;
                  *)
                      ;;
              esac
              shift
          fi
          ${nginx} -t -c ${conffile} $FLAG
          RETVAL=$?
          return $RETVAL
      }
      
      rh_status() {
          status -p ${pidfile} ${nginx}
      }
      
      # See how we were called.
      case "$1" in
          start)
              rh_status >/dev/null 2>&1 && exit 0
              start
              ;;
          stop)
              stop
              ;;
          status)
              rh_status
              RETVAL=$?
              ;;
          restart)
              configtest -q || exit $RETVAL
              stop
              start
              ;;
          upgrade)
              rh_status >/dev/null 2>&1 || exit 0
              upgrade
              ;;
          condrestart|try-restart)
              if rh_status >/dev/null 2>&1; then
                  stop
                  start
              fi
              ;;
          force-reload|reload)
              reload
              ;;
          configtest)
              configtest
              ;;
          *)
              echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}"
              RETVAL=2
      esac
      
      exit $RETVAL
      

      chmod +x /etc/init.d/nginx

    6. 编辑配置

      vi /etc/nginx/nginx.conf
      
      • 修改访问用户

        # line:2
        user www;
        
      • 修改网站目录并开启PHP支持

        # line:43-46
            location / {
                root   /mnt/www;
                index  index.html index.htm index.php;
            }
        # line:65-71
            location ~ .php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /mnt/www$fastcgi_script_name;
                include        fastcgi_params;
            }
        
    7. 启动Nginx

      service nginx start
      

    安装MySQL 5.6.20

    1. 准备工作

      • 查找、删除系统中的MySQL

        rpm -qa | grep mysql
        # > mysql-libs-5.1.73-3.el6_5.x86_64
        rpm -e mysql-libs-5.1.73-3.el6_5.x86_64 --nodeps
        
      • 安装编译工具

        yum install -y cmake
        
      • 下载MySQL源码包

        wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.21.tar.gz
        
    2. 编译安装MySQL

      tar zxf mysql-5.6.21.tar.gz
      cd mysql-5.6.21
      
      cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mnt/data/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
      
      make -j5 install
      
    3. 创建MySQL用户

      groupadd -g 27 -r mysql
      useradd -r -u 27 -g mysql -s /sbin/nologin -d /root -c "MySQL" mysql
      
    4. 修改目录权限

      chown -R mysql.mysql /usr/local/mysql
      
    5. 初始化安装数据库

      /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/mnt/data/mysql --user=mysql
      
    6. 查看MySQL启动顺序、放置MySQL配置文件

      mysql --verbose --help | grep -A 1 'Default options'
      mv /usr/local/mysql/my.cnf /etc
      
    7. 启动MySQL(报错注意关闭seLinux)

      ln -s /usr/local/mysql/bin/mysql /bin/mysql
      cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
      chkconfig --add mysql
      chkconfig mysql on
      service mysql start
      
    8. 修改密码

      • 推荐方式:

        /usr/local/mysql/bin/mysql_secure_installation
        
      • 备用方式:

        mysql -u root -ph8znVjtSES17d_pg
        
        SET PASSWORD=password('admin888');
        GRANT all privileges on *.* TO 'root'@'%' identified by 'admin888' WITH GRANT OPTION;
        FLUSH PRIVILEGES;
        q
        
    9. 重新编译时,需要清除旧的对象文件和缓存信息。

      # make clean
      # rm -f CMakeCache.txt
      # rm -rf /etc/my.cnf
      

    安装PHP 5.6.4

    1. 安装编译使用的扩展

      yum install -y gcc gcc-c++
      
    2. 安装依赖库

      1. 安装libmcrypt

        下载页面:http://sourceforge.net/projects/mcrypt/files/Libmcrypt/

        cd /usr/local/src
        tar zxf /usr/local/src/libmcrypt-2.5.8.tar.gz
        cd /usr/local/src/libmcrypt-2.5.8/
        ./configure; make -j5 install
        
      2. 安装mhash

        下载页面:http://sourceforge.net/projects/mhash/files/mhash/

        cd /usr/loacl/src
        tar zxvf /usr/local/src/mhash-0.9.9.9.tar.gz
        cd /usr/local/src/mhash-0.9.9.9/
        ./configure; make -j5 install
        
      3. 配置运行库

        vi /etc/ld.so.conf
        
        line:2 加入
        /usr/local/lib
        
        ldconfig
        

        如果报错执行:export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

      4. 安装mcrypt

        下载页面:http://sourceforge.net/projects/mcrypt/files/MCrypt/

        tar zxf /usr/local/src/mcrypt-2.6.8.tar.gz
        cd /usr/local/src/mcrypt-2.6.8
        ./configure; make -j5 install
        
    3. 安装PHP扩展

      yum install -y libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel gd gd-devel glib2 glib2-devel ncurses ncurses-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel libcurl libcurl-devel
      
    4. 安装PHP

      1. 下载并解压

        下载页面:http://cn2.php.net/downloads.php

        tar jxf /usr/local/src/php-5.6.4.tar.bz2
        cd /usr/local/src/php-5.6.4
        
      2. 编译

        ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql --with-mysqli --with-pdo-mysql --with-curl --with-mcrypt --with-mhash --with-gd --with-openssl --with-xmlrpc --with-zlib --with-libxml-dir --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --enable-inline-optimization --enable-bcmath --enable-mbstring --enable-mbregex --enable-sockets --enable-zip --enable-debug --enable-maintainer-zts --enable-sysvsem --enable-shmop --enable-xml --enable-sysvsem --enable-sysvshm --enable-gd-native-ttf --enable-pcntl --enable-soap --enable-opcache --disable-rpath
        
      3. 安装,注意&&

        make -j5 && make install
        
    5. 移动配置文件

      cp /usr/local/src/php-5.6.4/php.ini-production /usr/local/php/etc/php.ini
      cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
      
    6. 添加php-fpm到service

      1. 开启php-fpm.pid

        vi /usr/local/php/etc/php-fpm.conf
        
        line:25 开启pid,改为
        pid = /var/run/php-fpm.pid
        
      2. 新建服务脚本

        vi /etc/init.d/php-fpm
        -----------------------
        
        #!/bin/bash
        #
        # Startup script for the PHP-FPM server.
        #
        # chkconfig: 345 85 15
        # description: PHP is an HTML-embedded scripting language
        # processname: php-fpm
        # config: /usr/local/php/etc/php.ini
        
        # Source function library.
        . /etc/rc.d/init.d/functions
        
        PHP_PATH=/usr/local/php
        DESC="php-fpm daemon"
        NAME=php-fpm
        # php-fpm路径
        DAEMON=$PHP_PATH/sbin/$NAME
        # 配置文件路径
        CONFIGFILE=$PHP_PATH/etc/php-fpm.conf
        # PID文件路径(在php-fpm.conf设置)
        PIDFILE=/var/run/$NAME.pid
        SCRIPTNAME=/etc/init.d/$NAME
        
        # Gracefully exit if the package has been removed.
        test -x $DAEMON || exit 0
        
        rh_start() {
            $DAEMON -y $CONFIGFILE || echo -n " already running"
        }
        
        rh_stop() {
            kill -QUIT `cat $PIDFILE` || echo -n " not running"
        }
        
        rh_reload() {
            kill -USR2 `cat $PIDFILE` || echo -n " can't reload"
        }
        
        case "$1" in
            start)
                echo -n "Starting $DESC: $NAME"
                rh_start
                echo "."
                ;;
            stop)
                echo -n "Stopping $DESC: $NAME"
                rh_stop
                echo "."
                ;;
            reload)
                echo -n "Reloading $DESC configuration..."
                rh_reload
                echo "reloaded."
                ;;
            restart)
                echo -n "Restarting $DESC: $NAME"
                rh_stop
                sleep 1
                rh_start
                echo "."
                ;;
            *)
                 echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
                 exit 3
                ;;
        esac
        exit 0
        
    7. 添加执行权限

      chmod +x /etc/init.d/php-fpm
      
    8. 启动php-fmp

      service php-fpm start
      

    添加自启动

    chkconfig --add php-fpm
    chkconfig php-fpm on
    chkconfig nginx on
    chkconfig mysql on
  • 相关阅读:
    【SpringBoot】02 概述
    【SpringBoot】01 快速上手
    【SpringMVC】12 文件上传和下载
    【SpringMVC】10 对Ajax的应用
    【SpringMVC】11 拦截器
    【SpringMVC】09 对JSON的应用
    【SpringMVC】08 Post请求乱码
    【SpringMVC】06 转发 & 重定向
    【Mybatis】Bonus02 补充
    【SpringMVC】05 RestFul风格
  • 原文地址:https://www.cnblogs.com/kpengfang/p/5050254.html
Copyright © 2020-2023  润新知