lnmp框架搭建操作

lnmp = linux + nginx + mysql + php/python


#########

nginx
#########

==============
nginx解压与安装:
==============
     tar zxf nginx-1.12.0.tar.gz
     cd nginx-1.12.0
     cd src/core/
     vim nginx.h
       ##修改标示符
       ------------------------
       14 #define NGINX_VER          "nginx"
       ------------------------

     cd ../..
     cd auto/cc
     vim gcc
       ##关掉debug 加快编译进度
       ---------------
       171 # debug
       172 #CFLAGS="$CFLAGS -g"
       ---------------

     cd -
     ./configure --help
     ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio
    ##报错: 没有安装gcc
        -------------------------
        ./configure: error: C compiler cc is not found
        ----------------------------

    yum install gcc -y
    ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio
      ##报错:安装pcre-devel
      ------------------------------
       ./configure: error: the HTTP rewrite module requires the PCRE library.
      -----------------------------

    yum install -y pcre-devel
    ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio
      ##报错:安装openssl
     ----------------------------
     ./configure: error: SSL modules require the OpenSSL library.
     -----------------------------

    yum install -y openssl-devel
    ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio
    make
    make install
    cd /usr/local/lnmp
    cd nginx/sbin
    cd conf/
    ln -s /usr/local/lnmp/nginx/sbin/nginx  /usr/local/sbin/  ##建立启动命令
    which nginx
    nginx -t  ##检测nginx配置有没有问题
    nginx
    netstat -antuple | grep :80
    curl -I localhost  
    cd ..
    cd html/
    vim test.html   ##编写测试文件
      ------------
       <h1>
         hello
       </h1>
      ------------
   
测试:
   在浏览器中输入 本机ip/test.html  就能看到刚才测试文件中的内容了  nginx服务器搭建成功




=======================
开启https与CA认证 虚拟主机
=======================
    cd /usr/local/lnmp/nginx/
    cd conf/
    ls
    vim nginx.conf
    lscpu
    vim nginx.conf
    vim /etc/security/limits.conf
      ----------------------------
      53 nginx           -           nproc       4096
      54 nginx           -           nofile      4096
      -----------------------------

    useradd -u 800 nginx
    id nginx
    ps -aux | grep nginx
    cd /usr/local/lnmp/nginx/
    cd conf/
    vim nginx.conf
    nginx
    nginx -s reload
    ps -aux
    cd /
    mkdir /web1
    cd web1/
    vim index.html
    cd /usr/local/lnmp/nginx/conf/
    vim nginx.conf
    nginx -s reload


    pwd
    cd /etc/pki
    cd tls/
    cd certs
    make cert.pem
    mv cert.pem /usr/local/lnmp/nginx/conf/
    cd /usr/local/lnmp/nginx/conf/
    nginx -t
    nginx -s reload

  vim nginx.conf
  --------------------------------
    2 user  nginx nginx;
    3 worker_processes  2;                                                        
    4 worker_cpu_affinity 01 10;

   14     worker_connections  4096;

   ##把https部分打开(把#去掉)
  104         ssl_certificate_key  cert.pem;

   ##下面是自己添加的(虚拟主机)
  117 server{
  118         listen 80;
  119         server_name www.test.org;
  120
  121         location /{
  122                 root /web1;
  123                 index index.html;
  124         }
  125 }
  -----------------------------------



=========
负载均衡
=========


    vim nginx.conf
    yum install httpd -y
    vim /etc/httpd/conf/httpd.conf
    -----------
    ##更改apache的监听接口由80改为8080
    ##更改ServerName 为本机ip
        -----------

    vim /etc/hosts
    /etc/init.d/httpd start
    nginx -t
    nginx -s reload

    vim nginx.conf
  --------------------------------
   18 http {
   19         upstream test{
            ##ip为2  3 的主机轮询 ip为1的主机备用,当2 3 全部宕机之后才会启用3
   20             server 172.25.12.2:80;
   21             server 172.25.12.3:80;
   22             server 172.25.12.1:8080 backup;
   23         }


  125 server{
  126         listen 80;
  127         server_name www.linux.org;
  128         rewrite ^(.*) https://$server_name$1 permanent;
  129         
  130 }


  132 server{
  133         listen 80;
  134         server_name www.test.org;
  135         
  136         location /{
  137                 proxy_pass http://test;
  138         }
  139 }
  140 }
  ------------------------------------


