N25-第十二周博客作業


1、請描述一次完整的http請求處理過程;

(1) 建立或處理連接:接收請求或拒絕請求;
(2) 接收請求:接收來自于網絡上的主機請求報文中對某特定資源的一次請求的過程;
(3) 處理請求:對請求報文進行解析,獲取客戶端請求的資源及請求方法等相關信息;
(4) 訪問資源:獲取請求報文中請求的資源;從磁盤中獲取
(5) 構建響應報文:
(6) 發送響應報文:
(7) 記錄日志:

2、httpd所支持的處理模型有哪些,他們的分別使用于哪些環境。

(1) prefork:多進程模型,每個進程響應一個請求;
一個主進程:負責生成子進程及回收子進程;負責創建套接字;負責接收請求,并將其派發給某子進程進行處理;
n個子進程:每個子進程處理一個請求;
工作模型:會預先生成幾個空閑進程,隨時等待用于響應用戶請求;最大空閑和最小空閑;
應用環境: 并發量不是很大的場景下
(2) worker:多進程多線程模型,每線程處理一個用戶請求;
一個主進程:負責生成子進程;負責創建套接字;負責接收請求,并將其派發給某子進程進行處理;
多個子進程:每個子進程負責生成多個線程;
每個線程:負責響應用戶請求;
并發響應數量:mn
m:子進程數量
n:每個子進程所能創建的最大線程數量;
應用環境: 高并發
(3) event:事件驅動模型,多進程模型,每個進程響應多個請求; m
n
一個主進程 :負責生成子進程;負責創建套接字;負責接收請求,并將其派發給某子進程進行處理;
子進程:基于事件驅動機制直接響應多個請求;

httpd-2.2: 仍為測試使用模型;
httpd-2.4:event可生產環境中使用;
應用環境: 提供更高的并發能力

3、源碼編譯安裝LAMP環境(基于wordpress程序),并寫出詳細的安裝、配置、測試過程。

系統環境: CentOS 7.2
httpd: 編譯安裝, httpd2.4
php5: 編譯安裝, php-5.5, 依賴mariadb, 需要先安裝mariadb
mariadb: 通用二進制格式, mariadb-5.5

安裝mariadb


(1) 卸載原有包

