• 08linux基础服务-LNMP


    1、LNMP软件所需要的软件包介绍

    MySQL  mysql主程序包

    PHP  php主程序包

    nginx  nginx主程序包

    libmcrypt  libmcrypt加密算法扩展库,支持3DES等加密

    pcre  php的依赖包

    本次实验中使用的各个软件的版本:

    libmcrypt-2.5.8

    mysql-5.6.26

    nginx-1.8.0

    pcre-8.37

    php-5.6.13

    2、安装相关基础的工具包

    [root@localhost src]# yum install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* pcre-devel  -y

    3、安装pcre

    [root@localhost src]# tar -xvf pcre-8.37.tar.bz2 -C /usr/local/

    注意:pcre此处解压此安装包即可,不需要安装,nginx需要注定pcre的源码不是安装后的路径,此包的功能是支持地址重写rewrite功能,pcre的依赖可以yum安装pcre和pcre-devel解决

    4、安装nginx

    [root@localhost src]# tar -zxvf nginx-1.8.0.tar.gz

    [root@localhost src]# cd nginx-1.8.0

    [root@localhost nginx-1.8.0]# ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/pcre-8.37/

    编译参数解释:

    --with-http_dav_module  #启用支持(增加PUT,DELETE,MKCOL创建集合,copy和move方法,默认关系,需要编译开启)

    --with-http_stub_status_module  #启用支持(获取nginx上次启动以来的工作状态)

    --with-http_addition_module  #启动支持(作为一个输出过滤器,支持不完全缓冲,分部分相应请求)

    --with-http_sub_module  #启动支持(允许一些其他文本替换nginx相应中的一些文本)

    --with-http_flv_module  #启用支持(提供支持flv视频文件支持)

    --with-http_mp4_module  #启用支持(提供支持MP4视频文件支持,提供伪媒体服务端支持)

    --with-pcre=/usr/local/pcre-8.37/  #需要注意,这是指的是源码

    [root@localhost nginx-1.8.0]# make && make install

    [root@localhost nginx-1.8.0]# useradd -M -u 8001 -s /sbin/nologin nginx  #创建一个用于运行nginx的用户

    [root@localhost nginx]# ll /usr/local/nginx/  #查看nginx的目录结构
    总用量 4  
    drwxr-xr-x. 2 root root 4096 8月 8 14:25 conf  #nginx相关配置文件
    drwxr-xr-x. 2 root root 40 8月 8 14:25 html  #网站根目录
    drwxr-xr-x. 2 root root 6 8月 8 14:25 logs  #日志文件
    drwxr-xr-x. 2 root root 19 8月 8 14:25 sbin  #nginx启动脚本

    配置nginx支持php文件

    [root@localhost nginx]# vim /usr/local/nginx/conf/nginx.conf

    #user  nobody;                 

    user nginx nginx;                   #添加此行

    ……

    并在所支持的主页面格式中添加php格式的主页,类似如下:

    location / {

                root   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;

            #}                     

     #找到上面这段内容,将这段内容复制,去掉#且修改为如下

    location ~ .php{

        root           html;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;      #将scripts修改为nginx的html,即Nginx页面目录,因为要处理的php文件也在这个目录下

        include        fastcgi_params;

    }

     

    启动ngixn服务

    [root@localhost nginx]# /usr/local/nginx/sbin/nginx
    [root@localhost nginx]# netstat -tlnp | grep nginx
    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 29087/nginx: master

    nginx维护命令

     [root@test ~]# /usr/local/nginx/sbin/nginx -t                  //检查配置文件语法是否有错误

    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

     [root@test ~]# /usr/local/nginx/sbin/nginx -s reload            //重新加载配置文而建(平滑重启)

    [root@test ~]# /usr/local/nginx/sbin/nginx -s stop        //停止Nginx,注意:启动没有任何参数

    [root@test ~]# echo "/usr/local/nginx/sbin/nginx &" >> /etc/rc.local          //开机启动

    平滑重启(保持了C-S链接,不断开,服务器只是重新加载了配置文件,没有开启和关闭的服务器的一个动作)

    5、安装MySQL

    解决依赖

    [root@localhost nginx]# yum -y install cmake ncurses-devel

    [root@localhost src]# tar -zxvf mysql-5.6.26.tar.gz

    [root@localhost src]# cd mysql-5.6.26

    [root@localhost mysql-5.6.26]# useradd -M -s /sbin/nologin mysql

    [root@localhost mysql-5.6.26]#cmake 

     -DCMAKE_INSTALL_PREFIX=/usr/local/mysql 

     -DMYSQL_UNIX_ADDR=/tmp/mysql.sock 

     -DDEFAULT_CHARSET=utf8 

     -DDEFAULT_COLLATION=utf8_general_ci 

     -DWITH_EXTRA_CHARSETS=all 

     -DWITH_MYISAM_STORAGE_ENGINE=1

     -DWITH_INNOBASE_STORAGE_ENGINE=1

     -DWITH_MEMORY_STORAGE_ENGINE=1

     -DWITH_READLINE=1

     -DENABLED_LOCAL_INFILE=1

     -DMYSQL_DATADIR=/usr/local/mysql/data 

     -DMYSQL-USER=mysql

    *******************************************编译参数解释**********************************************************************

    DCMAKE_INSTALL_PREFIX                                      #制定mysql的安装根目录,目录在安装的时候会自动创建,这个值也可以在服务器启动时,用--basedir来设置

    DMYSQL_UNIX_ADDR                                           #服务器与本地客户端进行通信的Unix套接字文件,必须是绝对路径,默认位置/tmp/mysql.sock,可以在服务器启动时,用--socket改变

    DDEFAULT_CHARSET                        #mysql默认使用的字符集,不指定将默认使用Latin1西欧字符集

    DDEFAULT_COLLATION                           #默认字符校对

    DWITH_EXTRA_CHARSETS                  #制定mysql拓展字符集,默认值也是all支持所有的字符集

    DWITH_MYISAM_STORAGE_ENGINE #静态编译MYISAM,INNOBASE,MEMORY存储引擎到MYSQL服务器,这样MYSQL就支持这三种存储引擎

    DWITH_INNOBASE_STORAGE_ENGINE

    DWITH_MEMORY_STORAGE_ENGINE

    DWITH_READLINE                    #支持readline库

    DENABLED_LOCAL_INFILE                    #允许本地倒入数据,启用加载本地数据

    DMYSQL_DATADIR                                #mysql数据库存放路径

    DMYSQL-USER                                    #运行mysql的用户

    [root@localhost mysql-5.6.26]# make -j 2 ; make install          //以2个进程来编译,不要超过CPU核心数上面的make过程比较漫长,我们使用了-j 2来增加编译速度

    配置mysql

             [root@test mysql-5.6.26]# cd && chown -R mysql:mysql /usr/local/mysql/                //属主属组更改

             [root@test ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf       //覆盖原配置文件

             [root@test ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld    //启动脚本

             [root@test ~]# vim /etc/init.d/ mysqld                                                   //更改启动脚本中指定mysql位置

    basedir=

    datadir=

    #修改为

    basedir=/usr/local/mysql

    datadir=/usr/local/mysql/data

             [root@test ~]# chkconfig mysqld  on                                         //开机启动

    初始化数据库

     [root@test ~]/usr/local/mysql/scripts/mysql_install_db 

    --defaults-file=/etc/my.cnf  

    --basedir=/usr/local/mysql/

    --datadir=/usr/local/mysql/data/

    --user=mysql

    #类似于在rpm安装的时候启动数据库弹出的初始化消息

    [root@test ~]# ls /usr/local/mysql/data/                     //初始化看这个下面有无mysql和test等数据库

    ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  test

    [root@test ~]# ln -s /usr/local/mysql/bin/* /bin/                  //这个里面是部分命令,让系统直接调用

    [root@test ~]# servie mysqld  start                                 //启动数据库

    [root@test ~]# mysql_secure_installation                                   //初始安全设置(设置root密码,123456)[记住,编译安装之前,记得除去mysql mysql-devel mysql-libs三个软件]

    [root@test ~]# mysql -uroot -p123456                                //测试登录(OK)

    mysql编译安装脚本

    #!/bin/bash

    yum remove  -y mysql mysql-server

    clear

    echo 'This shell will Auto Install Mysql5.6'

    yum install -y cmake ncurses-devel

    tar -xf mysql-5.6.26.tar.gz  -C  /usr/local/src && cd /usr/local/src/mysql-5.6.26

    useradd -M -s /sbin/nologin mysql

    mkdir /usr/local/mysql

    cmake

     -DCMAKE_INSTALL_PREFIX=/usr/local/mysql

     -DMYSQL_UNIX_ADDR=/tmp/mysql.sock

     -DDEFAULT_CHARSET=utf8

     -DDEFAULT_COLLATION=utf8_general_ci

     -DWITH_EXTRA_CHARSETS=all

     -DWITH_MYISAM_STORAGE_ENGINE=1

     -DWITH_INNOBASE_STORAGE_ENGINE=1

     -DWITH_MEMORY_STORAGE_ENGINE=1

     -DWITH_READLINE=1

     -DENABLED_LOCAL_INFILE=1

     -DMYSQL_DATADIR=/usr/local/mysql/data

     -DMYSQL-USER=mysql

    make -j 3 && make  install

    chown -R mysql:mysql  /usr/local/mysql

    /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

    mv /etc/my.cnf  /etc/my.cnf.bak

    cp -r /usr/local/mysql/support-file/my-default.cnf  /etc/my.cnf

    sed -i '/^[mysqld]/adatadir = /usr/local/mysql/data' /etc/my.cnf

    sed -i '/^[mysqld]/abasedir = /usr/local/mysql' /etc/my.cnf

    cp -r /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld

    chmod  +x /etc/init.d/mysqld

    echo "PATH=/usr/local/mysql/bin:$PATH" >>/etc/profile

    service mysqld restart

    echo

    echo "install success"

    source /etc/profile

    echo "source /etc/profile" >>/etc/rc.local

    service mysqld restart

    echo "If you now running mysql and others commands,Please running: source /etc/profile"

     脚本执行完,记得mysql_secure_installation   初始化数据库

    安装PHP

    解决依赖

           [root@test ~]# yum install php-pear -y                     

       //pear按照一定的分类来管理pear应用代码库,你

    pear代码可以组织到其中适当的目录中,其他人可以方便的检索并分享到你的成果;pear不仅仅是一个代码仓库,它同时也是一个标准,使用这个标准来书写你的php代码,将会增强你的程序的可读性,复用性,减少出错的几率;Pear通过两个类为你搭建了一个框架,实现了诸如析构函数,错误捕获功能,你通过继承就可以使用这些功能

    PHP添加libmcrypt拓展

           libmcrypt加密算法扩展库,支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+等算法 

    1、安装加密算法扩展库

    [root@test ~]# tar xf libmcrypt-2.5.8.tar.bz2 -C /usr/local/src/ ; cd /usr/local/src/libmcrypt-2.5.8/

    [root@test libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt ; make ; make install ; cd

    2、除开上面的依赖解决之外,还需要安装图片,xml,字体支持基本库,使用yum去安装,安装的时候,这些软件包自

    身也有依赖!

    [root@test  ~]# yum install -y libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype freetype-devel libzip libzip-devel

    3、需要添加到库文件路径

    由于系统默认规定只在/lib、/lib64、/lib/lib64下面找库文件,所以我们需要手动添加进去。

     [root@test ~]# vim /etc/ld.so.conf

    include ld.so.conf.d/*.conf                          #此行原有

    /usr/local/libmcrypt/lib                       #此行添加

    /usr/local/mysql/lib                           #此行添加

     [root@test ~]# ldconfig

    [root@test ~]# echo 'ldconfig' >> /etc/rc.local

    编译安装php

           [root@test ~]# tar xf php-5.6.13.tar.bz2 -C /usr/local/src/ ; cd /usr/local/src/php-5.6.13      

    [root@test php-5.6.13]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex  --enable-fpm --enable-mbstring --with-gd --enable-mysqlnd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --with-gettext --with-mcrypt=/usr/local/libmcrypt   

    *****************************************************************************************************************

    --with-config-file-path                         #设置 php.ini 的搜索路径。默认为 PREFIX/lib

    --with-mysql                        #mysql安装目录,对mysql的支持

    --with-mysqli                         #mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定。是一个数据库驱动

    --with-iconv-dir                      #种字符集间的转换

    --with-freetype-dir                  #打开对freetype字体库的支持

    --with-jpeg-dir                      #打开对jpeg图片的支持

    --with-png-dir                          #打开对png图片的支持

    --with-zlib                        #打开zlib库的支持,实现GZIP压缩输出     

    --with-libxml-dir=/usr                     #打开libxml2库的支持,libxml是一个用来解析XML文档的函数库

    --enable-xml                        #支持xml文档

    --disable-rpath                         #关闭额外的运行库文件

    --enable-bcmath                      #打开图片大小调整,用到zabbix监控的时候用到了这个模块

    --enable-shmop                       #shmop共享内存操作函数,可以与c/c++通讯

    --enable-sysvsem  #加上上面shmop,这样就使得你的PHP系统可以处理相关的IPC函数(活动在内核级别)。

    --enable-inline-optimization       #优化线程

    --with-curl                            #打开curl浏览工具的支持 

    --with-curlwrappers                    #运用curl工具打开url流 ,新版PHP5.6已弃用

    --enable-mbregex                    #支持多字节正则表达式

    --enable-fpm                       #CGI方式安装的启动程序,PHP-FPM服务

    --enable-mbstring                     #多字节,字符串的支持

    --with-gd                             #打开gd库的支持,是php处理图形的扩展库,GD库提供了一系列用来处理图片的API,使用GD库可以处理图片,或者生成图片。

    --enable-gd-native-ttf                    #支持TrueType字符串函数库

    --with-openssl                          #打开ssl支持

    --with-mhash                       #支持mhash算法扩展

    --enable-pcntl                          #freeTDS需要用到的,pcntl扩展可以支持php的多线程操作

    --enable-sockets                       #打开 sockets 支持

    --with-xmlrpc                       #打开xml-rpc的c语言

    --enable-zip                         #打开对zip的支持

    --enable-soap                          #扩展库通过soap协议实现了客服端与服务器端的数据交互操作

    --with-mcrypt                       #mcrypt算法扩展

    --with-zlib-dir=/usr/local/libzip   ##指定zip库路径

           [root@test php-5.6.13]# make -j 3 && make install ; cd

    如果上面在make的时候 提示libzip相关的报错可以安装下面的方法来解决

        执行 make clean

    然后 安装压缩支持库

    [root@test ~]# tar xf libzip-1.1.2.tar.gz -C /usr/local/src/

    [root@test src]# cd /usr/local/src/libzip-1.1.2/

    [root@test libzip-1.1.2]# ./configure --prefix=/usr/local/libzip && make && make install

    在重新编译:./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex  --enable-fpm --enable-mbstring --with-gd --enable-mysqlnd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --with-gettext --with-mcrypt=/usr/local/libmcrypt   --with-pcre-dir=/usr/local/src/pcre-8.37/ --with-zlib-dir=/usr/local/libzip

    配置php和php-fpm

    PHP配置文件:

           [root@test ~]# cp /usr/local/src/php-5.6.13/php.ini-production /usr/local/php/php.ini

    PHP-FPM配置文件:

           [root@test ~]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

    修改 /usr/local/php/etc/php-fpm.conf 运行用户和组改为nginx

    PHP-FPM启动脚本

           [root@test ~]# cp /usr/local/src/php-5.6.13/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

           [root@test ~]# chmod +x /etc/init.d/php-fpm

    [root@test ~]# chkconfig php-fpm on

    [root@test ~]# /etc/init.d/php-fpm start

    测试LNMP的PHP支持

           [root@test ~]# echo "<?php phpinfo(); ?>" > /usr/local/nginx/html/index.php

  • 相关阅读:
    vault学习笔记
    rabbit搭建
    安装windows虚拟机
    Java Unknown named curve: 1.3.132.0.10
    文件操作,读文件或者写文件
    Java 中带参无返回值方法的使用
    Java 中无参无返回值方法的使用
    mac系统如何显示和隐藏文件
    解决JSP页面显示乱码
    Java 中无参带返回值方法的使用
  • 原文地址:https://www.cnblogs.com/hackerlin/p/11321698.html
Copyright © 2020-2023  润新知