uptime
uptime
top
查看CPU,内存等使用状态,P 按CPU排序,M 按内存排序,q 退出
top
# P - 按CPU排序
# M - 按内存排序
# c - 显示COMMAND详细
# q - 退出
top -u user01
top -p pid_number
top -p pid_number_01,pid_number_02,pid_number_03
cat /proc/pid_number/status
结果输出到文件
top -b -n1
top -b -n1 > top.log
统计在线用户
who
who | cut -d" " -f1 | sort | uniq
# -F可以指定分隔符" ",默认为空格
who | awk -F" " '{print $1}' | sort | uniq
who | awk '{print $1}' | sort | uniq | wc -l
iftop
iftop - display bandwidth usage on an interface by host
12.5Kb 25.0Kb 37.5Kb 50.0Kb 62.5Kb
+----------------+-----------------+----------------+-----------------+-----------------
dev-c801 => unknown.alphabook.cn 832b 1.55Kb 1.42Kb
<= 22.1Kb 39.8Kb 36.2Kb
----------------------------------------------------------------------------------------
TX: cum: 18.0KB peak: 16.9Kb rates: 2.84Kb 7.78Kb 7.98Kb
RX: 90.7KB 82.7Kb 22.3Kb 43.4Kb 40.3Kb
TOTAL: 109KB 99.6Kb 25.1Kb 51.2Kb 48.3Kb
Nethogs
List putting the most intensive processes
yum install epel-release
yum install nethogs
pgrep & pkill & kill
查看和结束用户进程
SIGHUP 1 Hangup
SIGKILL 9 Kill Signal
SIGTERM 15 Terminate (Default)
pgrep -u user01 firefox
pkill -u user01 firefox
pkill -9 -u user01 firefox
pkill -u user01
pkill -t pts/10
kill pid_number
kill -9 pid_number
查询和结束僵尸进程
ps -A -o stat,pid,cmd,user | grep -e '^[Zz]' | awk '{print $2}' | xargs kill
查看进程树
pstree -p 12416
查看进程启动时间
ps -p PID -o lstart
不可中断睡眠 D (TASK_UNINTERRUPTIBLE)
进程处于D状态,基本上需要重启系统
atop
dnf install epel-release -y
dnf install atop -y
atop
free
查看内存使用情况(Cached内存在需要的时候自动释放)
https://www.linuxatemyram.com/
free -h
# cache memory 系统在需要的时候会自动释放
iostat
IO性能
iostat -dxh
df
查看磁盘使用情况
df -hT
du
查看文件夹的使用情况
du -sh
du -h --max-depth=3
服务
# 服务基本操作
systemctl status httpd
systemctl start httpd
systemctl stop httpd
systemctl restart httpd
systemctl reload httpd
systemctl is-enabled httpd
systemctl enable httpd
# 列出系统所有服务
systemctl list-unit-files
Process history
# Capture process information every 5 minutes
# Archive for one week (recycle)
my_day=$(date | awk '{print $1}')
my_time=$(date +%H%M)
my_host=$(hostname)
my_folder="/one/scripts/phistory/$my_host/$my_day"
my_file="/one/scripts/phistory/$my_host/$my_day/$my_time"
if [ ! -d $my_folder ]; then
mkdir -p $my_folder
fi
hostname > $my_file
date >> $my_file
top -b -n1 >> $my_file
ps aux >> $my_file
lsof
lsof | grep my_file
ulimt
ulimit -n
# 配置文件
/etc/security/limits.conf
Out of Memory
grep -i "out of memory" /var/log/message
Disable over commit
In major Linux distributions, the kernel allows by default for processes to request more memory than is currently free in the system to improve the memory utilization. This is based on heuristics that the processes never truly use all the memory they request. However, if your system is at risk of running out of memory, and you wish to prevent losing tasks to OOM killer, it is possible to disallow memory overcommit.
To change how the system handles overcommit calls Linux has an application called ‘sysctl’ that is used to modify kernel parameters at runtime. You can list all sysctl controlled parameters using the following.
sysctl -a | grep vm.overcommit
vm.overcommit_memory = 0
vm.overcommit_ratio = 50
vm.overcommit_kbytes = 0
# This parameter has 3 different values:
# 0 means to “Estimate if we have enough RAM”
# 1 equals to “Always allow”
# 2 that is used here tells the kernel to “Say no if the system doesn’t have the memory”
# disable over commit(immediately and lost after system reboot)
sysctl -w vm.overcommit_memory=2
sysctl -w vm.overcommit_ratio=100
# disable over commit(permanently)
vi /etc/sysctl.conf
# Add below lines
vm.overcommit_memory=2
vm.overcommit_ratio=100
Reference:
https://www.kernel.org/doc/html/latest/vm/overcommit-accounting.html
rsyslog
# systemctl status rsyslog
● rsyslog.service - System Logging Service
Loaded: loaded (/usr/lib/systemd/system/rsyslog.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-06-21 11:27:46 CST; 1 months 11 days ago
Docs: man:rsyslogd(8)
http://www.rsyslog.com/doc/
Main PID: 1158 (rsyslogd)
CGroup: /system.slice/rsyslog.service
└─1158 /usr/sbin/rsyslogd -n
配置文件
/etc/rsyslog.conf
删除/var/log目录下的日志文件后,不自动产生新的日志文件,尝试重启服务
systemctl restart rsyslog