這篇文章將為大家詳細(xì)講解有關(guān)LAMP架構(gòu)中Apache服務(wù)基于IP的虛擬主機(jī)配置的示例分析,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
創(chuàng)新互聯(lián)建站主營(yíng)商州網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,app軟件開(kāi)發(fā)公司,商州h5成都微信小程序搭建,商州網(wǎng)站營(yíng)銷推廣歡迎商州等地區(qū)企業(yè)咨詢
基于IP的虛擬主機(jī)配置
基于IP的虛擬主機(jī)————就是說(shuō)每個(gè)虛擬主機(jī)使用一個(gè)獨(dú)立的IP地址
服務(wù)器配置多塊網(wǎng)卡實(shí)現(xiàn),或者同一塊網(wǎng)卡配置多個(gè)IP實(shí)現(xiàn)都可以
今天模擬的環(huán)境是同一網(wǎng)卡配置多個(gè)IP地址實(shí)現(xiàn)基于IP的虛擬主機(jī)配置
一:新增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上新增一個(gè)IP地址用于測(cè)試使用
[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
二:聯(lián)通性測(cè)試
在本地客戶端主機(jī)上測(cè)試聯(lián)通性
C:\Users\Administrator>ping 192.168.1.20
正在 Ping 192.168.1.20 具有 32 字節(jié)的數(shù)據(jù):
來(lái)自 192.168.1.20 的回復(fù): 字節(jié)=32 時(shí)間<1ms TTL=64
來(lái)自 192.168.1.20 的回復(fù): 字節(jié)=32 時(shí)間<1ms TTL=64
來(lái)自 192.168.1.20 的回復(fù): 字節(jié)=32 時(shí)間<1ms TTL=64
來(lái)自 192.168.1.20 的回復(fù): 字節(jié)=32 時(shí)間<1ms TTL=64
192.168.1.20 的 Ping 統(tǒng)計(jì)信息:
數(shù)據(jù)包: 已發(fā)送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),
往返行程的估計(jì)時(shí)間(以毫秒為單位):
最短 = 0ms,最長(zhǎng) = 0ms,平均 = 0ms
三:備份虛擬主機(jī)配置文件
提示:生產(chǎn)環(huán)境一定要養(yǎng)成良好的習(xí)慣
[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
四:配置虛擬主機(jī)配置文件
[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
#
# 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
#
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
上面的標(biāo)記部分為修改的配置
[root@Centos extra]# ../../bin/apachectl graceful
httpd not running, trying to start
發(fā)現(xiàn)httpd服務(wù)并沒(méi)有開(kāi)機(jī)自啟動(dòng)
檢查發(fā)現(xiàn)/etc/init.d/下沒(méi)有httpd服務(wù)
[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 加入啟動(dòng)
[root@Centos init.d]# chkconfig --list httpd 查看啟動(dòng)情況
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
五:測(cè)試訪問(wèn)
[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
打開(kāi)本地客戶端瀏覽器
經(jīng)測(cè)試表示之前的配置是正確的,同樣的方法可以配置多個(gè)基于IP的虛擬主機(jī)
關(guān)于“LAMP架構(gòu)中Apache服務(wù)基于IP的虛擬主機(jī)配置的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。