精华内容
下载资源
问答
  • lamp分离部署

    2020-11-02 00:04:44
    LAMP分离部署 LAMP简介: LAMP是指一组通常一起使用来运行动态网站或者服务器的开源软件名称首字母缩写: Linux Apache Mariadb或者MySQL PHP、Python或Perl //安装开发工具包 [root@localhost ~]# yum grouplist ...

    LAMP分离部署

    LAMP简介:

    LAMP是指一组通常一起使用来运行动态网站或者服务器的开源软件名称首字母缩写:
    Linux
    Apache
    Mariadb或者MySQL
    PHP、Python或Perl

    安装httpd

    //关闭防火墙和SELINUX
     systemctl stop firewalld
     systemctl disable firewalld
     setenforce 0
     setenforce: SELinux is disabled
    

    //安装开发工具包

    [root@localhost ~]# yum grouplist Development Tools
    

    //创建apache服务的用户和组

    [root@localhost ~]# useradd -r -M -s /sbin/nologin apache
    [root@localhost ~]# id apache
    uid=994(apache) gid=991(apache) groups=991(apache)
    
    

    //安装依赖包

    [root@localhost ~]#   yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
    
    [root@localhost ~]# cd apr-1.6.5
    [root@localhost apr-1.6.5]# vim configure
      cfgfile="${ofile}T"
        trap "$RM \"$cfgfile\"; exit 1" 1 2 15
        # $RM "$cfgfile"        //将此行加上注释,或者删除此行
    
    [root@localhost apr-1.6.5]# . /configure --prefix=/usr/local/apr
    [root@localhost apr-1.6.5]# make
    [root@localhost apr-1.6.5]# make install
    
    //配置,编译安装
    [root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    
    [root@localhost httpd-2.4.34]# ./configure --prefix=/usr/local/apache \
    --sysconfdir=/etc/httpd24 \
    --enable-so \
    --enable-ssl \
    --enable-cgi \
    --enable-rewrite \
    --with-zlib \
    --with-pcre \
    --with-apr=/usr/local/apr \
    --with-apr-util=/usr/local/apr-util/ \
    --enable-modules=most \
    --enable-mpms-shared=all \
    --with-mpm=prefork
    
    [root@localhost httpd-2.4.34]# make && make install
    

    //安装后配置

    [root@localhost httpd-2.4.34]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
    [root@localhost httpd-2.4.34]# source /etc/profile.d/httpd.sh 
    [root@localhost httpd-2.4.34]# cd
    [root@localhost ~]# which httpd
    /usr/local/apache/bin/httpd
    [root@localhost ~]# 
    
    
    //做一个软连接
    [root@localhost ~]# ln -s /usr/local/apache/include /usr/include/apache
    
    //取消ServerName前面的注释
    [root@localhost ~]# vim /etc/httpd24/httpd.conf 
    ServerName www.example.com:80
    

    安装mysql

    //安装依赖包

     yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
    
    

    //创建用户和组

    [root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
    [root@localhost ~]# id mysql
    uid=992(mysql) gid=989(mysql) groups=989(mysql)
    [root@localhost ~]# 
    

    //下载二进制格式的mysql软件包

    [root@localhost ~]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz  -C /usr/local/
    

    //修改目录/usr/local/mysql的属主属组

    [root@localhost local]# ln -s mysql-5.7.31-linux-glibc2.12-x86_64 mysql
    [root@localhost local]# chown -R mysql.mysql mysql*
    
    

    //添加环境变量

    [root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
    [root@localhost ~]# source /etc/profile.d/mysql.sh 
    [root@localhost ~]# 
    

    //建立数据存放目录

    [root@localhost ~]# mkdir /opt/data
    [root@localhost ~]# chown -R mysql.mysql /opt/data
    

    //初始化数据库

    [root@localhost ~]# mysqld --initialize-insecure  --datadir=/opt/data --user=mysql
    2020-10-29T08:03:06.602356Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2020-10-29T08:03:07.006957Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2020-10-29T08:03:07.161237Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2020-10-29T08:03:07.282358Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2dcc8417-19bd-11eb-9ce9-000c29c8dc20.
    2020-10-29T08:03:07.284341Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2020-10-29T08:03:07.668465Z 0 [Warning] CA certificate ca.pem is self signed.
    2020-10-29T08:03:08.026149Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
    
    

    //配置mysql

    [root@localhost ~]# vim /etc/my.cnf
    [root@localhost ~]# ln -s /usr/local/mysql/include /usr/include/mysql/
    [root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
    /usr/local/mysql/lib
    
    [root@localhost ~]# ldconfig 
    
    [root@localhost ~]# mv /etc/my.cnf{,-bak}
    
    //生成配置文件
    [root@localhost ~]# cat > /etc/my.cnf <<EOF
    [mysqld]
    basedir = /usr/local/mysql
    datadir = /opt/data
    socket = /tmp/mysql.sock
    port = 3306
    pid-file = /opt/data/mysql.pid
    user = mysql
    skip-name-resolve
    EOF
    

    //配置服务启动脚本

    [root@localhost ~]# cd /usr/local/mysql
    [root@localhost mysql]# ls
    bin   include  LICENSE  README  support-files
    docs  lib      man      share
    [root@localhost mysql]# cd support-files/
    [root@localhost support-files]# ls
    magic                mysql-log-rotate
    mysqld_multi.server  mysql.server
    [root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
    
    
    [root@localhost ~]# vim /etc/init.d/mysqld 
    basedir=/usr/local/mysql
    datadir=/opt/data
    

    安装php

    //安装依赖包

    [root@localhost ~]#  yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel
    
    [root@localhost ~]# yum list all |grep php|grep mysql
    php-mysqlnd.x86_64                                   7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream  
    
    
    [root@localhost ~]# yum -y install php-mysqlnd 
    
    
    [root@localhost ~]# tar xf php-7.2.8.tar.xz 
    
    ./configure --prefix=/usr/local/php7  \
    --with-config-file-path=/etc \
    --enable-fpm \
    --enable-inline-optimization \
    --disable-debug \
    --disable-rpath \
    --enable-shared \
    --enable-soap \
    --with-openssl \
    --enable-bcmath \
    --with-iconv \
    --with-bz2 \
    --enable-calendar \
    --with-curl \
    --enable-exif  \
    --enable-ftp \
    --with-gd \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib-dir \
    --with-freetype-dir \
    --with-gettext \
    --enable-json \
    --enable-mbstring \
    --enable-pdo \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --with-readline \
    --enable-shmop \
    --enable-simplexml \
    --enable-sockets \
    --enable-zip \
    --enable-mysqlnd-compression-support \
    --with-pear \
    --enable-pcntl \
    --enable-posix
    

    //编译过程

    [root@localhost php-7.2.8]# make instal
    

    安装后配置

    [root@localhost php-7.2.8]#  echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php.sh
    [root@localhost php-7.2.8]# source /etc/profile.d/php.sh
    [root@localhost php-7.2.8]# which php
    /usr/local/php7/bin/php
    [root@localhost php-7.2.8]# 
    
    

    //配置php-fpm

    [root@localhost php-7.2.8]# cp php.ini-production /etc/php.ini 
    cp: overwrite '/etc/php.ini'? y
    
    [root@localhost php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    [root@localhost php-7.2.8]# chmod  +x /etc/init.d/php-fpm 
    [root@localhost php-7.2.8]# 
    
    
    [root@localhost php-7.2.8]# cd /usr/local/php7/
    [root@localhost php7]# ls
    bin  etc  include  lib  php  sbin  var
    [root@localhost php7]# cd etc/
    [root@localhost etc]# ls
    pear.conf  php-fpm.conf.default  php-fpm.d
    [root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
    
    [root@localhost etc]# cd php-fpm.d/
    [root@localhost php-fpm.d]# ls
    www.conf.default
    [root@localhost php-fpm.d]# cp www.conf.default www.conf
    [root@localhost php-fpm.d]# ls
    
    //编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf):
    //配置fpm的相关选项为你所需要的值:
    [root@localhost etc]# vim /usr/local/php7/etc/php-fpm.conf
    pm.max_children = 50
    pm.start_servers = 5
    pm.min_spare_servers = 2
    pm.max_spare_servers = 8
    
    

    //启动php-fpm

    [root@localhost etc]# service php-fpm start
    Starting php-fpm  done
    [root@localhost etc]# ss -antl
    State  Recv-Q Send-Q  Local Address:Port   Peer Address:Port                                                    
    LISTEN 0      128           0.0.0.0:22          0.0.0.0:*                                                       
    LISTEN 0      128         127.0.0.1:9000        0.0.0.0:*                                                       
    LISTEN 0      128                 *:80                *:*                                                       
    LISTEN 0      128              [::]:22             [::]:*                                                       
    LISTEN 0      80                  *:3306              *:*                                                       
    [root@localhost etc]# 
    
    更改监听端口,让httpd服务器能找到
    [root@localhost]#  vim /usr/local/php7/etc/php-fpm.d/www.conf
    listen = 0.0.0.0:9000    #改为全0.0.0.0,使所有的ip都可以访问
    
    再次重启
    [root@localhost]# service  php-fpm restart
    Gracefully shutting down php-fpm . done
    Starting php-fpm  done
    [root@localhost]# ss -antl
    State             Recv-Q            Send-Q                       Local Address:Port                       Peer Address:Port           
    LISTEN            0                 128                                0.0.0.0:9000                            0.0.0.0:*              
    LISTEN            0                 128                                0.0.0.0:22                              0.0.0.0:*              
    LISTEN            0                 128                                   [::]:22    
    
    配置apache

    启用代理模块
    在apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩展,因此,这两个模块都要加载,编辑httpd.conf文件,取消以下两行内容的注释:

    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
    
    [root@localhost ~]# vim /etc/httpd24/httpd.conf 
    Include /etc/httpd24/extra/httpd-vhosts.conf
    

    配置虚拟主机

    在需要使用fcgi的虚拟主机中添加类似如下两行:

    ProxyRequests Off       //关闭正向代理
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
    
    
    [root@localhost ~]# vim /etc/httpd24/extra/httpd-vhosts.conf 
    //在配置文件的最后加入以下内容
    <VirtualHost *:80>
        DocumentRoot "/usr/local/apache/htdocs"
        ServerName www.example.com
        ErrorLog "logs/www.example.com-error_log"
        CustomLog "logs/www.example.com-access_log" common
        ProxyRequests Off
        ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.11.128:9000/usr/local/apache/htdocs/wangqing.com/$1
        <Directory "/usr/local/apache/htdocs">
            Require all granted
        </Directory>
    </VirtualHost>
    

    //生成php测试页面

    [root@localhost htdocs]# vim index.php
    <?php
        phpinfo();
    ?>
    
    [root@localhost apache]# chown -R apache.apache htdocs/
    [root@localhost apache]# ll
    total 36
    drwxr-xr-x.  2 root   root    262 Oct 29 15:31 bin
    drwxr-xr-x.  2 root   root    167 Oct 29 15:31 build
    drwxr-xr-x.  2 root   root     78 Oct 29 15:31 cgi-bin
    drwxr-xr-x.  3 root   root   4096 Oct 29 15:31 error
    drwxr-xr-x.  2 apache apache   41 Oct 29 19:04 htdocs
    drwxr-xr-x.  3 root   root   8192 Oct 29 15:31 icons
    drwxr-xr-x.  2 root   root   4096 Oct 29 15:31 include
    drwxr-xr-x.  2 root   root     58 Oct 29 15:44 logs
    drwxr-xr-x.  4 root   root     30 Oct 29 15:31 man
    drwxr-xr-x. 14 root   root   8192 Oct 29 15:31 manual
    drwxr-xr-x.  2 root   root   4096 Oct 29 15:31 modules
    [root@localhost apache]# 
    
    //搜索AddType,添加以下内容 添加下两行
    [root@localhost apache]# vim /etc/httpd24/httpd.conf
        AddType application/x-httpd-php .php  #添加此行
        AddType application/x-httpd-php-source .phps  #添加此行
    
    
    [root@localhost apache]# vim /etc/httpd24/httpd.conf
    index.php 
    
    
    
    

    在这里插入图片描述

    展开全文
  • LAMP分离部署

    2020-10-31 10:22:17
    LAMP LAMP简介 LAMP是指一组通常一起使用来运行动态网站或者服务器的开源软件名称首字母缩写: Linux Apache Mariadb或者MySQL PHP、Python或Perl web服务器工作流程 web服务器的资源分为两种,静态资源和...

    LAMP简介

    • LAMP是指一组通常一起使用来运行动态网站或者服务器的开源软件名称首字母缩写:
      • Linux
      • Apache
      • Mariadb或者MySQL
      • PHP、Python或Perl

    web服务器工作流程

    在这里插入图片描述

    • web服务器的资源分为两种,静态资源和动态资源

      • 静态资源就是指静态内容,客户端从服务器获得的资源的表现形式与原文件相同。可以简单的理解为就是直接存储于文件系统中的资源
      • 动态资源则通常是程序文件,需要在服务器执行之后,将执行的结果返回给客户端
    • 浏览器向服务器发送http请求,服务器 (Apache)接受请求,由于php作为Apache的组件模块也会一起启动,它们具有相同的生命周期。Apache会将一些静态资源保存,然后去调用php处理模块进行php脚本的处理。脚本处理完后,Apache将处理完的信息通过http response的方式发送给浏览器,浏览器解析,渲染等一系列操作后呈现整个网页。

    • 上图中阶段1显示的是httpd服务器(即apache)和php服务器通过FastCGI协议进行通信,且php作为独立的服务进程运行

    • 阶段2显示的是php程序和mysql数据库间通过mysql协议进行通信。php与mysql本没有什么联系,但是由Php语言写成的程序可以与mysql进行数据交互。同理perl和python写的程序也可以与mysql数据库进行交互


    CGI和FASTCGI

    • CGI :通用网关接口(Common Gateway Interface),CGI是外部应用程序(CGI程序)与WEB服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的过程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,CGI将web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体。
    • FASTCGI :Fast Common Gateway Interface,是CGI的改良版,CGI是通过启用一个解释器进程来处理每个请求,耗时且耗资源,而FastCGI则是通过master-worker形式来处理每个请求,即启动一个master主进程,然后根据配置启动几个worker进程,当请求进来时,master会从worker进程中选择一个去处理请求,这样就避免了重复的生成和杀死进程带来的频繁cpu上下文切换而导致耗时

    httpd与php结合的方式

    httpd与php结合的方式有三种:

    • modules:php将以httpd的扩展模块形式存在,需要加载动态资源时,httpd可以直接通过php模块来加工资源并返回给客户端
      • httpd prefork:libphp5.so(多进程模型的php)
      • httpd event or worker:libphp5-zts.so(线程模型的php)
    • CGI:httpd需要加载动态资源时,通过CGI与php解释器联系,获得php执行的结果,此时httpd负责与php连接的建立和断开等
    • FastCGI:利用php-fpm机制,启动为服务进程,php自行运行为一个服务,https通过socket与php通信

    web工作流程

    • 客户端通过http协议请求web服务器资源
    • web服务器收到请求后判断客户端请求的资源是静态资源或是动态资源
      • 若是静态资源则直接从本地文件系统取之返回给客户端。
      • 否则若为动态资源则通过FastCGI协议与php服务器联系,通过CGI程序的master进程调度worker进程来执行程序以获得客户端请求的动态资源,并将执行的结果通过FastCGI协议返回给httpd服务器,httpd服务器收到php的执行结果后将其封装为http响应报文响应给客户端。在执行程序获取动态资源时若需要获得数据库中的资源时,由Php服务器通过mysql协议与MySQL/MariaDB服务器交互,获取之后返回给httpd,httpd将从php服务器收到的执行结果封装成http响应报文响应给客户端。

    LAMP平台构建

    • 环境说明
    系统平台IP地址需要安装的服务
    Redhat 8192.168.86.129httpd-2.4
    Redhat 7192.168.86.132MySQL-5.7
    Redhat 7192.168.86.133PHP、php-mysql
    • LAMP平台软件安装的次序

    httpd --> mysql --> php

    注: php要求httpd使用prefork MPM

    安装httpd


    安装MySQL


    安装PHP

    //在redha 7中安装PHP需要配置yum源
    [root@php ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    [root@php ~]# rpm -Uvh remi-release-7.rpm
    [root@php ~]# yum makecache --enablerepo=remi-php74
    //安装依赖包,Redhat 7和Redhat 8所需要的依赖包不同
    [root@php ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php72-php-mysqlnd
    
    //在Redhat 8中不需要这么麻烦,Redhat 8的本地yum源中就有php的安装包
    //安装依赖包
    [root@php ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php-mysqlnd
    
    
    //下载php
    [root@php ~]# cd /usr/local/src/
    [root@php ~]# wget http://cn.php.net/distributions/php-7.2.8.tar.gz
    
    
    //编译安装php
    [root@php src]# tar xf php-7.2.8.tar.gz -C /usr/local/
    [root@php src]# cd /usr/local/php-7.2.8/
    [root@php php-7.2.8]# ./configure --prefix=/usr/local/php7  \
    --with-config-file-path=/etc \		#指定配置文件存的位置
    --enable-fpm \
    --enable-inline-optimization \
    --disable-debug \
    --disable-rpath \
    --enable-shared \
    --enable-soap \
    --with-openssl \
    --enable-bcmath \
    --with-iconv \
    --with-bz2 \
    --enable-calendar \
    --with-curl \
    --enable-exif  \
    --enable-ftp \
    --with-gd \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib-dir \
    --with-freetype-dir \
    --with-gettext \
    --enable-json \
    --enable-mbstring \
    --enable-pdo \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --with-readline \
    --enable-shmop \
    --enable-simplexml \
    --enable-sockets \
    --enable-zip \
    --enable-mysqlnd-compression-support \
    --with-pear \
    --enable-pcntl \
    --enable-posix
    
    [root@php php-7.2.8]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
    [root@localhost php-7.2.8]# make install
    
    //配置环境变量
    [root@php php-7.2.8]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
    [root@php php-7.2.8]# source /etc/profile.d/php7.sh 
    [root@php php-7.2.8]# echo $PATH
    /usr/local/php7/bin:/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    
    
    //配置php-fpm
    [root@php php-7.2.8]# pwd
    /usr/local/php-7.2.8
    [root@php php-7.2.8]# ls php.ini*
    php.ini-development(开发环境)  php.ini-production(生产环境)
    [root@php php-7.2.8]# \cp php.ini-production /etc/php.ini
    [root@php php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    [root@php php-7.2.8]# chmod +x /etc/init.d/php-fpm
    [root@php php-7.2.8]# cd /usr/local/php7/etc/
    [root@php etc]# cp php-fpm.conf.default php-fpm.conf
    [root@php etc]# ls
    pear.conf  php-fpm.conf  php-fpm.conf.default  php-fpm.d
    [root@php etc]# cd php-fpm.d/
    [root@php php-fpm.d]# cp www.conf.default www.conf
    [root@php php-fpm.d]# ls
    www.conf  www.conf.default
    
    //编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf),在最后添加以下内容
    [root@php php-fpm.d]# cd ..
    [root@php etc]# vim php-fpm.conf
    pm.max_children = 50    #最多同时提供50个进程提供50个并发服务
    pm.start_servers = 5    #启动时启动5个进程
    pm.min_spare_servers = 2    #最小空闲进程数
    pm.max_spare_servers = 8    #最大空闲进程数
    //上面的参数可以根据实际情况做修改
    
    
    //启动php-fpm
    [root@php ~]# service php-fpm start 
    Starting php-fpm  done
    
    
    //查看端口,默认情况下,fpm监听在127.0.0.1的9000端口
    [root@php ~]# ss -antl
    State       Recv-Q       Send-Q               Local Address:Port               Peer Address:Port       
    LISTEN      0            128                        0.0.0.0:22                      0.0.0.0:*          
    LISTEN      0            128                      127.0.0.1:9000                    0.0.0.0:*          
    LISTEN      0            128                              *:80                            *:*          
    LISTEN      0            128                           [::]:22                         [::]:*          
    LISTEN      0            80                               *:3306                          *:*     
    

    配置Apache

    启用代理模块

    • 在apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩展,因此,这两个模块都要加载,编辑httpd.conf文件,取消以下两行内容的注释:
    [root@apache ~]# vim /etc/httpd24/httpd.conf 
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
    

    配置虚拟主机

    • 在需要使用fcgi的虚拟主机中添加如下两行:
    //取消主配置文件中的这一行的注释
    [root@apache ~]# vim /etc/httpd24/httpd.conf 
    Include /etc/httpd24/extra/httpd-vhosts.conf			#包含httpd-vhosts.conf,然后可以直接在/etc/httpd24/extra/httpd-vhosts.conf中配置虚拟主机
    [root@apache ~]# vim /etc/httpd24/extra/httpd-vhosts.conf
    <VirtualHost *:80>
        DocumentRoot "/usr/local/httpd/htdocs"
        phpName www.example.com
        ErrorLog "logs/dummy-host.example.com-error_log"
        CustomLog "logs/dummy-host.example.com-access_log" common
        ProxyRequests Off		#关闭正向代理
        ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.86.133:9000/usr/local/httpd/htdocs/$1		#添加反向代理,表示把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI,所以这里直接在fcgi://192.168.86.133:9000后指明了这两个参数,其它参数的传递已经被mod_proxy_fcgi.so进行了封装,不需要手动指定。
         <Directory "/usr/local/httpd/htdocs">
            Options none
            AllowOverride none
            Require all granted
        </Directory>
    </VirtualHost>
    注意: 这里的网页指定路径在实际工作中请更改为php服务器上网站存放的路径,反向代理的地址请写php服务器的地址
    
    
    
    
    //在配置文件中添加以下内容
    [root@apache ~]# vim /etc/httpd24/httpd.conf 
        AddType application/x-compress .Z
        AddType application/x-gzip .gz .tgz
        AddType application/x-httpd-php .php		#添加这一行
        AddType application/x-httpd-php-source .phps	#添加这一行
    
    <IfModule dir_module>
        DirectoryIndex index.php index.html				#在这一行加上刚刚创建的php测试页面
    </IfModule>
    
    
    //重启apache服务
    

    配置php

    • 创建php测试页面
    //生成php测试页面
    [root@php ~]# vim /usr/local/httpd/htdocs/index.php 
    
    <?php
       phpinfo();
    ?>
    
    //修改属组和属主
    [root@php ~]# chown apache.apache /usr/local/httpd/htdocs/
    [root@php ~]# ll -d /usr/local/httpd/htdocs/
    drwxr-xr-x 2 apache apache 24 Oct 30 15:21 /usr/local/httpd/htdocs/
    
    • 修改php的配置文件修改其监听的IP地址
    [root@php ~]# cd /usr/local/php7/etc/php-fpm.d/www.conf
    listen = 0.0.0.0:9000
    
    //重启php服务
    [root@php ~]# service php-fpm restart 
    Gracefully shutting down php-fpm . done
    Starting php-fpm  done
    

    在浏览器中验证

    在这里插入图片描述

    展开全文
  • LAMP 分离部署

    2021-07-22 09:56:19
    LAMP分离部署 环境准备 系统 IP CentOS 192.168.126.136 CentOS 192.168.126.144 CentOS 192.168.126.148 CentOS 192.168.126.49 安装过程 //关闭防火墙 [root@ansible ansible]# ansible all -m ...

    LAMP分离部署

    环境准备

    系统IP
    CentOS192.168.126.136
    CentOS192.168.126.144
    CentOS192.168.126.148
    CentOS192.168.126.49

    安装过程

    //关闭防火墙
    [root@ansible ansible]# ansible all -m shell -a 'systemctl stop firewalld && systemctl disable firewalld '
    192.168.126.148 | CHANGED | rc=0 >>
    
    192.168.126.144 | CHANGED | rc=0 >>
    
    192.168.126.149 | CHANGED | rc=0 >>
    

    //关闭SELINUX

    [root@ansible ansible]# ansible all -m lineinfile -a 'path=/etc/selinux/config regexp="^SELINUX=" line="SELINUX=disabled"'
    192.168.126.144 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "backup": "", 
        "changed": false, 
        "msg": ""
    }
    192.168.126.149 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "backup": "", 
        "changed": false, 
        "msg": ""
    }
    192.168.126.148 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "backup": "", 
        "changed": false, 
        "msg": ""
    }
    
    //在node1上安装HTTPD服务
    [root@ansible ansible]# ansible httpd -m yum -a "name=httpd"
    192.168.126.144 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/libexec/platform-python"
        },
        "changed": false,
        "msg": "Nothing to do",
        "rc": 0,
        "results": []
    }
    

    //在node2上安装MySQL服务

    [root@ansible ansible]# ansible mysql -m yum -a 'name=mariadb*'
    192.168.126.148 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": false, 
        "msg": "", 
        "rc": 0, 
        "results": [
            "package providing mariadb* is already installed"
        ]
    }
    

    //在node3上安装php服务

    [root@ansible ansible]# ansible php -m yum -a "name=php"
    192.168.126.149 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": false, 
        "msg": "", 
        "rc": 0, 
        "results": [
            "php-5.4.16-48.el7.x86_64 providing php is already installed"
        ]
    }
    

    //创建脚本文件

    [root@ansible ansible]# cat mkf.sh 
    #! /bin/bash
    echo 102.168.126.144      apache >> /etc/hosts
    echo 192.168.126.148      mysql >> /etc/hosts
    echo 192.168.126.149      php >> /etc/hosts
    //解析
    [root@ansible ansible]# ansible all -m script -a '/etc/ansible/mkf.sh'
    192.168.126.144 | CHANGED => {
        "changed": true, 
        "rc": 0, 
        "stderr": "Shared connection to 192.168.126.144 closed.\r\n", 
        "stderr_lines": [
            "Shared connection to 192.168.126.144 closed."
        ], 
        "stdout": "", 
        "stdout_lines": []
    }
    192.168.126.149 | CHANGED => {
        "changed": true, 
        "rc": 0, 
        "stderr": "Shared connection to 192.168.126.149 closed.\r\n", 
        "stderr_lines": [
            "Shared connection to 192.168.126.149 closed."
        ], 
        "stdout": "", 
        "stdout_lines": []
    }
    192.168.126.148 | CHANGED => {
        "changed": true, 
        "rc": 0, 
        "stderr": "Shared connection to 192.168.126.148 closed.\r\n", 
        "stderr_lines": [
            "Shared connection to 192.168.126.148 closed."
        ], 
        "stdout": "", 
        "stdout_lines": []
    }
    

    //启动httpd、mysql、php服务,并设置开机自启

    [root@ansible ansible]# ansible apache -m service -a "name=httpd state=started enabled=yes"
    192.168.126.144 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "enabled": true, 
        "name": "httpd", 
        "state": "started", 
        "status": {
            "ActiveEnterTimestampMonotonic": "0", 
            "ActiveExitTimestampMonotonic": "0", 
            "ActiveState": "inactive", 
            "After": "systemd-journald.socket network.target remote-fs.target basic.target tmp.mount -.mount nss-lookup.target system.slice", 
            "AllowIsolate": "no", 
            "AmbientCapabilities": "0", 
            "AssertResult": "no", 
            "AssertTimestampMonotonic": "0", 
            "Before": "shutdown.target", 
            "BlockIOAccounting": "no", 
            "BlockIOWeight": "18446744073709551615", 
            "CPUAccounting": "no", 
            "CPUQuotaPerSecUSec": "infinity", 
            "CPUSchedulingPolicy": "0", 
            "CPUSchedulingPriority": "0", 
            "CPUSchedulingResetOnFork": "no", 
            "CPUShares": "18446744073709551615", 
            "CanIsolate": "no", 
            "CanReload": "yes", 
            "CanStart": "yes", 
            "CanStop": "yes", 
            "CapabilityBoundingSet": "18446744073709551615", 
            "ConditionResult": "no", 
            "ConditionTimestampMonotonic": "0", 
            "Conflicts": "shutdown.target", 
            "ControlPID": "0", 
            "DefaultDependencies": "yes", 
            "Delegate": "no", 
            "Description": "The Apache HTTP Server", 
            "DevicePolicy": "auto", 
            "Documentation": "man:httpd(8) man:apachectl(8)", 
            "EnvironmentFile": "/etc/sysconfig/httpd (ignore_errors=no)", 
            "ExecMainCode": "0", 
            "ExecMainExitTimestampMonotonic": "0", 
            "ExecMainPID": "0", 
            "ExecMainStartTimestampMonotonic": "0", 
            "ExecMainStatus": "0", 
            "ExecReload": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -k graceful ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
            "ExecStart": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -DFOREGROUND ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
            "ExecStop": "{ path=/bin/kill ; argv[]=/bin/kill -WINCH ${MAINPID} ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
            "FailureAction": "none", 
            "FileDescriptorStoreMax": "0", 
            "FragmentPath": "/usr/lib/systemd/system/httpd.service", 
            "GuessMainPID": "yes", 
            "IOScheduling": "0", 
            "Id": "httpd.service", 
            "IgnoreOnIsolate": "no", 
            "IgnoreOnSnapshot": "no", 
            "IgnoreSIGPIPE": "yes", 
            "InactiveEnterTimestampMonotonic": "0", 
            "InactiveExitTimestampMonotonic": "0", 
            "JobTimeoutAction": "none", 
            "JobTimeoutUSec": "0", 
            "KillMode": "control-group", 
            "KillSignal": "18", 
            "LimitAS": "18446744073709551615", 
            "LimitCORE": "18446744073709551615", 
            "LimitCPU": "18446744073709551615", 
            "LimitDATA": "18446744073709551615", 
            "LimitFSIZE": "18446744073709551615", 
            "LimitLOCKS": "18446744073709551615", 
            "LimitMEMLOCK": "65536", 
            "LimitMSGQUEUE": "819200", 
            "LimitNICE": "0", 
            "LimitNOFILE": "4096", 
            "LimitNPROC": "7152", 
            "LimitRSS": "18446744073709551615", 
            "LimitRTPRIO": "0", 
            "LimitRTTIME": "18446744073709551615", 
            "LimitSIGPENDING": "7152", 
            "LimitSTACK": "18446744073709551615", 
            "LoadState": "loaded", 
            "MainPID": "0", 
            "MemoryAccounting": "no", 
            "MemoryCurrent": "18446744073709551615", 
            "MemoryLimit": "18446744073709551615", 
            "MountFlags": "0", 
            "Names": "httpd.service", 
            "NeedDaemonReload": "no", 
            "Nice": "0", 
            "NoNewPrivileges": "no", 
            "NonBlocking": "no", 
            "NotifyAccess": "main", 
            "OOMScoreAdjust": "0", 
            "OnFailureJobMode": "replace", 
            "PermissionsStartOnly": "no", 
            "PrivateDevices": "no", 
            "PrivateNetwork": "no", 
            "PrivateTmp": "yes", 
            "ProtectHome": "no", 
            "ProtectSystem": "no", 
            "RefuseManualStart": "no", 
            "RefuseManualStop": "no", 
            "RemainAfterExit": "no", 
            "Requires": "-.mount basic.target", 
            "RequiresMountsFor": "/var/tmp", 
            "Restart": "no", 
            ~~省略~~ 
    
    [root@ansible ansible]# ansible mysql -m service -a "name=mariadb state=started enabled=yes"
    192.168.126.148 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "enabled": true, 
        "name": "mariadb", 
        "state": "started", 
        "status": {
            "ActiveEnterTimestampMonotonic": "0", 
            "ActiveExitTimestampMonotonic": "0", 
            "ActiveState": "inactive", 
            "After": "-.mount tmp.mount syslog.target system.slice systemd-journald.socket network.target basic.target", 
            "AllowIsolate": "no", 
            "AmbientCapabilities": "0", 
            "AssertResult": "no", 
            "AssertTimestampMonotonic": "0", 
            "Before": "shutdown.target", 
            "BlockIOAccounting": "no", 
            "BlockIOWeight": "18446744073709551615", 
            "CPUAccounting": "no", 
            "CPUQuotaPerSecUSec": "infinity", 
            "CPUSchedulingPolicy": "0", 
            "CPUSchedulingPriority": "0", 
            "CPUSchedulingResetOnFork": "no", 
            "CPUShares": "18446744073709551615", 
            "CanIsolate": "no", 
            "CanReload": "no", 
            "CanStart": "yes", 
            "CanStop": "yes", 
            "CapabilityBoundingSet": "18446744073709551615", 
            "ConditionResult": "no", 
            "ConditionTimestampMonotonic": "0", 
            "Conflicts": "shutdown.target", 
            "ControlPID": "0", 
            "DefaultDependencies": "yes", 
            "Delegate": "no", 
            "Description": "MariaDB database server", 
            "DevicePolicy": "auto", 
            "ExecMainCode": "0", 
            "ExecMainExitTimestampMonotonic": "0", 
            "ExecMainPID": "0", 
            "ExecMainStartTimestampMonotonic": "0", 
            "ExecMainStatus": "0"
            ~~省略~~ 
    
    [root@ansible ansible]# ansible php -m service -a "name=php-fpm state=started enabled=yes"
    192.168.126.149 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "enabled": true, 
        "name": "php-fpm", 
        "state": "started", 
        "status": {
            "ActiveEnterTimestampMonotonic": "0", 
            "ActiveExitTimestampMonotonic": "0", 
            "ActiveState": "inactive", 
            "After": "basic.target syslog.target system.slice systemd-journald.socket -.mount tmp.mount network.target", 
            "AllowIsolate": "no", 
            "AmbientCapabilities": "0", 
            "AssertResult": "no", 
            "AssertTimestampMonotonic": "0", 
            "Before": "shutdown.target", 
            "BlockIOAccounting": "no", 
            "BlockIOWeight": "18446744073709551615", 
            "CPUAccounting": "no", 
            "CPUQuotaPerSecUSec": "infinity", 
            "CPUSchedulingPolicy": "0", 
            "CPUSchedulingPriority": "0", 
            "CPUSchedulingResetOnFork": "no", 
            "CPUShares": "18446744073709551615", 
            "CanIsolate": "no", 
            "CanReload": "yes", 
            "CanStart": "yes", 
            "CanStop": "yes", 
            "CapabilityBoundingSet": "18446744073709551615", 
            "ConditionResult": "no", 
            "ConditionTimestampMonotonic": "0", 
            "Conflicts": "shutdown.target", 
            "ControlPID": "0", 
            "DefaultDependencies": "yes", 
            "Delegate": "no", 
            "Description": "The PHP FastCGI Process Manager", 
            "DevicePolicy": "auto", 
            "EnvironmentFile": "/etc/sysconfig/php-fpm (ignore_errors=no)", 
            "ExecMainCode": "0", 
            "ExecMainExitTimestampMonotonic": "0", 
            "ExecMainPID": "0", 
            "ExecMainStartTimestampMonotonic": "0", 
            "ExecMainStatus": "0", 
            "ExecReload": "{ path=/bin/kill ; argv[]=/bin/kill -USR2 $MAINPID ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
            "ExecStart": "{ path=/usr/sbin/php-fpm ; argv[]=/usr/sbin/php-fpm --nodaemonize ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
            "FailureAction": "none", 
            "FileDescriptorStoreMax": "0", 
            "FragmentPath": "/usr/lib/systemd/system/php-fpm.service", 
            "GuessMainPID": "yes", 
            "IOScheduling": "0", 
            "Id": "php-fpm.service",
    

    //使用shell、lineinfile、copy模块来修改httpd的配置

    [root@ansible ansible]# ansible apache -m shell -a 'sed -i "/DirectoryIndex/s/index.html/index.php index.html/g" /etc/httpd/conf/httpd.conf'
    192.168.126.144 | CHANGED | rc=0 >> 
    
    [root@ansible ansible]# ansible apache -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf insertafter="AddType application/x-gzip.gz.tgz" line="AddType application/x-httpd-php .php"'
    192.168.126.144 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "backup": "", 
        "changed": true, 
        "msg": "line added"
    }   
    
    [root@ansible ansible]# ansible apache -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf insertafter="AddType application/x-gzip .gz.tgz" line="AddType application/x-httpd-php-source.phps"'
    192.168.126.144 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "backup": "", 
        "changed": true, 
        "msg": "line added"
    }
    
    [root@ansible ansible]# ansible apache -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf insertafter="# LoadModule foo_module modules/mod_foo.so" line="LoadModule proxy_module modules/mod_proxy.so"'
    192.168.126.144 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "backup": "", 
        "changed": true, 
        "msg": "line added"
    }
    
    [root@ansible ansible]# ansible apache -m lineinfile -a 'path=/etc/httpd/conf/httpd.conf insertafter="# LoadModule foo_module modules/mod_foo.so" line="LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so"'
    192.168.126.144 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "backup": "", 
        "changed": true, 
        "msg": "line added"
    }
    

    //把虚拟站点文件传输到apache服务器上

    [root@ansible ansible]# cat /root/httpd.conf 
    <VirtualHost *:80>
            DocumentRoot "/var/www/html/"
            ServerName www.mkf.com
            ProxyRequests Off
            ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.126.149:8800/www/html/$1
    </VirtualHost>
    
    [root@ansible ansible]# ansible apache -m copy -a 'src=/root/httpd.conf dest=/etc/httpd/conf.d/'
    192.168.126.144 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "checksum": "df113d18483bfccfe4b4621ddfa44922c95a8548", 
        "dest": "/etc/httpd/conf.d/httpd.conf", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "a1972762529884da5120d31d08de5698", 
        "mode": "0644", 
        "owner": "root", 
        "size": 205, 
        "src": "/root/.ansible/tmp/ansible-tmp-1626921192.98-47279-86143886268835/source", 
        "state": "file", 
        "uid": 0
    }
    
    [root@php ~]# cat /etc/httpd/conf/httpd.conf
    #Example:
    #LoadModule foo_module modules/mod_foo.so
    #
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
    Include conf.modules.d/*.conf
    

    //使用lineinfile模块来修改php的配置文件

    [root@ansible ansible]# ansible php -m lineinfile -a 'path=/etc/php-fpm.d/www.conf regexp="listen = /usr" line="listen = 0.0.0.0:8800"'
    192.168.126.149 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "backup": "", 
        "changed": true, 
        "msg": "line added"
    }
    
    [root@ansible ansible]# ansible php -m lineinfile -a 'path=/etc/php-fpm.d/www.conf regexp="listen.allowed_clients = 127.0.0.1" line="listen.allowed_clients = 192.168.126.149"'
    192.168.126.149 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "backup": "", 
        "changed": true, 
        "msg": "line replaced"
    }
    

    //把php测试文件index.php放到php服务器上

    [root@ansible ansible]# ansible php -m copy -a 'src=/root/index.php dest=/www/html/'
    192.168.126.149 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "checksum": "8cdacfa1ec940e21858b76583aaf876549d8556d", 
        "dest": "/www/html/index.php", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "bf1c9e55ca2bfcfcdfd08d6d7ae2c8f6", 
        "mode": "0644", 
        "owner": "root", 
        "size": 13, 
        "src": "/root/.ansible/tmp/ansible-tmp-1626922616.43-77844-39004525474201/source", 
        "state": "file", 
        "uid": 0
    }
    

    //网站源码要放在php服务端的/var/www/html目录
    //httpd服务配置添加远程调用php服务

    [root@apache ~]# vim /etc/httpd/conf/httpd.conf
    #probably should define those extensions to indicate media types:
        #
        AddType application/x-compress .Z
        AddType application/x-gzip .gz .tgz
        AddType application/x-httpd-php-source .phps
        AddType application/x-httpd-php .php
        Proxyrequests Off
        ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.14.10:9000/var/www/html/$1
    

    //修改php服务监听方式

    [root@php ~]# vim /etc/php-fpm.d/www.conf
    ; Note: This value is mandatory.
    ;listen = /run/php-fpm/www.sock
    listen = 9000
    
    ; Set listen(2) backlog. A value of '-1' means unlimited.
    ; Default Value: 511
    ;listen.backlog = 511
    

    //使用service模块重启服务

    [root@ansible ansible]# ansible apache -m service -a 'name=httpd state=restarted'
    192.168.126.144 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "name": "httpd", 
        "state": "started", 
        "status": {
            "ActiveEnterTimestamp": "四 2021-07-22 12:20:24 CST", 
            "ActiveEnterTimestampMonotonic": "1242819340", 
            "ActiveExitTimestampMonotonic": "0", 
            "ActiveState": "active", 
            "After": "-.mount system.slice tmp.mount remote-fs.target nss-lookup.target network.target basic.target systemd-journald.socket", 
            "AllowIsolate": "no", 
            "AmbientCapabilities": "0", 
            "AssertResult": "yes", 
            "AssertTimestamp": "四 2021-07-22 12:20:24 CST", 
            "AssertTimestampMonotonic": "1242781584", 
            "Before": "shutdown.target multi-user.target", 
            "BlockIOAccounting": "no", 
            "BlockIOWeight": "18446744073709551615", 
            "CPUAccounting": "no", 
            "CPUQuotaPerSecUSec": "infinity", 
            "CPUSchedulingPolicy": "0", 
            "CPUSchedulingPriority": "0", 
            "CPUSchedulingResetOnFork": "no", 
            "CPUShares": "18446744073709551615", 
            "CanIsolate": "no", 
            "CanReload": "yes", 
            "CanStart": "yes", 
            "CanStop": "yes", 
            "CapabilityBoundingSet": "18446744073709551615", 
            "ConditionResult": "yes", 
            "ConditionTimestamp": "四 2021-07-22 12:20:24 CST", 
            "ConditionTimestampMonotonic": "1242781584", 
            "Conflicts": "shutdown.target", 
            "ControlGroup": "/system.slice/httpd.service", 
            "ControlPID": "0", 
            "DefaultDependencies": "yes", 
            "Delegate": "no", 
            "Description": "The Apache HTTP Server", 
            "DevicePolicy": "auto", 
            "Documentation": "man:httpd(8) man:apachectl(8)", 
            "EnvironmentFile": "/etc/sysconfig/httpd (ignore_errors=no)", 
            "ExecMainCode": "0", 
            "ExecMainExitTimestampMonotonic": "0", 
            "ExecMainPID": "28535", 
            "ExecMainStartTimestamp": "四 2021-07-22 12:20:24 CST", 
            "ExecMainStartTimestampMonotonic": "1242782155", 
            "ExecMainStatus": "0", 
            "ExecReload": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -k graceful ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
            "ExecStart": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -DFOREGROUND ; ignore_errors=no ; start_time=[四 2021-07-22 12:20:24 CST] ; stop_time=[n/a] ; pid=28535 ; code=(null) ; status=0/0 }", 
            "ExecStop": "{ path=/bin/kill ; argv[]=/bin/kill -WINCH ${MAINPID} ; ignore_errors=no ; start_time=[四 2021-07-22 12:18:05 CST] ; stop_time=[四 2021-07-22 12:18:05 CST] ; pid=25482 ; code=exited ; status=1 }", 
            "FailureAction": "none", 
            "FileDescriptorStoreMax": "0", 
            "FragmentPath": "/usr/lib/systemd/system/httpd.service", 
            "GuessMainPID": "yes", 
            "IOScheduling": "0", 
            "Id": "httpd.service", 
            "IgnoreOnIsolate": "no", 
            "IgnoreOnSnapshot": "no", 
            "IgnoreSIGPIPE": "yes", 
            "InactiveEnterTimestamp": "四 2021-07-22 12:18:05 CST", 
            "InactiveEnterTimestampMonotonic": "1103554956", 
            "InactiveExitTimestamp": "四 2021-07-22 12:20:24 CST", 
            "InactiveExitTimestampMonotonic": "1242782184", 
            "JobTimeoutAction": "none", 
            "JobTimeoutUSec": "0", 
            "KillMode": "control-group", 
            "KillSignal": "18", 
            "LimitAS": "18446744073709551615", 
            "LimitCORE": "18446744073709551615", 
            "LimitCPU": "18446744073709551615", 
            "LimitDATA": "18446744073709551615", 
            "LimitFSIZE": "18446744073709551615", 
            "LimitLOCKS": "18446744073709551615", 
            "LimitMEMLOCK": "65536", 
            "LimitMSGQUEUE": "819200", 
            "LimitNICE": "0", 
            "LimitNOFILE": "4096", 
            "LimitNPROC": "7152", 
            "LimitRSS": "18446744073709551615", 
            "LimitRTPRIO": "0", 
            "LimitRTTIME": "18446744073709551615", 
            "LimitSIGPENDING": "7152", 
            "LimitSTACK": "18446744073709551615", 
            "LoadState": "loaded", 
            "MainPID": "28535", 
            "MemoryAccounting": "no", 
            "MemoryCurrent": "18446744073709551615", 
            "MemoryLimit": "18446744073709551615", 
            "MountFlags": "0", 
            "Names": "httpd.service", 
            "NeedDaemonReload": "no", 
            "Nice": "0", 
            "NoNewPrivileges": "no", 
            "NonBlocking": "no", 
            "NotifyAccess": "main", 
            "OOMScoreAdjust": "0", 
            "OnFailureJobMode": "replace", 
            "PermissionsStartOnly": "no", 
            "PrivateDevices": "no", 
            "PrivateNetwork": "no", 
            "PrivateTmp": "yes", 
            "ProtectHome": "no", 
            "ProtectSystem": "no", 
            "RefuseManualStart": "no", 
            "RefuseManualStop": "no", 
            "RemainAfterExit": "no", 
            "Requires": "basic.target -.mount", 
            "RequiresMountsFor": "/var/tmp", 
            "Restart": "no", 
            "RestartUSec": "100ms", 
            "Result": "success", 
            "RootDirectoryStartOnly": "no", 
            "RuntimeDirectoryMode": "0755", 
            "SameProcessGroup": "no", 
            "SecureBits": "0", 
            "SendSIGHUP": "no", 
            "SendSIGKILL": "yes", 
            "Slice": "system.slice", 
            "StandardError": "inherit", 
            "StandardInput": "null", 
            "StandardOutput": "journal", 
            "StartLimitAction": "none", 
            "StartLimitBurst": "5", 
            "StartLimitInterval": "10000000", 
            "StartupBlockIOWeight": "18446744073709551615", 
            "StartupCPUShares": "18446744073709551615", 
            "StatusErrno": "0", 
            "StatusText": "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec", 
            "StopWhenUnneeded": "no", 
            "SubState": "running", 
            "SyslogLevelPrefix": "yes", 
            "SyslogPriority": "30", 
            "SystemCallErrorNumber": "0", 
            "TTYReset": "no", 
            "TTYVHangup": "no", 
            "TTYVTDisallocate": "no", 
            "TasksAccounting": "no", 
            "TasksCurrent": "6", 
            "TasksMax": "18446744073709551615", 
            "TimeoutStartUSec": "1min 30s", 
            "TimeoutStopUSec": "1min 30s", 
            "TimerSlackNSec": "50000", 
            "Transient": "no", 
            "Type": "notify", 
            "UMask": "0022", 
            "UnitFilePreset": "disabled", 
            "UnitFileState": "enabled", 
            "WantedBy": "multi-user.target", 
            "Wants": "system.slice", 
            "WatchdogTimestamp": "四 2021-07-22 12:20:24 CST", 
            "WatchdogTimestampMonotonic": "1242819315", 
            "WatchdogUSec": "0"
        }
    }
    
    [root@ansible ~]# ansible php -m service -a 'name=php-fpm state=restarted'192.168.126.149 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "name": "php-fpm", 
        "state": "started", 
        "status": {
            "ActiveEnterTimestamp": "四 2021-07-22 13:19:09 CST", 
            "ActiveEnterTimestampMonotonic": "409639815", 
            "ActiveExitTimestampMonotonic": "0", 
            "ActiveState": "active", 
            "After": "systemd-journald.socket tmp.mount system.slice -.mount syslog.target network.target basic.target", 
            "AllowIsolate": "no", 
            "AmbientCapabilities": "0", 
            "AssertResult": "yes", 
            "AssertTimestamp": "四 2021-07-22 13:19:09 CST", 
       ~~省略~~
    
    [root@ansible ~]# ansible mysql -m service -a 'name=mariadb state=restarted'
    192.168.126.148 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "name": "mariadb", 
        "state": "started", 
        "status": {
            "ActiveEnterTimestamp": "四 2021-07-22 13:12:30 CST", 
            "ActiveEnterTimestampMonotonic": "12795795", 
            "ActiveExitTimestampMonotonic": "0", 
            "ActiveState": "active", 
            "After": "system.slice syslog.target basic.target -.mount systemd-journald.socket tmp.mount network.target", 
            "AllowIsolate": "no", 
            "AmbientCapabilities": "0", 
            "AssertResult": "yes", 
            "AssertTimestamp": "四 2021-07-22 13:12:26 CST", 
            "AssertTimestampMonotonic": "9286224", 
            "Before": "shutdown.target multi-user.target", 
            "BlockIOAccounting": "no", 
            "BlockIOWeight": "18446744073709551615", 
            "CPUAccounting": "no", 
            "CPUQuotaPerSecUSec": "infinity", 
            "CPUSchedulingPolicy": "0", 
            "CPUSchedulingPriority": "0", 
            "CPUSchedulingResetOnFork": "no", 
            "CPUShares": "18446744073709551615", 
            "CanIsolate": "no", 
    

    访问apache主机的IP

    在这里插入图片描述
    配置文件出问题,但是服务可以使用

    展开全文
  • lamp搭建 环境说明: 服务器类型 ip地址 应用 操作系统 httpd 192.168.159.135 httpd centos7 mysql 192.168.159.132 mysql centos7 php 192.168.159.136 php centos7 安装httpd: # 关闭防火墙和...

    文章目录

    lamp搭建

    环境说明:

    服务器类型ip地址应用操作系统
    httpd192.168.159.135httpdcentos7
    mysql192.168.159.132mysqlcentos7
    php192.168.159.136phpcentos7

    安装httpd:

    # 关闭防火墙和SELINUX
    [root@longnian ~]# systemctl stop firewalld
    [root@longnian ~]# systemctl disable firewalld
    [root@longnian ~]# setenforce 0
    setenforce: SELinux is disabled
    
    # YUM源配置
    [root@longnian ~]# cd /etc/yum.repos.d/
    [root@longnian yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
    [root@longnian yum.repos.d]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
    [root@longnian yum.repos.d]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
    [root@longnian yum.repos.d]# yum -y install epel-release vim
    
    # 安装开发工具包
    [root@longnian ~]# yum groups mark install 'Development Tools'
    
    # 创建apache服务的用户和组
    [root@longnian ~]# groupadd -r apache
    [root@longnian ~]# useradd -r -M -s /sbin/nologin -g apache apache
    
    # 安装依赖包
    [root@longnian ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
    
    # 下载和安装apr以及apr-util
    [root@longnian ~]# cd /usr/src/
    [root@longnian src]# wget http://mirror.bit.edu.cn/apache/apr/apr-1.6.5.tar.gz
    
    [root@longnian src]# wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
    
    [root@longnian src]# ls
    apr-1.6.5.tar.gz       debug    mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
    apr-util-1.6.1.tar.gz  kernels
    [root@longnian src]# tar xf apr-1.6.5.tar.gz 
    [root@longnian src]# tar xf apr-util-1.6.1.tar.gz 
    [root@longnian src]# ls
    apr-1.6.5         apr-util-1.6.1.tar.gz  mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
    apr-1.6.5.tar.gz  debug
    apr-util-1.6.1    kernels
    [root@longnian src]# cd apr-1.6.5
    [root@longnian apr-1.6.5]# vim configure
        cfgfile="${ofile}T"
        trap "$RM \"$cfgfile\"; exit 1" 1 2 15
        # $RM "$cfgfile"
    
    [root@longnian apr-1.6.5]# ./configure --prefix=/usr/local/apr
    
    [root@longnian apr-1.6.5]# make && make install
    
    [root@longnian apr-1.6.5]# cd /usr/src/apr-util-1.6.1
    [root@longnian apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    
    [root@longnian apr-util-1.6.1]# make && make install
    
    # 编译安装httpd
    [root@longnian ~]# cd /usr/src
    [root@longnian ~]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.43.tar.gz
    
    
    
    [root@longnian ~]# ls
    httpd-2.4.43.tar.gz
    [root@longnian ~]# tar xf httpd-2.4.43.tar.gz
    [root@longnian ~]# cd httpd-2.4.43
    [root@longnian httpd-2.4.43]# ./configure --prefix=/usr/local/apache \
    --sysconfdir=/etc/httpd24 \
    --enable-so \
    --enable-ssl \
    --enable-cgi \
    --enable-rewrite \
    --with-zlib \
    --with-pcre \
    --with-apr=/usr/local/apr \
    --with-apr-util=/usr/local/apr-util/ \
    --enable-modules=most \
    --enable-mpms-shared=all \
    --with-mpm=prefork
    
    [root@longnian httpd-2.4.43]# make && make install
    
    # 安装后配置
    [root@longnian ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
    [root@longnian ~]# source /etc/profile.d/httpd.sh
    [root@longnian ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
    [root@longnian ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config
    
    # 取消ServerName前面的注释
    [root@longnian ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf 
    
    # 启动apache
    [root@longnian ~]# apachectl start
    [root@longnian ~]# ss -anlt
    State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
    LISTEN      0      128             *:111                         *:*                  
    LISTEN      0      128             *:20048                       *:*                  
    LISTEN      0      128             *:22                          *:*                  
    LISTEN      0      100     127.0.0.1:25                          *:*                  
    LISTEN      0      128             *:3260                        *:*                  
    LISTEN      0      64              *:59680                       *:*                  
    LISTEN      0      64              *:2049                        *:*                  
    LISTEN      0      128             *:43943                       *:*                  
    LISTEN      0      64             :::38029                      :::*                  
    LISTEN      0      128            :::54030                      :::*                  
    LISTEN      0      128            :::111                        :::*                  
    LISTEN      0      128            :::80                         :::*                  
    LISTEN      0      128            :::20048                      :::*                  
    LISTEN      0      32             :::21                         :::*                  
    LISTEN      0      128            :::22                         :::*                  
    LISTEN      0      100           ::1:25                         :::*                  
    LISTEN      0      128            :::3260                       :::*                  
    LISTEN      0      64             :::2049                       :::*
    

    安装mysql:

    # 关闭防火墙和SELINUX
    [root@longnian ~]# systemctl stop firewalld
    [root@longnian ~]# systemctl disable firewalld
    Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
    Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
    [root@longnian ~]# setenforce 0
    setenforce: SELinux is disabled
    
    # 安装依赖包
    [root@longnian ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
    
    # 创建用户和组
    [root@longnian src]# groupadd -r -g 306 mysql
    [root@longnian src]# useradd -r -M -s /sbin/nologin -g 306 -u 306 mysql
    
    
    # 下载二进制格式的mysql软件包
    [root@longnian ~]# cd /usr/src/
    [root@longnian src]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
    
    # 解压软件至/usr/local/
    [root@longnian src]# ls
    debug  kernels  mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
    [root@longnian src]# tar xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
    [root@longnian ~]# ls /usr/local/
    bin  games    lib    libexec                              sbin   src
    etc  include  lib64  mysql-5.7.24-linux-glibc2.12-x86_64  share
    [root@longnian ~]# cd /usr/local/
    [root@longnian local]# ln -sv mysql-5.7.24-linux-glibc2.12-x86_64/ mysql
    ‘mysql’ -> ‘mysql-5.7.24-linux-glibc2.12-x86_64/’
    [root@longnian local]# ll
    总用量 0
    drwxr-xr-x. 2 root root   6 8月  12 2015 bin
    drwxr-xr-x. 2 root root   6 8月  12 2015 etc
    drwxr-xr-x. 2 root root   6 8月  12 2015 games
    drwxr-xr-x. 2 root root   6 8月  12 2015 include
    drwxr-xr-x. 2 root root   6 8月  12 2015 lib
    drwxr-xr-x. 2 root root   6 8月  12 2015 lib64
    drwxr-xr-x. 2 root root   6 8月  12 2015 libexec
    lrwxrwxrwx  1 root root  36 6月  17 05:47 mysql -> mysql-5.7.24-linux-glibc2.12-x86_64/
    drwxr-xr-x  9 root root 120 6月  17 03:44 mysql-5.7.24-linux-glibc2.12-x86_64
    drwxr-xr-x. 2 root root   6 8月  12 2015 sbin
    drwxr-xr-x. 5 root root  46 4月  26 19:28 share
    drwxr-xr-x. 2 root root   6 8月  12 2015 src
    
    
    # 修改目录/usr/local/mysql的属主属组
    [root@longnian ~]# chown -R mysql.mysql /usr/local/mysql
    [root@longnian local]# ll /usr/local/mysql -d
    lrwxrwxrwx 1 mysql mysql 36 6月  17 05:47 /usr/local/mysql -> mysql-5.7.24-linux-glibc2.12-x86_64/
    
    
    
    # 添加环境变量
    [root@longnian ~]# ls /usr/local/mysql
    bin  COPYING  docs  include  lib  man  README  share  support-files
    [root@longnian ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
    [root@longnian ~]# . /etc/profile.d/mysql.sh
    [root@longnian ~]# echo $PATH
    /usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    
    
    
    # 建立数据存放目录
    [root@longnian mysql]# mkdir /opt/data
    [root@longnian mysql]# chown -R mysql.mysql /opt/data/
    [root@longnian local]# ll /opt/
    总用量 0
    drwxr-xr-x 2 mysql mysql 6 6月  17 05:49 data
    
    
    
    # 初始化数据库
    [root@longnian ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
    2020-06-16T21:50:40.761225Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2020-06-16T21:50:40.958277Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2020-06-16T21:50:41.021566Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2020-06-16T21:50:41.084252Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 6c01283b-b01b-11ea-a2e8-000c294a7e86.
    2020-06-16T21:50:41.085737Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2020-06-16T21:50:41.099008Z 1 [Note] A temporary password is generated for root@localhost: 6E5po9tuj_qI
    # 请注意,这个命令的最后会生成一个临时密码,此处密码是6E5po9tuj_qI
    
    
    # 配置mysql
    [root@longnian ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
    ‘/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
    [root@longnian ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
    [root@longnian ~]# ldconfig      
    
    # 生成配置文件
    [root@longnian ~]# cat > /etc/my.cnf <<EOF
    [mysqld]
    basedir = /usr/local/mysql
    datadir = /opt/data
    socket = /tmp/mysql.sock
    port = 3306
    pid-file = /opt/data/mysql.pid
    user = mysql
    skip-name-resolve
    EOF
    
    
    # 配置服务启动脚本
    [root@longnian ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    [root@longnian ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
    [root@longnian ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld
    
    
    
    # 启动mysql
    [root@longnian ~]# service mysqld start
    Starting MySQL.. SUCCESS!  
    [root@longnian ~]# ss -anlt
    State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
    LISTEN      0      64              *:39946                       *:*                  
    LISTEN      0      128             *:111                         *:*                  
    LISTEN      0      128             *:20048                       *:*                  
    LISTEN      0      128             *:22                          *:*                  
    LISTEN      0      128             *:34360                       *:*                  
    LISTEN      0      100     127.0.0.1:25                          *:*                  
    LISTEN      0      128             *:3260                        *:*                  
    LISTEN      0      64              *:2049                        *:*                  
    LISTEN      0      80             :::3306                       :::*                  
    LISTEN      0      64             :::43533                      :::*                  
    LISTEN      0      128            :::111                        :::*                  
    LISTEN      0      128            :::20048                      :::*                  
    LISTEN      0      128            :::60469                      :::*                  
    LISTEN      0      128            :::22                         :::*                  
    LISTEN      0      100           ::1:25                         :::*                  
    LISTEN      0      128            :::3260                       :::*                  
    LISTEN      0      64             :::2049                       :::*
     
     
    
    # 修改密码
    # 使用临时密码登录
    [root@longnian ~]# mysql -uroot -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.7.22
    
    Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> 
    
    # 设置新密码
    mysql> set password = password('longnian123.');
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    mysql> quit
    Bye
    

    安装php:

    # 关闭防火墙和SELINUX
    [root@longnian ~]# systemctl stop firewalld
    [root@longnian ~]# systemctl disable firewalld
    [root@longnian ~]# getenforce 
    Disabled
    
    # 配置yum源
    [root@longnian ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    [root@longnian ~]# rpm -Uvh remi-release-7.rpm
    [root@longnian ~]# yum makecache --enablerepo=remi-php74
    
    # 安装依赖包
    [root@longnian ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php72-php-mysqlnd
    
    # 下载php
    [root@longnian ~]# cd /usr/src/
    [root@longnian src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
    下载过程略....
    
    
    # 编译安装php
    [root@longnian src]# tar xf php-7.2.8.tar.xz
    [root@longnian src]# cd php-7.2.8
    [root@longnian php-7.2.8]# ./configure --prefix=/usr/local/php7  \
    --with-config-file-path=/etc \
    --enable-fpm \
    --enable-inline-optimization \
    --disable-debug \
    --disable-rpath \
    --enable-shared \
    --enable-soap \
    --with-openssl \
    --enable-bcmath \
    --with-iconv \
    --with-bz2 \
    --enable-calendar \
    --with-curl \
    --enable-exif  \
    --enable-ftp \
    --with-gd \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib-dir \
    --with-freetype-dir \
    --with-gettext \
    --enable-json \
    --enable-mbstring \
    --enable-pdo \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --with-readline \
    --enable-shmop \
    --enable-simplexml \
    --enable-sockets \
    --enable-zip \
    --enable-mysqlnd-compression-support \
    --with-pear \
    --enable-pcntl \
    --enable-posix
    [root@longnian php-7.2.8]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
    
    [root@longnian php-7.2.8]# make install
    
    # 安装后配置
    [root@longnian ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
    [root@longnian ~]# source /etc/profile.d/php7.sh
    [root@longnian php-7.2.8]# which php
    /usr/local/php7/bin/php
    
    # 配置php-fpm
    [root@longnian php-7.2.8]# cp php.ini-production /etc/php.ini
    [root@longnian php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    [root@longnian php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
    [root@longnian php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
    [root@longnian php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
    
    # 编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf):
    # 配置fpm的相关选项为你所需要的值:
    [root@longnian ~]# vim /usr/local/php7/etc/php-fpm.conf
    .....
    .....
    pm.max_children = 50    ;最多同时提供50个进程提供50个并发服务
    pm.start_servers = 5    ;启动时启动5个进程
    pm.min_spare_servers = 2    ;最小空闲进程数
    pm.max_spare_servers = 8    ;最大空闲进程数
    
    [root@longnian ~]# tail /usr/local/php7/etc/php-fpm.conf
    ; file.
    ; Relative path can also be used. They will be prefixed by:
    ;  - the global prefix if it's been set (-p argument)
    ;  - /usr/local/php7 otherwise
    include=/usr/local/php7/etc/php-fpm.d/*.conf
    pm.max_children = 50
    pm.start_servers = 5
    pm.min_spare_servers = 2
    pm.max_spare_servers = 8
    
    
    
    # 启动php-fpm
    [root@longnian ~]# service php-fpm start
    Starting php-fpm  done
    
    # 默认情况下,fpm监听在127.0.0.1的9000端口,也可以使用如下命令验证其是否已经监听在相应的套接字
    [root@longnian ~]# ss -anlt
    State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
    LISTEN      0      128     127.0.0.1:9000                        *:*                  
    LISTEN      0      64              *:39946                       *:*                  
    LISTEN      0      128             *:111                         *:*                  
    LISTEN      0      128             *:20048                       *:*                  
    LISTEN      0      128             *:22                          *:*                  
    LISTEN      0      128             *:34360                       *:*                  
    LISTEN      0      100     127.0.0.1:25                          *:*                  
    LISTEN      0      128             *:3260                        *:*                  
    LISTEN      0      64              *:2049                        *:*                  
    LISTEN      0      64             :::43533                      :::*                  
    LISTEN      0      128            :::111                        :::*                  
    LISTEN      0      128            :::20048                      :::*                  
    LISTEN      0      128            :::60469                      :::*                  
    LISTEN      0      128            :::22                         :::*                  
    LISTEN      0      100           ::1:25                         :::*                  
    LISTEN      0      128            :::3260                       :::*                  
    LISTEN      0      64             :::2049                       :::*
    

    httpd,mysql,php安装完成后做以下操作:
    httpd服务端:

    # 启用代理模块
    [root@longnian ~]# sed -i '/proxy_module/s/#//g' /etc/httpd24/httpd.conf
    [root@longnian ~]# sed -i '/proxy_fcgi_module/s/#//g' /etc/httpd24/httpd.conf
    
    # 编辑配置文件添加以下内容
    [root@longnian ~]# vim /etc/httpd24/httpd.conf
    <VirtualHost *:80>
        DocumentRoot "/usr/local/apache/htdocs/"
        ServerName www.longniand.com
        ProxyRequests Off
        ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.159.136:9000/usr/local/apache/htdocs/$1
        <Directory "/usr/local/apache/htdocs/">
            Options none
            AllowOverride none
            Require all granted
        </Directory>
    </VirtualHost>
    
    # 搜索AddType,添加以下内容
    	AddType application/x-compress .Z
        AddType application/x-gzip .gz .tgz
        AddType application/x-httpd-php .php       		# 添加此行
        AddType application/x-httpd-php-source .phps        # 添加此行
    
    [root@longnian htdocs]# sed -i '/    DirectoryIndex/s/index.html/index.php index.html/g' /etc/httpd24/httpd.conf   
    # 做完上面的操作后保存退出
    

    php服务端:

    # 修改php-fpm的配置文件 
    [root@longnian ~]# vim /usr/local/php7/etc/php-fpm.d/www.conf
    listen = 192.168.159.136:9000		# 找到此行将自己的ip地址监听
    ;listen.allowed_clients = 192.168.159.135		#找到此行将httpd地址设置可访问
    # 保存退出
    
    # 创建根目录
    [root@longnian ~]# cd /usr/local/apache/htdocs
    [root@longnian htdocs]# vim index.php
    <?php
        phpinfo();
    ?>
    

    重启httpd服务和php服务

    [root@longnian ~]# service php-fpm restart
    Gracefully shutting down php-fpm . done
    Starting php-fpm  done
    
    [root@longnian ~]# apachectl stop
    [root@longnian ~]# apachectl start
    

    添加hosts文件

    windows端:
    C:\Windows\System32\drivers\etc\hosts
    添加:192.168.159.135      www.longniand.com
    

    验证

    展开全文

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 4,287
精华内容 1,714
关键字:

lamp分离部署