源码编译安装openresty并安装nginx-module-vts插件
1.创建目录
mkdir -p /usr/local/openrestyMM/rpmbuild
mkdir -p /usr/local/openrestyMM/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
2.安装依赖
yum install -y rpm-build redhat-rpm-config rpmdevtools yum-utils
yum install -y gcc gcc-c++ pcre zlib openssl ccache
yum install -y openssl-devel zlib-devel pcre-devel gcc make perl perl-Data-Dumper libtool ElectricFence systemtap-sdt-devel valgrind-devel
3.拷贝插件
git clone https://github.com/vozlt/nginx-module-vts.git ./nginx-module-vts
#git clone https://gitee.com/wangxiaoming_936/nginx-module-vts.git /tmp/openresty-tmp/nginx-module-vts
git clone https://github.com/openresty/openresty.git ./openresty
#git clone https://gitee.com/mirrors_openresty/openresty_1.git /tmp/openresty-tmp/openresty
git clone https://github.com/openresty/openresty-packaging.git ./openresty-packaging
#git clone https://gitee.com/mirrors_openresty/openresty-packaging.git /tmp/openresty-tmp/openresty-packaging
4.下载openresty源码
wget https://openresty.org/download/openresty-1.21.4.3.tar.gz -P /usr/local/openrestyMM/rpmbuild/SOURCES/
5.拷贝目录
echo '%_topdir /usr/local/openrestyMM/rpmbuild' > $HOME/.rpmmacros
cp /usr/local/openrestyMM/openresty-packaging/rpm/SOURCES/* /usr/local/openrestyMM/rpmbuild/SOURCES/
cp /usr/local/openrestyMM/openresty-packaging/rpm/SPECS/*.spec /usr/local/openrestyMM/rpmbuild/SPECS/
cp /usr/local/openrestyMM/openresty/patches/* /usr/local/openrestyMM/rpmbuild/SOURCES/
cd /usr/local/openrestyMM/rpmbuild/SPECS
6.编辑写入
vim openresty.spec
--add-module=/usr/local/openrestyMM/nginx-module-vts \
7.rpmbuild构建rpm包
#wget https://www.zlib.net/zlib-1.3.tar.xz -P /usr/local/openrestyMM/rpmbuild/SOURCES/ --no-check-certificate
rpmbuild -ba openresty-zlib.spec
yum install -y ../RPMS/x86_64/openresty-zlib-*
#wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz -P /usr/local/openrestyMM/rpmbuild/SOURCES/ --no-check-certificate
rpmbuild -ba openresty-openssl111.spec
yum install -y ../RPMS/x86_64/openresty-openssl111-*
#wget https://zenlayer.dl.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.tar.bz2 -P /usr/local/openrestyMM/rpmbuild/SOURCES/ --no-check-certificate
rpmbuild -ba openresty-pcre.spec
yum install -y ../RPMS/x86_64/openresty-pcre-*
rpmbuild -ba openresty.spec
7.1构建rpm包可能的错误
报错 /r问题解决
yum install dos2unix
dos2unix openresty.spec
解决cc yum install epel-release
8.查找需要的rpm包
ls -l /usr/local/openrestyMM/rpmbuild/RPMS/x86_64| grep -v -E 'debug|devel' | awk '{print $NF}'
下载下来就是这几个。
9.后续操作
将这几个所需要的rpm上传到你需要的服务器上,进行安装/或者更新操作。如果原本有的 记得先备份一下原本的config文件,避免被覆盖了。
然后在安装好后的nginx.conf文件编写
1:在nginx.conf中http块添加vhost_traffic_status_zone;
2:在nginx.conf中server段中添加location块
location /ompmonitorstatus {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
10.重启ngxinx
cd /usr/local/openresty/nginx/sbin
./nginx -t
./nginx -s reload
11.测试接口是否正常返回
curl http://127.0.0.1:80/ompmonitorstatus/format/json
有返回数据即成功