openresty监控模块nginx-module-vts编译安装

下载vts插件:(如果报错说/usr/local不为空可以先下载到其他路径,然后必须再移过来)

git clone git://github.com/vozlt/nginx-module-vts.git /usr/local

下载openresty-packaging:生成Openresty RPM包的配置文件

git clone https://github.com/openresty/openresty-packaging.git ~/

有些文章中提及要下载Openresty源码,实际操作时发现编译rpm时会自动下载

下载你需要编译的版本的openresty源码:

wget https://openresty.org/download/openresty-1.15.8.2.tar.gz
mv openresty-1.15.8.2.tar.gz ~/rpmbuild/SOURCES/

准备打包环境

安装rpm build工具包

yum install rpm-build redhat-rpm-config rpmdevtools yum-utils

安装OpenResty依赖包

yum install -y openssl-devel zlib-devel pcre-devel gcc make perl perl-Data-Dumper libtool ElectricFence systemtap-sdt-devel valgrind-devel

因为我是基于centos7 mini编译的,还需要其他一些包:

yum -y install gcc gcc-c++ pcre zlib openssl ccache

在编译RPM包的过程中,会存在彼此依赖的情况,为了方便编译,直接在编译服务器上把这些依赖包全部装上

yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
yum install -y openresty-zlib-asan-devel openresty-openssl-asan-devel openresty-pcre-asan-devel \
openresty-zlib-devel openresty-openssl-debug-devel openresty-pcre-devel openresty-openssl-devel

准备RPM环境

mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
cp ~/openresty-packaging/rpm/SOURCES/* ~/rpmbuild/SOURCES/
cp ~/openresty-packaging/rpm/SPECS/*.spec ./rpmbuild/SPECS

打包

cd ~/rpmbuild/SPECS

修改openresty.spec添加vts插件

vi openresty.spec

可以修改需要编译的版本号,然后在configure参数中加入如下内容:(注意等会前后不要有空格,参考的文章中误加空格导致编译错误)

--add-module=/usr/local/nginx-module-vts \

在此目录执行 rpmbuild -ba openresty.spec

编译后的RPM包位于~/rpmbuild/RPMS/x86_64/目录,生成如下文件:

openresty-1.15.8.2-6.el7.x86_64.rpm
openresty-debuginfo-1.15.8.2-6.el7.x86_64.rpm
openresty-zlib-1.2.11-3.el7.x86_64.rpm
openresty-zlib-debuginfo-1.2.11-3.el7.x86_64.rpm
openresty-zlib-devel-1.2.11-3.el7.x86_64.rpm

debuginfo和zlib-devel包部署时候不需要,部署所需包为:

openresty-1.15.8.2-6.el7.x86_64.rpm
openresty-openssl-1.1.0k-3.el7.x86_64.rpm
openresty-pcre-8.43-1.el7.x86_64.rpm
openresty-zlib-1.2.11-3.el7.x86_64.rpm

部署新Openresty:(注意备份现有配置)

yum remove openresty
rpm -ivh *rpm

配置vts,在nginx.conf配置文件中加入如下内容

http {
    vhost_traffic_status_zone;
    ...
    server {
        ...
        location /status {
            vhost_traffic_status_display;
            vhost_traffic_status_display_format html;
        }
    }
}

可能遇到的问题

依赖的openresty模块不存在

在执行打包过程中可能会出现以下错误

1

2

3

4

5

6

openresty-zlib-asan-devel >= 1.2.11-6 is needed by openresty-asan-1.13.6.2-6.el7.centos.x86_64

openresty-openssl-asan-devel >= 1.1.0h-1 is needed by openresty-asan-1.13.6.2-6.el7.centos.x86_64

openresty-pcre-asan-devel >= 8.42-1 is needed by openresty-asan-1.13.6.2-6.el7.centos.x86_64

openresty-zlib-devel >= 1.2.11-3 is needed by openresty-debug-1.13.6.2-1.el7.centos.x86_64

openresty-openssl-debug-devel >= 1.1.0h-1 is needed by openresty-debug-1.13.6.2-1.el7.centos.x86_64

openresty-pcre-devel >= 8.42-1 is needed by openresty-debug-1.13.6.2-1.el7.centos.x86_64

解决办法

1

2

yum install openresty-zlib-asan-devel openresty-openssl-asan-devel openresty-pcre-asan-devel \

openresty-zlib-devel openresty-openssl-debug-devel openresty-pcre-devel openresty-openssl-devel

 

你可能感兴趣的:(Linux)