redhat or centos rpm包搭建apache

简介:

                               apache(又称httpd)

  Apache是Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。
 
apache的搭建:
 
用rpm包搭建
a)
先挂载光盘
mount /dev/cdrom /media/
 
b)
进入你的光盘文件中  
cd /media/Server/(5.x的是/media/Server/,6.x的是/media/Packages)
rpm -ivh httpd-tools-2.2.15-15.el6.centos.1.i686            (apache的工具包)
rpm -ivh httpd-manual-2.2.15-15.el6.centos.1.noarch         (apache的帮助手册文档)
rpm -ivh httpd-devel-2.2.15-15.el6.centos.1.i686            (apache的开发工具包)    
rpm -ivh httpd-2.2.15-15.el6.centos.1.i686                  (apache的程序软件包)
自己解决依赖性包
 
or(或者自己搭建yum了用yum安装)
 
yum -y install httpd* (这样也会安装这个四个包)
 
 
c)
rpm包安装完成后,了解apache服务器相关的主要目录和文件
 
/etc/httpd                                (apache服务器的根目录)
/etc/httpd/conf/httpd.conf/               (apache服务器的主配置文件)
/var/www/html/                            (网页文档的默认的根目录)
/etc/init.d/httpd                         (apache服务的控制脚本文件)
/usr/sbin/httpd                           (apache服务的主要执行程序)
/var/log/httpd/access_log                 (访问日志文件)
/var/log/httpd/error_log                  (错误的日志文件 )
/etc/httpd/logs/error_log                 (日志文件,服务开启不了就查看日志)
 
d)
搭建完成后开启服务
[root@Centos httpd]# service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for Centos
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
                                                           [  OK  ]
第一次启动的时候,会提示这样的信息,不过这样apache也是开启了,改一下配置文件就可以不提示上面的信息了。
 
e)
vim /etc/httpd/conf/httpd.conf
 
###添加这句(直接copy)
ServerName 192.168.4.184:80 
###保存退出
ServerName 192.168.4.184:80 (有域名就写域名ServerName www.abc.com:80)
在重启服务就不会提示上面的信息了。
[root@Centos httpd]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
重启之后就测试一下看apache能不能正常访问
可以先在你搭建的服务器上关闭防火墙和selinux
iptables -F  (关闭防火墙)
setenforce 0 (关闭selinux)
用IE浏览器直接测试 http://ip(域名)测试能访问
 
基本的已经搭建完成了
 
#####################apache的相关操作#####################
 
基于客户端地址的访问控制
<directory>
deny from [address1] [address2]…… 拒绝哪些地址
allow from [address1] [address2]…… 允许哪些地址
order allow,deny: 先允许后拒绝,默认拒绝所有未明确允许的客户端地址
order deny,allow: 先拒绝后允许,默认允许所有未明确允许的客户端地址
</directory>
 
 
1、httpd的虚拟目录(可以做不同的网页)
虚拟目录的优点,虚拟目录只是一个链接,所以易于移动和扩充
 
a)先建立虚拟目录
mkdir -p /data/web  (这个data目录你可以是一个很大的硬盘挂载过来的,-p是递归的建立)
mkdir -p /data/web/test01  (建立两个虚拟目录一个是test01,一个是test02)
mkdir -p /data/web/test02  
b)在httpd配置文件中,加入虚拟目录所需的配置
vim /etc/httpd/conf/httpd.conf 
 
#####添加这句
Include vhost/vhost.conf
#####然后保存退出
 
c)新建配置文件里面加入的目录和文件
mkdir /etc/httpd/vhost
touch /etc/httpd/vhost/vhost.conf
 
d)修改虚拟目录的配置文件
vim /etc/httpd/vhost/vhost.conf
 
######添加如下几行
Alias /test01 "/data/web/test01/"
<Directory "/data/web/test01">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
Alias /test02 "/data/web/test02/"
<Directory "/data/web/test02">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
####加入这些然后保存退出
 
e)为test01和test02建立两个网页文件来测试一下
echo "this is test01 website welcome" >> /data/web/test01/index.html
echo "this is test02 website welcome" >> /data/web/test02/index.html
然后用浏览器来测试一下
http://192.168.4.184/test01(输入这里之后直接回车,因为我们定义别名的时候没加/)
   显示this is test01 webiste welcome
http://192.168.4.184/test02
  显示this is test02 website welcome
则httpd的虚拟目录ok了。
 
 
2、认证和授权
(i)、对用户设置认证和授权
a)修改虚拟目录的配置文件
vim /etc/httpd/vhost/vhost.conf
修改虚拟目录的配置文件,让访问test01时,需要进行授权认证才能访问
 
#####
Alias /test01 "/data/web/test01/"
<Directory "/data/web/test01">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    AuthType basic
    AuthName "welcome test"
    AuthUserFile /etc/httpd/httppwd
    Require user test test01
