日常运维管理初级基础技巧(图文)

Linux日常运维管理技巧

 

监控系统状态

w/uptime 查看系统负载

 

 

 

cat /proc/cpuinfo 查看cpu核数

 

 

vmstat 监控系统状态

 

 

 top查看进程使用资源情况

 

 

top -c 显示详细的进程信息

 

 

 top -bn1 静态显示所有进程

q退出;

数字1显示所有核cpu;

大写字母M按内存使用排序;

大写字母P按cpu使用排序

 

 

sar

sar -n DEV  网卡流量

 

 

sar -q  系统负载

 

 

sar -b  磁盘读写

 

 

sar -f /var/log/sa/saxx  历史文件

 

 

iostat -x  磁盘使用

 

 

free 查看内存使用情况

 

 

 free -m / -g / -h

-m以MB为单位显示

-g 以GB为单位显示

-h 更人性化地显示

 

 

 

ps 查看系统进程

 

 

 用法:ps aux、ps -elf

 

 

 

 STAT部分说明

 D 不能中断的进程

 R run状态的进程

 S sleep状态的进程

 T 暂停的进程

 Z 僵尸进程

 < 高优先级进程

 N 低优先级进程

 L 内存中被锁了内存分页

 s 主进程

 l 多线程进程

 + 前台进程

 

 

 

netstat 查看网络状态

 

 

netstat -lnp 查看监听端口

 

 

netstat -an 查看系统的网络连接状况

 

 

netstat -lntp 只看出tcp的,不包含socket

 

 

抓包工具tcpdump

 用法:tcpdump -nn

 tcpdump -nn -i ens33

 

 

 tcpdump -nn -i ens33 port 22

 

Linux系统日志

/var/log/messages

/etc/logrotate.conf 日志切割配置文件

参考https://my.oschina.net/u/2000675/blog/908189

dmesg命令

/var/log/dmesg 日志

last命令,调用的文件/var/log/wtmp

 

 

lastb命令查看登录失败的用户,对应的文件时/var/log/btmp

 

 

/var/log/secure

 

screen工具

 screen是一个虚拟终端

 yum install -y screen

 screen直接回车就进入了虚拟终端

 ctral a组合键再按d退出虚拟终端,但不是结束

 screen -ls 查看虚拟终端列表

 

 

 screen -r id 进入指定的终端

 screen -S aming 对虚拟终端进行命名

 screen -r aming 进入命名过的虚拟终端

 

 

Linux网络管理

Linux网卡相关

ifconfig查看网卡ip(yum install net-tools)

 

 

ifup ens33 启动网卡

ifdown ens33 关闭网卡

设定虚拟网卡ens33:1

mii-tool ens33 查看网卡是否连接

ethtool ens33 也可以查看网卡是否连接

更改主机名 hostnamectl set-hostname aminglinux  -----/etc/hostname 不用重启

 

 

 

 

DNS配置文件/etc/resolv.conf

 

 

/etc/hosts文件

 

 

 

linux7防火墙

linux6 的防火墙壁:netfilter

linux7 的防火墙壁:firewall

systemctl status firewall

systemctl stop firewall

systemctl start firewall

systemctl disable firewall

systemctl enable firewall

 
 

iptables规则表

iptables 是linux上里的一个工具,用于控制网络访问:

安装iptables的服务:

yum install -y iptables-services

systemctl status iptables

systemctl start iptables

systemctl stop iptables

systemctl disable iptables

systemctl enable iptables

iptables -nvL ---查看访问规则

 

 

规则表:

filter ----默认的规则表,过滤

nat -------转发

 

链:

数据库的流向:

直接访问主机

prerouting----->input---->localhost--->output---->postrouting

通过主机转发

prerouting----->foreard---->postrouting

链的访问方式:

从上往上,最上同先效

 

 

iptables 选项:

-A  --->append:在指定链的最后添加规则

-I  --->insert:在指定链的最前面添加规则

-D ---->delete:在指定链上删除规则

 

--添加规则,禁指定网段的的IP访问:

 iptables -A INPUT -s 192.168.175.0/24 -i ens33 -j DROP

 iptables -I INPUT -s 192.168.175.0/24 -i ens33 -j DROP

  

--禁止pint:

 iptables -I INPUT -p icmp -j DROP

 iptables -I INPUT -p icmp --icmp-type 8 -j REJECT

 

--禁止访问指定端口的服务:

 iptables -I INPUT -p tcp --dport 22 -j DROP

 

--显示编号

 iptables -nvL --line-numbers

 

 

--删除INPUT链上的第1条规则

 iptables -D INPUT 1

 

--使用默认规则

 iptables -P INPUT DROP

 

--保存规则:会把IPTABLES的规则写到文件里:/etc/sysconfig/iptables,下次重启服务后会去读这个配置文件:

 service iptables save

猜你喜欢

转载自blog.csdn.net/qq_42774325/article/details/81318857