1. free
- total 内存总数
- used 已使用内存数
- free 空闲内存数
- shared 多个进程共享的内存总额
- -buffers/caches 已用内存数 used-buffers-caches
- +buffers/caches 可用内存数 used+buffers+caches
2. 硬盘负载 iostat
- 安装方法:yum install -y sysstat
[root@localhost ~]# iostat -x
Linux 3.10.0-514.el7.x86_64 (localhost.localdomain) 2018年01月16日 _x86_64_ (1 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.06 0.00 0.15 0.27 0.00 99.52
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
sda 0.00 0.07 0.86 0.28 33.69 4.63 67.04 0.02 19.09 15.00 31.77 5.07 0.58
scd0 0.00 0.00 0.14 0.00 0.35 0.00 5.09 0.00 1.03 1.03 0.00 1.03 0.01
dm-0 0.00 0.00 0.72 0.32 32.29 4.20 70.18 0.02 24.01 17.87 37.91 5.54 0.58
dm-1 0.00 0.00 0.03 0.00 0.22 0.00 16.69 0.00 0.34 0.34 0.00 0.34 0.00
- iostat -x 1(1秒刷新一次) 5(刷新5次)
- 如果%util接近100%,说明产生的I/O请求太多,I/O系统已经满负荷,该磁盘可能存在瓶颈;
- 如果idle小于70%,I/O压力比较大,说明读取进程中有较多的wait;
同时还可以结合:b参数(等待资源的进程数),wa参数(I/O等待所占用的CPU时间的百分比,高于30%时I/O的压力就比较高了)
-
svctm(平均每次设备I/O操作服务时间)应小于await(平均每次设备I/O操作等待时间),因为同时等待的请求的时间被重复计算了;
一般来说,svctm的大小和磁盘性能有关,CPU/内存的负荷也会对其有一定的影响,请求过多会间接导致svctm增加
-
await的大小一般取决于svctm以及I/O队列的长度和I/O请求的发出模式;
svctm比较接近await,说明I/O几乎没有等待时间;
await远大于svctm,说明I/O队列太长,应用得到响应的时间也边长;
如果响应时间超过客户允许范围,这是应该考虑更换更快的磁盘,调整内核elevator的算法,优化应用或升级CPU;
-
avgrq-sz(平均队列长度),可以作为衡量系统I/O负荷的指标,但是由于avgrq-sz是按照单位时间计算出的平均值,不能反映出瞬间的I/O洪水;
3. 系统平均负载 uptime w top
[root@localhost ~]# uptime
22:27:04 up 1:39, 1 user, load average: 0.00, 0.01, 0.05
- 如果vmstat中r经常大于3或4,且id经常少于50,则表示CPU的负荷很重;
System load averages is the average number of processes that are either in a runnable or uninterruptable state.
A process in a runnable state is either using the CPU or waiting to use the CPU.
A process in uninterruptable state is waiting for some I/O access, eg waiting for disk.
The averages are taken over the three time intervals.
Load averages are not normalized for the number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the time while on a 4 CPU system it means it was idle 75% of the time.
4. vmstat
- vmstat 1(每1秒刷新一次) 4(刷新4次)
-
procs
-
r 等待运行的进程数;
-
b 处在非中断睡眠状态的进程数;
-
w 被交换出去的可运行的进程数;(此数由Linux计算得出,但Linux并不耗尽交换空间);
-
memory
-
swpd 虚拟内存使用情况,单位KB;
-
free 空闲内存,KB;
-
buff 被用来作为缓存的内存数,KB;
-
swap
-
si 从磁盘到内存的交换也数量,KB;
-
so 从内存交换到磁盘的交换页数量,KB;
-
io
-
bi 发送到块设备的块数,单位为块;
-
bo 从块设备接收到的块数,单位为块;
- 磁盘块的大小,通常是4096KB;
Centos6 tune2fs:
/dev/sda1 | grep block
Centos7 xfs:
xfs_info /dev/sda1 | grep bsize
-
system
-
in 每秒的中断数,包括时钟中断
-
cs 每秒的环境(上下文)切换次数
-
cpu 按CPU的总使用百分比显示
-
us CPU使用时间
-
sy CPU系统使用时间
-
id 闲置时间
- 标准情况下r<5,b≈0
-
r经常大于3或4,且id经常少于50,表示CPU的负荷很重;
- si、so长期不等于0,表示内存不足;
- disk经常不等于0,且在b中的队列大于2或3,表示io的性能不好;
5. shell脚本调试
bash -x test.sh
vim test.sh
#!/bin/bash
echo '---start---'
set -x
调试部分
set +x
echo '---end---'
6. shell不常用变量
变量名 |
变量作用 |
PWD |
当前工作的目录,等同于 pwd 命令的输出结果 |
RANDOM |
每次引用都会生成一个0~32767的随机整数 |
SECONDS |
脚本已经运行的时间(秒) |
PPID |
当前进程的父进程 |
EDITOR |
用于确认命令行编辑器所用的程序,通常是vi |
HOME |
当前用户家目录 |
7. Centos7的nc命令
发送方:
cat /etc/passwd | nc -l 8181
接收方:
nc 192.168.157.128 8181
测试端口:
nc -w 1 qq.com 80 < /dev/null && echo "tcp port ok"
8. screen命令
创建一个共享窗口:
screen -S screen_name
连接到这个远程窗口:
screen -x screen_name
9. 抓包
tcpdump -nn -i eth0 dst host 10.19.33.230 and dst port 3307 -w ./datacapture.cap
10. curl工具
curl -H "Content-Type: application/octet-stream" -XPOST "http://192.168.129.205:5701/stt/offsr?speechId=458002003446568.wav&format=audio/16LE;rate=8000;stereo&isAddPunct=true&isTransDigit=&SpkDiariz=true" --data-binary @/home/pachira/mlq/wav/stereo.wav
curl http://fae:pachira123@192.168.128.58:8080/job/PQA-2.0/lastSuccessfulBuild/artifact/PQA-2.2.0.27.tar.gz > PQA-2.2.0.27.tar.gz
11. sed理解
sed -i '/^SELINUX=/ s/enforcing/disabled/i' /etc/selinux/config
/^SELINUX=/ 定位在 以 "SELINUX="字符串开头的行
s/enforcing/disabled/i 将该行的"enforcing"替换为"disabled",查找"enforcing"时忽略大小写
12. 数据统计
cat test.txt | sort | uniq -c
sort 对内容进行排序
uniq -c 对内容进行分组统计
13. 清理内存
echo 1 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
14. 多机互信
ssh-keygen
cat id_rsa.pub > authorized_keys
scp -r .ssh 192.168.111.129:/root/
15. cpu核数计算
- CPU个数
cat /proc/cpuinfo | grep 'physical id' | sort | uniq | wc -l
- 每个CPU中物理核数
cat /proc/cpuinfo | grep 'cpu cores' | uniq
- 全部逻辑核数
cat /proc/cpuinfo | grep 'processor' | wc -l
16. 查看网卡是否正常安装
lspci | grep Ethernet
dmesg | grep error
17. shell输出日志
write_log() {
printf "$(date +"%Y-%m-%d %H:%M:%S")\t" &>> $2
printf "$1\n" &>> $2
}
write_log hahahahaha /tmp/aaa.log
18. 打印表头索引
head -n 1 1974-11-28.dim | awk -F\| '{for(i=1; i<=NF; i++){printf"%s\t%s\n", i, $i}}'
19. 远程执行shell命令
for h in `cat host.list`
do
echo "* * * * * date > /tmp/date.temp" | ssh $h 'crontab';
done
20. ntpd时间同步
ntpdate + crontab的方式只能保证每一分钟时间相同;
对于某些高精度场景,使用该方法服务器时间精度不足;
可以启动node的ntpd服务,通过ntpd服务网向ntpserver同步时间;
这种同步是实时的,精度比ntpdate + crontab高;
21. 源码部署和rpm包部署
源码部署,更适合需要依赖物理cpu运行的服务;
例如tomcat是依赖jvm虚拟机运行的,使用源码和rpm包部署的差别就不是很大;
22. java服务导出pdf报表乱码
报错:
Font \"微软雅黑\" is not available to the JVM. See the Javadoc for more details.
解决方法:
1. 从windows系统下载 msyh.ttc,拷贝到服务器 /usr/share/fonts/chinese/TrueType;
2. 执行安装字体命令;
cd /usr/share/fonts/chinese/TrueType
mkfontscale
mkfontdir
fc-cache –fv
3. 查看安装的字体;
fc-list | less
4. 重启报表服务;
23. tar打包忽略特定文件
tar -czvf data-source.tar.gz data-source --exclude="*wav"
24. ping 带时间戳
ping 127.0.0.1 | awk '{ print $0"\t" strftime("%Y-%m-%d %H:%M:%S",systime())}'
25.ffmpeg使用方法
ffmpeg -i abc.wav
查看abc.wav的格式
ffmpeg -i in.wav out.wav
把in.wav转码成8k16bit录音,保存成out.wav
ffmpeg -i in.mp3 -ar 8000 -ab 128k -ac 1 out.wav
把 in.mp3 转码成8k16bit单声道录音
单/双声道 转 单声道参数:
-ar 8000 8k
-ab 128k 比特率
-ac 1 单声道
双声道 转 双声道 参数:
-ar 8000 8k
-ab 256k 比特率
-ac 2 双声道
--------------------------------------------------------------------------------
转码视频:
ffmpeg -i src.mp4 -b 2000k dst.mp4
网友评论