################
mysql源码编译安装
################

    tar zxf mysql-boost-5.7.17.tar.gz
    cd mysql-5.7.17/
    ls
    cd  ..
    ls
    yum install  cmake-2.8.12.2-4.el6.x86_64.rpm -y      
    
   ##mysql源码编译会非常慢,我的用了有一个半小时
   ##每次编译完如果有报错,就看报错,缺什么装什么,装完之后把CMakeCache.txt 删掉,这是缓存文件,会缓存上次编译的结果,重新编译,直到没有报错
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all
    yum install gcc-c++ -y
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0/
    rm -fr CMakeCache.txt
    yum install -y ncurses-devel
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0/
    make
    make install
    rpm -qa |grep mysql
    l
    ls
    cd /etc
    cp my.cnf my.cnf.bak
    cd /usr/local/lnmp/mysql/
    ls
    cd support-files/
    ls
    vim my-default.cnf
    cp my-default.cnf  /etc/my.cnf
    cat /etc/my.cnf.bak
    cp mysql.server  /etc/init.d/mysqld
    cd ..
    ll
    id mysql
    useradd -u 27  -s /sbin/nologin mysql
    id mysql
    groupmod -g 27 mysql
    id mysql
    pwd
    chown mysql.mysql -R .
    ll
    cd bin/
    ls
    pwd
    vim ~/.bash_profile
    source ~/.bash_profile
    echo $PATH
    mysqld --initialize  ##这一步会生成data目录 以及密码(密码在最后,初次登陆需要这个密码)
    mysql
    cd data
    ls
    cd ..
    /etc/init.d/mysqld start
    cd data
    ll
    chown mysql.mysql * -R
    ll
    /etc/init.d/mysqld start
    cd /var/lib/mysql
    cd ..
    ll
    chown mysql.mysql -R .
    ll
    /etc/init.d/mysqld start
    mysql
    mysql -p      ##登陆密码是执行mysqld --initialize 时生成的密码
    mysql_secure_installation  -p     ##安全配置向导
    mysql -p



DQL  

##############
php源码编译安装
##############

     tar jxf php-5.6.20.tar.bz2
     cd php-5.6.20
     ls
     
     ##php源码编译时不会生成缓存文件,其他与mysql安装时一样,看报错
     ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
     yum install -y libxml2-devel
     ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
     yum install -y libcurl-devel
     ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
     cd ~
     yum install gd-devel-2.0.35-11.el6.x86_64.rpm
     yum install re2c-0.13.5-1.el6.x86_64.rpm
     ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
     cd -
     ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
     yum install gmp-devel -y
     ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
     cd ~
     yum install libmcrypt-devel-2.5.8-9.el6.x86_64.rpm -y
     yum install libmcrypt-2.5.8-9.el6.x86_64.rpm -y
     ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
     cd -
     ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
     yum install net-snmp-devel -y
     ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
     make
     make install
     cd /usr/local/lnmp/php/
     cd etc/
     cp php-fpm.conf.default php-fpm.conf
     cd ~/php-5.6.20
     cp php.ini-production /usr/local/lnmp/php/etc/php.ini
     cd /usr/local/lnmp/php/etc/
     ls
     ll /usr/local/lnmp/mysql/data/mysql.sock
     vim php.ini
     ------------------------------
      1001 pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock
      1150 mysql.default_socket =/usr/local/lnmp/mysql/data/mysql.sock
      1209 mysqli.default_socket =/usr/local/lnmp/mysql/data/mysql.sock
     ------------------------------

     pwd
     vim php-fpm.conf
      ------------------
       25 pid = run/php-fpm.pid
      ------------------

     cd ~/php-5.6.20
     cd sapi/
     ls
     cd fpm/
     ls
     cp init.d.php-fpm /etc/init.d/php-fpm
     chmod +x /etc/init.d/php-fpm
     /etc/init.d/php-fpm start
     vim /usr/local/lnmp/nginx/conf/nginx.conf
     nginx -s reload
       cd /usr/local/nginx/html/
       vim index.php
        -----------------
         hello php
        -----------------


 /usr/local/lnmp/nginx/conf/nginx.conf
---------------------------------------------------------------
 50         location / {
 51             root   html;
 52             index  index.php index.html index.htm;                                       
 53         }

 72         location ~ \.php$ {
 73             root           html;
 74             fastcgi_pass   127.0.0.1:9000;
 75             fastcgi_index  index.php;
 76             #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 77             include        fastcgi.conf;
 78         }
-------------------------------------------------------------

*****
检测:*
*****
   打开浏览器,输入本机ip弹出的界面是你自己写的index.php文件,就代表搭建成功

############
bbs论坛的安装
############
    1  cd ~
    2  ls
    3  tar zxf Discuz_X3.2_SC_UTF8.zip
    4  yum install unzip
    5  unzip Discuz_X3.2_SC_UTF8.zip
    6  cd Discuz_X3.2_SC_UTF8.zip
    7  ls
    8  cd readme/
    9  ls
   10  cd ..
   11  mv upload/ /usr/local/lnmp/nginx/html/bbs
   12  cd /usr/local/lnmp/nginx/html/bbs
   13  ls
   14  chmod 777 -R config/ data uc_client/ uc_server/
   15  cd ..
   16  cd mysql/data
   17  cd ..
   18  ll
   19  chmod 755 data
   20  ll
   21  cd ../nginx/html/bbs/in
   22  cd ../nginx/html/bbs/
   23  cd install/
   24  ls
   25  rm -fr index.php




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值