天天看點

nginx-1.16.1 自動化安裝及Prometheus監控配置

nginx-1.16.1 自動化安裝及Prometheus監控配置

環境介紹

作業系統: CentOS7.6

Nginx-1.16.1

軟體準備:

# Nginx下載下傳: 
wget http://nginx.org/download/nginx-1.16.1.tar.gz

# pcre 下載下傳: https://ftp.pcre.org/pub/pcre/
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz

# zlib 下載下傳: 
wget https://fossies.org/linux/misc/zlib-1.2.11.tar.gz

# openssl 下載下傳: http://distfiles.macports.org/openssl/
wget http://distfiles.macports.org/openssl/openssl-1.0.2s.tar.gz

# nginx_upstream_check_module
https://github.com/yaoweibin/nginx_upstream_check_module

wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz      

1. 安裝基礎工具:

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

2. 安裝 Nginx-1.16.1

cd /usr/local/src/

3. 建立nginx使用者:

useradd nginx

解壓:

tar -zxvf nginx-1.16.1.tar.gz

cd nginx-1.16.1

./configure --prefix=/usr/local/nginx-1.16.1 --with-http_ssl_module --with-http_gzip_static_module --with-pcre=/usr/local/src/pcre-8.43 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.0.2s --with-http_stub_status_module --with-http_realip_module --add-module=/usr/local/src/nginx_upstream_check_module-master --with-http_sysguard_module --add-module=nginx-module-vts

make

make install

4. 環境變量配置

在/etc/profile 中加入:

export NGINX_HOME=/usr/local/nginx

export PATH=$PATH:$NGINX_HOME/sbin

5. 開機啟動配置

vim /usr/lib/systemd/system/nginx.service

[Unit]

Description=nginx

After=network.target

[Service]

Type=forking

User=nginx

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx reload

ExecStop=/usr/local/nginx/sbin/nginx quit

PrivateTmp=true

[Install]

WantedBy=multi-user.target

systemctl daemon-reload

# 加入開機啟動

systemctl enable nginx .service

systemctl status nginx .service

systemctl restart nginx .service

6. prometheus監控nginx

# 插件

https://github.com/hnlq715/nginx-vts-exporter

# 模闆

https://grafana.com/grafana/dashboards/2949

人們永遠沒有足夠的時間把它做好,但永遠有足夠的時間重新來過。

可是,因為并不是總有機會重做一遍,你必須做得更好,換句話說,

人們永遠沒有足夠的時間去考慮到底是不是想要它,但永遠有足夠的時間去為之後悔。

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

淺掘千口井,不如深挖一口井!當知識支撐不了野心時,那就靜下心來學習吧!運維技術交流QQ群:618354452

個人微信公衆号,定期釋出技術文章和運維感悟。歡迎大家關注交流。

nginx-1.16.1 自動化安裝及Prometheus監控配置