[root@localhost ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
注意: postfix依賴mariadb-libs, 因此此處不卸載mariadb-libs

(2) 下載mariadb二進制包
https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-5.5.54/bintar-linux-x86_64/mariadb-5.5.54-linux-x86_64.tar.gz
(3) 創建mysql用戶

[root@localhost ~]# useradd -r mysql

(4) 展開到指定目錄

[root@localhost ~]# tar xf mariadb-5.5.54-linux-x86_64.tar.gz -C /usr/local

(5) 創建軟鏈接并修改目錄權限

[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -s mariadb-5.5.54-linux-x86_64/ mysql
[root@localhost local]# cd mysql/
[root@localhost mysql]# chown -R root.mysql ./*
[root@localhost mysql]# ll
total 204
drwxr-xr-x  2 root mysql   4096 Apr  4 11:21 bin
-rw-r--r--  1 root mysql  17987 Dec 22 23:58 COPYING
-rw-r--r--  1 root mysql  26545 Dec 22 23:58 COPYING.LESSER
drwxr-xr-x  3 root mysql     17 Apr  4 11:21 data
-rw-r--r--  1 root mysql   8245 Dec 22 23:58 EXCEPTIONS-CLIENT
drwxr-xr-x  3 root mysql     18 Apr  4 11:21 include
-rw-r--r--  1 root mysql   8694 Dec 22 23:58 INSTALL-BINARY
drwxr-xr-x  3 root mysql   4096 Apr  4 11:21 lib
drwxr-xr-x  4 root mysql     28 Apr  4 11:21 man
drwxr-xr-x 11 root mysql   4096 Apr  4 11:21 mysql-test
-rw-r--r--  1 root mysql 108813 Dec 22 23:58 README
drwxr-xr-x  2 root mysql     29 Apr  4 11:21 scripts
drwxr-xr-x 27 root mysql   4096 Apr  4 11:21 share
drwxr-xr-x  4 root mysql   4096 Apr  4 11:21 sql-bench
drwxr-xr-x  3 root mysql   4096 Apr  4 11:21 support-files

(6) 創建數據目錄并修改權限

[root@localhost mysql]# mkdir -p /mydata/data
[root@localhost mysql]# chown -R mysql.mysql /mydata/data

(7) 創建配置文件所在目錄,并拷貝模版配置文件

[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
備注: 如果使用/etc/mysql/my.cnf,會導致下面初始化數據庫失敗,因為將配置文件改為/etc/my.cnf,而且這個配置文件的優先級是最高的

(8) 修改配置文件

[root@localhost mysql]# vim /etc/my.cnf
[mysqld]
.
.
.
datadir = /mydata/data
innodb_file_per_table =ON
skip_name_resolve = ON

(9) 創建啟動腳本并設置開機啟動

[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# ll /etc/rc.d/init.d/mysqld
-rwxr-xr-x 1 root root 11982 Apr  4 11:40 /etc/rc.d/init.d/mysqld
# 已經有可執行權限,無需再添加
[root@localhost mysql]# chkconfig --add mysqld

(10) 初始化數據庫

[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data

(11) 啟動數據庫

[root@localhost mysql]# service mysqld start
Starting MySQL.170404 12:06:09 mysqld_safe Logging to '/mydata/data/localhost.localdomain.err'.
170404 12:06:09 mysqld_safe Starting mysqld daemon with databases from /mydata/data
.. SUCCESS!
[root@localhost mysql]# ss -tnl | grep 3306
LISTEN     0      50           *:3306                     *:*

(12) 設置二進制程序環境變量

[root@localhost mysql]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost mysql]# . /etc/profile.d/mysql.sh
測試二進制程序: 
[root@localhost mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.54-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

(13) 配置庫文件路徑

[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost mysql]# ldconfig
[root@localhost mysql]# ldconfig -p | grep mysql
        libmysqld.so.18 (libc6,x86-64) => /usr/local/mysql/lib/libmysqld.so.18
        libmysqld.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqld.so
        libmysqlclient.so.18 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient.so.18
        libmysqlclient.so.18 (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so.18
        libmysqlclient.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so

編譯安裝Apache


(1) 安裝開發包

[root@localhost ~]# yum -y groupinstall "Development Tools"
[root@localhost ~]# yum  install  pcre-devel  apr-devel  apr-util-devel  openssl-devel

(2) 編譯安裝httpd2.4

[root@localhost ~]# tar xf httpd-2.4.25.tar.bz2
[root@localhost ~]# cd httpd-2.4.25/
[root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/apache24 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-rewrite --with-zlib --with-pcre --with-apr=/usr --with-apr-util=/usr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[root@localhost httpd-2.4.25]# make -j 4 && make install

(3) 配置環境變量

[root@localhost httpd-2.4.25]# vim /etc/profile.d/httpd.sh
export PATH=/usr/local/apache24/bin:$PATH
[root@localhost httpd-2.4.25]# . /etc/profile.d/httpd.sh

(4) 啟動服務

[root@localhost httpd-2.4.25]# apachectl start
[root@localhost httpd-2.4.25]# ss -tnl | grep 80
LISTEN     0      128         :::80                      :::*
[root@localhost httpd-2.4.25]# curl 172.16.0.10
<html><body><h1>It works!</h1></body></html>

編譯安裝php


注意:
如果httpd是prework模型, php編譯的是進程式php5模塊
如果httpd是worker或event模型, php編譯的是線程式的php5zts 模塊
兩種不通用
php編譯的模塊和httpd mpm類型相關, httpd不能隨意更改mpm模型,因為php模塊不兼容

(1) 查看當前httpd mpm模型

[root@localhost httpd-2.4.25]# httpd -M | grep mpm
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
 mpm_prefork_module (shared)

(2) 安裝依賴包

[root@localhost ~]# yum -y install libxml2-devel libmcrypt-devel bzip2-devel
安裝mcrypt.h  
[root@localhost php-5.5.38]# vim  /etc/yum.repos.d/epel.repo
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/7Server/x86_64/
enabled=0
gpgcheck=0
[root@localhost php-5.5.38]# yum -y install libmcrypt-devel --enablerepo=epel

(3) 編譯安裝php

[root@localhost ~]# tar xf php-5.5.38.tar.bz2
[root@localhost ~]# cd php-5.5.38/
[root@localhost php-5.5.38]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
[root@localhost php-5.5.38]# make -j 4 && make install

(4) 生成配置文件

[root@localhost php-5.5.38]# cp php.ini-production /etc/php.ini

(5) 修改httpd配置文件

[root@localhost php-5.5.38]# cd /etc/httpd24/
[root@localhost httpd24]# cp httpd.conf{,.backup}
[root@localhost httpd24]# vim httpd.conf
#查找AddType,放到其他類型后面即可
AddType application/x-httpd-php .php
# 添加默認頁index.php
<IfModule dir_module>
    DirectoryIndex  index.php index.html
</IfModule>
重新啟動服務
[root@localhost httpd24]# apachectl stop
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[root@localhost httpd24]# apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

(6) 創建默認頁

[root@localhost httpd24]# vim /usr/local/apache24/htdocs/index.php
<?php
        phpinfo();
?>

(7) 測試php頁面
N25-第十二周博客作業

(8) 測試php程序和mariadb的連接

[root@localhost httpd24]# vim /usr/local/apache24/htdocs/index.php
<?php
        $conn = mysql_connect('127.0.0.1','root','');
        if ($conn)
                echo "OK";
        else
                echo "Failure";
?>

N25-第十二周博客作業

安裝wordpress


(1) 下載wordpress,并拷貝到httpd根目錄

[root@localhost ~]# cp wordpress-4.7.3-zh_CN.zip /usr/local/apache24/htdocs/

(2) 創建數據庫

MariaDB [(none)]> CREATE DATABASE wpdb;
MariaDB [(none)]> GRANT ALL ON wpdb.* TO wpuser@'172.16.%.%' IDENTIFIED BY 'wppass';
MariaDB [(none)]> FLUSH PRIVILEGES;

(3) 解壓縮

[root@localhost ~]# cd /usr/local/apache24/htdocs/
[root@localhost htdocs]# unzip wordpress-4.7.3-zh_CN.zip

(4) 創建wordpress配置文件

[root@localhost htdocs]# cd wordpress/
[root@localhost wordpress]# cp wp-config-sample.php wp-config.php

(5) 修改wordpress配置文件

[root@localhost wordpress]# vim wp-config.php
/** WordPress數據庫的名稱 */
define('DB_NAME', 'wpdb');

/** MySQL數據庫用戶名 */
define('DB_USER', 'wpuser');

/** MySQL數據庫密碼 */
define('DB_PASSWORD', 'wppass');

/** MySQL主機 */
define('DB_HOST', '172.16.0.10');

(6) 通過頁面安裝wordpress
N25-第十二周博客作業
N25-第十二周博客作業

4、建立httpd服務器(基于編譯的方式進行),要求:

提供兩個基于名稱的虛擬主機:
(a)www1.stuX.com,頁面文件目錄為/web/vhosts/www1;錯誤日志為/var/log/httpd/www1.err,訪問日志為/var/log/httpd/www1.access;
(b)www2.stuX.com,頁面文件目錄為/web/vhosts/www2;錯誤日志為/var/log/httpd/www2.err,訪問日志為/var/log/httpd/www2.access;
(c)為兩個虛擬主機建立各自的主頁文件index.html,內容分別為其對應的主機名;
(d)通過www1.stuX.com/server-status輸出httpd工作狀態相關信息,且只允許提供帳號密碼才能訪問(status:status);

系統環境: CentOS 7.2
軟件: httpd2.4編譯安裝 (基于第三題)

(1) 創建網站目錄,網頁文件

[root@localhost wordpress]# mkdir -p /web/vhosts/{www1,www2}
[root@localhost wordpress]# echo "www1.stu1.com" > /web/vhosts/www1/index.html
[root@localhost wordpress]# echo "www2.stu2.com" > /web/vhosts/www2/index.html

(2) 創建虛擬主機配置文件

# 編譯安裝httpd2.4后沒有該目錄,手動創建
[root@localhost ~]# mkdir /etc/httpd24/conf.d
[root@localhost ~]# cd /etc/httpd24/conf.d
[root@localhost conf.d]# vim vhost.conf
#基于域名的虛擬主機
<VirtualHost *:80>
        ServerName www1.stu1.com
        DocumentRoot "/web/vhosts/www1"
        ErrorLog /var/log/httpd/www1.err
        CustomLog /var/log/httpd/www1.access common

        <Directory "/web/vhosts/www1">
                Options None
                AllowOverride None
                Require all granted
        </Directory>

#啟動server-status頁面并限制用戶訪問
        <Location /server-status>
                SetHandler server-status
                AuthType Basic
                AuthName "Apache Server Status"
                AuthUserFile "/etc/httpd24/.htpasswd"
                Require valid-user
        </Location>

</VirtualHost>

<VirtualHost *:80>
        ServerName www2.stu2.com
        DocumentRoot "/web/vhosts/www2"
        ErrorLog /var/log/httpd/www2.err
        CustomLog /var/log/httpd/www2.access common

        <Directory "/web/vhosts/www2">
                Options None
                AllowOverride None
                Require all granted
        </Directory>
</VirtualHost>

(3) 創建可查看狀態頁的用戶

[root@localhost conf.d]# htpasswd -c -m /etc/httpd24/.htpasswd tom
New password:
Re-type new password:
Adding password for user tom

(4) 修改httpd主配置文件, 導入新創建的配置文件目錄

[root@localhost ~]# cd /etc/httpd24/
[root@localhost httpd24]# vim httpd.conf
Include /etc/httpd24/conf.d/

[root@localhost httpd24]# httpd -t
[root@localhost httpd24]# apachectl restart

(5) 測試
首頁:
N25-第十二周博客作業
N25-第十二周博客作業
日志文件:

[root@localhost conf.d]# ll /var/log/httpd | grep www
-rw-r--r--  1 root root   69 Apr  5 00:06 www1.access
-rw-r--r--  1 root root    0 Apr  5 00:04 www1.err
-rw-r--r--  1 root root  279 Apr  5 00:14 www2.access
-rw-r--r--  1 root root  471 Apr  5 00:10 www2.err

狀態頁:
N25-第十二周博客作業
N25-第十二周博客作業

5、為第4題中的第2個虛擬主機提供https服務,使得用戶可以通過https安全的訪問此web站點;

(1)要求使用證書認證,證書中要求使用的國家(CN)、州(HA)、城市(ZZ)和組織(MageEdu);
(2)設置部門為Ops,主機名為www2.stuX.com,郵件為admin@stuX.com;

環境:
CentOS7.2 httpd(https) 172.16.0.10
CentOS7.2 CA 172.16.0.11

(1) CA服務器生成私鑰

[root@localhost ~]# cd /etc/pki/CA/
[root@localhost CA]# (umask 077;openssl genrsa -out private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus
...............................................+++
.+++
e is 65537 (0x10001)

(2) CA服務器生成自簽證書

[root@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem  -days 3655
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HA
Locality Name (eg, city) [Default City]:ZZ
Organization Name (eg, company) [Default Company Ltd]:MageEdu
Organizational Unit Name (eg, section) []:Ops
Common Name (eg, your name or your server's hostname) []:www2.stu2.com
Email Address []:admin@stu2.com

(3) 為CA提供所需的目錄及文件

[root@localhost CA]# touch serial index.txt
[root@localhost CA]# echo 01 > serial

(4) web服務器生成私鑰

[root@localhost conf.d]# cd /etc/httpd
[root@localhost httpd]# mkdir ssl
[root@localhost httpd]# cd ssl
[root@localhost ssl]# (umask 077;openssl genrsa -out httpd.key 1024)
Generating RSA private key, 1024 bit long modulus
.++++++
....++++++
e is 65537 (0x10001)

(5) web服務器生成證書簽署請求

[root@localhost ssl]# openssl req -new -key httpd.key -out httpd.csr -days 365
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HA
Locality Name (eg, city) [Default City]:ZZ
Organization Name (eg, company) [Default Company Ltd]:MageEdu
Organizational Unit Name (eg, section) []:Ops
Common Name (eg, your name or your server's hostname) []:www2.stu2.com
Email Address []:admin@stu2.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

(6) web服務器將請求發給CA主機

[root@localhost ssl]# scp httpd.csr root@172.16.0.11:/tmp
The authenticity of host '172.16.0.11 (172.16.0.11)' can't be established.
ECDSA key fingerprint is 1f:20:4c:18:14:7d:d9:56:52:38:16:d1:0d:94:a0:be.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.0.11' (ECDSA) to the list of known hosts.
root@172.16.0.11's password:
Permission denied, please try again.
root@172.16.0.11's password:
httpd.csr                                             100%  680     0.7KB/s   00:00

(7) CA服務器簽署證書

[root@localhost CA]# openssl ca -in /tmp/httpd.csr -out certs/httpd.crt  -days 365
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Mar 14 22:19:44 2017 GMT
            Not After : Mar 14 22:19:44 2018 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = HA
            organizationName          = MageEdu
            organizationalUnitName    = Ops
            commonName                = www2.stu2.com
            emailAddress              = admin@stu2.com
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                5D:12:02:29:4F:23:B0:F0:13:C6:52:A3:77:27:B5:3D:5D:F8:A9:04
            X509v3 Authority Key Identifier:
                keyid:BE:11:68:1F:90:97:DE:92:33:78:EB:5A:C2:B9:B7:37:D6:CD:CC:C7

Certificate is to be certified until Mar 14 22:19:44 2018 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

(8) CA服務器將證書拷貝到web服務器

[root@localhost CA]# scp certs/httpd.crt 172.16.0.10:/etc/httpd/ssl/

(9) 在web服務器查看證書

[root@localhost ssl]# ls
httpd.crt  httpd.csr  httpd.key

(10) web服務器配置httpd支持ssl及使用的證書

安裝mod_ssl模塊
[root@localhost ssl]# yum -y install mod_ssl
加載如下模塊及開啟httpd的ssl:
[root@localhost extra]# vim /etc/httpd24/httpd.conf
LoadModule socache_shmcb_modulemodules/mod_socache_shmcb.so
LoadModule ssl_module modules/mod_ssl.so
# Secure (SSL/TLS) connections
Include /etc/httpd24/extra/httpd-ssl.conf

(11) 配置httpd以支持ssl

[root@localhost extra]# vim /etc/httpd24/extra/httpd-ssl.conf
增加:
ServerName www2.stu2.com
DocumentRoot "/web/vhosts/www2"

<Directory "/web/vhosts/www2">
        Options None
        AllowOverride None
        Require all granted
</Directory>


修改: 
SSLCertificateFile "/etc/httpd/ssl/httpd.crt"
SSLCertificateKeyFile "/etc/httpd/ssl/httpd.key"
[root@localhost extra]# httpd -t

(12)重啟服務

[root@localhost httpd]# apachectl restart
[root@localhost extra]# ss -tnl | egrep "80|443"
LISTEN     0      128         :::80                      :::*
LISTEN     0      128         :::443                     :::*

(13) 測試

  1. 將ca證書cacert.pem拷貝到windows主機
  2. 在windowns上配置hosts文件
  3. 在chrome上導入ca證書
  4. 打開https站點
    N25-第十二周博客作業

注意: 在配置證書時,web服務器使用的是/etc/httpd路徑, 為了和httpd的路徑保證一致, 使用/etc/httpd24路徑較好

6、在LAMP架構中,請分別以php編譯成httpd模塊形式和php以fpm工作為獨立守護進程的方式來支持httpd,列出詳細的過程。

php編譯成httpd模塊形式見第3題

php以fpm工作為獨立守護進程

一. 安裝php-pfm

(1) 安裝httpd,php-fpm,mariadb,php-mysql

[root@localhost ~]# yum -y install httpd php-fpm mariadb-server php-mysql

(2) 修改php-fpm配置文件

[root@localhost ~]# vim /etc/php-fpm.d/www.conf
listen = 0.0.0.0:9000

(3) 啟動php-fmp服務

[root@localhost ~]# systemctl start php-fpm.service

二. 安裝httpd(中心主機配置)

(1) 安裝httpd
前面已安裝
查看已加載fcgi模塊

[root@localhost ~]# httpd -M | grep fcgi
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
 proxy_fcgi_module (shared)

(2) 創建fcgi配置文件

[root@localhost ~]# vim /etc/httpd/conf.d/fcgi.conf
# 設置默認頁
DirectoryIndex index.php

 #是不是開啟正向代理
ProxyRequests off

#轉發哪些內容到后端
#.php后綴的url請求轉發給后端,$1表示小括號內的內容
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1

(3) 啟動httpd服務

[root@localhost ~]# httpd -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Syntax OK
[root@localhost ~]# systemctl start httpd.service

(4) 準備php頁面

[root@localhost ~]# vim /var/www/html/index.php
<?php
        phpinfo();
?>

(5) 測試
N25-第十二周博客作業

三. 安裝httpd(虛擬主機)

(1) 關掉中心主機

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
#DocumentRoot "/var/www/html"

(2) 配置虛擬主機

[root@localhost ~]# cd /etc/httpd/conf.d
[root@localhost conf.d]# mv fcgi.conf vhosts.conf
[root@localhost conf.d]# vim vhosts.conf
DirectoryIndex index.php

<VirtualHost *:80>
        ServerName www.b.net
        DocumentRoot /apps/vhosts/b.net

        #是不是開啟正向代理
        ProxyRequests off

        #轉發哪些內容到后端
        #.php后綴的url請求轉發給后端,$1表示小括號內的內容
        ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/apps/vhosts/b.net/$1
        <Directory "/apps/vhosts/b.net">
                Options None
                AllowOverride None
                Require all granted
        </Directory>
</VirtualHost>

[root@localhost conf.d]# httpd -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Syntax OK

[root@localhost conf.d]# systemctl reload httpd.service

(3) 準備php目錄和頁面

[root@localhost conf.d]# mkdir -pv /apps/vhosts/b.net
[root@localhost conf.d]# vim /apps/vhosts/b.net/index.php
<?php
        phpinfo();
?>

(4) 測試
N25-第十二周博客作業

四. 配置mariadb

(1) 安裝mariadb
上面已安裝
(2) 啟動mariadb

[root@www ~]# systemctl start mariadb.service

(3) 配置mariadb

[root@localhost ~]# vim /etc/my.cnf
skip_name_resolve = ON
[root@www ~]# systemctl restart mariadb.service

(4) 授權

[root@www ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, 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 root@'172.16.%.%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
測試: 
[root@www ~]# mysql -h172.16.0.11 -uroot -p123456

(5) 修改php頁面

[root@www ~]# vim /apps/vhosts/b.net/index.php
www.b.net
<?php
        $conn = mysql_connect('172.16.0.11','root','123456');
        if ($conn)
                echo "OK";
        else
                echo "Failure";

?>
[root@www ~]# systemctl reload php-fpm.service

(6) 測試
N25-第十二周博客作業

停止maridb服務
N25-第十二周博客作業

原創文章,作者:hansj,如若轉載,請注明出處:http://www.www58058.com/72925

(0)
hansjhansj
上一篇 2017-04-09
下一篇 2017-04-09

相關推薦

  • dd工具

    dd     dd命令:convert and copy a file     用法:        ddif=/PATH/FROM/SRC of=/PATH/TO/DEST       &…

    Linux干貨 2016-09-02
  • Week 1–Linux基礎1

    一. 計算機是由什么組成的? 計算機有什么作用呢?  1.計算機是由硬件系統與軟件系統兩大部分組成的. 那么是什么呢?  硬件系統: 1.1 輸入組件(如鼠標,鍵盤等); 輸出組件(顯示器,打印機等); 1.2 核心大腦–CPU(里面包含有 算術邏輯、控制、記憶等單元); 1.3 為了與以上2大重要部件連接的,肯定需要一個可以…

    Linux干貨 2016-12-05
  • 簡單shell腳本習題

    習題 作業 簡單shell腳本習題 習題1 答案 習題2 答案 習題3 答案 習題4 答案 習題5 答案 習題6 答案 習題1 編寫腳本/root/bin/systeminfo.sh,顯示當前主機系統信息,包括主機名,IPv4地址,操作系統版本,內核版本, CPU型號,內存大小,硬盤大小。 答案 #!/bin/bash IPADDR=$(…

    Linux干貨 2017-04-10
  • 馬哥linux0803課堂筆記

    課堂筆記   重定向的幾種方式 標準輸入 0 (stdin) 標準輸出 1 (stdout) 標準錯誤 2 (stderr)   標準輸入的重定向方法 cat < file cat << string (多行重定向) xxx aaa string結束 cat file | cat   標準輸出的重定向 ls e…

    Linux干貨 2016-08-08
  • 推薦-Openssl加密解密及PKI,創建私有CA!

    Openssl加密解密及PKI,創建私有CA Openssl加密解密及PKI,創建私有CA Openssl加密解密及PKI,創建私有CA 一、什么是SSL? 二、SSL協議出現的目的? 三、密碼算法 四、SSL握手通信 五、IKE是啥? 六、PKI是啥? 七、Openssl開源項目 八、創建私有CA 九、吊銷證書 附:Openssh基于密鑰認證 一、什么是S…

    Linux干貨 2016-04-05
  • ifconfig

    ifconfig 命令詳解

    Linux干貨 2018-02-10

評論列表(1條)

  • 馬哥教育
    馬哥教育 2017-04-13 09:47

    贊,比較詳細的總結了~~繼續加油~

欧美性久久久久