NGINX Amplify 是一款基于 SaaS 适用于开源 NGINX 和 NGINX Plus 的监控工具,不但可以监控服务器性能,还能监控底层操作系统,应用程序服务器(如 PHP-FPM),数据库和其他组件运行状况。
Amplify 安装
Amplify 需要 stub_status 模块,首先检查 Nginx 有没安装 stub_status 模块:
nginx -V 2>&1 | grep -o http_stub_status_module
有 http_stub_status_module 字样返回表示已安装,如没有,需要编译 Nginx 时添加参数 --with-http_stub_status_module
注册 Amplify:https://amplify.nginx.com/signup/,登录,选择 + New System 开始安装,以 root 用户执行指引给出的命令:
curl -L -O https://github.com/nginxinc/nginx-amplify-agent/raw/master/packages/install.sh
或者:
wget https://github.com/nginxinc/nginx-amplify-agent/raw/master/packages/install.sh
接着 root 身份执行(注意填写自己的 API KEY):
API_KEY='OxOXOxOXOxOXOxOXOxOXOxOXOxOX' sh ./install.sh
安装很快,不到一分钟就搞定了。让 amplify-agent 开启启动:
chkconfig amplify-agent on
命令 service amplify-agent { start | restart | stop | status }
管理查看 amplify-agent 状态。
Amplify 配置
Nginx 配置
下面内容保存为 stub_status.conf 文件,然后放到 /usr/local/nginx/conf/vhost/ 路径下(请根据实际修改路径)
server {
listen 127.0.0.1:80;
server_name 127.0.0.1;
location /nginx_status {
stub_status;
allow 127.0.0.1;
deny all;
}
}
在 nginx.conf 文件 http 中添加/修改如下配置:
log_format main_ext '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"$host" sn="$server_name" '
'rt=$request_time '
'ua="$upstream_addr" us="$upstream_status" '
'ut="$upstream_response_time" ul="$upstream_response_length" '
'cs=$upstream_cache_status' ;
网站配置 xx.com.conf 文件 server { ... } 中添加/修改如下配置:
access_log /home/wwwlogs/cyhour.com.log main_ext;
error_log /home/wwwlogs/cyhour.com.error.log warn;
php-fpm 配置
这个配置位置可能有些不一样,具体需要找一下,修改的内容为:
listen.owner = www
listen.group = www
listen.mode = 0666
下面增加代码:
pm.status_path = /php_status
MySQL 配置
其实就是在数据库中创建一个对应的用户(xxxxxxxx 为 amplify-agent 账号密码):
mysql -u root -p
[..]
mysql> CREATE USER 'amplify-agent'@'localhost' IDENTIFIED BY 'xxxxxxxx';
尝试使用 amplify-agent 登录 SQL,成功登录即可。
mysql -u amplify-agent -p
修改 Amplify 配置
vi /etc/amplify-agent/agent.conf
一般只需修改如下部分就可以:
[nginx]
user = www
[extensions]
phpfpm = True
mysql = True
[mysql]
host = 127.0.0.1
port = 3306
unix_socket = /tmp/mysql.sock
user = amplify-agent
password = xxxxxxxx
附:nginx 用户可通过 nginx -V 查询到;mysql.sock 路径可在 /etc/my.cnf 配置文件中获取。
修改完配置,需重启服务:
service nginx restart && service php-fpm restart && service amplify-agent restart
如无异常,等待一会就会有数据显示。
测试环境:搬瓦工 CentOS 7 X64 + LNMP
参考文章
DCC 的小窝 - Amplify —— 深度整合的全方位监控
kn007 - 为什么用 Nginx Amplify
沙发一个,看不懂,呵呵 。
@郑永 就一个监控 VPS 的工具嘛。
已经折腾不动了……
@灰常记忆 那就先歇歇。
用的NGINX,vps日常监控没什么必要,看网站.log分析就好了
@zlsin 折腾着玩……
太厉害啦~~我很少看这些,流量也用不完,网站不卡很少去管,哈哈。
@山小炮 流量能用完就爽咯……