mac ab压力测试工具

96 阅读1分钟

Mac 使用ab命令进行压测

文章来源:www.shuzhiduo.com/A/mo5kNk92J…

1.在Mac中配置Apache

①启动Apache,打开终端

 sudo apachectl -v

image.png

  1. sudo apachectl start 这样Apache就启动了。打开Safari浏览器地址栏输入 “http://localhost”,可以看到内容为“It works!”的页面

②设置虚拟端终机

打开Apache的配置文件

sudo vi /etc/apache2/httpd.conf

在httpd.conf中找到“#Include /private/etc/apache2/extra/httpd-vhosts.conf”,去掉前面的“#”,保存并退出,去掉这一行的#意思是从/extra/httpd-vhosts.conf这个文件导入虚拟主机配置。

#Include /private/etc/apache2/extra/httpd-vhosts.conf

然后重启Apache

sudo apachectl restart

运行如下命令:

sudo vi /etc/apache2/extra/httpd-vhosts.conf

就打开了配置虚拟主机文件httpd-vhost.conf,配置虚拟主机了。需要注意的是该文件默认开启了两个作为例子的虚拟主机: 需要增加如下配置:

<VirtualHost *:80>
	DocumentRoot "/Library/WebServer/Documents"
	ServerName localhost
	ErrorLog "/private/var/log/apache2/localhost-error_log"
	CustomLog "/private/var/log/apache2/localhost-access_log" common
</VirtualHost><VirtualHost *:80>
	DocumentRoot "/Users/snandy/work"
	ServerName mysites
	ErrorLog "/private/var/log/apache2/sites-error_log"
	CustomLog "/private/var/log/apache2/sites-access_log" common
<Directory />
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order deny,allow
            Allow from all
  </Directory>
</VirtualHost>

保存并退出

  1. :wq
  2. sudo apachectl restart

2.配置完成之后进行压测

  1. ab -n 4 -c 2 https://www.baidu.com/ -n后面的是请求数

-c后面的是并发数

关闭 sudo apachectl -k stop