1. 程式人生 > >httpd服務配置與部署

httpd服務配置與部署

hosts .sh wget seed sts 不同的 glob wall recv

1.編譯安裝httpd-2.4
2.配置三種不同風格的虛擬主機
1 相同Ip不同端口
2相同端口不同ip
3相同IP相同端口不同域名
實驗環境說明:**

主機名 操作系統 ip地址
root@bogon ~ rhel7 192.168.43.199

更改主機名,關掉防火墻和selinux。

     [root@bogon ~]# systemctl stop firewalld.service
   [root@bogon ~]#  setenforce 0
   [root@bogon ~]# getenforce 
   Permissive*

#安裝開發環境

 [root@bogon ~]# yum groupinstall "Development Tools" -y
 過程略.......
 [root@bogon ~]# yum -y install openssl-devel pcre-devel expat-devel lib tool
 過程略......
 #下載並安裝apr-1.4+apr-util-1.4

 [root@bogon src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.tar.bz2
 過程略
 [root@bogon src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
 過程略

#下載完成後對其進行解壓

 [root@bogon src]# ls
apr-1.6.3.tar.bz2  apr-util-1.6.1.tar.bz2  debug  httpd-2.4.34.tar.bz2  kernels
[root@bogon src]# tar xf apr-1.6.3.tar.bz2 
[root@bogon src]# tar xf apr-util-1.6.1.tar.bz2 
[root@bogon 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文件

[root@bogon 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,編譯安裝過程省略。

[root@bogon apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@bogon apr-1.6.3]# make && make install
[root@bogon apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@bogon apr-util-1.6.1]# make && make install

#下載編譯安裝httpd:

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

#開啟服務

[root@bogon bin]# ./apachectl start
httpd (pid 62102) already running

#查看進程

[root@bogon 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
[root@bogon 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不同端口.

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

#更改配置文件內容。

[root@bogon ~]# 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
[root@httpd ~]# vim /etc/httpd24/httpd.conf 
#Listen 12.34.56.78:80
Listen 80
Listen 8080   #添加監聽8080端口

編輯配置文件:

[root@httpd ~]# 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服務:

[root@httpd bin]# ./apachectl restart

Windows開機服務驗證:
技術分享圖片
技術分享圖片
2.2相同端口不同的ip
#增加虛擬主機2的ip

[root@bogon ~]# ip addr add 192.168.43.111/24 dev ens33
[root@bogon ~]# 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地址:

[root@bogon 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服務:

[root@bogon ~]# cd /usr/local/apache/bin
[root@bogon bin]# ./apachectl restart
[root@bogon bin]# ss -ant

#在Windows瀏覽器上進行驗證:
技術分享圖片

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

[root@bogon 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服務配置與部署