httpd安装编译

1.httpd简介

httpd是Apache超文本传输协议(HTTP)服务器的主程序。被设计为一个独立运行的后台进程,它会建立一个处理请求的子进程或线程的池。

通常,httpd不应该被直接调用,而应该在类Unix系统中由apachectl调用,在Windows中作为服务运行。

2.httpd版本

本文主要介绍httpd的两大版本,httpd-2.2和httpd-2.4。

  • CentOS6系列的版本默认提供的是httpd-2.2版本的rpm包
  • CentOS7系列的版本默认提供的是httpd-2.4版本的rpm包

2.1 httpd-2.4新增的模块

httpd-2.4在之前的版本基础上新增了几大模块,下面就几个常用的来介绍一下。

模块功能
mod_proxy_fcgi反向代理时支持apache服务器后端协议的模块
mod_ratelimit提供速率限制功能的模块
mod_remoteip基于ip的访问控制机制被改变,不再支持使用Order,Deny,Allow来做基于IP的访问控制

3.httpd基础

3.1 httpd自带的工具程序

工具功能
htpasswdbasic认证基于文件实现时,用到的帐号密码生成工具
apachectlhttpd自带的服务控制脚本,支持start,stop,restart
apxs由httpd-devel包提供的,扩展httpd使用第三方模块的工具
rotatelogs日志滚动工具
suexec访问某些有特殊权限配置的资源时,临时切换至指定用户运行的工具
abapache benchmark,httpd的压力测试工具

3.2 rpm包安装的httpd程序环境