</Directory>
Alias /test02 "/data/web/test02/"
<Directory "/data/web/test02">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
######保存退出
命令的解释
    AuthType basic                      (basic认证)
    AuthName "welcome test"              (认证提示的名字)
   AuthUserFile /etc/httpd/httppwd     (认证的文件)
    require user test test01         (允许的用户名)
 
 
重启httpd
 
然后用IE测试:http://192.168.4.184/test01
需要输入用户名和密码才能访问
 
b)为test用户建立密码,能访问test01这个目录的密码
[root@Centos httpd]# pwd
/etc/httpd  在这个目录下
[root@Centos httpd]# htpasswd -c httppwd test(添加第一个用户)
New password: 
Re-type new password:  
 
htpasswd  httppwd test01(添加第二个,或者多个的时候都不需要-c了)
需要在这个里面添加多个
vim /etc/httpd/vhost/vhost.conf
#####
require user test test01(依次在后面添加就可以了)
 
然后重启httpd服务
 
(ii)、对组设置认证和授权
cd ../
vim /etc/httpd/vhost/vhost.conf
修改虚拟目录的配置文件,让访问test01时,需要进行授权认证才能访问
 
########
Alias /test01 "/data/web/test01/"
<Directory "/data/web/test01">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    AuthType basic
    AuthName "welcome admin"
    AuthUserFile /etc/httpd/httppwd
    AuthGroupFile /etc/httpd/httpgrp
    Require group admin
</Directory>
Alias /test02 "/data/web/test02/"
<Directory "/data/web/test02">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
########然后保存退出
 
 
vim /etc/httpd/httpgrp
###
admin:test test01(需要加入直接玩后面添加)
####然后保存退出
 
[root@Centos httpd]# pwd
/etc/httpd在这个目录下面
htpasswd httppwd test
htpasswd httppwd test01
 
然后重启服务
service httpd restart
 
然后用IE测试:http://192.168.4.184/test01
需要输入用户名和密码才能访问,这里的用户名必须是能让组访问的里面
 
 
 
3、虚拟主机
 
(i)、不同ip,同一个域名,同端口
a)修改apache的配置文件
vim /etc/httpd/conf/httpd.conf 
 
####
Include vhost/vhost.conf  (这句是建立虚拟目录的时候添加的,这个不注释是有区别的)
Include virtualhost/virtualhost.conf (这句是新添加的)
#####这里不注释,然后保存退出
 
b)新建虚拟主机的目录和配置文件                                    
mkdir -p /etc/httpd/virtualhost (新建一个虚拟主机的目录,这里对应httpd配置文件里面的Include内容)
 
vim /etc/httpd/virtualhost/virtualhost.conf  (新建一个虚拟主机目录的配置文件,这里也一样)
 
#####
<VirtualHost 192.168.4.1:80>
    ServerAdmin webmaster@dummy-host.example.com   
    DocumentRoot /data/web/test01  
    ServerName dummy-host.example.com 
    ErrorLog     /data/log/test01.error_log           
    CustomLog  /data/log/test01.access_log combined
</VirtualHost>
 
<VirtualHost 192.168.4.2:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /data/web/test02
    ServerName dummy-host.example.com 
    ErrorLog     /data/log/test02.error_log           
    CustomLog  /data/log/test02.access_log combined
</VirtualHost>
#####保存退出
参数的解释:
ServerAdmin webmaster@dummy-host.example.com   
(这个可以随便写)
DocumentRoot /data/web/test01  
(这个是存放网页文件的目录)
ServerName dummy-host.example.com            
(这个是写域名的,有自己的域名,就写自己的域名,没有域名随便写了也不要紧,因为我们用ip访问)
CustomLog  /data/log/virtualhost/access_log combined
用于设置httpd服务器访问日志文件的路径和格式类型,这个文件里面写入这你登录的记录
ErrorLog     /data/log/error_log
用于设置错误日志文件的路径和文件名(如果你设置了,那这个目录和文件必须存在,木有就新建)这个文件
写入的是,你登录错误的记录
 
c)现在新建虚拟主机配置文件里面指定的目录,因为没有,那就要新建
mkdir -p /data/log/ (ErrorLog 和CustomLog指定的路径)
cd /data/log/ 
touch test01.error_log test01.access_log  test02.error_log test02.access_log 
 
然后重启服务 service httpd restart
 
d)模拟ip出来
ifconfig eth0:0 192.168.4.1 up
ifconfig eth0:1 192.168.4.2 up
虚拟两个ip出来,实际环境服务器最好用真实的网卡,这个只是临时模拟的,当网卡重启之后
虚拟的网卡就木有了,如果想reboot之后都存在,那就把网卡写到配置文件里面去
 
