Prometheus php-fpm监控安装部署

Posted Mend。

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Prometheus php-fpm监控安装部署相关的知识,希望对你有一定的参考价值。

1.进入默认php配置文件:/etc/php/7.3/fpm/php-fpm.conf 添加:pm.status_path = /fpm_status

echo "pm.status_path = /fpm_status" >>/etc/php/7.3/fpm/php-fpm.conf 

2.在nginx配置文件下面添加fpm-status location配置:/etc/nginx/conf.d/nginx-php.conf

    location ~ ^/(fpm_status|health)$ 
        fastcgi_pass unix:/run/php/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    

systemctl restart php7.3-fpm

systemctl reload nginx

测试一下:curl http://localhost:9090/fpm_status 有数据就ok

安装这个文件: php-fpm-exporter.linux.amd64 (官网地址:https://github.com/bakins/php-fpm-exporter/releases)

安装好了 :

mkdir /usr/local/php-fpm-exporter/
scp root123@172.0.100.1:~/php-fpm-exporter /usr/local/php-fpm-exporter/
cd /usr/local/php-fpm-exporter/
chmod +x  php-fpm-exporter
nohup ./php-fpm-exporter --addr="172.0.100.49:9190" --endpoint="http://172.0.100.49:9090/fpm_status" >nohup.out 2>&1 &

netstat -ntpl |grep 

测试:curl 172.0.100.49:9190/metrics(也可以不用测试)

nohup /usr/local/php-fpm-exporter/php-fpm-exporter --addr="`ip a|grep global|awk -F\'[ ]+|/\' \'print $3\'`:9190" --endpoint="http://`ip a|grep global|awk -F\'[ ]+|/\' \'print \\$3\'`:9090/fpm_status" >/usr/local/php-fpm-exporter/nohup.out 2>&1 &
server 
    listen       9090 backlog=8192;
    server_name  172.0.100.33;
    root   /data/qcnft_php/public;
    access_log  /data/log/nginx/qcsc_access.log  log_json;
    error_log /data/log/nginx/qcsc_error.log;

    keepalive_timeout 60s;
    
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    
    index index.html index.htm index.php;
    
    charset utf-8;
    
    location / 
        try_files $uri $uri/ /index.php?$query_string; 
    
      
    location = /favicon.ico  access_log off; log_not_found off; 
    location = /robots.txt   access_log off; log_not_found off; 
    
    error_page 404 /index.php;
    
    location ~ /\\.(?!well-known).* 
        deny all;
    
    
    location = /nginx_status 
    	stub_status on;
    access_log off;
    


    location ~ \\.php$ 
        fastcgi_pass   unix:/run/php/php-fpm.sock;
        fastcgi_index  index.php;
    fastcgi_read_timeout 150;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    
    location ~ /\\.(?!well-known).* 
        deny all;
    
    location ~ ^/(fpm_status|health)$ 
        fastcgi_pass unix:/run/php/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    


Prometheus 监控思科交换机---各中间件安装部署

Prometheus 监控思科交换机

因为领导比较青睐 Prometheus 开源监控,因为鄙人自身也是网络专业出身,所以便希望能用 prometheus 监控公司的交换机,公司大量的交换机在业务区,比较繁杂,虽然日常监控都可以用 Solarwinds 和 Opmanager 进行日常网络行为监控管理,但是 Solarwinds 界面比较比较有上古世纪的感觉,Opmanager 又比较卡,对服务器硬件配置稍微高了点,而且没有比开源 Prometheus 的更方便管理、进行修改配置等操作。况且现在 prometheus 有较多的公司正在使用,可搜集的资料较多,但相对来说,监控交换机的这方面, snmp_exporter 的发展就相对较为缓慢一点,不过相信我们越来越多的人使用,终究会更加完善。

Prometheus 监控思科交换机文档完整地址:https://blog.51cto.com/liujingyu/category9.html

Prometheus + snmp_exporter + Alertmanager + Grafana 安装部署

  • 各程序说明

    • Prometheus:用于做主监控端,收集 snmp_exporter 数据信息
    • snmp_exporter:用于监控交换机设备,收集交换机数据信息
    • Alertmanager: 用于做报警端,当交换机挂掉或者CPU信息或者内存占用过高进行报警(邮件报警),也可以对接口流量阈值进行报警
    • Grafana: 把 Prometheus 收集的数据进行比较友好的界面展示
  • 使用版本

    • CentOS 7.8-2003-Minimal(4核 8G 100G)
    • prometheus 版本 2.21.0 监听 9090 端口
    • alertmanager 版本 0.21.0 监听 9093, 9094 端口
    • snmp_exporter 版本 0.19.0 监听 9116 端口,SNMP 是 UDP 协议 161 和 162 端口,所以不建议 docker 部署
    • Grafana 版本 7.2.0(docker部署) 监听 3000 端口
  • 官网地址:

1.系统安装后初始步骤(优化服务器):

yum install wget yum-utils net-tools vim unzip bash-completion -y

yum update -y

ulimit -n
sed -i "s/* soft nofile 65535/ /g" /etc/security/limits.conf
sed -i "s/* hard nofile 65535/ /g" /etc/security/limits.conf
echo "* soft nofile 65535" >>/etc/security/limits.conf
echo "* hard nofile 65535" >>/etc/security/limits.conf
ulimit -n 65535
echo "修改后文件数量"
ulimit -n

echo "优化内核参数"
echo "net.ipv4.ip_local_port_range = 1024 65535" >>/etc/sysctl.conf
echo "net.ipv4.tcp_syncookies = 1" >>/etc/sysctl.conf
echo "net.ipv4.tcp_tw_reuse = 1" >>/etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle = 1" >>/etc/sysctl.conf
echo "net.ipv4.tcp_fin_timeout = 30" >>/etc/sysctl.conf
echo "net.core.somaxconn = 20480" >>/etc/sysctl.conf
echo "net.core.netdev_max_backlog = 20480" >>/etc/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog = 20480" >>/etc/sysctl.conf
echo "net.ipv4.tcp_max_tw_buckets = 800000" >>/etc/sysctl.conf

sysctl -p

sed -i ‘s/=enforcing/=disabled/g‘ /etc/selinux/config
setenforce 0
systemctl disabled firewalld
systemctl stop firewalld

2.下载所需要的安装包

wget https://github.com/prometheus/prometheus/releases/download/v2.21.0/prometheus-2.21.0.linux-amd64.tar.gz

wget https://github.com/prometheus/snmp_exporter/releases/download/v0.19.0/snmp_exporter-0.19.0.linux-amd64.tar.gz

wget https://github.com/prometheus/alertmanager/releases/download/v0.21.0/alertmanager-0.21.0.linux-amd64.tar.gz

tar -xvf prometheus-2.21.0.linux-amd64.tar.gz
mv prometheus-2.21.0.linux-amd64 /opt/prometheus

tar -xf snmp_exporter-0.19.0.linux-amd64.tar.gz
mv snmp_exporter-0.19.0.linux-amd64 /opt/snmp_exporter

tar -xf alertmanager-0.21.0.linux-amd64.tar.gz
mv alertmanager-0.21.0.linux-amd64 /opt/alertmanager

cat > /etc/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus
After=network.target
[Service]
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/opt/prometheus/data
User=prometheus
[Install]
WantedBy=multi-user.target
EOF

cat > /etc/systemd/system/snmp_exporter.service <<EOF
[Unit]
Description=node_exporter
After=network.target

[Service]
ExecStart=/opt/snmp_exporter/snmp_exporter --config.file=/opt/snmp_exporter/snmp.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

cat > /etc/systemd/system/snmp_exporter.service <<EOF
[Unit]
Description=node_exporter
After=network.target

[Service]
ExecStart=/opt/alertmanager/alertmanager --config.file=/opt/alertmanager/alertmanager.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

useradd prometheus
chown -R prometheus:prometheus /opt/{snmp_exporter,prometheus,alertmanager}

systemctl daemon-reload
systemctl enable prometheus && systemctl enable snmp_exporter && systemctl enable alertmanager
systemctl start prometheus && systemctl start snmp_exporter && systemctl start alertmanager

3.安装Grafana

wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
systemctl enable docker && systemctl start docker 

docker login --username=LOGIN_NAME registry.cn-beijing.aliyuncs.com #登录阿里云仓库

docker pull registry.cn-beijing.aliyuncs.com/liujingyu/grafana-chinese:7.2.0
docker image ls
docker tag registry.cn-beijing.aliyuncs.com/liujingyu/grafana-chinese:7.2.0 grafana-chinese:7.2.0

docker run -tdi --name grafana-server --restart=always -p 3000:3000 grafana-chinese:7.2.0

具体配置调整请查看后续文章

以上是关于Prometheus php-fpm监控安装部署的主要内容,如果未能解决你的问题,请参考以下文章

部署Prometheus+Grafana监控Docker

监控利器-Prometheus安装与部署+实现邮箱报警

Prometheus 监控思科交换机---各中间件安装部署

Prometheus(普罗米修斯)安装部署

Prometheus(普罗米修斯)安装部署

Linux系统裸金属环境下部署prometheus监控