您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關LAMP架構中Apache服務基于IP的虛擬主機配置的示例分析,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
基于IP的虛擬主機配置
基于IP的虛擬主機————就是說每個虛擬主機使用一個獨立的IP地址
服務器配置多塊網卡實現,或者同一塊網卡配置多個IP實現都可以
今天模擬的環境是同一網卡配置多個IP地址實現基于IP的虛擬主機配置
一:新增IP地址
[root@Centos ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:AA:CA:2B
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feaa:ca2b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2345 errors:0 dropped:0 overruns:0 frame:0
TX packets:694 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:224750 (219.4 KiB) TX bytes:92020 (89.8 KiB)
在eth0上新增一個IP地址用于測試使用
[root@Centos ~]# ifconfig eth0:20 192.168.1.20 netmask 255.255.255.0 up
[root@Centos ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:AA:CA:2B
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feaa:ca2b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2468 errors:0 dropped:0 overruns:0 frame:0
TX packets:767 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:235882 (230.3 KiB) TX bytes:100158 (97.8 KiB)
eth0:20 Link encap:Ethernet HWaddr 00:0C:29:AA:CA:2B
inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
二:聯通性測試
在本地客戶端主機上測試聯通性
C:\Users\Administrator>ping 192.168.1.20
正在 Ping 192.168.1.20 具有 32 字節的數據:
來自 192.168.1.20 的回復: 字節=32 時間<1ms TTL=64
來自 192.168.1.20 的回復: 字節=32 時間<1ms TTL=64
來自 192.168.1.20 的回復: 字節=32 時間<1ms TTL=64
來自 192.168.1.20 的回復: 字節=32 時間<1ms TTL=64
192.168.1.20 的 Ping 統計信息:
數據包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),
往返行程的估計時間(以毫秒為單位):
最短 = 0ms,最長 = 0ms,平均 = 0ms
三:備份虛擬主機配置文件
提示:生產環境一定要養成良好的習慣
[root@Centos ~]# cd /application/apache/conf/extra/
[root@Centos extra]# cp httpd-vhosts.conf httpd-vhosts.conf.$(date +%F)
[root@Centos extra]# ls -ll
total 76
-rw-r--r--. 1 root root 2895 Sep 12 03:30 httpd-autoindex.conf
-rw-r--r--. 1 root root 1852 Sep 12 03:30 httpd-dav.conf
-rw-r--r--. 1 root root 2942 Sep 12 03:30 httpd-default.conf
-rw-r--r--. 1 root root 1119 Sep 12 03:30 httpd-info.conf
-rw-r--r--. 1 root root 5078 Sep 12 03:30 httpd-languages.conf
-rw-r--r--. 1 root root 1039 Sep 12 03:30 httpd-manual.conf
-rw-r--r--. 1 root root 4444 Sep 12 03:30 httpd-mpm.conf
-rw-r--r--. 1 root root 2243 Sep 12 03:30 httpd-multilang-errordoc.conf
-rw-r--r--. 1 root root 13506 Sep 12 03:30 httpd-ssl.conf
-rw-r--r--. 1 root root 694 Sep 12 03:30 httpd-userdir.conf
-rw-r--r--. 1 root root 1037 Sep 13 06:35 httpd-vhosts.conf
-rw-r--r--. 1 root root 1481 Sep 13 06:28 httpd-vhosts.conf.2016-09-13
-rw-r--r--. 1 root root 1037 Sep 15 02:04 httpd-vhosts.conf.2016-09-15
-rw-r--r--. 1 root root 3161 Sep 12 03:30 proxy-html.conf
四:配置虛擬主機配置文件
[root@Centos extra]# vi httpd-vhosts.conf
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost 192.168.1.20:80>
ServerAdmin admini@abc.com
DocumentRoot "/data/www/bbs"
ServerName 192.168.1.20
ServerAlias abc.com
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
上面的標記部分為修改的配置
[root@Centos extra]# ../../bin/apachectl graceful
httpd not running, trying to start
發現httpd服務并沒有開機自啟動
檢查發現/etc/init.d/下沒有httpd服務
[root@Centos extra]# cd /etc/init.d/
[root@Centos init.d]# ls
abrt-ccpp crond killall ntpd rpcgssd sshd
abrtd cups lvm2-lvmetad ntpdate rpcidmapd sssd
abrt-oops dnsmasq lvm2-monitor oddjobd rpcsvcgssd sysstat
acpid firstboot mdmonitor portreserve rsyslog udev-post
atd functions messagebus postfix sandbox wdaemon
auditd haldaemon netconsole psacct saslauthd winbind
autofs halt netfs quota_nld single wpa_supplicant
blk-availability ip6tables network rdisc smartd ypbind
bluetooth iptables NetworkManager restorecond snmpd
certmonger irqbalance nfs rngd snmptrapd
cpuspeed kdump nfslock rpcbind spice-vdagentd
[root@Centos init.d]# cp /application/apache/bin/apachectl ./httpd
不支持chkconfig
[root@Centos init.d]# chkconfig --add httpd
service httpd does not support chkconfig
因此編輯下面的文件,增加如下配置
[root@Centos init.d]# vi /etc/init.d/httpd
#!/bin/sh
#
#chkconfig:345 85 15
#description:Start and stop the Apache HTTP Server
[root@Centos init.d]# chkconfig --add httpd 加入啟動
[root@Centos init.d]# chkconfig --list httpd 查看啟動情況
httpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[root@Centos init.d]# cd -
/application/apache/conf/extra
[root@Centos extra]# ../../bin/apachectl -t
Syntax OK
[root@Centos extra]# ../../bin/apachectl graceful
[root@Centos extra]# lsof -i tcp:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 2390 root 4u IPv6 16911 0t0 TCP *:http (LISTEN)
httpd 2531 daemon 4u IPv6 16911 0t0 TCP *:http (LISTEN)
httpd 2532 daemon 4u IPv6 16911 0t0 TCP *:http (LISTEN)
httpd 2533 daemon 4u IPv6 16911 0t0 TCP *:http (LISTEN)
[root@Centos extra]# ps -ef |grep httpd
root 2390 1 0 02:08 ? 00:00:00 /application/apache2.4.23/bin/httpd -k graceful
daemon 2531 2390 0 02:22 ? 00:00:00 /application/apache2.4.23/bin/httpd -k graceful
daemon 2532 2390 0 02:22 ? 00:00:00 /application/apache2.4.23/bin/httpd -k graceful
daemon 2533 2390 0 02:22 ? 00:00:00 /application/apache2.4.23/bin/httpd -k graceful
root 2623 1934 0 02:24 pts/1 00:00:00 grep httpd
五:測試訪問
[root@Centos extra]# echo '192.168.1.20:80 this server is the server of bbs stie'>>/data/www/bbs/index.html
[root@Centos extra]# cat /data/www/bbs/index.html
welcome to bbs.abc.com
192.168.1.20:80 this server is the server of bbs stie
打開本地客戶端瀏覽器
經測試表示之前的配置是正確的,同樣的方法可以配置多個基于IP的虛擬主機
關于“LAMP架構中Apache服務基于IP的虛擬主機配置的示例分析”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。