Homework Week-12 LAMP部署

1、请描述一次完整的http请求处理过程;

    http全称超文本传输协议,属于应用层协议;常见客户端应用是各种浏览器。

    一次服务器端完整http请求处理过程:

    (1)建立或处理连接:接收请求或拒绝请求;

    (2)接收请求:接收来自于网络上的主机请求报文中对某特定资源的一次请求过程;

        http传输前要使用TCP协议通过三次握手建立连接(TCP是传输层的传输控制协议,是一种面向连接的、可靠的基于字节流的传输层控制协议)

    (3)处理请求:对请求报文进行解析,获取客户端请求资源及请求方法等相关信息;

    (4)访问资源:获取请求报文中请求的资源;

    (5)构件响应报文;

    (6)发送响应报文;

    (7)记录日志。

————————————————————————————————————–

2、httpd所支持的处理模型有哪些,他们的分别使用于哪些环境。

    处理模型:

    (1)单进程I/O模型:启动一个进程处理用户请求;一次只能处理一个请求,多个请求被串行响应;

        响应1+1+1+…

    (2)多进程I/O结构:并行启动多个进程,每个进程响应一个请求;一个客户端可以发多个请求;

        响应n

    (3)复用的I/O结构:一个进程响应n个请求:

        多线程模式:一个进程生成n个线程,一个线程处理一个请求;响应n*1个;

        事件驱动:一个进程直接响应n个请求;响应1*n个;

    (4)复用的多进程I/O结构:启动m个进程,每个进程生产n个线程,响应请求m*n个。

————————————————————————————————

3、源码编译安装LAMP环境(基于wordpress程序),并写出详细的安装、配置、测试过程。

方法一:源码编译安装LAMP在CentOS 7上:

下载mariadb-10.0.13.tar.gz,httpd-2.4.9.tar.bz2,php-5.4.26.tar.bz2

(1)安装mariadb

yum install -y gcc gcc-c++ libtool automake autoconf cmake python-devel libxml2-devel libpng-devel c
url-devel freetype-devel mesa-libGL-devel mysql-server mysql-devel libvorbis-devel
tar xf mariadb-10.0.13.tar.gz -C /usr/local
ln -sv mariadb-10.0.13 mysql
cd mysql/
cmake . -LH
make
make install
useradd mysql
chown -R root.mysql ./*
mkdir /mydata/data -p
chown -R mysql.mysql /mydata/data/
mkdir /etc/mysql
cp support_files/my-medium.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
    [mysqld]后添加几行代码    
    datadir=/mydata/data
    innodb_file_per_table=ON
    skip_name_resolve=ON
cp support-files/mysql.service /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
scripts/mysql_install_db --user=mysql --datadir=/mydata/data
service mysqld start
vim /etc/profile.d/mysql.sh
    export PATH=/usr/local/mysql/bin:$PATH
./etc/profile.d/mysql.sh
vim /etc/ld.so.conf.d/mysql.conf
    /usr/local/mysql/lib
ldconfid

(2)安装httpd 2.4

yum -y groupinstall "开发工具" "服务器开发平台"
yum install -y pcre-devel apr-util-devel apr-devel openssl-devel
tar xf httpd-2.4.9.tar.bz2 -C /usr/local
cd /usr/local
cd httpd-2.4.9
./configure --prefix=/usr/local/apache24 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl 
--enable-rewrite --with-zlib --with-pcre --with-apr=/usr --with-arp-util=/usr --enable-modules=most 
--enable-mpms-shared=all --with-mpm=prefork  
make -j 4 && make install
vim /etc/profile.d/httpd.sh
    export PATH=/usr/local/apache24/bin:$PATH
apachectl start
ss -tnl
访问http://192.168.1.103,显示http测试页

(3)安装php

yum install libxml2-devel libmcrypt-devel
./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-apx2=/usr/local/apache24/bin/apxs --with-mcrypt 
--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 
make -j 4 && make install
在php安装目录下
cp php.ini-production /etc/php.ini
cd /etc/http24
cp httpd.conf {,.backup}
vim httpd.conf
    AddType application/x-httpd-php .php
    DirectoryIndex index.php index.html
apachectl stop
apachectl start
vim /usr/ocal/apcahe24/htdocs/index.php
    <?php
        phpinfo();
    ?>
rm /usr/local/apache24/htdocs/index.html
访问http://192.168.1.103

方法二:直接安装部署LAMP在CentOS 7上:   

(1)安装httpd

yum install httpd -y    #安装httpd
rpm -ql httpd    #查看httpd安装的文件
systemctl start httpd.service    #启动服务
systemctl status httpd.service    #查看服务状态
ss -tnl    #查看80端口监听
浏览器访问http://192.168.1.101,显示测试页安装成功

mkdir -pv /web/host1    #创建新的Main server文档页面路径
vim /web/host1/index.html    #创建首页文件,添加一行html代码
    <h1> New Location. </h1>
    
vim /etc/httpd/conf/httpd.conf    #编辑配置文件
DocumentRoot "/var/www/html"    修改成    DocumentRoot "/web/host1"
    <Directory "/var/www">    修改成    <Directory "/web/host1">
    
浏览器访问http://192.168.1.101,显示New Location.页

(2)安装php

yum install php    #安装php
rpm -ql php
systemctl restart httpd.service    #php作为httpd的模块安装 重启httpd服务
systemctl status httpd.service
ss -tnl
mv /web/host1/index.html /web/host1/index.php    #将index.html修改成index.php

vim  /web/host1/index.php    #修改首页文件,加入几行代码
    <?php
        phpinfo();
    ?>
systemctl restart httpd.service    #重启服务

浏览器访问http://192.168.1.101,显示php信息页

(3)安装mariadb

yum install maridb-server -y
yum install php-mysql -y

vim /web/host1/index.php    #修改php代码
    <?php
        $conn=mysql_connection('192.168.1.101','testuser','testpass');
        if($conn)
            echo "ok";
        else
            echo "failure";
    ?>
    
vim /etc/my.cnf.d/server.cnf
    [mysqld]
    skip_name_resolve=ON    #禁止登录反解主机名
    
mysql
    >GRANT ALL ON testdb.* TO testuser@'192.168.1.102' IDENTIFIED BY 'testpass';//数据库登录授权
    >FLUSH PRIVILEGES;
    
systemctl start httpd.service    #启动服务
systemctl start mariadb.service

浏览器访问http://192.168.1.101,显示ok

(4)安装wordpress,下载wordpress-4.5.tar.gz放在/web/host1/目录下

cd /web/host1
tar xf wordpress-4.5.tar.gz
cd wordpress
cp wp-config-sample.php wp-config.php
mysql    #连接数据库
>GRANT ALL ON wpdb.* TO wpuser@192.168.1.101 IDENTIFIED BY 'wpdb';
>CREATE DATABASE wpdb;
>exit
vim wp-config.php    #配置连接的数据库名称、用户、密码和主机信息
    define('DB_NAME','wpdb');
    define('DB_USER','wpuser');
    define('DB_PASSWORD','wppass');
    define('DB_HOST','192.168.1.101');
访问http://192.168.1.101/wordpress,填写信息,安装生成

blob.png

————————————————————————————————

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

将/etc/httpd/conf/httpd.conf文件中的DocumentRoot行注释,Directory中的路径删除
在/etc/httpd/conf.d中创建配置文件vhosts.conf,写入

<VirtualHost 192.168.1.101:80>
        ServerName www1.stu.com
        DocumentRoot "/web/vhosts/www1"
        Options none
</VirtualHost>

<Location "/web/vhosts/www1/server-status">
        sethandler server-status
        options none
        authtype basic
        authname "log"
        authuserfile "/etc/httpd/conf/.htpasswd"
        require user "tom"
</Location>

<VirtualHost 192.168.1.101:80>
        ServerName www2.stu.com
        DocumentRoot "/web/vhosts/www2"
</VirtualHost>
vim /web/vhosts/www1/index.html
    <h1>www1.stu.com</h1>
   
vim /web/vhosts/www2/index.html
    <h1>www2.stu.com</h1>

vim /etc/httpd/conf/httpd.conf    #开启httpd内置模块
    LoadMoudule status_module modules/mod_status.so
vim /etc/hosts     #添加DNS解析记录
    192.168.1.101 www1.stu.com www2.stu.com
htpasswd -c -m /etc/httpd/conf/.htpasswd tom    #创建账号密码文件
systemctl start httpd.service

    Homework Week-12 LAMP部署  Homework Week-12 LAMP部署

5、为第4题中的第2个虚拟主机提供https服务,使得用户可以通过https安全的访问此web站点;

   (1)要求使用证书认证,证书中要求使用的国家(CN)、州(HA)、城市(ZZ)和组织(MageEdu);

   (2)设置部门为Ops,主机名为www2.stuX.com,邮件为admin@stuX.com;

192.168.1.103作为CA服务器,192.168.1.101作为https服务器

.103

cd /etc/pki/CA/
(umask 077;openssl genrsa -out private/cakey.pem 2048)
openssl req -new -x509 -key private/cakey.pem -out cacert.pem    #生成CA自己的证书
#填写CA证书信息:CN HA ZZ MageEdu Ops ca.maedu.com caadmin@magedu.com

touch serial index.txt

echo 01>serial

.101

cd /etc/httpd
mkdir ssl/
(umask 077;openssl genrsa -out httpd.key 1024)    #创建私钥
openssl req -new -key httpd.key -out httpd.csr   
#填写证书信息:CN HA ZZ MageEdu Ops www2.stu.com webadmin@stu.com
scp httpd.csr root@192.168.1.103:/tmp/

.103

openssl ca -in /tmp/httpd.csr -out certs/httpd.crt
scp certs/httpd.crt 192.168.1.101:/etc/httpd/ssl/

.101

yum -y install mod-ssl
systemctl restart httpd.service
ss -tnl #监听443端口

.103

openssl s_client -connect www2.stu.com:443 -CAfile /etc/pki/CA/cacert.pem

6、在LAMP架构中,请分别以php编译成httpd模块形式和php以fpm工作为独立守护进程的方式来支持httpd,列出详细的过程。

(1)php编译成httpd模块形式

yum install libxml2-devel libmcrypt-devel
./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

make & make install

(2)php以fpm工作为独立守护进程方式

yum install php-fpm -y
yum install httpd -y
vim /etc/httpd/conf.d/fcgi.conf
     DirectoryIndex index.php
     ProxyRequests Off
     ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
     
httpd -t

systemctl start httpd.service

vim /var/www/html/index.php
<?php
     phpinfo()
?>

访问172.16.100.67/index.php和172.16.100.67验证

原创文章,作者:N22_Elephant,如若转载,请注明出处:http://www.178linux.com/54524

(0)
上一篇 2016-12-05 17:03
下一篇 2016-12-05 17:03

相关推荐

  • 8-15作业

    1、写个脚本,实现以下三角形    *   ***  ***** ******* #!/bin/bash # read -p " input a number : " n for l&nbs…

    Linux干货 2016-08-21
  • Linux磁盘管理实操

    Linux磁盘管理实操 1、创建一个10G分区,并格式为ext4文件系统。 先使用fdisk工具创建一个10G的新分区。使用fdisk打开要创建磁盘分区的物理设备fdisk /dev/sdb,然后使用n指令创建新的分区,分区类型选此处选择为主分区,第一个柱面使用默认的1,最后的柱面,使用+10G这种表示方式,表示创建的分区大小为10G。 创建后可以使用p指令…

    系统运维 2016-12-13
  • linux基础命令

    1. 属主 属组 其他人    当一个进程访问文件时,首先匹配的是uid,其次是gid,最后是other 2. 认证信息库存储位置:    用户的认证信息库:/etc/shadow    组的认证信息库:/etc/gsh…

    Linux干货 2017-09-03
  • Mysql备份I

    Mysql备份I I备份在什么时候会被需要 硬件故障 机器无法启动 机器突然消失了怎么办 业务出现异常 一定要先select 在操作 类似drop或delete的操作 攻击 程序bug 业务特殊需求  重要数据多处多次多版本备份 至少有2份远程备份文件2处本地备份 II哪些东西需…

    Linux干货 2016-06-09
  • 磁盘管理

    上图sda disk information中对 255 heads,63 sectors/track,1958 cylinders的解析: sda磁盘总共有1958个cylinder(柱面),每个cylinder(柱面)有63个sectors(扇区),每个sectors(扇区)有255个heads(磁头) 那么这块sda的总的磁头数量为:255*63*19…

    2017-08-20
  • N26-第二周

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。(盗图了,哈哈哈) 文件查看类命令:cat, tac, head, tail, more, less,touch    cat 查看文件内容   tac命令   反向查看文件内容  注:可对照上图 分屏查看命令:more  …

    Linux干货 2017-01-07