使用Mininet,我需要设置一个模拟网络来测试Web浏览性能,其中一台主机运行Apache2服务器,然后从另一台主机访问它。我已经在物理机上配置了一个网站,并已验证其工作正常。
为了开始模拟,我使用下面的玩具mininet python脚本simpleTest.py
和最简单的拓扑结构,其中h1和h2可以相互ping通。在仿真之前,apache2在宿主机器上停止。
#!/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.cli import CLI
class SingleSwitchTopo(Topo):
"Single switch connected to n hosts."
def build(self, n=2):
switch = self.addSwitch('s1')
for h in range(n):
host = self.addHost('h%s' % (h + 1))
self.addLink(host, switch)
def simpleTest():
"Create and test a simple network"
topo = SingleSwitchTopo(n=2)
net = Mininet(topo)
net.start()
CLI(net)
net.stop()
if __name__ == '__main__':
simpleTest()
字符串
在使用sudo python3 simpleTest.py
运行脚本之后,我分别在h1和h2上启动两个xterm,
mininet>xterm h1 h2
型
稍后,在h1的xterm窗口中使用
[Node: h1's xterm]# systemctl start apache2
型
但是,我无法从h2的xterm窗口访问该网站,而h2可以ping h1的IP(10.0.0.1)成功。使用telnet 10.0.0.1 80
返回“Connection refused”。事实上,甚至h1的xterm窗口中的telnet 127.0.0.1 80
也会返回“Connection refused”。另一方面,从物理机的浏览器或终端访问网站没有问题。
我猜从Mininet中访问apache2是不成功的,因为h1和h2在网络名称空间中,而使用systemctl启动的apache2(即使从h1的xterm调用)仍然在物理机器上?
那么,是否有可能使apache2在h1的空间中运行,并通过h1的IP地址10.0.0.1?从h2访问任何指导都是高度赞赏的。
1条答案
按热度按时间kyks70gy1#
受@larsks评论的启发,我想出了一个解决方案。
基本上,apache 2命令(
/usr/sbin/apache2
)需要直接从h1的xterm窗口执行。在执行它之前,必须设置一些环境变量,如果apache 2通过systemctl
或/etc/init.d/apache2
启动,则这些环境变量将从/etc/apache2/envvars
自动设置。因此,我复制了/etc/apache2/envvars
并将其重命名为单独的脚本,比如$(pwd)/start_apache2_manually.sh
。在start_apache2_manually.sh
的末尾,添加一行apache2 -D FOREGROUND
。从h1的xterm窗口运行脚本./start_apache2_manually.sh
可以通过模拟网络从h2访问网站。