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.178linux.com/72925

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

相关推荐

  • 日志分析工具Awstats实战之Nginx篇-分析结果静态化

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1316979 前言: Awstats 是在 SourceForge 上发展很快的一个基原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处…

    Linux干货 2016-08-15
  • Linux发展史

    1、Linux是什么     Linux 是一套 Unix-like 的作业系统,是 Unix 的一种,它控制整个系统基本服务的核心程式 (kernel) 是由 Linus 带头开发出来的,「Linux」这个名称便是以「Linus's Minix」来命名,Linus 选择用「大众公有版权」 (GPL)的方式来发行这份程…

    Linux干货 2016-10-19
  • N22-第六周作业

    1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; :%s@[[:space:]]\+@#&@g    2、复制/boot/grub/grub.conf至/tmp目录中,删除/tmp/grub.conf文件中的行首的空白字符; :%s#…

    Linux干货 2016-09-26
  • 计算机网络基础知识与Linux网络配置

    本文主要内容是: 1.讲述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。 2、IP地址的分类有哪些?子网掩码的表示形式及其作用 3、计算机网络的分成模型有哪些(OSI模型和TCP/IP模型),每一层的功能及涉及到的物理设备有哪些。 4、如何给网络接口配置多个地址,有哪些方式? 5、常用的网络管理类工具有哪些,并用示例形式描述他们的使用方…

    Linux干货 2016-11-14
  • Linux上实现rsyslog+mysql+loganalyz进行日志收集

    在我们的运维工作中,常常会对系统上的日志进行收集,手动管理少量的几台服务器的日志收集没有太大难度,但是企业当中批量的管理成千上万台服务器的时候,这时候想一台台的收集日志未免太浪费时间了,这时候我们需要一个批量管理日志的系统来解决这一难题,今天我给大家带来的使用 1、syslog介绍       &n…

    Linux干货 2016-10-24
  • mogilefs部署

    mogilefs实验环境: 1.需要两台tracker主机 2.一台mariadb 3.nginx_mogilefs_module模块要编译安装 在tracker主机: 1.上下载rpm包 mkdir mogilefs/ cd mogilefs lftp 172.16.0.1 get MogileFS-Server-2.46-2.el7.centos.noa…

    Linux干货 2017-08-08

评论列表(1条)

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

    赞,比较详细的总结了~~继续加油~