説明する
このスクリプトは、まず必要な依存関係をインストールし、次に OpenResty をダウンロードしてインストールし、次に Nginx 監視プラグインをダウンロードしてインストールします。最後にOpenRestyを起動します。このスクリプトは CentOS システムにのみ適用できることに注意してください。他のオペレーティング システムにインストールする必要がある場合は、公式ドキュメントを参照してください。
脚本
#!/bin/bash
# Step 1:安装依赖
sudo yum install -y wget openssl-devel pcre-devel gcc make git
# Step 2:下载并安装 OpenResty
wget https://openresty.org/download/openresty-1.19.9.1.tar.gz
tar -xzvf openresty-1.19.9.1.tar.gz
cd openresty-1.19.9.1
./configure --prefix=/usr/local/openresty \
--with-http_stub_status_module \
--with-pcre-jit \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_ssl_module \
--with-pcre
make -j2
sudo make install
# Step 3:下载并安装 Nginx 监控插件
cd /usr/local/openresty/nginx
sudo mkdir conf.d
sudo wget https://raw.githubusercontent.com/vozlt/nginx-module-vts/master/conf/nginx.conf
sudo wget https://raw.githubusercontent.com/vozlt/nginx-module-vts/master/statistics/format_jsonp.js
sudo wget https://raw.githubusercontent.com/vozlt/nginx-module-vts/master/statistics/format_prometheus.pl
sudo wget https://raw.githubusercontent.com/vozlt/nginx-module-vts/master/statistics/format_json.pl
# Step 4:启动 OpenResty
sudo /usr/local/openresty/nginx/sbin/nginx
echo "OpenResty 安装完成!"