@zhangsiming65965
2019-02-23T12:09:15.000000Z
字数 15580
阅读 146
云计算
如果有梦想,就放开的去追;
因为只有奋斗,才能改变命运。
精简安装策略:
1.仅安装需要的,按需安装,不用不装;
2.开发包、基本网络包、基本应用包。
3.系统盘按照默认分区方式 ,数据盘单独挂载
[root@ZhangSiming ~]# systemctl stop NetworkManager
[root@ZhangSiming ~]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
#如果不关闭此服务,那么此服务会接管Linux的网络设置。有时候会导致修改了网卡配置文件IP,但是网卡的IP不变的情况;或者导致IP地址自动变化的故障。
1./etc/resolv.conf:临时修改DNS地址,重启网卡会被网卡里面的DNS配置覆盖;
2./etc/sysconfig/network-scripts/ifcfg-ens32网卡中配置DNS。
[root@ZhangSiming tomcat]# cat /etc/hostname
ZhangSiming
#修改之后重启生效,仅限于CentOS7.5
[root@ZhangSiming tomcat]# tail -1 /etc/hosts
192.168.17.143 ZhangSiming
127.0.0.1 ZhangSiming
#注意一定要有127.0.0.1的映射,因为有些服务需要验证自身的主机名有没有被映射
[root@ZhangSiming ~]# cat yum.sh
#!/bin/bash
ping -c 1 www.baidu.com &>/dev/null
if [ $? != 0 ];then
echo "network problem"
exit 1
fi
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm &>/dev/null
yum -y install http://repository.it4i.cz/mirrors/repoforge/redhat/el7/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm &>/dev/null
yum -y clean all &>/dev/null
yum makecache &>/dev/null
yum -y update &>/dev/null
echo "yum is ready!"
[root@ZhangSiming ~]# sh yum.sh
yum is ready!
#yum配置优化完成
[root@ZhangSiming ~]# ls /etc/yum.repos.d/
epel.repo local.repo mirrors-rpmforge-testing
epel.repo.rpmnew mirrors-rpmforge rpmforge.repo
epel-testing.repo mirrors-rpmforge-extras
#注意,CentOS7和CentOS6的网yum源地址不同,自行查找下载配套的即可
推荐时间服务器:ntp.sjtu.edu.cn ntp1.aliyun.com
[root@ZhangSiming ~]# yum -y install ntpdate
[root@ZhangSiming ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp: ‘/usr/share/zoneinfo/Asia/Shanghai’ and ‘/etc/localtime’ are the same file
#修改时区
[root@ZhangSiming ~]# ntpdate ntp.sjtu.edu.cn
#校准时间
23 Feb 14:58:12 ntpdate[1523]: step time server 202.108.6.95 offset -2.118379 sec
[root@ZhangSiming ~]# echo '*/5* * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn >> /var/log/ntp.log 2>&1; /sbin/hwclock -w' >> /var/spool/cron/root
#加入定时任务,每5分钟执行一次;/sbin/hwclock -w 的意思是将时钟信息刷新到bios里
[root@ZhangSiming ~]# crontab -l
*/5* * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn >> /var/log/ntp.log 2>&1; /sbin/hwclock -w
crond:定时任务、network:网络服务、rsyslog:日志服务、sshd:远程连接服务、sysstat:系统工具包
[root@ZhangSiming ~]# systemctl enable crond.service
[root@ZhangSiming ~]# systemctl enable network.service
network.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig network on
[root@ZhangSiming ~]# systemctl enable sshd.service
[root@ZhangSiming ~]# systemctl enable sysstat.service
[root@ZhangSiming ~]# systemctl enable syslog.service
#CentOS7查看开机自启动服务的命令
[root@ZhangSiming ~]# systemctl list-unit-files | grep enabled
auditd.service enabled
autovt@.service enabled
crond.service enabled
dbus-org.freedesktop.NetworkManager.service enabled
dbus-org.freedesktop.nm-dispatcher.service enabled
getty@.service enabled
irqbalance.service enabled
kdump.service enabled
[root@ZhangSiming ~]# cat /etc/passwd
[root@ZhangSiming ~]# cat /etc/group
[root@ZhangSiming ~]# which groupdel
/usr/sbin/groupdel
#删除用户组
[root@ZhangSiming ~]# which userdel
/usr/sbin/userdel
#删除用户,-r删除用户同时删除家目录
#普通大文件
[root@ZhangSiming ~]# du -sh /\* 2>/dev/null | sort -rn
#*前\为优化markdown文档显示,实际操作需要去除
231M /var
97M /boot
72K /root
31M /etc
12K /home
7.6M /run
4.2G /media
1.2G /usr
0 /tmp
0 /sys
0 /srv
0 /sbin
0 /proc
0 /opt
0 /mnt
0 /lib64
0 /lib
0 /dev
0 /bin
#找出占地方大的目录,再去到对应目录进行大文件排查删除优化
#定时任务清理的关键目录路径
/var/spool/mail/ #邮件路径
/var/spool/postfix/maildrop #小碎片路径
#定时任务有屏幕输出的时候,会发送邮件到/var/spool/mail/对应用户文件内;如果服务器未开启postfix服务,则会在/var/spool/postfix/maildrop目录下生成一个一个的碎片文件,这些文件会占用inode
[root@ZhangSiming ~]# ulimit -a
core file size (blocks, -c) 0
#core文件的最大值
data seg size (kbytes, -d) unlimited
#进程的数据段大小
scheduling priority (-e) 0
#调度优先级
file size (blocks, -f) unlimited
#文件大小
pending signals (-i) 3802
#最多有多少个待处理的信号
max locked memory (kbytes, -l) 64
#一个任务锁住的物理内存最大值
max memory size (kbytes, -m)
unlimited
#一个任务的物理内存最大值
open files (-n) 1024
#一个进程最多可以打开多少文件
pipe size (512 bytes, -p) 8
#管道的最大空间为大
POSIX message queues (bytes, -q) 819200
#POSIX的消息队列的最大值为多大
real-time priority (-r) 0
#real-time调度优先级
stack size (kbytes, -s) 8192
#进程的栈的最大值为多大
cpu time (seconds, -t) unlimited
#进程使用cpu的时间
max user processes (-u) 3802
#当前用户同时打开的进程的最大个数为
virtual memory (kbytes, -v) unlimited
#虚拟内存空间
file locks (-x) unlimited
#可以锁住的最大文件个数
ulimit + 上面显示每一条后面的字母可临时调整内核参数,即时生效
[root@ZhangSiming ~]# sed -n '60,67p' /etc/security/limits.conf
* soft core unlimited
* hard core unlimited
#开启并且不限制core文件大小,
* soft fsize unlimited
* hard fsize unlimited
#不限制最大文件大小
* soft nofile 65536
* hard nofile 65536
#单个进程的最大文件打开数为65536
* soft nproc 65536
* hard nproc 65536
#最大进程数为65536
[root@ZhangSiming ~]# exit
logout
#退出登录即可生效
[root@ZhangSiming ~]# ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 3802
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65536
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 65536
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
- ext4:Linux原生态文件格式
- xfs:Centos7开始默认支持
读操作频繁,同时小文件众多的应用:首选ext4文件系统
写操作频繁的应用,首选xfs。
交给开发来做。
[root@ZhangSiming tomcat]# sestatus
SELinux status: disabled
[root@ZhangSiming tomcat]# vim /etc/selinux/config
[root@ZhangSiming tomcat]# sed -n '7p' /etc/selinux/config
SELINUX=disabled
#SELINUX再生产环境中不是很好用,一般需要关闭
[root@ZhangSiming ~]# systemctl start firewalld
[root@ZhangSiming ~]# iptables -F
iptables -P INPUT ACCEPT
iptables -F
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A INPUT -s 1.1.1.0/24 -p tcp -m tcp --dport 22 -j ACCEPT
iptables -A INPUT -s 2.2.2.2/32 -p tcp -m tcp --dport 22 -j ACCEPT
iptables -A INPUT -i eth1 -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP
iptables -A INPUT -p tcp -m tcp --tcp-flags FIN,SYN FIN,SYN -j DROP
iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,RST SYN,RST -j DROP
iptables -A INPUT -p tcp -m tcp --tcp-flags FIN,RST FIN,RST -j DROP
iptables -A INPUT -p tcp -m tcp --tcp-flags FIN,ACK FIN -j DROP
iptables -A INPUT -p tcp -m tcp --tcp-flags PSH,ACK PSH -j DROP
iptables -A INPUT -p tcp -m tcp --tcp-flags ACK,URG URG -j DROP
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
#上述为firewalld配置范例,根据不同公司有不同修改
[root@ZhangSiming ~]# cat -n /etc/ssh/sshd_config.bak | sed -n '17p;38p;43p;47p;65p;79p;115p'
cat: /etc/ssh/sshd_config.bak: No such file or directory
[root@ZhangSiming ~]# cat -n /etc/ssh/sshd_config | sed -n '17p;38p;43p;47p;65p;79p;115p'
17 Port 22221
#修改端口为22221,一个是不用默认端口安全,一个是1w以上的端口不会被nmap扫描出来
38 PermitRootLogin no
#禁止root用户登录(小规模服务方便管理可以开启)
43 PubkeyAuthentication yes
#允许使用ssh公钥连接
47 AuthorizedKeysFile .ssh/authorized_keys
#公钥放置位置
65 PasswordAuthentication no
#不允许密码认证连接方式
79 GSSAPIAuthentication no
#关闭GSSAPI认证,加快ssh速率
115 UseDNS no
#关闭DNS反向解析,加快ssh速率
把公钥放到需要连接的服务器,然后管理人员通过私钥即可xshell连接到对应服务器。
注意两点:
1.公钥权限600,不能太高,不安全。事实上太高也连不上;
2.如果想要登录普通用户,可以公钥发普通用户家目录对应位置;也可以root公钥连接上了之后su - 普通用户(sudo提前提好相应权限)
[root@ZhangSiming ~]# vim /etc/sudoers
[root@ZhangSiming ~]# sed -n '93p' /etc/sudoers
yunjisuan ALL=(ALL) NOPASSWD:ALL
[root@ZhangSiming ~]# su - yunjisuan
Last login: Sat Feb 23 13:58:57 CST 2019 on pts/0
[yunjisuan@ZhangSiming ~]$ sudo -l
Matching Defaults entries for yunjisuan on ZhangSiming:
!visiblepw, always_set_home, match_group_by_gid, env_reset,
env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS",
env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE",
env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES",
env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE",
env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY",
secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin
User yunjisuan may run the following commands on ZhangSiming:
(ALL) NOPASSWD: ALL
#由于不能给所有人root账号,所以把给普通运维的账号sudo提权为root账号的权限,方便管理
#i锁就是设定文件不能被删除、改名、设定链接关系,同时不能写入或新增内容
[root@ZhangSiming /]# chattr +i /etc/sudoers
[root@ZhangSiming /]# chattr +i /etc/shadow
[root@ZhangSiming /]# chattr +i /etc/passwd
[root@ZhangSiming /]# chattr +i /etc/grub.conf
#CentOS6是grub.conf,CentOS7已经改为grub2.cfg并且已经系统保护好了
[root@ZhangSiming /]# chattr +i /etc/grub2.cfg
chattr: Operation not supported while reading flags on /etc/grub2.cfg
磁盘分区,RAID设置,swap设置等......
1./usr/local/nginx/logs/error.log:服务应用类日志查询
2./var/log/messages:系统应用类日志查询
3./var/log/secure:登录日志查询
4.dmesg:系统日志查询
5./var/tmp,/tmp:容易被攻击的点查询
6.crontab -l,/etc/crontab:计划任务查询(经常攻击对象)
[root@ZhangSiming ~]# tail -100 /var/log/secure | grep Accepted
Feb 18 17:05:47 ZhangSiming sshd[1182]: Accepted password for root from 192.168.17.1 port 55746 ssh2
Feb 18 17:34:53 ZhangSiming sshd[5796]: Accepted password for root from 192.168.17.1 port 56240 ssh2
Feb 20 15:20:42 ZhangSiming sshd[1215]: Accepted password for root from 192.168.17.1 port 53580 ssh2
Feb 23 14:20:09 ZhangSiming sshd[1184]: Accepted password for root from 192.168.17.1 port 58714 ssh2
#/var/log/secure日志可以看到谁ssh了服务器,进行排查
#另外,黑客入侵一般是入侵定时任务,所以定时任务可以进行排查,lsof追踪文件辅助排查
主要消耗CPU的业务:动态Web服务,mail服务.
[root@ZhangSiming ~]# cat /proc/cpuinfo | grep "cores" | uniq | wc -l
1
#或者top,然后按1
[root@ZhangSiming ~]# top -n1 | head -1
top - 17:25:37 up 3:05, 3 users, load average: 0.01, 0.02, 0.05
[root@ZhangSiming ~]# w
17:25:50 up 3:06, 3 users, load average: 0.01, 0.02, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 14:20 3:05m 0.01s 0.01s -bash
root pts/0 192.168.17.1 16:24 6.00s 0.11s 0.00s w
root pts/1 192.168.17.1 16:17 46:14 0.01s 0.01s -bash
[root@ZhangSiming ~]# uptime
17:25:56 up 3:06, 3 users, load average: 0.01, 0.02, 0.05
[root@ZhangSiming ~]# cat /proc/loadavg
0.01 0.02 0.05 1/119 8460
[root@ZhangSiming ~]# cat /proc/cpuinfo | grep "physical id" | uniq | wc -l
1
#cpu个数
[root@ZhangSiming ~]# cat /proc/cpuinfo | grep "cores" | uniq | wc -l
1
#cpu物理核心总个数
[root@ZhangSiming ~]# cat /proc/cpuinfo | grep "processor" | uniq | wc -l
1
#cpu逻辑核心个数
#如果cpu总物理核心个数等于逻辑核心个数,那么cpu不支持超线程
[root@ZhangSiming ~]# vmstat 3 5
#每3秒刷新一次,输出5次
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
3 0 0 343264 2784 536164 0 0 14 35 59 69 0 0 100 0 0
0 0 0 343264 2784 536164 0 0 0 0 81 84 0 0 100 0 0
0 0 0 343264 2784 536164 0 0 0 0 78 81 0 0 100 0 0
0 0 0 343264 2784 536164 0 0 0 0 84 90 0 0 100 0 0
0 0 0 343264 2784 536164 0 0 0 0 80 82 0 0 100 0 0
字符 | 部位 | 解释 |
---|---|---|
r | procs | 表示运行和等待cpu时间片的进程数,这个值如果长期大于系统CPU个数,说明CPU不足,需要增加CPU |
b | procs | 表示在等待资源的进程数,比如正在等待I/O,或者内存交换等。长期大于0,那么说明CPU不足 |
swpd | memory | 表示切换到内存交换区的内存数量(以k为单位)。如果swpd的值不为0,或者比较大,只要si,so的值长期为0,这种情况下一般不用担心,不会影响系统性能 |
free | memory | 表示当前空闲的物理内存数量(以k为单位) |
buff | memory | 表示buffers cache的内存数量,一般对块设备的读写才需要缓冲 |
cache | memory | 表示page cached的内存数量,一般作为文件系统cached,频繁访问的文件都会被cached,如果cache值较大,说明cached的文件数较多,如果此时IO中bi比较小,说明文件系统效率比较好 |
si | swap | 表示由磁盘调入内存,也就是内存进入内存交换区的数量 |
so | swap | 表示由内存调入磁盘,也就是内存交换区进入内存的数量。(一般情况下,si,so的值都为0,如果si,so的值长期不为0,则表示系统内存不足。需要增加系统内存) |
bi | io | 表示从块设备读入数据的总量(即读磁盘)(每秒kb) |
bo | io | 表示写入到块设备的数据重量(即写磁盘)(每秒kb) |
in | system | 表示在某一时间间隔中观测到的每秒设备中断数 |
cs | system | 表示每秒产生的上下文切换次数 |
us | cpu | 显示了用户进程消耗的CPU时间百分比。us的值比较高时,说明用户进程消耗的cpu时间多,但是如果长期大于50%,就需要考虑优化程序或算法 |
sy | cpu | 显示了内核进程消耗的CPU时间百分比。Sy的值比较高时,说明内核消耗的CPU资源很多 |
id | cpu | 显示了CPU处在空闲状态的时间百分比 |
wa | cpu | 显示了IO等待所占用的CPU时间百分比 |
综上所述:重点注意r(等待cpu的进程数)、us(进程占用的cpu百分比)、sy(内核占用的cpu百分比)、id(空闲cpu百分比)列的值
[root@ZhangSiming ~]# iostat -c 3 5
#3秒刷新一次,显示5次的数据
Linux 3.10.0-862.el7.x86_64 (ZhangSiming) 02/23/2019 _x86_64_ (1 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.14 0.00 0.21 0.02 0.00 99.63
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.00 0.00 100.00
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.00 0.00 100.00
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.33 0.00 0.00 99.67
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.00 0.00 100.00
字符 | 解释 |
---|---|
%user | cpu处在用户模式下的时间百分比 |
%nice | cpu处在nice值的用户下的时间百分比 |
%system | cpu处在系统模式下的时间百分比 |
%iowait | cpu处在io等待下的时间百分比(如果%iowait的值过高,表示硬盘存在I/O瓶颈) |
%steal | 管理程序维护另一个虚拟处理器时,虚拟CPU的无意识等待时间百分比 |
%idle | CPU空闲时间百分比 |
综上所述,应该重点关注iowait和idle列。
消耗内存的业务:内存数据库(redis)、Tomcat、ELKstack、gitlab。
物理内存和虚拟交换内存的分配策略:
- 如果物理内存大于16G,那么swap等于物理内存或者是物理内存两倍都是可以的;
- 如果物理内存小于16G,那么swap和内存大小保持一致。
[root@ZhangSiming ~]# free -m
total used free shared buff/cache available
Mem: 974 112 335 7 526 648
Swap: 2047 0 2047
#剩余内存335M
#buffers+cache526M
#系统可用的剩余内存648M
一般情况我们可以这样去判断内存:
- 系统可用剩余内存总量/系统物理内存重量>70%时,表示系统内存资源非常充足,不影响系统性能;
- 系统可用剩余内存总量/系统物理内存重量<20%时,表示系统内存资源紧缺,需要增加系统内存;
- 20%<系统可用剩余内存总量/系统物理内存重量<70%时,表示系统内存资源基本能满足应用需求,暂时不影响系统性能
[root@ZhangSiming ~]# sar -r 3
#-r显示内存信息,每3s刷新一次
Linux 3.10.0-862.el7.x86_64 (ZhangSiming) 02/23/2019 _x86_64_ (1 CPU)
07:00:40 PM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty
07:00:43 PM 343240 654716 65.61 2784 401072 286760 9.26 305456 148532 0
07:00:46 PM 343224 654732 65.61 2784 401072 286760 9.26 305460 148532 0
07:00:49 PM 343224 654732 65.61 2784 401072 286760 9.26 305460 148532 0
字符 | 解释 |
---|---|
kbmemfree | 表示空闲物理内存大小 |
kbmemused | 表示已经使用的物理内存大小 |
%memused | 表示已经使用内存占总内存百分比 |
kbbuffers | 表示buffers占用的大小 |
kbcached | 表示cache占用的大小 |
kbcommit | 表示应用程序当前使用的内存大小 |
%commit | 表示应用程序的使用百分比 |
消耗磁盘的业务:数据库服务器
• RAID技术(RAID 0/1/5/10)
• SSD磁盘
[root@ZhangSiming ~]# iostat -d 2 3
Linux 3.10.0-862.el7.x86_64 (ZhangSiming) 02/23/2019 _x86_64_ (1 CPU)
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.71 10.86 28.97 186175 496650
scd0 0.03 0.64 0.00 11000 0
dm-0 0.69 10.25 28.84 175669 494451
dm-1 0.01 0.13 0.00 2228 0
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.00 0.00 0.00 0 0
scd0 0.00 0.00 0.00 0 0
dm-0 0.00 0.00 0.00 0 0
dm-1 0.00 0.00 0.00 0 0
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.00 0.00 0.00 0 0
scd0 0.00 0.00 0.00 0 0
dm-0 0.00 0.00 0.00 0 0
dm-1 0.00 0.00 0.00 0 0
字符 | 解释 |
---|---|
Device | 设备名称 |
tps | 表示每秒到物理磁盘的传送数,也就是每秒的I/O流量。一个传送就是一个I/O请求,多个逻辑请求可以被合并为一个物理I/O请求 |
kB_read/s | 每秒读取的数据块 |
kB_wrtn/s | 每秒写入的数据块 |
kB_read | 读取的所有数据块总数 |
kB_wrtn | 写入的所有数据块总数 |
消耗带宽的业务:分布式文件系统,视频业务平台
• 网卡/交换机的选择:起码千兆网卡/千兆普通交换机/万兆核心交换机
• 操作系统双网卡绑定:通过绑定提高网卡带宽吞吐量
[root@ZhangSiming ~]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.125) 56(84) bytes of data.
64 bytes from 61.135.169.125 (61.135.169.125): icmp_seq=1 ttl=128 time=23.5 ms
64 bytes from 61.135.169.125 (61.135.169.125): icmp_seq=2 ttl=128 time=30.7 ms
64 bytes from 61.135.169.125 (61.135.169.125): icmp_seq=3 ttl=128 time=86.3 ms
64 bytes from 61.135.169.125 (61.135.169.125): icmp_seq=4 ttl=128 time=27.3 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3006ms
rtt min/avg/max/mdev = 23.555/42.012/86.392/25.749 ms
#time值表示两台主机间的延迟情况
#packet loss表示网络丢包率,值越小,网络质量越高
[root@ZhangSiming ~]# netstat -rn
#查看路由状况
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.17.2 0.0.0.0 UG 0 0 0 ens32
192.168.17.0 0.0.0.0 255.255.255.0 U 0 0 0 ens32
[root@ZhangSiming ~]# netstat -i
#查看网卡接口状况
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
ens32 1500 63500 0 0 0 16182 0 0 0 BMRU
lo 65536 0 0 0 0 0 0 0 0 LRU
#route -n也可以看路由状况
[root@ZhangSiming ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.17.2 0.0.0.0 UG 100 0 0 ens32
192.168.17.0 0.0.0.0 255.255.255.0 U 100 0 0 ens32
[root@ZhangSiming ~]# traceroute www.baidu.com
traceroute to www.baidu.com (61.135.169.125), 30 hops max, 60 byte packets
1 gateway (192.168.17.2) 0.134 ms 0.146 ms 0.084 ms
2 * * *
3 * * *
4 * * *
5 * * *
#traceroute虽然可以追踪网络路由,但是中间路由都被***屏蔽了,难以得到直观的显示
[root@ZhangSiming ~]# mtr -n -c 2 --report www.baidu.com
#-n:不用主机解析
#-c:发送数据包数量
#--report:结果显示
Start: Sat Feb 23 19:21:09 2019
HOST: ZhangSiming Loss% Snt Last Avg Best Wrst StDev
1.|-- 192.168.17.2 0.0% 2 0.2 0.2 0.2 0.2 0.0
2.|-- 192.168.43.1 0.0% 2 3.1 7.7 3.1 12.3 6.5
3.|-- ??? 100.0 2 0.0 0.0 0.0 0.0 0.0
4.|-- ??? 100.0 2 0.0 0.0 0.0 0.0 0.0
5.|-- 114.247.23.161 0.0% 2 21.3 24.3 21.3 27.2 4.1
6.|-- 114.247.9.129 0.0% 2 19.0 25.1 19.0 31.2 8.6
7.|-- 61.51.169.205 0.0% 2 30.3 26.3 22.2 30.3 5.7
8.|-- 61.148.143.106 0.0% 2 22.9 22.6 22.4 22.9 0.0
9.|-- 123.125.248.110 0.0% 2 20.6 21.8 20.6 23.0 1.4
10.|-- ??? 100.0 2 0.0 0.0 0.0 0.0 0.0
11.|-- ??? 100.0 2 0.0 0.0 0.0 0.0 0.0
12.|-- 61.135.169.121 0.0% 2 20.5 21.1 20.5 21.7 0.0
#mtr这个命令虽然也有看不出来的,但是基本上得到的信息比traceroute多的多
影响因素 | 评判标准 | 评判标准 | 评判标准 |
---|---|---|---|
好 | 坏 | 糟糕 | |
cpu | user%+sys%<70 | user%+sys%=85 | user%+sys%>=90 |
内存 | si=0;so=0 | si、so有但是不多 | si、so非常多 |
磁盘 | iowait%<20 | iowait%=35 | iowait%=50 |