zoukankan      html  css  js  c++  java
  • 阿里云lnmp手动搭建Centos6.X

    阿里云lnmp手动搭建Centos6.X

    1.查看当前系统版本。

    #cat /etc/redhat-release

    2.关闭SElinux 查看启动状态: #getenforce (1.enforcing 为开启状态 (2.Disadnled 为关闭状态 临时关闭SELinux: setenforce 0 永久关闭SElinux: vim /etc/selinux/config 光标锁定在SELINUX=enforcing 这一行,编辑修改 SELinux=disabled 保存修改;

    3.安装NGINX或者tengine(tengine拥有特殊的安装module选项) (1)添加NGINX运行用户: groupadd -r nginx useradd -r -g nginx nginx (2)下载源码包进行编译安装

    wget http://nginx.org/download/nginx-1.10.2.tar.gz
    tar xvf nginx-1.10.2.tar.gz -C /usr/local/src
    yum groupinstall "Development tools"
    yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
    cd /usr/local/src/nginx-1.10.2
    ./configure
    --prefix=/usr/local/nginx
    --sbin-path=/usr/sbin/nginx
    --conf-path=/etc/nginx/nginx.conf
    --error-log-path=/var/log/nginx/error.log
    --http-log-path=/var/log/nginx/access.log
    --pid-path=/var/run/nginx.pid
    --lock-path=/var/run/nginx.lock
    --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
    --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi
    --http-scgi-temp-path=/var/tmp/nginx/scgi
    --user=nginx
    --group=nginx
    --with-pcre
    --with-http_v2_module
    --with-http_ssl_module
    --with-http_realip_module
    --with-http_addition_module
    --with-http_sub_module
    --with-http_dav_module
    --with-http_flv_module
    --with-http_mp4_module
    --with-http_gunzip_module
    --with-http_gzip_static_module
    --with-http_random_index_module
    --with-http_secure_link_module
    --with-http_stub_status_module
    --with-http_auth_request_module
    --with-mail
    --with-mail_ssl_module
    --with-file-aio
    --with-ipv6
    --with-http_v2_module
    --with-threads
    --with-stream
    --with-stream_ssl_module
    make && make install
    mkdir -p /var/tmp/nginx/client

    (3).添加sysV启动脚本 vim新建文件,或者touch一个new file: vim /etc/init.d/nginx 键入如下内容:

    (3).添加sysV启动脚本 vim新建文件,或者touch一个new file: vim /etc/init.d/nginx 键入如下内容:

    #!/bin/sh 
    #

    # nginx - this script starts and stops the nginx daemon

    #

    # chkconfig:   - 85 15

    # description: Nginx is an HTTP(S) server, HTTP(S) reverse

    # proxy and IMAP/POP3 proxy server

    # processname: nginx

    # config:     /etc/nginx/nginx.conf

    # config:     /etc/sysconfig/nginx

    # pidfile:     /var/run/nginx.pid

    # Source function library.

    . /etc/rc.d/init.d/functions

    # Source networking configuration.

    . /etc/sysconfig/network

    # Check that networking is up.

    [ "$NETWORKING" = "no" ] && exit 0
    nginx="/usr/sbin/nginx"
    prog=$(basename $nginx)
    NGINX_CONF_FILE="/etc/nginx/nginx.conf"
    [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
    lockfile=/var/lock/subsys/nginx
    start() {
      [ -x $nginx ] || exit 5
      [ -f $NGINX_CONF_FILE ] || exit 6
       echo -n $"Starting $prog: "
      daemon $nginx -c $NGINX_CONF_FILE
       retval=$?
       echo
      [ $retval -eq 0 ] && touch $lockfile
      return $retval
    }
    stop() {
       echo -n $"Stopping $prog: "
      killproc $prog -QUIT
       retval=$?
       echo
      [ $retval -eq 0 ] && rm -f $lockfile
      return $retval
    killall -9 nginx
    }
    restart() {
      configtest || return $?
       stop
       sleep 1
       start
    }
    reload() {
      configtest || return $?
       echo -n $"Reloading $prog: "
      killproc $nginx -HUP
    RETVAL=$?
       echo
    }
    force_reload() {
       restart
    }
    configtest() {
    $nginx -t -c $NGINX_CONF_FILE
    }
    rh_status() {
      status $prog
    }
    rh_status_q() {
      rh_status >/dev/null 2>&1
    }
    case "$1" in
       start)
          rh_status_q && exit 0
       $1
          ;;
       stop)
          rh_status_q || exit 0
           $1
          ;;
       restart|configtest)
           $1
          ;;
      reload)
          rh_status_q || exit 7
           $1
          ;;
      force-reload)
          force_reload
          ;;
      status)
          rh_status
          ;;
      condrestart|try-restart)
          rh_status_q || exit 0
              ;;
      *)
         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
           exit 2
    esac

    保存退出。 添加可执行权限: chmod +x /etc/init.d/nginx 添加到服务: chkconfig --add nginx chkconfig --level nginx 345 on chkconfig --list 启动服务: service nginx start 浏览器检查————end。

    4.安装mysql (1)准备编译环境: yum groupinstall "Server Platform Development" "Development tools" -y yum install cmake -y (2)准备mysql的数据存放目录,用户以及组 mkdir /mnt/data groupadd -r mysql useradd -r -g mysql -s /sbin/nologin mysql id mysql chown -R mysql:mysql /mnt/data (3)下载稳定版的源码包进行编译安装:

    wget https://downloads.mysql.com/archives/get/file/mysql-5.6.24.tar.gz
    tar xvf mysql-5.6.24.tar.gz -C /usr/local/src
    cd /usr/local/src/mysql-5.6.24
    cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
    -DMYSQL_DATADIR=/mnt/data
    -DSYSCONFDIR=/etc
    -DWITH_INNOBASE_STORAGE_ENGINE=1
    -DWITH_ARCHIVE_STORAGE_ENGINE=1
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1
    -DWITH_READLINE=1
    -DWITH_SSL=system
    -DWITH_ZLIB=system
    -DWITH_LIBWRAP=0
    -DMYSQL_TCP_PORT=3306
    -DMYSQL_UNIX_ADDR=/tmp/mysql.sock
    -DDEFAULT_CHARSET=utf8
    -DDEFAULT_COLLATION=utf8_general_ci
    make && make install

    (4)修改安装目录的属组为mysql chown -R mysql:mysql /usr/local/mysql/ (5)初始化数据库: cd /usr/local/mysql /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/mnt/data/ (6)创建配置文件以及启动脚本: cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf (7)设置开机自启动 chkconfig --add mysqld chkconfig --level 345 mysqld on (8)修改配置文件: echo -e "basedir = /usr/local/mysql datadir= /mnt/data " >> /etc/my.cnf (9)设置path环境变量: echo "export PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh source /etc/pidfile.d/mysql.sh (10)启动服务: service mysqld start mysql -h127.0.0.1

    (4)修改安装目录的属组为mysql chown -R mysql:mysql /usr/local/mysql/ (5)初始化数据库: cd /usr/local/mysql /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/mnt/data/ (6)创建配置文件以及启动脚本: cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf (7)设置开机自启动 chkconfig --add mysqld chkconfig --level 345 mysqld on (8)修改配置文件: echo -e "basedir = /usr/local/mysql datadir= /mnt/data " >> /etc/my.cnf (9)设置path环境变量: echo "export PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh source /etc/pidfile.d/mysql.sh (10)启动服务: service mysqld start mysql -h127.0.0.1

    4.安装PHP-FPM Nginx作为web服务器,当它接收到请求后,不支持对外部程序的直接调用或者解析,必须通过FastCGI进行调用。 如果是PHP请求,则交给PHP解释器处理,并把结果返回给客户端。PHP-FPM是支持解析PHP的一个FastCGI进程管理器。 提供了更好管理PHP进程的方式,可以有效控制内存和进程、可以平滑重载PHP配置。 (1)安装依赖包: yum install libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel (2)下载稳定版源码包进行编译安装:

    wget http://cn2.php.net/get/php-5.6.23.tar.bz2/from/this/mirror
    cp mirror php-5.6.23.tar.bz2
    tar xvf php-5.6.23.tar.bz2 -C /usr/local/src
    cd /usr/local/src/php-5.6.23
    ./configure --prefix=/usr/local/php
    --with-config-file-scan-dir=/etc/php.d
    --with-config-file-path=/etc
    --with-mysql=/usr/local/mysql
    --with-mysqli=/usr/local/mysql/bin/mysql_config
    --enable-mbstring
    --with-freetype-dir
    --with-jpeg-dir
    --with-png-dir
    --with-zlib
    --with-libxml-dir=/usr
    --with-openssl
    --enable-xml
    --enable-sockets
    --enable-fpm
    --with-mcrypt
    --with-bz2
    make && make install

    (3)添加PHP和PHP—FPM配置文件: cp /usr/local/src/php-5.6.23/php.ini-production /etc/php.ini cd /usr/local/php/etc/ cp php-fpm.conf.default php-fpm.conf sed -i 's@;pid = run/php-fpm.pid@pid = /usr/local/php/var/run/php-fpm.pid@' php-fpm.conf (4)添加PHP-FPM启动脚本: cp /usr/local/src/php-5.6.23/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm (5)添加PHP-FPM到服务列表并设置自启: chkconfig --add php-fpm chkconfig --list php-fpm chkconfig php-fpm on (6)启动服务: service PHP-FPM start (7)添加NGINX 对FastCGI的支持: 一、备份默认的NGINX配置文件: cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf 二、输入命令vi /etc/nginx/nginx.conf打开Nginx的配置文件,按下i键,在所支持的主页面格式中添加php格式的主页,类似如下: location / { root /usr/local/nginx/html; index index.php index.html index.htm; } 三、取消下面内容的注释: location ~ .php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; } 四、将将root html;改成root /usr/local/nginx/html; 五、将fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;改成fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name; 之后保存退出。 六、添加PHP测试文件: 输入命令vi /usr/local/nginx/html/index.php打开index.php文件,按下i键,然后写入如下内容:

    (3)添加PHP和PHP—FPM配置文件: cp /usr/local/src/php-5.6.23/php.ini-production /etc/php.ini cd /usr/local/php/etc/ cp php-fpm.conf.default php-fpm.conf sed -i 's@;pid = run/php-fpm.pid@pid = /usr/local/php/var/run/php-fpm.pid@' php-fpm.conf (4)添加PHP-FPM启动脚本: cp /usr/local/src/php-5.6.23/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm (5)添加PHP-FPM到服务列表并设置自启: chkconfig --add php-fpm chkconfig --list php-fpm chkconfig php-fpm on (6)启动服务: service PHP-FPM start (7)添加NGINX 对FastCGI的支持: 一、备份默认的NGINX配置文件: cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf 二、输入命令vi /etc/nginx/nginx.conf打开Nginx的配置文件,按下i键,在所支持的主页面格式中添加php格式的主页,类似如下: location / { root /usr/local/nginx/html; index index.php index.html index.htm; } 三、取消下面内容的注释: location ~ .php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; } 四、将将root html;改成root /usr/local/nginx/html; 五、将fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;改成fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name; 之后保存退出。 六、添加PHP测试文件: 输入命令vi /usr/local/nginx/html/index.php打开index.php文件,按下i键,然后写入如下内容:

    <?php
    $conn=mysql_connect('127.0.0.1','root','');
    if ($conn){
    echo "LNMP platform connect to mysql is successful!";
    }else{
    echo "LNMP platform connect to mysql is failed!";
    }
    phpinfo();
    ?>

    保存,在浏览器中测试————end。

    保存,在浏览器中测试————end。

  • 相关阅读:
    JSK42586.Tree(动态开点线段树+树上启发式合并)
    CF1188B.Count Pairsl(数学)
    2021ICPC亚洲区域赛(昆明)复盘
    1009F.Dominant Indices (树上启发式合并)
    246E.Bloods Counsin Return(离线+树上启发式合并)
    208E.Blood Cousins(离线+倍增LCA+树上启发式合并)
    208E.Blood Cousins (离线+树上启发式合并)
    570D.Tree Requests (离线+树上启发式合并)
    Java从入门到实战之(6)SSM框架使用
    Java从入门到实战之(5)Java集合对比汇总
  • 原文地址:https://www.cnblogs.com/observe/p/11455232.html
Copyright © 2011-2022 走看看