查看系统负载
$ w
12:17:53 up 4 days, 15:56, 1 user, load average: 0.15(1分钟之内平均负载), 0.14(5分钟), 0.14 (15分钟)
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 116.238.189.141 12:17 0.00s 0.00s 0.00s w
cat /proc/cpuinfo //查看cpu信息
少于cpu核数时,负载偏低
大于cpu核数时,负载偏高
uptime
12:29:28 up 4 days, 16:08, 1 user, load average: 0.09, 0.14, 0.14
系统负载的原因
vmstat 1 5 :一秒钟显示1次,显示5次
vmstat 1 5
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 1328516 99020 447708 0 0 1 1 53 13 0 0 100 0 0
0 0 0 1328508 99020 447708 0 0 0 0 178 349 0 0 100 0 0
0 0 0 1328508 99020 447708 0 0 0 0 180 353 1 0 99 0 0
0 0 0 1328508 99020 447708 0 0 0 0 161 335 0 1 99 0 0
0 0 0 1328508 99020 447708 0 0 0 0 155 334 0 0 100 0 0
1)procs 显示进程相关信息
r :表示运行和等待cpu时间片的进程数,如果长期大于服务器cpu的个数,则说明cpu不够用了;
b :表示等待资源的进程数,比如等待I/O, 内存等,这列的值如果长时间大于1,则需要关注一下了;
2)memory 内存相关信息
swpd :表示切换到交换分区中的内存数量 ;
free :当前空闲的内存数量;
buff :缓冲大小,(即将写入磁盘的);
cache :缓存大小,(从磁盘中读取的);
3)swap 内存交换情况
si :由交换区写入到内存的数据量;
so :由内存写入到交换区的数据量;
4)io 磁盘使用情况
bi :从块设备读取数据的量(读磁盘);
bo: 从块设备写入数据的量(写磁盘);
5)system 显示采集间隔内发生的中断次数
in :表示在某一时间间隔中观测到的每秒设备中断数;
cs :表示每秒产生的上下文切换次数;
6)CPU 显示cpu的使用状态
us :显示了用户下所花费 cpu 时间的百分比;
sy :显示系统花费cpu时间百分比;
id :表示cpu处于空闲状态的时间百分比;
wa :表示I/O等待所占用cpu时间百分比;
st :表示被偷走的cpu所占百分比(一般都为0,不用关注);
以上所介绍的各个参数中,阿铭经常会关注r列,b列,和wa列,三列代表的含义在上边说得已经很清楚。IO部分的bi以及bo也是要经常参考的对象。如果磁盘io压力很大时,这两列的数值会比较高。另外当si, so两列的数值比较高,并且在不断变化时,说明内存不够了,内存中的数据频繁交换到交换分区中,这往往对系统性能影响极大。
top 显示进程所占系统资源
动态监控进程所占系统资源,每隔3秒变一次, top重点查看的还是下面的进程使用系统资源详细状况
RES:进程所占内存大小,%MEM:用内存百分比
M:按照内存使用大小排序; 数字 ‘1’ 可以列出各颗cpu的使用状态
top -bn1 :非动态打印系统资源使用情况
sar
sar -n DEV 1 10 //查看网卡流量
平均时间: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
平均时间: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
平均时间: eth0 438.38 260.00 611.12 16.66 0.00 0.00 0.00
$ ls /var/log/sa //存放位置
sa08 sa10 sa12 sa14 sa16 sa18 sa20 sar09 sar11 sar13 sar15 sar17 sar19
sa09 sa11 sa13 sa15 sa17 sa19 sar08 sar10 sar12 sar14 sar16 sar18
$ sar -n DEV -f /var/log/sa/sa19
sar -q //查看历史负载
sar -b //查看磁盘
free 查看内存
$ free -m
total used free shared buffers cached
Mem: 1893 197 1695 0 23 128
-/+ buffers/cache: 45 1848
Swap: 0 0 0
真正使用的是第二行 buffer/cache 的数据,1848=1695+23+128
buffer:是内存中划分出的准备写到磁盘的
cache:是内存中划分出的准备从磁盘读到内存中的
netstat 查看网络连接状况
netstat命令用来打印网络连接状况、系统所开放端口、路由表等信息
netstat -lnp (打印当前系统启动哪些端口)
netstat -an (打印网络连接状况)
抓包工具
tcpdump -nn(第一个n指定host为数字,第二个n指定port为数字)
$ tcpdump -nn -c 10(-c指定抓包数量)
ip:服务器ip地址 > 目标ip地址
-i eth0 //指定网卡
tcpdump -nn port 22 //指定端口
tcpdump -nn tcp/udp //指定协议
tcpdump -nn tcp and port 80 and host 192.168.0.1 //指定协议、端口、ip
tcpdump -nn -s0 port 22 -w 1.cap //写入文件,-s0表示完整抓包,抓包的内容,>2.cap是数据包的流向
tupdump -r 1.cap //查看二进制中数据包的流向
---------------------------------------
tshark 位于包 wireshark
tshark -nn //和tcpdump -nn相同
tshark -n -t a -R http.request -T fields -e "frame.time" -e "ip.src" -e "http.host" -e "http.request.method" -e "http.request.uri"
我在云上面运转这条命令就是一直等待,这是云上面运行的
,但是虚拟机上面却不会这是为什么?
防火墙
selinux
配置文件 /etc/selinux/config
1 # This file controls the state of SELinux on the system.
2 # SELINUX= can take one of these three values:
3 # enforcing - SELinux security policy is enforced. 对应setenforce 1 #遇到匹配规则时,完全阻断
4 # permissive - SELinux prints warnings instead of enforcing. 对应setenforce 0 #遇到问题时记录日志
5 # disabled - SELinux is fully disabled. #关闭
6 SELINUX=disabled
7 # SELINUXTYPE= type of policy in use. Possible values are:
8 # targeted - Only targeted network daemons are protected.
9 # strict - Full SELinux protection.
10 SELINUXTYPE=targeted
getenforce 查看enforce状况
临时关闭 setenforce 0 ; setenforce 1
rpm -qf `witch setenforce` //注意反引号
netfilter防火墙
工具:iptables
结构:table >> chain >> 规则
三张表:
filter--作用:对包进行过滤的
nat
mangle
格式:iptables -t filter -nvL //规则查看
添加规则:$ iptables -I INPUT -p tcp --dport 80 -s 192.168.0.1 -j DROP/REJECT /ACCEPT
// -I:表示插入insert,-D:表示删除,-F:清空规则;
// DROP-过滤,REJECT-反对,ACCEPT-接收
保存规则:service iptables save 默认保存位置 :/etc/sysconfig/iptables
规则备份:$ iptables-save > guizebeifen.ipt
规则恢复:$ iptables-restore < guizebeifen.ipt
计数清零:iptables -Z
任务计划
min hour date month week
分 时 日 月 周
0-59 0-23 1-31 1-12 1-7
每隔八小时 : 0 */8 * * *
1时,12时,18时:0 1,12,18 * * *
:30 9-18 * * *
crontab -e :编辑命令
crontab -l :查看命令
保存位置:/var/spool/cron/root
系统服务
1
ntsysv
yum install -y ntsysv
reboot
2
chkconfig --list
chkconfig servname off:服务关闭 运行级别(2-5)
chkconfig --level 345 servname on/off
chkconfig --add servname:添加服务
chkconfig --del servname:删除服务
系统服务位置 /etc/init.d
ps 查看系统进程
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 2900 1320 ? Ss Dec15 0:01 /sbin/init
PID :进程id
STAT :进程状态
D:不能中断的进程(通常为IO)
R 正在运行中的进程
S 已经中断的进程,通常情况下,系统中大部分进程都是这个状态
T 已经停止或者暂停的进程,如果我们正在运行一个命令,比如说 sleep 10 如果我们按一下ctrl -z 让他暂停,那么我们用ps查看就会显示T这个状态
W 这个好像是说,从内核2.6xx 以后,表示为没有足够的内存页分配
X 已经死掉的进程(这个好像从来不会出现)
Z 僵尸进程,杀不掉,打不死的垃圾进程,占系统一小点资源,不过没有关系。如果太多,就有问题了。一般不会出现。
< 高优先级进程
N 低优先级进程
L 在内存中被锁了内存分页
s 主进程
l 多线程进程
+ 代表在前台运行的进程
系统日志
/var/log/messages :系统内核、yum安装 ,配置文件 : /etc/logrotate.conf :确定日志切割
/var/log/wtmp:用户登录历史,命令:last
/var/log/btmp :无效用户登录历史,命令:lastb
/var/log/maillog:邮件历史
/var/log/secure :验证信息,暴力破解的
/var/log/dmesh:系统启动过程中硬件的信息
命令 dmesh :实时更新的硬件错误信息
-----------------------------------------------------------------------------------------------
ps aux
kill pid
kill -9 pid
killall proname
xargs和exec
find /var/log -type f -mtime +10 -exec cp {} {}.bak \;
find /var/log -type f -mtime +10 | xargs -i cp {} {}.1 //带有两个参数时,加上-i选项
find /var/log -name \*.1 | xargs rm //直接操作时,不用加上-i
ls |xargs :将ls的结果全部合成一行
screen
1 丢入后台的同时加上命令nohup ,生成nohup.out文件,cat nohup.out
nohup sleep 100 &
2 screen
虚拟终端
yum install -y screen
screen -S test1 //进入自定义命名的虚拟终端test1
ctrl + a + d //暂时退出,后台运行
ctrl + d //真正退出
screen -ls //查看运行的screen
There are screens on:
29232.test1 (Detached)
29216.pts-0.suning (Detached)
screen -r test1/29216 //虚拟终端的自定义名称或者id号
curl
功能:访问web,下载文件
$ curl www.baidu.com //显示此网址的源码
$ curl -I www.baidu.com //显示状态
HTTP/1.1 200 OK
Server: bfe/1.0.8.18
Date: Sun, 25 Dec 2016 08:21:59 GMT
Content-Type: text/html
Content-Length: 277
Last-Modified: Mon, 13 Jun 2016 02:50:06 GMT
Connection: Keep-Alive
ETag: "575e1f5e-115"
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Pragma: no-cache
Accept-Ranges: bytes
$ curl -x :代理, 指本机访问目标网址时,将目标IP 改为代理IP
$ curl -x 220.181.112.244:80 www.baidu.com -I //访问ip:220.181.112.244;而不是自定义的www.baidu.com的ip
$ curl -Iv www.baidu.com //显示访问过程
* About to connect() to www.baidu.com port 80 (#0)
* Trying 220.181.112.244... connected
* Connected to www.baidu.com (220.181.112.244) port 80 (#0)
> HEAD / HTTP/1.1
> User-Agent: curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
user-agent:浏览器标识
> Host: www.baidu.com
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Server: bfe/1.0.8.18
Server: bfe/1.0.8.18
< Date: Sun, 25 Dec 2016 08:50:58 GMT
Date: Sun, 25 Dec 2016 08:50:58 GMT
< Content-Type: text/html
Content-Type: text/html
< Content-Length: 277
Content-Length: 277
< Last-Modified: Mon, 13 Jun 2016 02:50:05 GMT
Last-Modified: Mon, 13 Jun 2016 02:50:05 GMT
< Connection: Keep-Alive
Connection: Keep-Alive
< ETag: "575e1f5d-115"
ETag: "575e1f5d-115"
< Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
< Pragma: no-cache
Pragma: no-cache
< Accept-Ranges: bytes
Accept-Ranges: bytes
<
* Connection #0 to host www.baidu.com left intact
* Closing connection #0
curl -u username:password URL //访问需要用户名和密码的站点
curl -u 1107914055@qq.com:688992suning https://mail.qq.com
curl -O https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/holiday/xmas2016/logo.gif
//以默认的名称保存
curl -o he https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/holiday/xmas2016/logo.gif
// 自定义浏览器标识
curl -A 'user-agent' www.baidu.com //指定浏览器标识
编辑回复