1. 程式人生 > >httpd的編譯安裝和三類虛擬機器

httpd的編譯安裝和三類虛擬機器

編譯安裝httpd-2.4

實驗環境

主機名 型別 IP
[[email protected] ~] 服務端 192.168.102.128
  • 關閉防火牆
  • 關閉selinux

安裝開發環境

[[email protected] ~]# yum groupinstall "Development Tools"
[[email protected] ~]# useradd -r -g apache apache              #建立apache使用者並將其加入apache組中
[
[email protected]
~]# yum -y install openssl-devel pcre-devel expat-devel libtool

下載並解壓apr-1.6.3和apr-util-1.6.1

[[email protected] ~]# cd /usr/src/
[[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]# 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-1.6.3.tar.bz2 apr-util-1.6.1 apr-util-1.6.1.tar.bz2 debug kernels [[email protected] src]# cd apr-1.6.3 [[email protected] apr-1.6.3]# vim configure cfgfile="${ofile}T" trap "$RM \"$cfgfile\"; exit 1" 1 2 15 # $RM "$cfgfile" #刪除此行,或者加上註釋

編譯安裝

[[email protected] apr-1.6.3]# ./configure --prefix=/usr/local/apr
[[email protected] apr-1.6.3]# make && make install
[[email protected] apr-1.6.3]# cd /usr/src/apr-util-1.6.1
[[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-2.4

[[email protected] ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.3
4.tar.bz2
[[email protected] ~]# ls
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] httpd-2.4.34]cd /usr/local/apache/bin
[[email protected] bin]# ./apachectl start

查詢正在執行的httpd服務程序

[[email protected] ~]# ps -ef |grep httpd
root      40225      1  0 10:47 ?        00:00:01 /usr/local/apache/bin/httpd -k start
root      40446   6276  0 10:57 pts/2    00:00:00 vim /etc/httpd24/httpd.conf
daemon    40766  40225  0 11:17 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    40767  40225  0 11:17 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    40768  40225  0 11:17 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    40769  40225  0 11:17 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    40770  40225  0 11:17 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    40825  40225  0 11:23 ?        00:00:00 /usr/local/apache/bin/httpd -k start
root      43027   6276  0 15:18 pts/2    00:00:00 grep --color=auto httpd

在Windows上面驗證(用谷歌或者火狐)
在這裡插入圖片描述

配置三種類型虛擬機器

1、相同IP不同埠

[[email protected] htdocs]# pwd
/usr/local/apache/htdocs
[[email protected] htdocs]# mkdir ow
[[email protected] htdocs]# mkdir wf
[[email protected] htdocs]# touch mm.log
[[email protected] htdocs]# echo 'hello' > ow/index.html
[[email protected] htdocs]# echo 'hello world' > wf/index.html
[[email protected] htdocs]# ls
mm.log index.html ow wf

更改配置檔案

[[email protected] ~]# vim /etc/httpd24/httpd.conf 
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. [email protected]
#
ServerAdmin [email protected]     #設定管理員郵箱


-------------
# 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

-----------------
#Listen 12.34.56.78:80
Listen 80
Listen 8080   #新增監聽8080埠


-----------------
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin   #在配置檔案下增加如下內容
</IfModule> 
<VirtualHost 192.168.102.128:80>         #虛擬主機1
    ServerName www.ddkddkddk.com
    DocumentRoot "/usr/local/apache/htdocs/ow"
    ErrorLog "/usr/local/apache/htdocs/mm.log"
    CustomLog "/usr/local/apache/htdocs/mm.log" combined
    <Directory /usr/local/apache/htdocs/ow>
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost 192.168.102.128:8080>         #虛擬主機2,埠為8080
    ServerName www.wf.com
    DocumentRoot "/usr/local/apache/htdocs/wf"
    ErrorLog "/usr/local/apache/htdocs/mm.log"
    CustomLog "/usr/local/apache/htdocs/mm.log" combined
    <Directory /usr/local/apache/htdocs/wf>
        Require all granted
    </Directory>
</VirtualHost>

--------------------
重啟
[[email protected] bin]# ./apachectl restart
[[email protected]r bin]# pwd
/usr/local/apache/bin

Windows驗證
在這裡插入圖片描述
在這裡插入圖片描述

2、相同埠不同IP

[[email protected] ~]# ip addr add 192.168.102.129/24 dev ens33    #增加ip
[[email protected] ~]# ip a                     #檢視ip
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:df:b0:34 brd ff:ff:ff:ff:ff:ff
    inet 192.168.102.128/24 brd 192.168.118.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.102.129/24 scope global secondary ens33
       valid_lft forever preferred_lft forever

改配置

[[email protected] ~]# vim /etc/httpd24/httpd.conf 
##
#       but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>        
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin           #在配置檔案末尾增加如下內容
</IfModule>       
<VirtualHost 192.168.102.128:80>           #虛擬主機1
    ServerName www.ddkddkddk.com
    DocumentRoot "/usr/local/apache/htdocs/ow"
    ErrorLog "/usr/local/apache/htdocs/mm.log"
    CustomLog "/usr/local/apache/htdocs/mm.log" combined
    <Directory /usr/local/apache/htdocs/ow>
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost 192.168.102.129:80>            #虛擬主機2  ip為192.168.102.129
    ServerName www.dxkdxkdxk.com
    DocumentRoot "/usr/local/apache/htdocs/wf"
    ErrorLog "/usr/local/apache/htdocs/mm.log"
    CustomLog "/usr/local/apache/htdocs/mm.log" combined
    <Directory /usr/local/apache/htdocs/wf>
        Require all granted
    </Directory>
</VirtualHost>

------------------
[[email protected] bin]# ./apachectl restart
[[email protected] bin]# pwd
/usr/local/apache/bin

Windows驗證
在這裡插入圖片描述
在這裡插入圖片描述
2、相同IP相同埠不同域名
更改配置

[[email protected] ~]# vim /etc/httpd24/httpd.conf 
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin       #在配置檔案下增加如下內容
</IfModule>
<VirtualHost 192.168.102.128:80>     #虛擬主機1與虛擬主機二ip和埠號相同
    ServerName www.ddkddkddk.com              #虛擬主機1訪問域名
    DocumentRoot "/usr/local/apache/htdocs/ow"
    ErrorLog "/usr/local/apache/htdocs/mm.log"
    CustomLog "/usr/local/apache/htdocs/mm.log" combined
    <Directory /usr/local/apache/htdocs/ow>
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost 192.168.102.128:80>
    ServerName www.dxkdxkdxk.com         #虛擬主機二訪問域名
    DocumentRoot "/usr/local/apache/htdocs/wf"
    ErrorLog "/usr/local/apache/htdocs/mm.log"
    CustomLog "/usr/local/apache/htdocs/mm.log" combined
    <Directory /usr/local/apache/htdocs/wf>
        Require all granted
    </Directory>
</VirtualHost>

windows
在這裡插入圖片描述
在這裡插入圖片描述
重啟

[[email protected] bin]# ./apachectl restart
[[email protected] bin]# pwd
/usr/local/apache/bin

windows驗證
在這裡插入圖片描述
在這裡插入圖片描述
nice!成功!