跳到主要内容

linux常见问题处理

  • 服务器日志查找
  • nginx配置
  • 服务器资源排查
  • 报错排查

nginx相关​

  • 查看nginx加载的配置文件:nginx -t
    • 常见位置有 /etc/nginx/nginx.conf、/usr/local/nginx/conf/nginx.conf
  • 查看某个域名的nginx配置
    • 通过nginx -t查看nginx的配置文件之后,可以通过grep来检索递归nginx的目录下,查找域名配置文件
    • 用于查找这个域名出现在哪个配置文件里 grep -R "你要找的域名" /data/app/nginx/conf/
text
# 查看nginx配置
nginx -t

# 查看某个域名的nginx配置
grep -r "www-xxx.com" data/app/nginx/conf

查看pm2日志记录​

  • 查看指定日期的pm2记录
  • PM2 默认日志目录通常是 : ~/.pm2/logs
bash
# 查看有哪些 PM2 服务
pm2 list

# 查看指定服务最近 200 行日志
pm2 logs 服务名 --lines 200

# 导出日志 2026-08-20 当天所有 PM2 日志 导出到/tmp/pm2-2026-08-20.log
grep "2026-08-20" ~/.pm2/logs/*.log > /tmp/pm2-2026-08-20.log

下载日志​

  • 使用scp命令,基于ssh远程文件复制命令
    • 支持上传和下载
bash
scp -P 2223 dev@localhost:/tmp/demo-node-out.log ~/Downloads/

软链接相关​

  • -s = symbolic,创建符号链接(软链接)
  • -f = force,强制覆盖目标位置已经存在的文件或链接
bash
# 创建软链接
ln -sf /etc/nginx/sites-available/demo.conf /etc/nginx/sites-enabled/demo.conf

# 查看软链接
ls -l /etc/nginx/sites-enabled/

看进程情况​

  • 通过ps命令查看进程
    • ps:process status 进程状态
  • 排查服务的进程是否还在
  • a = all,显示其他用户的进程
  • u = user,以用户为主的详细格式显示
  • x = 显示没有终端 TTY 的进程
bash
ps
ps aux
# 查看node进程
ps aux | grep node

看磁盘情况​

  • df -h
    • disk free,查看磁盘空间使用情况
bash
df -h

看内存情况​

  • free 命令显示系统内存的使用情况
bash
free -h

DNS查询​

  • nslookup domain
  • 查域名解析
bash
nslookup baidu.com

服务管理​

  • systemctl命令
bash
# 查看nginx服务状态
systemctl status nginx