在Ubuntu LNMP(Linux, Nginx, MySQL, PHP)环境中,监控服务器状态是非常重要的,以确保系统的稳定性和性能。以下是一些常用的方法和工具来监控服务器状态:
1. 使用系统自带的工具
top
top命令可以实时显示系统中各个进程的资源占用状况。
top
htop
htop是top的增强版,提供了更友好的用户界面和更多的功能。
sudo apt-get install htop
htop
vmstat
vmstat可以显示虚拟内存统计信息,以及CPU使用情况。
vmstat 1
iostat
iostat可以显示CPU和I/O设备的统计信息。
sudo apt-get install sysstat
iostat -x 1
free
free命令显示系统内存的使用情况。
free -h
2. 使用Nginx监控工具
nginx-status
Nginx自带的模块,可以通过访问特定的URL来查看Nginx的状态。
首先,确保Nginx配置文件中启用了ngx_http_stub_status_module模块。
location /nginx_status {
stub_status on;
allow 127.0.0.1; # 限制访问IP
deny all;
}
然后,访问http://your_server_ip/nginx_status即可查看Nginx状态。
3. 使用MySQL监控工具
mysqladmin
mysqladmin可以用来监控MySQL服务器的状态。
mysqladmin -u root -p status
mysqldumpslow
mysqldumpslow可以用来分析MySQL的慢查询日志。
sudo apt-get install mysqldumpslow
mysqldumpslow /var/log/mysql/slow.log
4. 使用第三方监控工具
Prometheus + Grafana
Prometheus是一个开源的监控系统和时间序列数据库,Grafana是一个开源的分析和监控平台。两者结合可以提供强大的监控和可视化功能。
- 安装Prometheus:
wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz
tar xvfz prometheus-2.30.3.linux-amd64.tar.gz
cd prometheus-2.30.3.linux-amd64
- 配置Prometheus:
编辑
prometheus.yml文件,添加监控目标。
scrape_configs:
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
- job_name: 'nginx'
static_configs:
- targets: ['your_server_ip:9113']
- job_name: 'mysql'
static_configs:
- targets: ['your_server_ip:9104']
- 启动Prometheus:
./prometheus --config.file=prometheus.yml
- 安装Grafana:
sudo apt-get install grafana
- 配置Grafana:
启动Grafana并访问
http://your_server_ip:3000,使用默认用户名和密码(admin/admin)登录,然后添加Prometheus作为数据源。
5. 使用日志分析工具
ELK Stack
ELK Stack(Elasticsearch, Logstash, Kibana)是一个流行的日志管理和分析解决方案。
- 安装Elasticsearch:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.0-linux-x86_64.tar.gz
tar xvfz elasticsearch-7.10.0-linux-x86_64.tar.gz
cd elasticsearch-7.10.0
./bin/elasticsearch
- 安装Logstash:
wget https://artifacts.elastic.co/downloads/logstash/logstash-7.10.0-linux-x86_64.tar.gz
tar xvfz logstash-7.10.0-linux-x86_64.tar.gz
cd logstash-7.10.0
./bin/logstash -f /etc/logstash/conf.d/your-config.conf
- 安装Kibana:
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.10.0-linux-x86_64.tar.gz
tar xvfz kibana-7.10.0-linux-x86_64.tar.gz
cd kibana-7.10.0
./bin/kibana
通过以上方法和工具,你可以有效地监控Ubuntu LNMP服务器的状态,确保系统的稳定运行。
以上就是关于“Ubuntu LNMP中如何监控服务器状态”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm