mahimahi安装及运行

mahimahi介绍

Mahimahi是MIT提出的一套用于网络仿真和分析的用户空间工具,可记录来自基于HTTP的应用程序流量,并在模拟的网络条件下重放流量内容进行准确的测量。

Docker

我是在docker上面搭的环境,容器的操作系统用的是Ubuntu 22.04。特别注意,mahimahi运行的时候需要访问到/dev/net/tun,一般方式运行起来的容器找不到这个文件,必须在创建容器的时候就使用–privileged来允许容器映射宿主机/dev中的全部文件!(血泪教训啊……第一次搭的环境本来都已经成功编译了,结果跑不起来,尝试了半天也没能让当前容器访问到宿主机的/dev,只好又创建了一个新容器,重新搭了一遍)

创建并启动容器命令:

docker run --privileged -v /path/in/host:/path/in/container --name container_name -it ubuntu:22.04 bash

其中,--privileged选项会给Docker容器提供额外的权限;-v指定宿主机和容器目录的映射关系,就是说,在容器内/path/in/container目录是宿主机/path/in/host目录的映射,这样便于在宿主机和容器间传递文件;--name指定容器的名字,如果不指定,系统就会分配一个随机的(很搞笑的)名字,比如“silly_varahamihira”;-it选项会让Docker容器在交互模式下运行;bash是你想在容器中运行的指令,这里我希望获得一个bash。

执行完上述命令,你就创建并启动了一个容器,并且此时你已经在容器内部了。如果此时在宿主机上开另一个bash并执行docker ps,你的容器应该在列。可以在容器内部使用exit退出容器,退出后再执行docker ps就看不到这个容器了,但执行docker ps -a能看到所有存在的容器,可以在此看到你的容器。如果想再次启动容器,可以使用docker start container_id_or_name命令,然后用docker exec -it container_name bash进入容器命令行。

Mahimahi安装

我这里无法使用apt-get直接安装mahimahi,报错找不到mahimahi包。所以我直接源码安装。

两个很好的教程:网络模拟和分析工具–Mahimahi的安装教程网络仿真工具Mahimahi的安装和基础用法

我的docker刚创建,环境非常的干净,连vim都没有,正好可以记录一下mahimahi依赖的所有包。

首先要更新一下apt:apt update,但获得报错:

Get:1 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [129 kB]
Err:2 http://security.ubuntu.com/ubuntu jammy-security InRelease    
  Couldn't create temporary file /tmp/apt.conf.XXLh0Z for passing config to apt-key
Err:1 http://archive.ubuntu.com/ubuntu jammy InRelease
  Couldn't create temporary file /tmp/apt.conf.Y0klwg for passing config to apt-key
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [128 kB]
Err:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
  Couldn't create temporary file /tmp/apt.conf.FVVrOZ for passing config to apt-key
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [127 kB]
Err:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
  Couldn't create temporary file /tmp/apt.conf.2CBY68 for passing config to apt-key
Reading package lists... Done
W: GPG error: http://security.ubuntu.com/ubuntu jammy-security InRelease: Couldn't create temporary file /tmp/apt.conf.XXLh0Z for passing config to apt-key
E: The repository 'http://security.ubuntu.com/ubuntu jammy-security InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://archive.ubuntu.com/ubuntu jammy InRelease: Couldn't create temporary file /tmp/apt.conf.Y0klwg for passing config to apt-key
E: The repository 'http://archive.ubuntu.com/ubuntu jammy InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://archive.ubuntu.com/ubuntu jammy-updates InRelease: Couldn't create temporary file /tmp/apt.conf.FVVrOZ for passing config to apt-key
E: The repository 'http://archive.ubuntu.com/ubuntu jammy-updates InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://archive.ubuntu.com/ubuntu jammy-backports InRelease: Couldn't create temporary file /tmp/apt.conf.2CBY68 for passing config to apt-key
E: The repository 'http://archive.ubuntu.com/ubuntu jammy-backports InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

解决方案:先执行chmod 1777 /tmp,再执行apt update就不报错了。(这部分我在博客中有所记录)

然后开始安装依赖包:

apt install autoconf automake libtool
apt install libprotobuf-dev
apt install apache2-dev 
apt install openssl #这个好像系统会自带
apt install libssl-dev
apt install "^libxcb.*" libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev
apt install libcairo2-dev
apt install libpango1.0-dev
apt install protobuf-compiler
apt install libprotobuf-dev
apt install iptables
apt install iproute2
apt install dnsmasq

依赖安装好了之后,开始编译安装Mahimahi:

# 掠过git clone环节,假设已经clone好了
cd mahimahi
./autogen.sh
./configure #这一步会检查依赖包是否全部安装完成,如有缺漏,安装好相应依赖包后再次执行本命令
make
make install #官方要求用sudo,但因为我在docker中天然是root,就不用sudo了

如果前面依赖安装的没问题,至此mahimahi安装完成。我第一次配环境的时候遇到./configure检查通过,但make的时候报错src/protobufs/下http_record.pb.cc和http_record.pb.h引入的google/protobuf/下部分头文件找不到的情况。检查发现这两个文件是在make过程中自动生成的,因此怀疑是libprotobuf-dev和protobuf-compiler版本不匹配造成,因为当时我的libprotobuf-dev是通过apt安装的,版本是3.12.4,而protobuf-compiler是通过发行版安装的,版本是3.7.0,后来通过将protobuf-compiler换成3.12.4解决了此问题。不过如果二者都是通过apt安装应该就不会遇到这个问题。

检查是否安装成功:在mahimahi目录下执行mm-delay 20,执行后命令行开头出现[delay 20 ms]就说明Mahimahi安装成功。

但这一步我还遇到了报错:

Died on std::runtime_error: mm-delay: please run as non-root

竟然不允许我用root权限运行这个指令……于是我只好在docker上用adduser usrname命令给自己开了一个非root用户。(小知识,用adduser创建新用户会自动在/home中创建一个以该用户名为文件名的目录,而用useradd创建用户则不会)

另外,如果创建docker的时候没有用--privileged选项,这一步也会报错:

Died on unix_error: open /dev/net/tun: No such file or directory

这我确实无力挽救,从头再配一遍吧哈哈哈哈哈哈哈orz

Mahimahi运行

(未完待续)

  • 13
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值