文件/目录对应的功能
/var/log/httpd/access.log访问日志
/var/log/httpd/error_log错误日志
/var/www/html/站点文档目录
/usr/lib64/httpd/modules/模块文件路径
/etc/httpd/conf/httpd.conf主配置文件
/etc/httpd/conf.modules.d/*.conf模块配置文件
模块配置文件辅助配置文件

mpm:以DSO机制提供,配置文件为/etc/httpd/conf.modules.d/00-mpm.conf

编译安装httpd-2.4

httpd依赖于apr-1.4+,apr-util-1.4+,[apr-icon]

apr:apache portable runtime

//安装开发环境
[root@localhost ~]# yum groupinstall "Development Tools"
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.69-11.el7 will be installed
--> Processing Dependency: m4 >= 1.4.14 for package: autoconf-2.69-11.el7.noarch
--> Processing Dependency: perl(Data::Dumper) for package: autoconf-2.69-11.el7.noarch
---> Package automake.noarch 0:1.13.4-3.el7 will be installed
--> Processing Dependency: perl(Thread::Queue) for package: automake-1.13.4-3.el7.noarch 
......
......
Dependency Updated:
  elfutils-libelf.x86_64 0:0.170-4.el7             elfutils-libs.x86_64 0:0.170-4.el7
  glibc.x86_64 0:2.17-222.el7                      glibc-common.x86_64 0:2.17-222.el7
  libgcc.x86_64 0:4.8.5-28.el7_5.1                 libgomp.x86_64 0:4.8.5-28.el7_5.1
  libstdc++.x86_64 0:4.8.5-28.el7_5.1              rpm.x86_64 0:4.11.3-32.el7
  rpm-build-libs.x86_64 0:4.11.3-32.el7            rpm-libs.x86_64 0:4.11.3-32.el7
  rpm-python.x86_64 0:4.11.3-32.el7

Complete!

[root@localhost ~]# groupadd -r apache
[root@localhost ~]# useradd -r -g apache apache
[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package openssl-devel.x86_64 1:1.0.2k-12.el7 will be installed
--> Processing Dependency: openssl-libs(x86-64) = 1:1.0.2k-12.el7 for package: 1:openssl-devel-1.0.2k-12.el7.x86_64 
......
......
  libselinux-utils.x86_64 0:2.5-12.el7          libsepol.x86_64 0:2.5-8.1.el7
  libss.x86_64 0:1.42.9-12.el7_5                openssl.x86_64 1:1.0.2k-12.el7
  openssl-libs.x86_64 1:1.0.2k-12.el7

Complete!

//下载并安装apr-1.6+和apr-util-1.6+
[root@localhost ~]# cd /usr/src/
[root@localhost src]# tar xf apr-1.6.3.tar.bz2
[root@localhost src]# tar xf apr-util-1.6.1.tar.bz2
[root@localhost src]# ls
apr-1.6.3  apr-1.6.3.tar.bz2  apr-util-1.6.1  apr-util-1.6.1.tar.bz2  debug  kernels
[root@localhost src]# cd apr-1.6.3
[root@localhost apr-1.6.5]# vim configure
    cfgfile="${ofile}T"
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    # $RM "$cfgfile"        //将此行加上注释,或者删除此行
    
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr
配置过程略...
[root@localhost apr-1.6.3]# make && make install
编译安装过程略...

[root@localhost apr-1.6.3]# cd /usr/src/apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
配置过程略...
[root@localhost apr-util-1.6.1]# make && make install
编译安装过程略...

//编译安装httpd

[root@localhost ~]# ls
httpd-2.4.34.tar.bz2
[root@localhost ~]# tar xf httpd-2.4.34.tar.bz2
[root@localhost ~]# cd httpd-2.4.34
[root@localhost httpd-2.4.34]# ./configure --prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork

[root@localhost httpd-2.4.34]# make && make install
编译安装过程略...

虚拟主机

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

ServerAdmin root@localhost

ServerName gives the name and port that the server uses to identify itself.

This can often be determined automatically, but we recommend you specify

it explicitly to prevent problems during startup.

If your host doesn’t have a registered DNS name, enter its IP address here.

ServerName www.example.com:80 //取消此行前面的#号

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
//在配置文件的最后加上如下内容
[root@localhost ~]# tail -25 /etc/httpd/conf/httpd.conf

virtual host 1 # 虚拟主机1的配置

<VirtualHost 192.168.26.10:80>
ServerName www.test1.com
DocumentRoot “/usr/local/apache/htdogs/test1”
ErrorLog “logs/test1_error_log”
CustomLog “logs/test1_access_log” combined
<Directory /usr/local/apache/htdogs/test1>

Require ip 192.168.26.11


virtual host 2 # 虚拟主机2的配置

<VirtualHost 192.168.26.10:8080>
ServerName www.test2.com
DocumentRoot “/usr/local/apache/htdogs/test2”
ErrorLog “logs/test2_error_log”
CustomLog “logs/test2_access_log” combined
<Directory /usr/local/apache/htdogs/test2>

Require ip 192.168.26.11


修改配置文件
  在Listen 80后面加一行
   Listen 8080

//创建网页目录并修改属主属组
[root@localhost www]# cd /var/www/html
[root@localhost html]# ls
[root@localhost html]# mkdir www blog
[root@localhost html]# ll
总用量 0
drwxr-xr-x. 2 root root 6 1月 16 17:31 blog
drwxr-xr-x. 2 root root 6 1月 16 17:31 www

[root@localhost html]# chown -R apache.apache blog
[root@localhost html]# chown -R apache.apache www
[root@localhost html]# ll
总用量 0
drwxr-xr-x. 2 apache apache 6 1月 16 17:31 blog
drwxr-xr-x. 2 apache apache 6 1月 16 17:31 www

//创建网页
[root@localhost html]# pwd
/var/www/html
[root@localhost html]# ls
blog www
[root@localhost html]# echo ‘hello welcome to visit www’ > www/index.html
[root@localhost html]# echo ‘hello welcome to visit blog’ > blog/index.html
// 创建相应网页的日志记录
[root@localhost html]# mkdir /var/log/httpd/{www,blog}
[root@localhost html]# ll /var/log/httpd/
总用量 8
-rw-r–r--. 1 root root 1152 1月 16 17:22 access_log
drwxr-xr-x. 2 root root 6 1月 16 17:34 blog
-rw-r–r--. 1 root root 2686 1月 16 17:22 error_log
drwxr-xr-x. 2 root root 6 1月 16 17:34 www
//启动服务并查看是否有80端口
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# ss -antl

// 在客户机上验证
1.修改hosts文件
[root@localhost ~]# cat /etc/hosts

Host Database

localhost is used to configure the loopback interface

when the system is booting. Do not change this entry.

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
118.31.33.0 zabbix.forevercq.com
0.0.0.0 account.jetbrains.com

192.168.26.10 www.test1.com
192.168.26.10 blog.test2.com

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值