您的位置:首页 > 运维架构 > Linux

Linux 学习笔记——系统管理

2016-08-17 06:46 316 查看
w
cat /proc/cpuinfo | grep processor | wc -l

vmstat 1 5 每秒钟更新一次,更新5次
r : 每秒钟有几个进程使用或者排队CPU

b : 被阻塞的任务 IO 带宽

swpd : 单位kb ,有多少交换分区使用 ,并不意味交换分区不足 ,只要不变化,不大即可
free : 内存剩余多少
buff :
cache :
si : swap in 写入
so : swap out 读取
bi :
bo

top -bn1
top -d 1 -c

sar -n DEV 1 10
yum install -y sysstat 10分钟后才能查看
sar -n DEV -f /var/log/sa/sax
sar -q 历史负载
sar -b 磁盘IO

sar

free -m g 默认kb
buffer 缓冲,从内存写入硬盘

cache 缓存,从硬盘写入内存

ps aux
ps elf
S 休眠 sleep
s 主进程,父进程
< 优先级比较高
N 优先级比较低

+ 前台运行的进程
R 正在运行的进程

L 内存分页,被锁

l 多线程进程
Z 僵尸进程
X 死掉的进程
T 暂停的进程
D 不能中断的进程

netstat -lnp
netstat -an
netstat -an | grep 192.168.1.1:80 | grep ic estab 查看并发

tcpdump
yum -y install tcpdump
tcpdump -nn
tcpdump -nn -c 100
tcpdump -nn -i eth1 默认抓eth0
tcpdump -nn tcp and port 22
tcpdump -nn udp
tcpdump -nn tcp and port 22 and host 192.168.1.1 -w 1.cap 手动停止crlt c
tcpdump -r 1.cap 无法cat
tcpdump -nn -s0 tcp and port 22 and host 192.168.1.1 -c 10 > 1.cap -s0 完整的包
cat 1.cap

tshark
yum -y install wireshark
tshark -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

iptables 上面先生效
iptables -t filter -nvL t:nat mangle 默认filter 查看
iptables -t filter -I INPUT -p tcp --dport 80 -s 9.9.9.9 -j REJECT 插入 在上面,后I的规则优先级更高
iptables -t filter -A INPUT -p tcp --dport 80 -s 9.9.9.9 -j REJECT 增加 在下面 ==追加
iptables -t filter -D INPUT -p tcp --dport 80 -s 9.9.9.9 -j REJECT 删除
iptables -Z 计数器清零 针对规则,而策略无法清零
iptables -F 清空所有规则
指定端口必须指定协议
指定协议可以不需要指定端口

service iptables save
iptables-save > 1.ipt cat 1.ipt 备份
iptables-restore < 1.ipt 恢复
iptables -P INPUT ACCEPT 设置策略,总开关

iptables脚本
vim test.ipt.sh
#/bin/bash

ipt="/sbin/iptables"

$ipt -F
$ipt -P INPUT ACCEPT
$ipt -P OUTPUT ACCEPT
$ipt -P FORWARD ACCEPT

$ipt -A INPUT -p tcp -s 8.8.8.8 --dport=80 -j ACCEPT
$ipt -A INPUT -p tcp --dport=21 -j ACCEPT
$ipt -A INPUT -p tcp --dport=22 -j ACCEPT
$ipt -A INPUT -p tcp -j ACCEPT

crontab -l 查看
crontab -u user1 -l
crontab -e 编辑
分0-59 时0-23 日1-31 月1-12 周0-6或1-7

crontab -l > 备份
cat /var/spool/cron/root
0 */8 * * * 每个8小时,可以整除
30 9-18 * * *
0 1,3,5 * * *

ntsysv
yum -y install ntsysv

chkconfig --list
chkconfig atd off 2、3、4、5级别
chkconfig --list atd

chkconfig --level 345 atd on

chkconfig --add abc
chkconfig --del abc

ls /var/log/messages
vim /etc/logrotate.conf 日志配置切割等参数
kill -HUB

last /var/log/wtmp 查看用户登录历史
lastb 无效登录历史

cat /var/log/secure 登录log
cat /var/log/dmesg 硬件log
dmesg

find /var/log/ -type f -mtime +160 -exec cp {} {}.exec \;
find /var/log/ -type f -mtime +160 | xargs -i cp {} {}.xargs

nohup

rsync -avLPz 111/ 10.10.3.112:/tmp/111 默认当前登录用户,whoami
rsync -avLPz root@10.10.3.112:/tmp/111 ./
rsync -avLPz root@10.10.3.112:/tmp/111/ ./111
rsync -avLPz -e "ssh -p 22" root@10.10.3.112:/tmp/111/ ./111 指定端口

[root@TESTcentos6 tmp]# cat /etc/rsy
rsyncd.conf rsyslog.conf rsyslog.d/
[root@TESTcentos6 tmp]# cat /etc/rsyncd.conf
port=8730
log file=/var/log/rsync.log
pid file=/var/run/rsync.pid

===============================
vim /etc/rsyncd.conf
[aming]
path=/tmp/rsync
use chroot=yes #no true false
max connections=4
read only=yes
list=yes
uid=root
gid=root
auth users=aming
secrets file=/etc/rs.passwd
hosts allow=10.10.3.112 10.10.3.111 #多个IP空格

[aming1]
path=/tmp/rsync123
use chroot=yes #no true false 软连接
max connection=4
read only=yes #推
list=yes #rsync --port 8730 10.10.3.98:: 列出模块名
uid=root
gid=root
=======================更
改配置即时生效,无需重启服务
rsync --daemon

=======
vim /etc/rs.passwd

aming:123aaa
=====
chmod 400 /etc/rs.passwd
rsync -avPz --port 8730 aming@10.10.3.98::aming/1.txt ./ 默认是873
rsync -avPz --port 8730 ./111 aming@10.10.3.98::aming/
rsync -avPzL --port 8730 aming@10.10.3.98::aming/ ./444

vim /etc/rsync_passwd
chmod 400 /etc/rsync_passwd
rsync -avPzL --port 8730 --password-file=/etc/rsync_passwd aming@10.10.3.98::aming/ ./

==================
查找占用空间最大的10个文件或者目录,并从大到小排序
du -cksh * | sort -rn | head -n 10
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux 系统管理