美文网首页
webpagetest 私有化部署

webpagetest 私有化部署

作者: YBFQ_WH | 来源:发表于2020-04-07 13:39 被阅读0次

    webpagetest 私有化部署

    介绍

    webpagetest 是一款开源的 web 性能测试工具,开源地址,每个人都可在其公共实例上对自己的 web 应用进行性能测试(web应用必须提供公网IP或域名)

    wpt001.png

    具体的使用方法、参数设置,可自行查阅相关资料

    虽然,我们可以通过公共实例对 Web 应用进行性能测试,但是公共实例在全球安装的探针(agent)有事并不能完全满足我们的要求,此时就需要我们在本地搭建一个webpagetest 私有实例。

    安装过程

    下面对webpagetest 私有部署的过程进行一个详细描述。webpagetest安装分为两部分:server 端和 agent 端

    Server 安装

    环境信息

    阿里云ESC(OS: centos7, 2C2G)

    Apache 安装

    通过工具远程登录 ESC,安装 apache 服务(apache 在centos中也叫作 httpd)

    yum install httpd httpd-devel -y
    

    安装完成后,可通过 systemctl start httpd 命令启动 httpd 服务,本地浏览器通过 ESC公网IP 访问,如果看到如下及说明 apache 安装成功

    wpt002.png

    Apache默认安装路径信息
    网站的根目录:/var/www/html
    主配置文件:/etc/httpd/conf/httpd.conf
    模块路径:/usr/sbin/apachectl

    php7.2 安装

    • 安装命令(按顺序执行即可)
    
    # 安装epel源
    yum install epel-release 
    
    # 安装 remi 源
    rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
    
    yum update
    
    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    
    # 安装 php7.2w 及相关模块
    yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-pecl-apcu php-pecl-zip 
    php-devel php-pear
    
    
    # 添加了动态库文件so
    yum install mod_php72w
    
    • 修改配置信息

    php配置文件路径: /etc/php.ini

    在配置文件中,主要替换四个配置项:

    参数 原始值 修改值
    cgi.fix_pathinfo 1 0
    memory_limit 128M 256M
    post_max_size 8M 10M
    upload_max_filesize 2M 10M

    如果安装的是php72,那配置文件的路径就是在/etc/opt/remi/php72,可看如下链接:
    https://www.cnblogs.com/GarfieldTom/p/11439429.html

    • 修改 apache 配置信息

    修改配置文件,主要目的:

    1. 支持php
    2. 修改默认web目录

    apache配置文件路径:/etc/httpd/conf/httpd.conf

    位置(行) 操作 内容 说明
    56 添加 LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so 添加 libphp7.so 动态库文件,可通过 find / -name libphp*.so 命令查找位置
    67 修改 User apache --> User <your_user_name> your_user_name,系统中实际存在的用户,不能使用root;因为安装apache 时已经创建了用户 apache 和 用户组 apache,此时可不进行修改
    68 修改 Group apache --> Group <your_user_group> User 选项指定用户所属的用户组
    96 修改 ServerName www.example.com:80 --> ServerName 0.0.0.0:80 取消注释
    121 修改 DocumentRoot "/var/www/html" --> DocumentRoot "/var/<your__dir>/www" <your_dir>此处路径可自行确定,如我创建了一个新目录 webpagetest, 即:/var/webpagetest/www
    127 修改 <Directory "/var/www/html"> --> <Directory "/var/<your__dir>/www"> <your_dir> 含义如上;134行做同样的修改
    154 修改 AllowOverride None --> AllowOverride All
    167 修改 <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> 加入对 php 文件的解析
    288 增加 AddType application/x-httpd-php .php ; AddType application/x-httpd-php-source .phps 注意分号,内容要分行

    如上描述对 apache 配置文件完成修改后,进行如下验证

    
    # 检查配置文件语法规则
    apachectl -t  
    
    # 重新加载配置文件
    apachectl graceful
    
    # 重启 apache 服务
    systemctl restart httpd
    
    

    server 安装

    在 github 下载 webpagetest 的安装文件。关于 webpagetest 的版本信息要做如下说明

    阶段 版本 说明
    第一阶段 webpagetest 3.0 之前的版本 整个安装文件的结构简单:www(服务端)、agent(探针)、mobile(移动测试相关)
    第二阶段 webpagetest 18.10 之前 版本以年-月的形式进行命名;安装文件的目录结构调整很大,agent目录中的内容基本上第一阶段版本都不一致
    第三阶段 webpagetest 19.04 之后 agent 从安装文件中独立出来,有个专门的github仓库,并命名为 wptagent

    webpagetest 服务端和探针,不一定非要版本匹配进行安装,18.10 版本的服务端可以 webpagetest3.0 的 agent 进行匹配安装

    在github中下载 webpagetest-18.10.zip ,加压后,通过第三方工具将解压后文件夹的 www 文件夹,整体替换到 /var/webpagetest 中(apache 的 web 目录,根据自己的情况而定,就是 apahce 配置文件的 121 行替换内容)

    wpt003.png

    通过浏览器,访问ESC 公网IP,可以看到 wpt (webpagetest) 的服务端页面

    wpt004.png

    如果能显示上面的截图,说明sever的安装成功了一半,剩下的另一半就要根据页面(<ECS_IP>/install)的提示安装必要的依赖

    rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
    
    rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
    
    # 安装 ffmpeg
    yum install ffmpeg ffmpeg-devel -y
    
    yum install -y libjpeg* libpng* libtiff* libungif* freetype zlib
    
    # 安装 imageMagick
    yum install ImageMagick -y
    
    # 安装 exiftool
    yum install perl-Image-ExifTool -y
    
    # 安装 pillow ssim(pyssim)模块
    pip install Pillow  pyssim
    
    pip install psutil monotonic ujson
    
    yum install Xvfb
    
    

    上述命令按顺序执行即可

    缺少的依赖安装过完成后,在根据提示修改/var/webpagetest/www 下项目文件夹的读写权限,简单起见都调整 777

    重启apache服务(systemctl restart httpd),即可看到如下效果(在浏览器中访问:<ECS_IP>/install)

    wpt005.png

    Agent 安装

    环境信息

    阿里云ESC(OS: windows 10, 2C2G)

    agent

    提前说明,这里安装的 agent 是 webpagetest3.0 中的 agent,并非 webpagetest-18.10 中配套的 agent (因为版本配套 agent 安装后,不能进行测试,应该是自己的配置问题)

    在 ECS 中安装必要的浏览器,建议安装 chrome 和 Firefox,下载安装程序默认安装就行

    chrome 的版本不能太高,版本过高会导致测试时数据显示不完全

    • locations.ini 配置信息修改

    在配置 agent 之前,我们需要先在 server 端配置 locations.ini 信息 (/var/webpagetest/www/settings)

    wpt006.png

    locations.ini.sample 拷贝一份,去掉.sample 后缀,通过 vim 命令就行修改

    ; # Test Location 中的选项
    ; key 不能重复,如 1、2、3....
    ; value 对应的地点名称,名称不要重复
    ; default  的 value  默认地点名
    
    [locations]
    1=cn_bj
    2=cn_sh
    default=cn_bj
    
    ; # locations 中每个 value 都对应这里的个 section
    ; key  表示多个地点
    ; value  表示浏览器节点名(不建议直接用浏览器名,以免多个地点的浏览器名重复)
    ; label  表示地点的标签名(对应 WebPageTest 首页 Test Location 下拉框中每个组下的选项)
    ; group  对地点进行分组(对应 WebPageTest 首页 Test Location 下拉框中的组)
    
    [cn_bj]
    1=Bro_bj
    2=IE9_bj
    label="中国 北京"
    group=Desktop
    
    [cn_sh]
    1=Bro_sh
    2=IE9_sh
    label=“中国 上海”
    group=Desktop
    
    
    ; 浏览器详情项  每个浏览器节点 对应一个 section
    ; brower 浏览器名 同一个浏览器节点下不得重复(对应 WebPageTest 首页 Browser 下拉框中的选项)
    ; lable  随意,不要和其他 label 重复就行
    
    [Bro_bj]
    browser=Firefox,Chrome
    label=“中国 北京“
    
    [IE9_bj]
    browser=IE 9
    label=“中国 北京”
    
    
    [Bro_sh]
    browser=Firefox,Chrome
    label=“中国 上海“
    
    [IE9_sh]
    browser=IE 9
    label=“中国 上海”
    
    

    以上配置文件中,配置了两个 Test Location: cn_bj 和 cn_sh
    每个 Test Location,配置了两个浏览器节名 Bro_bj / IE9_bj 和 Bro_sh / IE9_sh
    其中Bro_xx 浏览器节,指定了2个浏览器: Chrome、Firefox

    • agent.ini 配置信息修改

    agent 的目录结构

    wpt007.png
    wptdriver.ini.sample 复制一份,去掉 .sample 后缀,编辑
    [WebPagetest]
    ; url: server 端地址 ( 运行 server 公网 IP )
    url=http://123.55.89.70/
    ; locations.ini 中定义的浏览器节点
    location=Bro_bj,IE9_bj,Bro_sh,IE9_sh
    ; 浏览器名
    browser=chrome, Firefox
    Time Limit=120
    ;key=TestKey123
    ;Automatically install and update support software (Flash, Silverlight, etc)
    ;software=http://www.webpagetest.org/installers/software.dat
    
    [chrome]
    ; exe  指定 chrome 安装路径
    exe="C:\Program Files\Google\Chrome\Application\chrome.exe"
    options='--load-extension="%WPTDIR%\extension" --user-data-dir="%PROFILE%" --no-proxy-server'
    installer=http://www.webpagetest.org/installers/browsers/chrome.dat
    
    [Firefox]
    ; exe: Firefox 安装路径
    exe="C:\Program Files\Mozilla Firefox\firefox.exe"
    options='-profile "%PROFILE%" -no-remote'
    installer=http://www.webpagetest.org/installers/browsers/firefox.dat
    template=firefox
    
    ; [Safari]
    ; exe="C:\Program Files\Safari\Safari.exe"
    
    [IE]
    exe="C:\Program Files\Internet Explorer\iexplore.exe"
    

    调整完成后,启动 agent,运行 wptdriver.exe

    重启 server 端 httpd 服务

    重启效果如下:

    wpt008.png

    server 连接到 agent,后续就可以进行 web 应用功能测试

    wpt009.png

    相关文章

      网友评论

          本文标题:webpagetest 私有化部署

          本文链接:https://www.haomeiwen.com/subject/itogphtx.html