zoukankan      html  css  js  c++  java
  • Httpd服务进阶知识-基于FASTCGI实现的LAMP架构

              Httpd服务进阶知识-基于FASTCGI实现的LAMP架构

                                                    作者:尹正杰

    版权声明:原创作品,谢绝转载!否则将追究法律责任。

    一.httpd+php结合的方式

    module: php
    
    fastcgi : php-fpm
    
    
    php-fpm:
        CentOS 6:
        PHP-5.3.2之前:默认不支持fpm机制;需要自行打补丁并编译安装
        httpd-2.2:默认不支持fcgi协议,需要自行编译此模块
        解决方案:编译安装httpd-2.4, php-5.3.3+
    CentOS 7:     httpd-2.4:rpm包默认编译支持fcgi模块     php-fpm包:专用于将php运行于fpm模式

    二.配置fastcgi实验准备

    1>.虚拟机配置

    [root@node101.yinzhengjie.org.cn ~]# cat /etc/redhat-release 
    CentOS Linux release 7.6.1810 (Core) 
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# uname -r
    3.10.0-957.el7.x86_64
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# uname -m
    x86_64
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# free -h
                  total        used        free      shared  buff/cache   available
    Mem:           3.7G        694M        1.4G         20M        1.6G        2.7G
    Swap:          3.9G          0B        3.9G
    [root@node101.yinzhengjie.org.cn ~]# 

    2>.角色分配

    node101.yinzhengjie.org.cn:
      HTTPD服务器
    
    node102.yinzhengjie.org.cn:
      FASTCGI服务器
     
    node103.yinzhengjie.org.cn:
      MariaDB服务器

     

    三.基于FASTCGI方式实现连接数据库案例实战

    1>.node101.yinzhengjie.org.cn节点操作

    [root@node101.yinzhengjie.org.cn ~]# yum -y install  httpd 
    Loaded plugins: fastestmirror
    Determining fastest mirrors
     * base: mirror.bit.edu.cn
     * extras: mirror.bit.edu.cn
     * updates: mirrors.huaweicloud.com
    base                                                                                                                                                 | 3.6 kB  00:00:00     
    extras                                                                                                                                               | 2.9 kB  00:00:00     
    updates                                                                                                                                              | 2.9 kB  00:00:00     
    (1/4): base/7/x86_64/group_gz                                                                                                                        | 165 kB  00:00:00     
    (2/4): extras/7/x86_64/primary_db                                                                                                                    | 153 kB  00:00:00     
    (3/4): updates/7/x86_64/primary_db                                                                                                                   | 5.8 MB  00:00:00     
    (4/4): base/7/x86_64/primary_db                                                                                                                      | 6.0 MB  00:00:03     
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.x86_64 0:2.4.6-90.el7.centos will be installed
    --> Processing Dependency: httpd-tools = 2.4.6-90.el7.centos for package: httpd-2.4.6-90.el7.centos.x86_64
    --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-90.el7.centos.x86_64
    --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-90.el7.centos.x86_64
    --> Running transaction check
    ---> Package apr.x86_64 0:1.4.8-5.el7 will be installed
    ---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
    ---> Package httpd-tools.x86_64 0:2.4.6-90.el7.centos will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ============================================================================================================================================================================
     Package                                   Arch                                 Version                                            Repository                          Size
    ============================================================================================================================================================================
    Installing:
     httpd                                     x86_64                               2.4.6-90.el7.centos                                base                               2.7 M
    Installing for dependencies:
     apr                                       x86_64                               1.4.8-5.el7                                        base                               103 k
     apr-util                                  x86_64                               1.5.2-6.el7                                        base                                92 k
     httpd-tools                               x86_64                               2.4.6-90.el7.centos                                base                                91 k
    
    Transaction Summary
    ============================================================================================================================================================================
    Install  1 Package (+3 Dependent packages)
    
    Total download size: 3.0 M
    Installed size: 9.9 M
    Downloading packages:
    (1/4): apr-util-1.5.2-6.el7.x86_64.rpm                                                                                                               |  92 kB  00:00:00     
    (2/4): apr-1.4.8-5.el7.x86_64.rpm                                                                                                                    | 103 kB  00:00:01     
    (3/4): httpd-2.4.6-90.el7.centos.x86_64.rpm                                                                                                          | 2.7 MB  00:00:01     
    (4/4): httpd-tools-2.4.6-90.el7.centos.x86_64.rpm                                                                                                    |  91 kB  00:00:00     
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Total                                                                                                                                       1.7 MB/s | 3.0 MB  00:00:01     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : apr-1.4.8-5.el7.x86_64                                                                                                                                   1/4 
      Installing : apr-util-1.5.2-6.el7.x86_64                                                                                                                              2/4 
      Installing : httpd-tools-2.4.6-90.el7.centos.x86_64                                                                                                                   3/4 
      Installing : httpd-2.4.6-90.el7.centos.x86_64                                                                                                                         4/4 
      Verifying  : apr-1.4.8-5.el7.x86_64                                                                                                                                   1/4 
      Verifying  : httpd-tools-2.4.6-90.el7.centos.x86_64                                                                                                                   2/4 
      Verifying  : apr-util-1.5.2-6.el7.x86_64                                                                                                                              3/4 
      Verifying  : httpd-2.4.6-90.el7.centos.x86_64                                                                                                                         4/4 
    
    Installed:
      httpd.x86_64 0:2.4.6-90.el7.centos                                                                                                                                        
    
    Dependency Installed:
      apr.x86_64 0:1.4.8-5.el7                          apr-util.x86_64 0:1.5.2-6.el7                          httpd-tools.x86_64 0:2.4.6-90.el7.centos                         
    
    Complete!
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# yum -y install httpd
    [root@node101.yinzhengjie.org.cn ~]# vim /etc/httpd/conf.d/fcgi.conf
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# cat /etc/httpd/conf.d/fcgi.conf                                  #编辑配置文件将动态资源内容交给fastcgi服务器处理
    DirectoryIndex index.php
    ProxyRequests Off
    ProxyPassMatch ^/(.*.php)$ fcgi://172.30.1.102:9000/data/html/$1
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# echo "172.30.1.101 node101.yinzhengjie.org.cn" > /var/www/html/index.html          #设置静态页面内容
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# systemctl start httpd
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# ss -ntl
    State      Recv-Q Send-Q                                         Local Address:Port                                                        Peer Address:Port              
    LISTEN     0      128                                                        *:80                                                                     *:*                  
    LISTEN     0      128                                                        *:22                                                                     *:*                  
    LISTEN     0      128                                                       :::22                                                                    :::*                  
    [root@node101.yinzhengjie.org.cn ~]# 

    2>.node102.yinzhengjie.org.cn节点操作

    [root@node102.yinzhengjie.org.cn ~]# yum -y install php-fpm php-mysql
    Loaded plugins: fastestmirror
    Determining fastest mirrors
     * base: mirror.bit.edu.cn
     * extras: mirror.bit.edu.cn
     * updates: mirror.jdcloud.com
    base                                                                                                                      | 3.6 kB  00:00:00     
    extras                                                                                                                    | 2.9 kB  00:00:00     
    updates                                                                                                                   | 2.9 kB  00:00:00     
    (1/4): base/7/x86_64/group_gz                                                                                             | 165 kB  00:00:00     
    (2/4): extras/7/x86_64/primary_db                                                                                         | 153 kB  00:00:00     
    (3/4): updates/7/x86_64/primary_db                                                                                        | 5.8 MB  00:00:00     
    (4/4): base/7/x86_64/primary_db                                                                                           | 6.0 MB  00:00:06     
    Resolving Dependencies
    --> Running transaction check
    ---> Package php-fpm.x86_64 0:5.4.16-46.1.el7_7 will be installed
    --> Processing Dependency: php-common(x86-64) = 5.4.16-46.1.el7_7 for package: php-fpm-5.4.16-46.1.el7_7.x86_64
    ---> Package php-mysql.x86_64 0:5.4.16-46.1.el7_7 will be installed
    --> Processing Dependency: php-pdo(x86-64) = 5.4.16-46.1.el7_7 for package: php-mysql-5.4.16-46.1.el7_7.x86_64
    --> Running transaction check
    ---> Package php-common.x86_64 0:5.4.16-46.1.el7_7 will be installed
    --> Processing Dependency: libzip.so.2()(64bit) for package: php-common-5.4.16-46.1.el7_7.x86_64
    ---> Package php-pdo.x86_64 0:5.4.16-46.1.el7_7 will be installed
    --> Running transaction check
    ---> Package libzip.x86_64 0:0.10.1-8.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =================================================================================================================================================
     Package                           Arch                          Version                                    Repository                      Size
    =================================================================================================================================================
    Installing:
     php-fpm                           x86_64                        5.4.16-46.1.el7_7                          updates                        1.4 M
     php-mysql                         x86_64                        5.4.16-46.1.el7_7                          updates                        101 k
    Installing for dependencies:
     libzip                            x86_64                        0.10.1-8.el7                               base                            48 k
     php-common                        x86_64                        5.4.16-46.1.el7_7                          updates                        565 k
     php-pdo                           x86_64                        5.4.16-46.1.el7_7                          updates                         99 k
    
    Transaction Summary
    =================================================================================================================================================
    Install  2 Packages (+3 Dependent packages)
    
    Total download size: 2.2 M
    Installed size: 8.8 M
    Downloading packages:
    (1/5): php-common-5.4.16-46.1.el7_7.x86_64.rpm                                                                            | 565 kB  00:00:00     
    (2/5): php-fpm-5.4.16-46.1.el7_7.x86_64.rpm                                                                               | 1.4 MB  00:00:00     
    (3/5): php-mysql-5.4.16-46.1.el7_7.x86_64.rpm                                                                             | 101 kB  00:00:00     
    (4/5): php-pdo-5.4.16-46.1.el7_7.x86_64.rpm                                                                               |  99 kB  00:00:00     
    (5/5): libzip-0.10.1-8.el7.x86_64.rpm                                                                                     |  48 kB  00:00:00     
    -------------------------------------------------------------------------------------------------------------------------------------------------
    Total                                                                                                            5.7 MB/s | 2.2 MB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : libzip-0.10.1-8.el7.x86_64                                                                                                    1/5 
      Installing : php-common-5.4.16-46.1.el7_7.x86_64                                                                                           2/5 
      Installing : php-pdo-5.4.16-46.1.el7_7.x86_64                                                                                              3/5 
      Installing : php-mysql-5.4.16-46.1.el7_7.x86_64                                                                                            4/5 
      Installing : php-fpm-5.4.16-46.1.el7_7.x86_64                                                                                              5/5 
      Verifying  : php-common-5.4.16-46.1.el7_7.x86_64                                                                                           1/5 
      Verifying  : libzip-0.10.1-8.el7.x86_64                                                                                                    2/5 
      Verifying  : php-pdo-5.4.16-46.1.el7_7.x86_64                                                                                              3/5 
      Verifying  : php-mysql-5.4.16-46.1.el7_7.x86_64                                                                                            4/5 
      Verifying  : php-fpm-5.4.16-46.1.el7_7.x86_64                                                                                              5/5 
    
    Installed:
      php-fpm.x86_64 0:5.4.16-46.1.el7_7                                     php-mysql.x86_64 0:5.4.16-46.1.el7_7                                    
    
    Dependency Installed:
      libzip.x86_64 0:0.10.1-8.el7               php-common.x86_64 0:5.4.16-46.1.el7_7               php-pdo.x86_64 0:5.4.16-46.1.el7_7              
    
    Complete!
    [root@node102.yinzhengjie.org.cn ~]#
    [root@node102.yinzhengjie.org.cn ~]# yum -y install php-fpm php-mysql
    [root@node102.yinzhengjie.org.cn ~]# rpm -ql php-fpm
    /etc/logrotate.d/php-fpm
    /etc/php-fpm.conf
    /etc/php-fpm.d
    /etc/php-fpm.d/www.conf
    /etc/sysconfig/php-fpm
    /run/php-fpm
    /usr/lib/systemd/system/php-fpm.service
    /usr/lib/tmpfiles.d/php-fpm.conf
    /usr/sbin/php-fpm
    /usr/share/doc/php-fpm-5.4.16
    /usr/share/doc/php-fpm-5.4.16/fpm_LICENSE
    /usr/share/doc/php-fpm-5.4.16/php-fpm.conf.default
    /usr/share/fpm
    /usr/share/fpm/status.html
    /usr/share/man/man8/php-fpm.8.gz
    /var/log/php-fpm
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# rpm -ql php-fpm                #查看php-fpm软件包安装了哪些文件
    [root@node102.yinzhengjie.org.cn ~]# rpm -q --scripts php-fpm
    preinstall scriptlet (using /bin/sh):
    # Add the "apache" user as we don't require httpd
    getent group  apache >/dev/null || 
      groupadd -g 48 -r apache
    getent passwd apache >/dev/null || 
      useradd -r -u 48 -g apache -s /sbin/nologin 
        -d /usr/share/httpd -c "Apache" apache
    exit 0
    postinstall scriptlet (using /bin/sh):
    
    if [ $1 -eq 1 ] ; then 
            # Initial installation 
            systemctl preset php-fpm.service >/dev/null 2>&1 || : 
    fi
    preuninstall scriptlet (using /bin/sh):
    
    if [ $1 -eq 0 ] ; then 
            # Package removal, not upgrade 
            systemctl --no-reload disable php-fpm.service > /dev/null 2>&1 || : 
            systemctl stop php-fpm.service > /dev/null 2>&1 || : 
    fi
    postuninstall scriptlet (using /bin/sh):
    
    systemctl daemon-reload >/dev/null 2>&1 || : 
    if [ $1 -ge 1 ] ; then 
            # Package upgrade, not uninstall 
            systemctl try-restart php-fpm.service >/dev/null 2>&1 || : 
    fi 
    
    
    # Handle upgrading from SysV initscript to native systemd unit.
    # We can tell if a SysV version of php-fpm was previously installed by
    # checking to see if the initscript is present.
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# rpm -q --scripts php-fpm          #安装php-fpm服务会做一些初始化配置,比如创建apache用户等
    [root@node102.yinzhengjie.org.cn ~]# egrep -v "^;|^ *$" /etc/php-fpm.d/www.conf
    [www]
    listen = 127.0.0.1:9000                              #监听IP地址需要修改哟
    listen.allowed_clients = 127.0.0.1                   #将这一行使用";"进行注释掉,它表示允许访问的客户端,注释它后允许所有客户端访问。
    user = apache
    group = apache
    pm = dynamic
    pm.max_children = 50
    pm.start_servers = 5
    pm.min_spare_servers = 5
    pm.max_spare_servers = 35
    slowlog = /var/log/php-fpm/www-slow.log
    php_admin_value[error_log] = /var/log/php-fpm/www-error.log
    php_admin_flag[log_errors] = on
    php_value[session.save_handler] = files
    php_value[session.save_path] = /var/lib/php/session
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# vim /etc/php-fpm.d/www.conf 
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# egrep -v "^;|^ *$" /etc/php-fpm.d/www.conf
    [www]
    listen = 9000
    user = apache
    group = apache
    pm = dynamic
    pm.max_children = 50
    pm.start_servers = 5
    pm.min_spare_servers = 5
    pm.max_spare_servers = 35
    slowlog = /var/log/php-fpm/www-slow.log
    php_admin_value[error_log] = /var/log/php-fpm/www-error.log
    php_admin_flag[log_errors] = on
    php_value[session.save_handler] = files
    php_value[session.save_path] = /var/lib/php/session
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# vim /etc/php-fpm.d/www.conf         #修改配置文件
    [root@node102.yinzhengjie.org.cn ~]# ss -ntl
    State       Recv-Q Send-Q                           Local Address:Port                                          Peer Address:Port              
    LISTEN      0      128                                          *:22                                                       *:*                  
    LISTEN      0      128                                         :::22                                                      :::*                  
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# systemctl start php-fpm
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# ss -ntl
    State       Recv-Q Send-Q                           Local Address:Port                                          Peer Address:Port              
    LISTEN      0      128                                          *:9000                                                     *:*                  
    LISTEN      0      128                                          *:22                                                       *:*                  
    LISTEN      0      128                                         :::22                                                      :::*                  
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# systemctl start php-fpm            #启动php-fpm服务
    [root@node102.yinzhengjie.org.cn ~]# mkdir /data/html -pv
    mkdir: created directory ‘/data’
    mkdir: created directory ‘/data/html’
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# vim /data/html/pdo2.php
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# cat /data/html/pdo2.php
    <?php
    try {
    $user='jason';
    $pass='yinzhengjie';
    $dbh = new PDO('mysql:host=172.30.1.103;dbname=mysql', $user, $pass);
    
    foreach($dbh->query('SELECT user,host,password from user') as $row) {
        print_r($row);
    }
    
    $dbh = null;
    } catch (PDOException $e) {
        print "Error!: ". $e->getMessage(). "<br/>";
        die();
    }
    ?>
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# ll /data/html/
    total 4
    -rw-r--r-- 1 root root 317 Dec 12 12:54 pdo2.php
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# cat /data/html/pdo2.php            #编写php连接数据库的测试代码

    3>.node103.yinzhengjie.org.cn节点操作

    [root@node103.yinzhengjie.org.cn ~]# yum -y install mariadb-server
    Loaded plugins: fastestmirror
    Determining fastest mirrors
     * base: mirror.bit.edu.cn
     * extras: mirror.bit.edu.cn
     * updates: mirror.jdcloud.com
    base                                                                                                                      | 3.6 kB  00:00:00     
    extras                                                                                                                    | 2.9 kB  00:00:00     
    updates                                                                                                                   | 2.9 kB  00:00:00     
    (1/4): base/7/x86_64/primary_db                                                                                           | 6.0 MB  00:00:00     
    (2/4): base/7/x86_64/group_gz                                                                                             | 165 kB  00:00:00     
    (3/4): extras/7/x86_64/primary_db                                                                                         | 153 kB  00:00:00     
    (4/4): updates/7/x86_64/primary_db                                                                                        | 5.8 MB  00:00:00     
    Resolving Dependencies
    --> Running transaction check
    ---> Package mariadb-server.x86_64 1:5.5.64-1.el7 will be installed
    --> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.64-1.el7 for package: 1:mariadb-server-5.5.64-1.el7.x86_64
    --> Processing Dependency: mariadb(x86-64) = 1:5.5.64-1.el7 for package: 1:mariadb-server-5.5.64-1.el7.x86_64
    --> Processing Dependency: perl-DBI for package: 1:mariadb-server-5.5.64-1.el7.x86_64
    --> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.64-1.el7.x86_64
    --> Processing Dependency: perl(DBI) for package: 1:mariadb-server-5.5.64-1.el7.x86_64
    --> Running transaction check
    ---> Package mariadb.x86_64 1:5.5.64-1.el7 will be installed
    ---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be updated
    ---> Package mariadb-libs.x86_64 1:5.5.64-1.el7 will be an update
    ---> Package perl-DBD-MySQL.x86_64 0:4.023-6.el7 will be installed
    ---> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed
    --> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.627-4.el7.x86_64
    --> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.627-4.el7.x86_64
    --> Running transaction check
    ---> Package perl-PlRPC.noarch 0:0.2020-14.el7 will be installed
    --> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-14.el7.noarch
    --> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-14.el7.noarch
    --> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-14.el7.noarch
    --> Running transaction check
    ---> Package perl-Net-Daemon.noarch 0:0.48-5.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =================================================================================================================================================
     Package                                Arch                          Version                                  Repository                   Size
    =================================================================================================================================================
    Installing:
     mariadb-server                         x86_64                        1:5.5.64-1.el7                           base                         11 M
    Installing for dependencies:
     mariadb                                x86_64                        1:5.5.64-1.el7                           base                        8.7 M
     perl-DBD-MySQL                         x86_64                        4.023-6.el7                              base                        140 k
     perl-DBI                               x86_64                        1.627-4.el7                              base                        802 k
     perl-Net-Daemon                        noarch                        0.48-5.el7                               base                         51 k
     perl-PlRPC                             noarch                        0.2020-14.el7                            base                         36 k
    Updating for dependencies:
     mariadb-libs                           x86_64                        1:5.5.64-1.el7                           base                        759 k
    
    Transaction Summary
    =================================================================================================================================================
    Install  1 Package  (+5 Dependent packages)
    Upgrade             ( 1 Dependent package)
    
    Total download size: 22 M
    Downloading packages:
    Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
    (1/7): mariadb-libs-5.5.64-1.el7.x86_64.rpm                                                                               | 759 kB  00:00:00     
    (2/7): mariadb-5.5.64-1.el7.x86_64.rpm                                                                                    | 8.7 MB  00:00:00     
    (3/7): perl-DBD-MySQL-4.023-6.el7.x86_64.rpm                                                                              | 140 kB  00:00:00     
    (4/7): perl-DBI-1.627-4.el7.x86_64.rpm                                                                                    | 802 kB  00:00:00     
    (5/7): perl-Net-Daemon-0.48-5.el7.noarch.rpm                                                                              |  51 kB  00:00:00     
    (6/7): perl-PlRPC-0.2020-14.el7.noarch.rpm                                                                                |  36 kB  00:00:00     
    (7/7): mariadb-server-5.5.64-1.el7.x86_64.rpm                                                                             |  11 MB  00:00:02     
    -------------------------------------------------------------------------------------------------------------------------------------------------
    Total                                                                                                            7.4 MB/s |  22 MB  00:00:02     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Updating   : 1:mariadb-libs-5.5.64-1.el7.x86_64                                                                                            1/8 
      Installing : 1:mariadb-5.5.64-1.el7.x86_64                                                                                                 2/8 
      Installing : perl-Net-Daemon-0.48-5.el7.noarch                                                                                             3/8 
      Installing : perl-PlRPC-0.2020-14.el7.noarch                                                                                               4/8 
      Installing : perl-DBI-1.627-4.el7.x86_64                                                                                                   5/8 
      Installing : perl-DBD-MySQL-4.023-6.el7.x86_64                                                                                             6/8 
      Installing : 1:mariadb-server-5.5.64-1.el7.x86_64                                                                                          7/8 
      Cleanup    : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                                          8/8 
      Verifying  : 1:mariadb-libs-5.5.64-1.el7.x86_64                                                                                            1/8 
      Verifying  : perl-Net-Daemon-0.48-5.el7.noarch                                                                                             2/8 
      Verifying  : 1:mariadb-5.5.64-1.el7.x86_64                                                                                                 3/8 
      Verifying  : perl-DBD-MySQL-4.023-6.el7.x86_64                                                                                             4/8 
      Verifying  : 1:mariadb-server-5.5.64-1.el7.x86_64                                                                                          5/8 
      Verifying  : perl-DBI-1.627-4.el7.x86_64                                                                                                   6/8 
      Verifying  : perl-PlRPC-0.2020-14.el7.noarch                                                                                               7/8 
      Verifying  : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                                          8/8 
    
    Installed:
      mariadb-server.x86_64 1:5.5.64-1.el7                                                                                                           
    
    Dependency Installed:
      mariadb.x86_64 1:5.5.64-1.el7       perl-DBD-MySQL.x86_64 0:4.023-6.el7   perl-DBI.x86_64 0:1.627-4.el7   perl-Net-Daemon.noarch 0:0.48-5.el7  
      perl-PlRPC.noarch 0:0.2020-14.el7  
    
    Dependency Updated:
      mariadb-libs.x86_64 1:5.5.64-1.el7                                                                                                             
    
    Complete!
    [root@node103.yinzhengjie.org.cn ~]# 
    [root@node103.yinzhengjie.org.cn ~]# yum -y install mariadb-server
    [root@node103.yinzhengjie.org.cn ~]# mysql_secure_installation 
    
    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
    
    In order to log into MariaDB to secure it, we'll need the current
    password for the root user.  If you've just installed MariaDB, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.
    
    Enter current password for root (enter for none): 
    OK, successfully used password, moving on...
    
    Setting the root password ensures that nobody can log into the MariaDB
    root user without the proper authorisation.
    
    Set root password? [Y/n] y
    New password: 
    Re-enter new password: 
    Password updated successfully!
    Reloading privilege tables..
     ... Success!
    
    
    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB without having to have a user account created for
    them.  This is intended only for testing, and to make the installation
    go a bit smoother.  You should remove them before moving into a
    production environment.
    
    Remove anonymous users? [Y/n] y
     ... Success!
    
    Normally, root should only be allowed to connect from 'localhost'.  This
    ensures that someone cannot guess at the root password from the network.
    
    Disallow root login remotely? [Y/n] n
     ... skipping.
    
    By default, MariaDB comes with a database named 'test' that anyone can
    access.  This is also intended only for testing, and should be removed
    before moving into a production environment.
    
    Remove test database and access to it? [Y/n] y
     - Dropping test database...
     ... Success!
     - Removing privileges on test database...
     ... Success!
    
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.
    
    Reload privilege tables now? [Y/n] y
     ... Success!
    
    Cleaning up...
    
    All done!  If you've completed all of the above steps, your MariaDB
    installation should now be secure.
    
    Thanks for using MariaDB!
    [root@node103.yinzhengjie.org.cn ~]# 
    [root@node103.yinzhengjie.org.cn ~]# 
    [root@node103.yinzhengjie.org.cn ~]# mysql_secure_installation
    [root@node103.yinzhengjie.org.cn ~]# mysql -uroot -pyinzhengjie
    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MariaDB connection id is 10
    Server version: 5.5.64-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    MariaDB [(none)]> GRANT ALL ON *.* TO jason@'172.30.1.%' IDENTIFIED BY 'yinzhengjie';
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]> QUIT
    Bye
    [root@node103.yinzhengjie.org.cn ~]# 
    [root@node103.yinzhengjie.org.cn ~]# 
    [root@node103.yinzhengjie.org.cn ~]# mysql -uroot -pyinzhengjie        #在数据库中授权,允许172.30.1.0/24网络主机访问

    4>.测试静态资源访问(访问:http://node101.yinzhengjie.org.cn/)

    5>.测试动态页面访问(http://node101.yinzhengjie.org.cn/pdo2.php)

    四.基于FASTCGI方式实现搭建workpress(软件环境我就不重复安装了,依旧是基于上面的环境直接配置php程序的)

    1>.node101.yinzhengjie.org.cn(将workpress博客项目解压一份到httpd服务器的网站根目录中,如果是静态资源直接在httpd服务器访问,生产环境一般fastcgi和httpd是部署在一起的)

    [root@node101.yinzhengjie.org.cn ~]# unzip wordpress-5.0-zh_CN.zip 
    [root@node101.yinzhengjie.org.cn ~]#
    [root@node101.yinzhengjie.org.cn ~]# mv wordpress /var/www/html/
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# ll
    total 11688
    -rw-r--r-- 1 root root 11966441 Oct 24 08:50 wordpress-5.0-zh_CN.zip
    [root@node101.yinzhengjie.org.cn ~]# 
    [root@node101.yinzhengjie.org.cn ~]# ll /var/www/html/
    total 8
    -rw-r--r-- 1 root root   40 Dec 12 12:58 index.html
    drwxr-xr-x 5 root root 4096 Dec 11  2018 wordpress
    [root@node101.yinzhengjie.org.cn ~]# ll /var/www/html/wordpress/
    total 192
    -rw-r--r--  1 root root   418 Sep 25  2013 index.php
    -rw-r--r--  1 root root 19935 Jan  7  2018 license.txt
    -rw-r--r--  1 root root  6989 Dec 11  2018 readme.html
    -rw-r--r--  1 root root  5458 May  2  2018 wp-activate.php
    drwxr-xr-x  9 root root  4096 Dec 11  2018 wp-admin
    -rw-r--r--  1 root root   364 Dec 19  2015 wp-blog-header.php
    -rw-r--r--  1 root root  1889 May  3  2018 wp-comments-post.php
    -rw-r--r--  1 root root  2735 Dec 11  2018 wp-config-sample.php
    drwxr-xr-x  5 root root    69 Dec 11  2018 wp-content
    -rw-r--r--  1 root root  3669 Aug 20  2017 wp-cron.php
    drwxr-xr-x 19 root root  8192 Dec 11  2018 wp-includes
    -rw-r--r--  1 root root  2422 Nov 21  2016 wp-links-opml.php
    -rw-r--r--  1 root root  3306 Aug 22  2017 wp-load.php
    -rw-r--r--  1 root root 37286 Oct 21  2018 wp-login.php
    -rw-r--r--  1 root root  8048 Jan 11  2017 wp-mail.php
    -rw-r--r--  1 root root 17421 Oct 23  2018 wp-settings.php
    -rw-r--r--  1 root root 30091 Apr 30  2018 wp-signup.php
    -rw-r--r--  1 root root  4620 Oct 24  2017 wp-trackback.php
    -rw-r--r--  1 root root  3065 Sep  1  2016 xmlrpc.php
    [root@node101.yinzhengjie.org.cn ~]# 

    2>.node102.yinzhengjie.org.cn(将workpress博客项目解压一份到fastcgi的网站根目录中,如果是动态资源会切换到fastcgi服务器访问,生产环境一般fastcgi和httpd是部署在一起的)

    [root@node102.yinzhengjie.org.cn ~]# ll
    total 11688
    -rw-r--r-- 1 root root 11966441 Dec 12 13:15 wordpress-5.0-zh_CN.zip
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# unzip wordpress-5.0-zh_CN.zip 
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# mv wordpress /data/html/
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# ll /data/html/
    total 8
    -rw-r--r-- 1 root root  317 Dec 12 12:54 pdo2.php
    drwxr-xr-x 5 root root 4096 Dec 11  2018 wordpress
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# cd /data/html/wordpress/
    [root@node102.yinzhengjie.org.cn /data/html/wordpress]# 
    [root@node102.yinzhengjie.org.cn /data/html/wordpress]# ls
    index.php    wp-activate.php     wp-comments-post.php  wp-cron.php        wp-load.php   wp-settings.php   xmlrpc.php
    license.txt  wp-admin            wp-config-sample.php  wp-includes        wp-login.php  wp-signup.php
    readme.html  wp-blog-header.php  wp-content            wp-links-opml.php  wp-mail.php   wp-trackback.php
    [root@node102.yinzhengjie.org.cn /data/html/wordpress]# 
    [root@node102.yinzhengjie.org.cn /data/html/wordpress]# cp wp-config-sample.php wp-config.php 
    [root@node102.yinzhengjie.org.cn /data/html/wordpress]# 
    [root@node102.yinzhengjie.org.cn /data/html/wordpress]# vim wp-config.php           #需要修改连接数据库相关的参数,如下图所示。

    3>.node103.yinzhengjie.org.cn

    [root@node103.yinzhengjie.org.cn ~]# mysql -uroot -pyinzhengjie
    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MariaDB connection id is 13
    Server version: 5.5.64-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    MariaDB [(none)]> 
    MariaDB [(none)]> CREATE DATABASE wordpress DEFAULT CHARACTER SET = utf8mb4;          #创建数据库
    Query OK, 1 row affected (0.00 sec)
    
    MariaDB [(none)]> 
    MariaDB [(none)]> QUIT
    Bye
    [root@node103.yinzhengjie.org.cn ~]# 
    [root@node103.yinzhengjie.org.cn ~]# 

    4>.访问wordpress博客程序开始webUI界面安装

    5>.访问博客首页

    6>.测试httpd基于fastcgi的性能

    [root@node101.yinzhengjie.org.cn ~]# ab -c 20 -n 100 http://node101.yinzhengjie.org.cn/wordpress/
    This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking node101.yinzhengjie.org.cn (be patient).....done
    
    
    Server Software:        Apache/2.4.6
    Server Hostname:        node101.yinzhengjie.org.cn
    Server Port:            80
    
    Document Path:          /wordpress/
    Document Length:        11131 bytes
    
    Concurrency Level:      20
    Time taken for tests:   23.124 seconds
    Complete requests:      100
    Failed requests:        0
    Write errors:           0
    Total transferred:      1140500 bytes
    HTML transferred:       1113100 bytes
    Requests per second:    4.32 [#/sec] (mean)
    Time per request:       4624.791 [ms] (mean)
    Time per request:       231.240 [ms] (mean, across all concurrent requests)
    Transfer rate:          48.17 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.1      0       0
    Processing:   368 4437 1265.3   4502    7303
    Waiting:      270 4105 1176.6   4136    6863
    Total:        368 4437 1265.3   4502    7303
    
    Percentage of the requests served within a certain time (ms)
      50%   4502
      66%   4607
      75%   4713
      80%   4811
      90%   6556
      95%   6757
      98%   7296
      99%   7303
     100%   7303 (longest request)
    [root@node101.yinzhengjie.org.cn ~]# 

    7>.至此,FASTCGI方式安装PHP程序完成

      感兴趣的小伙伴可以在使用基于FastCGI的方式安装一下phpadmin或Discuz!程序。
  • 相关阅读:
    hdu 4358 Boring counting 夜
    流式读取文件
    文件夹操作
    通过 fs 模块创建下列文件结构练习
    如何判断一个路径是否为文件夹
    文件读取
    写入流写入文件
    文件简单写入
    移动并重名文件,删除文件
    __dirname绝对路径
  • 原文地址:https://www.cnblogs.com/yinzhengjie/p/12020168.html
Copyright © 2011-2022 走看看