httpd服务配置与部署

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了httpd服务配置与部署相关的知识,希望对你有一定的参考价值。

1.编译安装httpd-2.4
2.配置三种不同风格的虚拟主机
1 相同Ip不同端口
2相同端口不同ip
3相同IP相同端口不同域名
实验环境说明:**

主机名 操作系统 ip地址
[email protected] ~ rhel7 192.168.43.199

更改主机名,关掉防火墙和selinux。

     [[email protected] ~]# systemctl stop firewalld.service
   [[email protected] ~]#  setenforce 0
   [[email protected] ~]# getenforce 
   Permissive*

#安装开发环境

 [[email protected] ~]# yum groupinstall "Development Tools" -y
 过程略.......
 [[email protected] ~]# yum -y install openssl-devel pcre-devel expat-devel lib tool
 过程略......
 #下载并安装apr-1.4+apr-util-1.4

 [[email protected] src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.tar.bz2
 过程略
 [[email protected] src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
 过程略

#下载完成后对其进行解压

 [[email protected] src]# ls
apr-1.6.3.tar.bz2  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.34.tar.bz2  kernels
[[email protected] src]# tar xf apr-1.6.3.tar.bz2 
[[email protected] src]# tar xf apr-util-1.6.1.tar.bz2 
[[email protected] src]# ls
apr-1.6.3          apr-util-1.6.1          debug                 kernels
apr-1.6.3.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.34.tar.bz2

#编辑configure文件

[[email protected] apr-1.6.3]# vim configure

 cfgfile=${ofile}T
    trap "$RM "$cfgfile"; exit 1" 1 2 15
    #$RM "$cfgfile"    加注释

#编译安装 apr-1.6.3和apr-util-1.6.1,编译安装过程省略。

[[email protected] apr-1.6.3]# ./configure --prefix=/usr/local/apr
[[email protected] apr-1.6.3]# make && make install
[[email protected] apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[[email protected] apr-util-1.6.1]# make && make install

#下载编译安装httpd:

[[email protected] ~]#wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.3
4.tar.bz2
[[email protected] ~]# ls
anaconda-ks.cfg  httpd-2.4.34.tar.bz2
[[email protected] ~]# tar xf httpd-2.4.34.tar.bz2 
[[email protected] ~]# cd httpd-2.4.34
[[email protected] 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
 [[email protected] httpd-2.4.34]# make && make install

#开启服务

[[email protected] bin]# ./apachectl start
httpd (pid 62102) already running

#查看进程

[[email protected] bin]# ps -ef |grep httpd
root      62102      1  0 22:47 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    62103  62102  0 22:47 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    62104  62102  0 22:47 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    62105  62102  0 22:47 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    62106  62102  0 22:47 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    62107  62102  0 22:47 ?        00:00:00 /usr/local/apache/bin/httpd -k start
root      62114   2085  0 22:52 pts/1    00:00:00 grep --color=auto httpd
[[email protected] bin]# ss -antl
State      Recv-Q Send-Q Local Address:Port                Peer Address:Port              
LISTEN     0      128                *:22                             *:*                  
LISTEN     0      100        127.0.0.1:25                             *:*                  
LISTEN     0      128               :::80                            :::*                  
LISTEN     0      128               :::22                            :::*                  
LISTEN     0      100              ::1:25                            :::*

#在客户机上验证
技术分享图片

2.配置三种不同风格的虚拟主机
2.1相同ip不同端口.

[[email protected] htdocs]# mkdir yiyi
[[email protected] htdocs]# mkdir scsc
[[email protected] htdocs]# echo ‘hello‘ > /usr/local/apache/htdocs/yiyi/index.html
[[email protected] htdocs]#echo ‘world‘ > /usr/local/apache/htdocs/scsc/index.html
[[email protected] htdocs]# ls
index.html  scsc  yiyi

#更改配置文件内容。

[[email protected] ~]# vim /etc/httpd24/httpd.conf                                                                                                                                                      # If your host doesn‘t have a registered DNS name, enter its IP addres    s here.

      ServerName www.example.com:80    #取消前面的#号
   #Deny access to the entirety of your server‘s filesystem. You must
[[email protected] ~]# vim /etc/httpd24/httpd.conf 
#Listen 12.34.56.78:80
Listen 80
Listen 8080   #添加监听8080端口

编辑配置文件:

[[email protected] ~]# vim /etc/httpd24/httpd.conf

<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin 
</IfModule> 
<VirtualHost 192.168.118.100:80>
ServerName www.ls.com
    DocumentRoot "/usr/local/apache/htdocs/tom"
    ErrorLog "/usr/local/apache/htdocs/haha.log"
    CustomLog "/usr/local/apache/htdocs/haha.log" combined
    <Directory /usr/local/apache/htdocs/tom>
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost 192.168.118.100:8080>
ServerName www.jerry.com
    DocumentRoot "/usr/local/apache/htdocs/jerry"
    ErrorLog "/usr/local/apache/htdocs/haha.log"
    CustomLog "/usr/local/apache/htdocs/haha.log" combined
    <Directory /usr/local/apache/htdocs/jerry>
        Require all granted
    </Directory>
</VirtualHost>
"/etc/httpd24/httpd.conf" 530L, 19464C

#重启httpd服务:

[[email protected] bin]# ./apachectl restart

Windows开机服务验证:
技术分享图片
技术分享图片
2.2相同端口不同的ip
#增加虚拟主机2的ip

[[email protected] ~]# ip addr add 192.168.43.111/24 dev ens33
[[email protected] ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:39:f7:f2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.199/24 brd 192.168.43.255 scope global dynamic ens33
       valid_lft 3509sec preferred_lft 3509sec
    inet 192.168.168.34/24 brd 192.168.168.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.43.111/24 scope global secondary ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::9059:e88a:8b54:f6fa/64 scope link 
       valid_lft forever preferred_lft forever

#更改配置文件虚拟主机2的IP地址:

[[email protected] bin]# vim /etc/httpd24/httpd.conf
#virtual host 2
<VirtualHost 192.168.43.111:80>
    ServerName www.scsc.com
    DocumentRoot "/usr/local/apache/htdocs/scsc"
    ErrorLog "logs/error_log"
    CustomLog "logs/access_log" combined
        <Directory /usr/local/apache/htdocs/scsc>
              Require all granted
        </Directory>
</VirtualHost>

#重启一下httpd服务:

[[email protected] ~]# cd /usr/local/apache/bin
[[email protected] bin]# ./apachectl restart
[[email protected] bin]# ss -ant

#在Windows浏览器上进行验证:
技术分享图片

技术分享图片
3.相同IP相同端口不同域名
#更改配置文件:

[[email protected] bin]# vim /etc/httpd24/httpd.conf 

</IfModule>
#virtual host 1
<VirtualHost 192.168.43.199:80>
    ServerName www.yiyi.com
    DocumentRoot "/usr/local/apache/htdocs/yiyi"
    ErrorLog "logs/error_log"
    CustomLog "logs/access_log" combined
        <Directory /usr/local/apache/htdocs/yiyi>
                Require all granted
        </Directory>
</VirtualHost>
#virtual host 2
<VirtualHost 192.168.43.199:80>
    ServerName www.scsc.com
    DocumentRoot "/usr/local/apache/htdocs/scsc"
    ErrorLog "logs/error_log"
    CustomLog "logs/access_log" combined
        <Directory /usr/local/apache/htdocs/scsc>
              Require all granted
        </Directory>
</VirtualHost>

#在windows客户机上增加环境变量,让虚拟域名和虚拟主机ip对照:
技术分享图片
#找到hosts文件增加如下内容:

127.0.0.1 wwis-dubc1-vip60.adobe.com 
127.0.0.1 activate-sjc0.adobe.com 
192.168.43.199 www.scsc.com
192.168.43.199 www.yiyi.com

#重启服务,在Windows上进行验证:
技术分享图片
技术分享图片

以上是关于httpd服务配置与部署的主要内容,如果未能解决你的问题,请参考以下文章

部署SaltStack及批量安装httpd服务

Puppet下部署相关服务(httpd)

安装httpd过程,将网站部署到httpd过程

lamp部署

部署SaltStack及批量安装httpd服务

awstats日志分析系统部署(httpd)