在Ubuntu LNMP(Linux, Nginx, MySQL, PHP)环境中,监控服务器状态是非常重要的,以确保系统的稳定性和性能。以下是一些常用的方法和工具来监控服务器状态:
top
命令可以实时显示系统中各个进程的资源占用状况。
top
htop
是top
的增强版,提供了更友好的用户界面和更多的功能。
sudo apt-get install htop
htop
vmstat
可以显示虚拟内存统计信息,以及CPU使用情况。
vmstat 1
iostat
可以显示CPU和I/O设备的统计信息。
sudo apt-get install sysstat
iostat -x 1
free
命令显示系统内存的使用情况。
free -h
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状态。
mysqladmin
可以用来监控MySQL服务器的状态。
mysqladmin -u root -p status
mysqldumpslow
可以用来分析MySQL的慢查询日志。
sudo apt-get install mysqldumpslow
mysqldumpslow /var/log/mysql/slow.log
Prometheus是一个开源的监控系统和时间序列数据库,Grafana是一个开源的分析和监控平台。两者结合可以提供强大的监控和可视化功能。
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.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 --config.file=prometheus.yml
sudo apt-get install grafana
http://your_server_ip:3000
,使用默认用户名和密码(admin/admin)登录,然后添加Prometheus作为数据源。ELK Stack(Elasticsearch, Logstash, Kibana)是一个流行的日志管理和分析解决方案。
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
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
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服务器的状态,确保系统的稳定运行。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: 怎样定制ubuntu installer界面