HTTP-2.4
2018-03-08 本文已影响1人
Miracle001
httpd-2.4
网页相同的两个网站,硬件配置相同,看谁的性能好
centos6
快照还原,禁止selinux和防火墙
getenforce
setenforce 0
vim /etc/selinux/config permissive 禁用selinux
chkconfig iptables off
service iptables stop
iptables -vnL
service httpd restart
centos7
yum -y install httpd
rpm -ql httpd
不同于centos6的内容
/etc/httpd/conf.modules.d和apr的包(centos6的版本过低)
systemctl start httpd 不设置开机启动,后期自己编译
systemctl status httpd
vim /etc/selinux/config
permissive 禁用selinux
systemctl stop firewalld
systemctl disable firewalld
iptables -F
iptables -vnL
cd /etc/httpd/conf.modules.d/ mpm存放路径,多功能处理模块
centos6: cat /etc/sysconfig/httpd centos6的mpm存放路径
httpd -M
httpd -M |grep prefork 启用
vim 00-mpm.conf
LoadModule mpm_event_module modules/mod_mpm_event.so 去掉#,启用event,加#禁用prefork
centos6中是静态编译的模块,centos7都是动态模块
httpd -M |grep event 启用
httpd -M |grep prefork 没有出现,即禁用
systemctl restart httpd
pstree -p
vim /etc/httpd/conf/httpd.conf
Include conf.modules.d/*.conf 模块的配置文件 看看即可
IncludeOptional conf.d/*.conf 配置文件放在此文件夹下也生效 看看即可
cd /var/www/html/
cp /var/log/messages m.txt 准备一个大文件
chmod +r m.txt; ll; mv m.txt index.html
systemctl restart httpd
浏览器:192.168.29.127
scp index.html 192.168.29.126:/var/www/html
centos6: ll /var/www/html; service httpd restart
浏览器:192.168.29.126
vim index.html centos6和centos7都操作
在文本的前后都加上<h1>...</h1>,看起来好看
centos5:
ab -c 100 -n 1000 http://192.168.29.126/ 每秒钟请求377-prefork
ab -c 100 -n 1000 http://192.168.29.127/ 每秒钟请求416-event
cd /etc/httpd/conf.modules.d
vim 00-mpm.conf
还原设置,启用prefork,禁用event
systemctl restart httpd
systemctl status httpd
mkdir -p /app/website1
echo "welcome to henansheng" > /app/website1/index.html
vim /etc/httpd/conf/httpd.conf
搜索:/DocumentRoot
DocumentRoot "/var/www/html" 更改为 DocumentRoot "/app/website1"
添加下面的信息:图1
<Directory "/app/website1">
Require all granted 所有用户都可以访问,不加此信息,则不允许访问,centos6是默认允许访问
</Directory>
systemctl restart httpd
浏览器:192.168.29.127
查看require指令的用法:区别于centos6的用法
http://httpd.apache.org/docs/2.4/mod/mod_authz_core.html#require
http://httpd.apache.org/docs/2.4/mod/mod_authz_core.html
vim /etc/httpd/conf/httpd.conf
<Directory "/app/website1"> 图2
<requireall>
Require all granted
require not ip 192.168.29.1 拒绝某个IP访问
</requireall>
</Directory>
或者
<Directory "/app/website1">
<requireall>
# Require all granted
require ip 192.168.29.1 允许某个IP访问,require ip 192.168.29 允许某个IP地址段访问
</requireall>
</Directory>
或者
<Directory "/app/website1">
<requireall>
# Require all granted
require not ip 192.168.29.1 不允许某个IP或者某个IP地址段访问
require ip 192.168.29.126 允许某个IP或者某个IP地址段访问
</requireall>
</Directory>
<Directory "/app/website1">
<requireall>或者<requireany>
require not ip 192.168.29.1 此写法语法错误
</requireall>或者</requireany>
</Directory>
systemctl restart httpd
浏览器:192.168.29.127 不能访问
centos5: curl 192.168.29.127 可以访问
虚拟主机
vim /etc/httpd/conf/httpd.conf
更改的部分都注释掉,回到默认的设置
cp -r /app/website1 /app/website2
cp -r /app/website1 /app/website3
vim /app/website2/index.html
welcome to henansheng_huojiaxian2
vim /app/website3/index.html
welcome to henansheng_huojiaxian_fengzhuangzhen3
vim /etc/httpd/conf.d/vhosts.conf centos7的主配置文件里没有VirtualHost的内容了
<virtualhost *:80>
documentroot /app/website1
servername www.a.com
errorlog logs/website1_error_log
customlog logs/website1_access_log combined
<directory "/app/website1">
require all granted 都可以访问,不用加 <requireall>... </requireall>
</directory>
</virtualhost>
<virtualhost *:80>
documentroot /app/website2
servername www.b.com
errorlog logs/website2_error_log
customlog logs/website2_access_log combined
<directory "/app/website2">
<requireany> 换成<requireall> 或者 删除<requireany>...</requireany>也可以
require ip 192.168.29.126 只允许192.168.29.126访问,其他不可以
</requireany>
</directory>
</virtualhost>
<virtualhost *:80>
documentroot /app/website3
servername www.c.com
errorlog logs/website3_error_log
customlog logs/website3_access_log combined
<directory "/app/website3">
<requireall> 不能换成<requireany>,not指令对于requireany无意义
require all granted
require not ip 192.168.29.126 允许192.168.29.126访问,其他可以
</requireall>
</directory>
</virtualhost>
httpd -t
systemctl restart httpd
centos5和centos6都操作
vim /etc/hosts 添加下面信息
192.168.28.127 www.a.com www.b.com www.c.com
centos5,centos6和centos7都操作
curl www.a.com
curl www.b.com
curl www.c.com
浏览器:192.168.28.127
ssl:安装mod_ssl,和httpd-2.2相同配置
yum -y install mod_ssl
rpm -ql mod_ssl
systemctl restart httpd
浏览器:https://192.168.28.127 可以访问
vim /etc/httpd/conf.d/ssl.conf
https的443端口,证书文件路径,以后自己搞证书文件路径,现在看看即可
vim /etc/httpd/conf.d/vhosts.conf 图3
把下面的信息放到虚拟主机1里面
KeepAlive on on为off,执行完操作后瞬间就会断开
KeepAliveTimeout 15000 ms
MaxKeepAliveRequests 100
毫秒级持久连接时长定义
systemctl restart httpd
参考文档
http://httpd.apache.org/docs/2.4/mod/core.html#keepalive
http://httpd.apache.org/docs/2.4/mod/core.html#maxkeepaliverequests
centos6
yum -y install telnet
curl -I www.a.com 未出现keepalive字样
telnet www.a.com 80
GET / HTTP/1.1 GET命令区分大小写,其他无所谓
HOST:WWW.A.COM
GET / HTTP/1.1
HOST:WWW.B.COM
Sendfile机制
sendfile()不但能减少切换次数而且还能减少拷贝次数
用sendfile()来进行网络传输的过程:
sendfile(socket, file, len);
硬盘 >> kernel buffer (快速拷贝到kernel socket buffer) >> 协议栈
vim /etc/httpd/conf/httpd.conf
搜索:/sendfile
反向代理功能 图4 图5
vim /etc/httpd/conf.d/vhosts.conf 图6
在虚拟主机里添加下面的信息,删除keepalive的信息
proxypass / http://192.168.29.126 我们在centos7上做,把请求转到centos6上,centos5访问
proxypassreverse / http://192.168.29.126
systemctl restart httpd
centos6
cd /var/www/html
echo centos6 > index.html
centos5
curl www.a.com
当访问bbs文件夹时,就转发,访问其他的,不转发
vim /etc/httpd/conf.d/vhosts.conf
proxypass /bbs http://192.168.29.126/forum 前后二者的名字可以不同
proxypassreverse /bbs http://192.168.29.126/forum
systemctl restart httpd
centos6
cd /var/www/html; mkdir forum; cd forum;
echo centos6 forum > index.html
centos5
curl www.a.com
curl http://www.a.com/bbs 出现301,即成功
浏览器:http://192.168.29.127
浏览器:http://192.168.29.127/bbs/
图1
image.png
图2
image.png
图3
image.png
图4
image.png
图5
image.png
图6
image.png
APR(Apache portable Run-time libraries,Apache可移植运行库)
主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。
APR主要还是由Apache使用,由于APR的较好的移植性,因此一些需要进行移植的C程序也开始使用APR。
在centos7编译安装httpd-2.4的最新版本
下载apr
apr-util安装的时候出现不兼容的问题,所以改用1.5版本的apr
rpm -qi apr
centos7上安装httpd-2.4,本机携带的apr版本1.4,足够用,不用再去网上下载
但是cento6上安装httpd-2.4,本机携带的apr版本1.3,不能使用,需要apr-1.4及以上版本才可以
网址:http://apr.apache.org/download.cgi 只是提供一个查询路径
apr-1.6.3.tar.bz2 和 apr-util-1.6.1.tar.bz2
网址:http://httpd.apache.org/ 可以下载
Apache httpd 2.4.29 Released——download——httpd-2.4.29.tar.bz2
centos7
systemctl stop httpd
ss -ntl
rz上传下载的3个文件:
apr-1.6.3.tar.bz2, apr-util-1.6.1.tar.bz2, httpd-2.4.29.tar.bz2
apr-util安装的时候出现不兼容的问题,所以改用1.5版本的apr:
apr-1.5.2.tar.bz2, apr-util-1.5.4.tar.bz2 文件包中有
mv apr-* httpd-2.4.29.tar.bz2 /usr/local/src/
cd /usr/local/src/ 此文件夹是专门存放源码文件
tar xvf apr-1.5.2.tar.bz2
tar xvf apr-util-1.5.4.tar.bz2
tar xvf httpd-2.4.29.tar.bz2
rpm -q apr; rpm -q apr-util 本机上就有这些包,不过版本太低
apache是基于apr的包,因此顺序要求:
先编译apr-1.5.2.tar.bz2
再编译apr-util-1.5.4.tar.bz2
后编译httpd-2.4.29.tar.bz2
yum -y groupinstall "Development tools"
ls /app/; rm -rf /app/*
cd apr-1.5.2/ 规划把文件路径放在/app/下面
./configure --prefix=/app/apr
rpm -q libtool; 出现libtool字样,不用管,已经有了
make && make install
cd ../apr-util-1.5.4/; ls
./configure --prefix=/app/apr-util --with-apr=/app/apr 依赖此模块
make && make install
cd ../httpd-2.4.29/ ;ls
./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/app/apr --with-apr-util=/app/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
缺什么包,装什么包,包名-devel
yum -y install pcre-devel
yum -y install openssl-devel
./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/app/apr --with-apr-util=/app/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
make && make install
cd /app/httpd24; ls; which httpd
cd bin/; ls; pwd; 我们设置的httpd不在路径里面
vim /etc/profile.d/app.sh
export PATH=/app/httpd24/bin:$PATH
. /etc/profile.d/app.sh
ps aux |grep httpd 没有启动
httpd -t 检查语法
ls; which apachectl
file apachectl; cat apachectl 服务启动的脚本,以后可以参考此文档做服务的启动脚本,start,stop,...
apachectl 默认就是启动
ps aux |grep httpd
浏览器:192.168.29.127 可以
cat /app/httpd24/htdocs/index.html
vim /app/httpd24/htdocs/index.html
<html><body><h1>httpd-2.4.29 It works!</h1></body></html>
浏览器:192.168.29.127
此脚本不合适在centos7上运行使用,不要操作了
复制centos6的service文件到centos7
centos6:scp /etc/init.d/httpd 192.168.29.127:/etc/init.d/httpd24
ls /etc/init.d/
vim /etc/init.d/httpd24
更改下面四处的文件路径即可
apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/httpd}
pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid} 进程编号存在的文件
lockfile=${LOCKFILE-/var/lock/subsys/httpd24} httpd程序启动,此文件就存在,否则,不存在
ls /app/httpd24/logs
cat /app/httpd24/logs/httpd.pid 进程编号存在的文件
chkconfig --list
chkconfig --add httpd24
chkconfig --list
service httpd24 start 开启后,提示找不到httpd24.service文件
ps aux |grep httpd24; pstree -p |grep httpd24
service httpd24 stopp
ps aux |grep httpd24; pstree -p |grep httpd24
apachectl
apachectl stop
浏览器:192.168.29.127
此脚本不合适在centos7上运行使用,不要操作了
在centos6 编译安装httpd-2.4
换一种编译方法:
解包后,把apr的包内容移到httpd-2.4包中,直接和httpd-2.4一起编译,如下
rpm -q apr; rpm -q apr-util 版本1.3过低,使用1.4以上才可以
service httpd stop; pstree -p |grep httpd; service httpd status 把本机的httpd服务关闭
chkconfig --list httpd 是否开机启动
chkconfig httpd off 不设置为开机启动
mkdir src; cd src 在根下直接创建
rz 上传apr的包至src文件夹下
tar xvf apr-1.5.2.tar.bz2
tar xvf apr-util-1.5.4.tar.bz2
tar xvf httpd-2.4.29.tar.bz2
cd /src/httpd-2.4.29/srclib
mv ~/src/apr-1.5.2 ./apr
mv ~/src/apr-util-1.5.4 ./apr-util; ls; cd ..; ls
yum -y groupinstall "Development tools"
编译时会缺少这两个包,所有直接安装
yum -y install pcre-devel openssl-devel
把 --with-apr=/app/apr --with-apr-util=/app/apr-util 换成 --with-included-apr
./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
make && make install
vim /etc/profile.d/app.sh
export PATH=/app/httpd24/bin:$PATH
. /etc/profile.d/app.sh
cp /etc/init.d/httpd /etc/init.d/httpd24
vim /etc/init.d/httpd24
更改为下面四处的文件路径即可
apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/httpd}
pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
ps aux |grep httpd 没有启动
apachectl 默认就是启动
ps aux |grep httpd
浏览器:192.168.29.126
apachectl stop; ps aux |grep httpd; pstree -p |grep httpd
浏览器:192.168.29.126 不能访问
服务停止后,就可以用service操作了
service httpd24 status
service httpd24 restart
chkconfig --list httpd24
chkconfig --add httpd24; chkconfig --list httpd24
cat /app/httpd24/htdocs/index.html
vim /app/httpd24/htdocs/index.html
<html><body><h1>Centos6.9 It works!</h1></body></html>
浏览器:192.168.29.127
whereis httpd
vim /etc/man.config 添加信息
MANPATH /app/httpd24/man
whereis httpd 没有/app/httpd24/man路径
下面的两步不要操作了
rpm -e httpd 删除httpd服务
man httpd 此时仍然可以查到