测试:当你用浏览器访问
http://192.168.4.1的时候其实是访问之前做的虚拟目录的test01里面的网页文件
这个时候是需要输入用户名和密码的,因为之前对test01做了认证授权
Include vhost/vhost.conf  httpd的配置文件这个木有注释掉,这个虚拟目录对test01里面的网页文件
是有认证和授权的
http://192.168.4.2这个可以直接访问
 
(ii)同ip不同端口号
vim /etc/httpd/virtualhost/virtualhost.conf  
 
#####
Listen 80
Listen 8080
<VirtualHost 192.168.4.1:80>
    ServerAdmin webmaster@dummy-host.example.com   
    DocumentRoot /data/web/test01  
    ServerName dummy-host.example.com 
    ErrorLog     /data/log/test01.error_log           
    CustomLog  /data/log/test01.access_log combined
</VirtualHost>
 
<VirtualHost 192.168.4.1:8080>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /data/web/test02
    ServerName dummy-host.example.com 
    ErrorLog     /data/log/test02.error_log           
    CustomLog  /data/log/test02.access_log combined
</VirtualHost>
#####保存退出
重启服务开始测试(这个其它的步骤和不同ip的一样,就是改一下配置文件)
 
(iii)同ip同端口不同域名
 
vim /etc/httpd/virtualhost/virtualhost.conf  (新建一个虚拟主机目录的配置文件,这里也一样)
 
#####
 
<VirtualHost 192.168.4.1:80>
    ServerAdmin webmaster@dummy-host.example.com   
    DocumentRoot /data/web/test01  
    ServerName   www.abc.com 
    ErrorLog     /data/log/test01.error_log           
    CustomLog  /data/log/test01.access_log combined
</VirtualHost>
 
<VirtualHost 192.168.4.1:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /data/web/test02
    ServerName   www.xyz.com
    ErrorLog     /data/log/test02.error_log           
    CustomLog  /data/log/test02.access_log combined
</VirtualHost>
#####保存退出
如果临时的不能搭建dns,可以用host文件代替
vim /etc/hosts
192.168.4.1  www.abc.com
192.168.4.1  www.xyz.com
 
重启服务开始测试(这个其它的步骤和不同ip的一样,就是改一下配置文件)
 
 
 
 
站点压力测评
 
tar  zcvf  webbench-
make  && make install
 
测试
webbench -c 500 -t 30 http://ip/test.php
-c表示并发数 -t表示时间









本文转自 jie783213507 51CTO博客,原文链接:http://blog.51cto.com/litaotao/1186911,如需转载请自行联系原作者
相关实践学习
基于函数计算快速搭建Hexo博客系统
本场景介绍如何使用阿里云函数计算服务命令行工具快速搭建一个Hexo博客。
目录
相关文章
|
4月前
|
Linux 网络安全 Apache
Centos下操作Apache httpd
Centos下操作Apache httpd
69 0
|
6月前
|
Java Linux 网络安全
【Linux环境】Centos 7启动jar包的详细步骤
【Linux环境】Centos 7启动jar包的详细步骤
212 0
|
7月前
|
Linux Shell 开发工具
centos7源码包安装git傻瓜式安装步骤
centos7源码包安装git傻瓜式安装步骤
230 0
|
7月前
|
网络协议 Linux 应用服务中间件
2022红帽企业版网络配置--centos7配置DHCP DNS绑定域名 FTP HTTP(apache) nginx samba
2022红帽企业版网络配置--centos7配置DHCP DNS绑定域名 FTP HTTP(apache) nginx samba
149 0
|
1月前
|
Java Linux
Flume【环境搭建 01】CentOS Linux release 7.5 安装配置 apache-flume-1.9.0 并验证
【2月更文挑战第16天】Flume【环境搭建 01】CentOS Linux release 7.5 安装配置 apache-flume-1.9.0 并验证
29 0
|
1月前
|
分布式计算 关系型数据库 MySQL
Sqoop【部署 01】CentOS Linux release 7.5 安装配置 sqoop-1.4.7 解决警告并验证(附Sqoop1+Sqoop2最新版安装包+MySQL驱动包资源)
【2月更文挑战第8天】Sqoop CentOS Linux release 7.5 安装配置 sqoop-1.4.7 解决警告并验证(附Sqoop1+Sqoop2最新版安装包+MySQL驱动包资源)
93 1
|
5月前
|
Linux
Centos查看已经安装的软件或者包
Centos查看已经安装的软件或者包
175 0
|
9天前
|
Linux Apache
CentOS 7 源码安装LAMP环境源 和apache监听别的端口
CentOS 7 源码安装LAMP环境源 和apache监听别的端口
12 0
|
8月前
|
Linux Apache
Apache Doris集群模式快速体验之CentOS7安装(1)2
Apache Doris集群模式快速体验之CentOS7安装(1)2
117 0
|
4月前
|
中间件 Linux 网络安全
CentOS 7系统下Apache服务部署
对前篇博客(十七)进行一个修正与补充 基于不同的端口号,实现多虚拟主机部署并访问
41 0