linux日常技巧

监控系统状态:

w/uptime 查看系统负载 :可以查看到系统的负载是否有压力。
 cat /proc/cpuinfo 查看cpu核数

7d148605409c345c384f67c1903e70e23b5.jpg
 vmstat 监控系统状态
 用法 vmstat 1
 关键的几列:r,b,swpd,si,so,bi,bo,us,wa

说明:

  • proc 显示进程相关信息

    • r:=run,表示运行中或等待cpu运行的进程数,如果该数长期大于服务器CPU个数,则说明CPU不够用了。

    • b: =block ,表示等待资源的进程数,如,等待I/O,内存等,这列的值如果长时间大于1,则需要关注一下。

  • memory 内存相关信息

    • swpd:表示切换到交换分区的内存量(当该数据不断变化时说明内存不足)

    • free:表示当前空闲的内存量

    • buff:缓冲大小

    • cache:缓存大小

  • swap 内存交换情况

    • si:=storage in,表示交换区写入到内存的数据量

    • so:=storage out,表示由内存写入到交换区的数据量

  • io 磁盘使用情况

    • bi:=block in,表示从块设备读取数据(写入内存)的量(即:读磁盘),单位为KB;

    • bo:=block out,表示(从内存读取)写入到块设备的数据(即:写磁盘),单位为KB;
      注: 此处数据会直接关系到proc出的b的值。

  • system 显示采集间隔内发生的中断次数

    • in:表示在某一时间间隔中观测到的每秒设备中断数

    • cs:表示每秒产生的上下文切换次数

  • CPU 显示CPU的使用状态(us+sy+id=100%)

    • us:表示用户资源所花费CPU的百分比(当该值长时间>50时说明CPU数量不足)

    • sy:表示系统资源所花费CPU的百分比

    • id:表示CPU处于空闲状态的百分比

    • wa:=wait,表示等待使用CPU的百分比(该数值大说明CPU不足)

    • st:表示被偷走的CPU所占百分比(该值一般为0,不用关注)

注意:需要关注的是r,b和wa这3列,

io部分和bi和bo也是要经常参考的对象,如果磁盘io压力很大,这两列的数值会比较高(大于5千算高)。

另外,当si和so两列的数值比较高并且不断变化时,说明内存不够了,内存中的数据频繁交换分区中,这往往对系统性能影响极大。

b11e5a6f0d4bb6ec6498987415a1f5bef41.jpg

 

 top查看进程使用资源情况
 top -c        显示详细的进程信息
 top -bn1   静态显示所有进程   (比较适合用于脚本)
 q退出,数字1显示所有核cpu,大写字母M按内存使用排序
 大写字母P按cpu使用排序

92c63d66638072be1395c1d9a040643b334.jpg

 

yum install -y sysstat     //安装这个包,才可以使用sar命令。命令用法如下:
sar -n DEV   1 10   查看网卡流量,每秒显示一次,显示10次。
 sar -q      查看系统历史负载(有助于帮助我们查看服务器过去某个时间的历史负载)
 sar -b  磁盘读写
 sar  -f /var/log/sa/saxx  历史文件
 nload命令需要安装以下2个包

yum install -y epel-release 和   yum install -y nload

5fcdfb35f3f2dd1f259a71ba747713c5258.jpg

eb58a4c193a30cdfc0ed08c5b3c9d736b95.jpg

直接nload  显示如下

2d5458ab3a96187eecc49521dd0640165ee.jpg

监控磁盘的使用情况:

 iostat -x  磁盘使用  (yum install -y sysstat)
 iotop 磁盘使用   (yum install -y iotop)

b92dee6478e1d773d566bf10e784bb000c0.jpg

731b81c5647ada80fbb0c36d825246d9dd4.jpg

 free 查看内存使用情况
 free -m / -g / -h(-m:以MB为单位显示 ; -g 以GB为单位显示   -h以适合大小的单位显示,更加直观的显示)
 buffer/cache区别
 公式:total=used+free+buff/cache
 avaliable包含free和buffer/cache剩余部分

ps命令的使用: 把当前的进程的快照给汇报一下

ps aux :查看系统进程的使用状况列出来。也可以用ps  -elf

ps aux|grep  sshd
 STAT部分说明
 D 不能中断的进程
 R run状态的进程
 S sleep状态的进程
 T 暂停的进程
 Z 僵尸进程
 < 高优先级进程
 N 低优先级进程
 L 内存中被锁了内存分页
 s 主进程
 l 多线程进程
 + 前台进程

1 进程里包含了线程,线程是进程的子单元

2 同一个进程下的线程全部共享相同的内存,而进程之间内存相互隔离。

ad71de77e1d98b90b4c80f1f76d95bf8c7b.jpg

netstat这个命令是用来查看网络状态的,linux作为服务器上的操作系统。这个服务器上会有很多服务,服务往往是跟客户端相互通信的,所以意味着他要有监听端口,要有对外的通信端口。那netstat命令查看的就是tcp/ip对外的状态,相当于说,服务器想让别人访问或互联,就需要打开一个口,一个端口。通过这个端口,让外界访问。netstat就是查看这个口的
 netstat -lnp 查看监听端口
 netstat -an 查看系统的网络连接状况
 netstat -lntp 只看出tcp的,不包含socket
 ss -an 和nestat异曲同工
 分享一个小技巧:
 netstat -an | awk '/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'

5d7999aa61b74897f306c8a009465e4b5ef.jpg

8a9b4b4dd892fed9076ba14d466ee377e42.jpg

 

 抓包工具tcpdump   (yum install -y tcpdump)
 用法:tcpdump -nn
 tcpdump -nn -i ens33
 tcpdump -nn port 80
 tcpdump -nn not port 22 and host 192.168.0.100
 tcpdump -nn -c 100 -w 1.cap
 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"
 yum install -y wireshark

75a826790a66335e73028c0369e6505c8ce.jpg

c2ee24f716f1bf3e56afbf6101afff1dc7e.jpg

d44d5f08992551cbf88ef6e3bd6018e1e14.jpg

ifconfig查看网卡ip(yum install net-tools)
 ifup ens33/ifdown ens33
 设定虚拟网卡ens33:1
 mii-tool ens33 查看网卡是否连接
 ethtool ens33 也可以查看网卡是否连接
 更改主机名 hostnamectl set-hostname aminglinux
 DNS配置文件/etc/resolv.conf
 /etc/hosts文件

8327a2499d9327c20c981ba9e7aa0f228f7.jpg

3fbbfc93ed6ff22cc3ea11bce8640443e56.jpg

d698a94d061978b5ff54527957a8190e6e8.jpg

 

linux的防火墙netfilter:

 selinux临时关闭 setenforce 0
 selinux永久关闭 vi /etc/selinux/config
 centos7之前使用netfilter防火墙
 centos7开始使用firewalld防火墙
 关闭firewalld开启netfilter方法
 systemctl stop firewalld
 systemctl disable firewalled
 yum install -y iptables-services
 systemctl enable iptables
 systemctl start iptables

e59f95b0ae4127cbe45608b3a2ee1f87284.jpg

[root@aming01 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@aming01 ~]# systemctl stop firewalld
[root@aming01 ~]# yum install -y iptables-service

[root@aming01 ~]# systemctl enable iptables
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
[root@aming01 ~]# systemctl start iptables
[root@aming01 ~]# iptables -nvL

 netfilter的5个表
 filter表用于过滤包,最常用的表,有INPUT、FORWARD、OUTPUT三个链
 nat表用于网络地址转换,有PREROUTING、OUTPUT、POSTROUTING三个链

 managle表用于给数据包做标记,几乎用不到
 raw表可以实现不追踪某些数据包,阿铭从来不用
 security表在centos6中并没有,用于强制访问控制(MAC)的网络规则,阿铭没用过
 参考文章 http://www.cnblogs.com/metoy/p/4320813.html

数据包流向与netfilter的5个链
 PREROUTING:数据包进入路由表之前
 INPUT:通过路由表后目的地为本机
 FORWARD:通过路由表后,目的地不为本机
 OUTPUT:由本机产生,向外发出
 POSTROUTING:发送到网卡接口之前

66689b280e8e229c20601ee0db75ed8111e.jpg

 

 查看iptables规则:iptables -nvL (iptables配置文件的存放位置:/etc/sysconfig/iptables)
 iptables -F 清空规则(cat /etc/sysconfig/iptables 规则文件的内容还是存在的,重启后还是会加载回来的)
 service iptables save 保存规则
 iptables -t nat //-t指定表
 iptables -Z  可以把计数器清零
 iptables -A INPUT -s 192.168.188.1 -p tcp --sport 1234 -d 192.168.188.128 --dport 80 -j DROP  //add增加一条规则
 iptables -I/-A/-D INPUT -s 1.1.1.1 -j DROP
 iptables -I INPUT -s 192.168.1.0/24 -i eth0 -j ACCEPT    //-I 插入一条规则
 iptables -nvL --line-numbers   //序号方式显示防火墙规则
 iptables -D INPUT 1      // 删除序号为1的防火墙规则
 iptables -P INPUT DROP    //如果在连接远程服务器,一旦执行这条命令将会断开。

[root@aming01 ~]# iptables -nvL    查看iptables的默认规则
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  149 12503 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
    1    52 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 139 packets, 16411 bytes)
 pkts bytes target     prot opt in     out     source               destination         
[root@aming01 ~]# iptables -Z ;iptables -nvL    //iptables -Z 把计数器清零。
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
1ebc368cc757810b3f436cfbf7439de72ab.jpg

722ab7ac8ae86a59b88ddf4985023452469.jpg

dabd9782ab8a56fe7f4de682c5d5649feae.jpg

8662327776196ea542495c5689e5f5b8fb4.jpg

 

iptables小案例
 vi /usr/local/sbin/iptables.sh //加入如下内容
#! /bin/bash
ipt="/usr/sbin/iptables"
$ipt -F
$ipt -P INPUT DROP
$ipt -P OUTPUT ACCEPT
$ipt -P FORWARD ACCEPT
$ipt -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT    
$ipt -A INPUT -s 192.168.133.0/24 -p tcp --dport 22 -j ACCEPT
$ipt -A INPUT -p tcp --dport 80 -j ACCEPT
$ipt -A INPUT -p tcp --dport 21 -j ACCEPT  
 icmp示例
 iptables -I INPUT -p icmp --icmp-type 8 -j DROP   禁止外面的机器ping自己的服务器

[root@aming01 ~]# ls /usr/local/sbin/
iptables.sh  nginx_logrotate.sh
[root@aming01 ~]# vim /usr/local/sbin/iptables.sh
[root@aming01 ~]# cat /usr/local/sbin/iptables.sh
#!/bin/bash
ipt="/usr/sbin/iptables"
$ipt  -F
$ipt  -P INPUT  DROP
$ipt  -P OUTPUT ACCEPT
$ipt  -P FORWARD  ACCEPT
$ipt  -A INPUT -m state --state  RELATED,ESTABLISH  -j ACCEPT
$ipt  -A INPUT -s 192.168.88.0/24 -p tcp --dport 22 -j ACCEPT
$ipt  -A INPUT -p tcp --dport 80 -j   ACCEPT
$ipt  -A INPUT -p tcp --dport 21 -j  ACCEPT
[root@aming01 ~]# sh  /usr/local/sbin/iptables.sh
[root@aming01 ~]# iptables -nvL
Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   30  2012 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    0     0 ACCEPT     tcp  --  *      *       192.168.88.0/24      0.0.0.0/0            tcp dpt:22
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:21

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 16 packets, 1520 bytes)
 pkts bytes target     prot opt in     out     source               destination         
[root@aming01 ~]#

 

nat表应用
 A机器两块网卡ens33(192.168.133.130)、ens37(192.168.100.1),ens33可以上外网,ens37仅仅是内部网络,B机器只有ens37(192.168.100.100),和A机器ens37可以通信互联。
 需求1:可以让B机器连接外网
 A机器上打开路由转发 echo "1">/proc/sys/net/ipv4/ip_forward
 A上执行 iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o ens33 -j MASQUERADE
 B上设置网关为192.168.100.1
 需求2:C机器只能和A通信,让C机器可以直接连通B机器的22端口
 A上打开路由转发echo "1">/ proc/sys/net/ipv4/ip_forward
  A上执行iptables -t nat -A PREROUTING -d 192.168.133.130 -p tcp --dport 1122 -j DNAT --to 192.168.100.100:22
 A上执行iptables -t nat -A POSTROUTING -s 192.168.100.100 -j SNAT --to 192.168.133.130
 B上设置网关为192.168.100.1

操作如下:1,首先在虚拟机1上面添加一块网卡,如下

9cf53d8bea4d597e166f02d6d043acf75c3.jpg

5203a12f42353ab3c639a1b4efacf7c7030.jpg

 

57d401d144051be16509225de66cdf42a3d.jpg

在机器2添加一块网卡

c1553cbf03bcc09d3108f2847ea32ba41eb.jpg

93f092e9a4046cccf0bef74c972b3efe2c8.jpg

给机器1的新增网卡添加一个IP地址(重启后失效,编辑配置文件可以永久生效)

96cd3719312b7864a039b7114cbb33f01a3.jpg

0bada50916d01e79a0773ddb7ca03b3c08d.jpg

7136d0e796e22e273e77007aef5fc591b72.jpg

在机器1做如下操作

37e8562bed9b394f0630837be3d47acdb60.jpg

00386c572ea90673e8ff8f91541bea2aca4.jpg

e3072072038f352ff074fe18931f4d59d11.jpg

165e032b27ca26a2b1bab2649cffa1eb269.jpg

022dacf230ee526c3d84743ad7f970458a8.jpg

 

 保存和备份iptables规则
 service iptables save //会把规则保存到/etc/sysconfig/iptables
 把iptables规则备份到my.ipt文件中
 iptables-save > my.ipt
 恢复刚才备份的规则
 iptables-restore < my.ipt

 

 

 

linux的防火墙firewalld:

 打开firewalld
 systemctl disable iptables
 systemctl stop iptables
 systemctl enable firewalld
 systemctl start firewalld
 firewalld默认有9个zone
 默认zone为public
 firewall-cmd --get-zones //查看所有zone
 firewall-cmd --get-default-zone//查看默认zone

645b7adc63e23c430406c5de6866053b109.jpg

fefc62e52951e55ba66b9e13a3d0b9b0fb9.jpg

 

 

cf050a635c1f88c286a19a06e798dc37d71.jpg

 

 firewall-cmd --set-default-zone=work //设定默认zone
 firewall-cmd --get-zone-of-interface=ens33 //查指定网卡
 firewall-cmd --zone=public --add-interface=lo //给指定网卡设置zone
 firewall-cmd --zone=dmz --change-interface=lo //针对网卡更改zone
 firewall-cmd --zone=dmz  --remove-interface=lo  //针对网卡删除zone
 firewall-cmd --get-active-zones  //查看系统所有网卡所在的zone

a9efe7d60817cd34debe6b199d032c6fb74.jpg
 

firewall-cmd --get-services  查看所有的servies
 firewall-cmd --list-services  //查看当前zone下有哪些service
 firewall-cmd --zone=public --add-service=http //把http增加到public zone下面
 firewall-cmd --zone=public --remove-service=http
 ls /usr/lib/firewalld/zones/ //zone的配置文件模板
 firewall-cmd --zone=public --add-service=http --permanent //更改配置文件,之后会在/etc/firewalld/zones目录下面生成配置文件
 需求:ftp服务自定义端口1121,需要在work zone下面放行ftp
 cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services
 vi /etc/firewalld/services/ftp.xml //把21改为1121
 cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/
 vi /etc/firewalld/zones/work.xml //增加一行
 <service name="ftp"/>
 firewall-cmd --reload //重新加载
 firewall-cmd --zone=work --list-services

 

[root@aming01 ~]# firewall-cmd --list-services
ssh dhcpv6-client
[root@aming01 ~]# firewall-cmd --zone=public  --list-services
ssh dhcpv6-client
[root@aming01 ~]# firewall-cmd --zone=block  --list-services

[root@aming01 ~]# firewall-cmd --zone=public --add-service=httpd
Error: INVALID_SERVICE: httpd
[root@aming01 ~]# firewall-cmd --zone=public --add-service=http
success
[root@aming01 ~]# firewall-cmd --zone=block  --list-services

[root@aming01 ~]# firewall-cmd --zone=public  --list-services
ssh dhcpv6-client http
[root@aming01 ~]# firewall-cmd --zone=public --add-service=ftp
success
[root@aming01 ~]# firewall-cmd --zone=public  --list-services
ssh dhcpv6-client http ftp
[root@aming01 ~]# firewall-cmd --zone=public --add-service=ftp  --permanent
success
[root@aming01 ~]# ls /etc/firewalld/zones/
public.xml  public.xml.old
[root@aming01 ~]# cat /etc/firewalld/zones/public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="ssh"/>
  <service name="dhcpv6-client"/>
  <service name="ftp"/>
</zone>
[root@aming01 ~]#

 

linux的任务计划:

crontab -u、-e、-l、-r    // -l  列出任务计划  -r 删除任务计划
 格式:分 时 日 月 周 user command
 文件/var/spool/cron/username
 分范围0-59,时范围0-23,日范围1-31,月范围1-12,周1-7
 可用格式1-5表示一个范围1到5
 可用格式1,2,3表示1或者2或者3
 可用格式*/2表示被2整除的数字,比如小时,那就是每隔2小时
 要保证服务是启动状态

crontab  -e     //编辑任务计划
 systemctl start crond.service   //启动任务计划

2ad1567e77a2245e107d090c4d61423ab65.jpg

d434df000cb711c23fac4287f6bcd3a1975.jpg

 

 

 

 

 

 

 

Linux系统服务管理-chkconfig

chkconfig --list
 chkconfig --level 3 network off
 chkconfig --level 345 network off
 chkconfig --del network
 chkconfig --add network

f2b4f3a9f642a971c5a324e551463321cac.jpg

Linux系统服务管理-systemd

 systemctl list-units --all --type=service
 几个常用的服务相关的命令
 systemctl enable crond.service //让服务开机启动
 systemctl disable crond //不让开机启动
 systemctl status crond //查看状态
 systemctl stop crond //停止服务
 systemctl start crond //启动服务
 systemctl restart crond //重启服务
 systemctl is-enabled crond //检查服务是否开机启动

 ls /usr/lib/systemd/system //系统所有unit,分为以下类型
 service 系统服务
 target 多个unit组成的组
 device 硬件设备
 mount 文件系统挂载点
 automount 自动挂载点
 path 文件或路径
 scope 不是由systemd启动的外部进程
 slice 进程组
 snapshot systemd快照
 socket 进程间通信套接字
 swap  swap文件
 timer 定时器

 unit相关的命令
 systemctl list-units //列出正在运行的unit
 systemctl list-units --all //列出所有,包括失败的或者inactive的
 systemctl list-units --all --state=inactive //列出inactive的unit
 systemctl list-units --type=service//列出状态为active的service
 systemctl is-active crond.service //查看某个服务是否为active

 系统为了方便管理用target来管理unit
 systemctl list-unit-files --type=target
 systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit
 systemctl get-default //查看系统默认的target
 systemctl set-default multi-user.target
 一个service属于一种类型的unit
 多个unit组成了一个target
 一个target里面包含了多个service
 cat /usr/lib/systemd/system/sshd.service //看[install]部分

 

扩展
firewalld自定义iptables规则  https://blog.51cto.com/jevic/1785162
提供一个iptables系列文章的博客  https://www.zsythink.net/archives/tag/iptables/page/2/
anacron https://www.jianshu.com/p/3009a9b7d024?from=timeline
systemd自定义启动脚本  http://www.jb51.net/article/100457.htm

 

Linux文件同步工具-rsync

 rsync -av /etc/passwd /tmp/1.txt
 rsync -av /tmp/1.txt 192.168.188.128:/tmp/2.txt
 rsync格式
 rsync [OPTION] … SRC   DEST
 rsync [OPTION] … SRC   [user@]host:DEST
 rsync [OPTION] … [user@]host:SRC   DEST
 rsync [OPTION] … SRC   [user@]host::DEST
 rsync [OPTION] … [user@]host::SRC   DEST

 rsync常用选项
 -a 包含-rtplgoD
 -r 同步目录时要加上,类似cp时的-r选项
 -v 同步时显示一些信息,让我们知道同步的过程
 -l 保留软连接
 -L 加上该选项后,同步软链接时会把源文件给同步
 -p 保持文件的权限属性
 -o 保持文件的属主
 -g 保持文件的属组
 -D 保持设备文件信息
 -t 保持文件的时间属性
 --delete 删除DEST中SRC没有的文件
 --exclude 过滤指定文件,如--exclude “logs”会把文件名包含logs的文件或者目录过滤掉,不同步
 -P 显示同步过程,比如速率,比-v更加详细
 -u 加上该选项后,如果DEST中的文件比SRC新,则不同步
 -z 传输时压缩

dde9d9e00ed3aa29dedcda18e15f3260328.jpg

 

 

 

 

 

 rsync通过ssh方式同步
 rsync -av test1/ 192.168.133.132:/tmp/test2/
 rsync -av -e "ssh -p 22" test1/ 192.168.133.132:/tmp/test2/
 rsync 通过服务的方式同步
 要编辑配置文件/etc/rsyncd.conf
 启动服务rsync --daemon
 格式:rsync -av test1/ 192.168.133.130::module/dir/

142d91d8cd9806aa9f0771cb26c2e0118c6.jpg

93db63a804e93f2c270ffe05ed49e601353.jpg

 

 rsyncd.conf样例
port=873
log file=/var/log/rsync.log
pid file=/var/run/rsyncd.pid
address=192.168.133.130
[test]
path=/root/rsync
use chroot=true
max connections=4
read only=no
list=true
uid=root
gid=root
auth users=test
secrets file=/etc/rsyncd.passwd
hosts allow=192.168.133.132 1.1.1.1 2.2.2.2  192.168.133.0/24

bcc8608928a76a0c3f4192cc074bca78376.jpg

 

 rsyncd.conf配置文件详解
 port:指定在哪个端口启动rsyncd服务,默认是873端口。
 log file:指定日志文件。
 pid file:指定pid文件,这个文件的作用涉及服务的启动、停止等进程管理操作。
 address:指定启动rsyncd服务的IP。假如你的机器有多个IP,就可以指定由其中一个启动rsyncd服务,如果不指定该参数,默认是在全部IP上启动。
 []:指定模块名,里面内容自定义。
 path:指定数据存放的路径。
 use chroot true|false:表示在传输文件前首先chroot到path参数所指定的目录下。这样做的原因是实现额外的安全防护,但缺点是需要以roots权限,并且不能备份指向外部的符号连接所指向的目录文件。默认情况下chroot值为true,如果你的数据当中有软连接文件,阿铭建议你设置成false。

 max connections:指定最大的连接数,默认是0,即没有限制。
 read only ture|false:如果为true,则不能上传到该模块指定的路径下。
 list:表示当用户查询该服务器上的可用模块时,该模块是否被列出,设定为true则列出,false则隐藏。
 uid/gid:指定传输文件时以哪个用户/组的身份传输。
 auth users:指定传输时要使用的用户名。
 secrets file:指定密码文件,该参数连同上面的参数如果不指定,则不使用密码验证。注意该密码文件的权限一定要是600。格式:用户名:密码
 hosts allow:表示被允许连接该模块的主机,可以是IP或者网段,如果是多个,中间用空格隔开。
 当设置了auth users和secrets file后,客户端连服务端也需要用用户名密码了,若想在命令行中带上密码,可以设定一个密码文件
 rsync -avL test@192.168.133.130::test/test1/  /tmp/test8/ --password-file=/etc/pass
 其中/etc/pass内容就是一个密码,权限要改为600

 

 

 

 

 

Linux系统日志

 /var/log/messages
 /etc/logrotate.conf 日志切割配置文件
 参考https://my.oschina.net/u/2000675/blog/908189
 dmesg命令  (dmesg -c 可以清空内存日志信息)
 /var/log/dmesg 日志
 last命令,调用的文件/var/log/wtmp
 lastb命令查看登录失败的用户,对应的文件时/var/log/btmp (如果遭到强力破解,这里将会记录大量的日志信息)
 /var/log/secure   (如果遭到强力破解,这里将会记录大量的日志信息)

 

 

 

Screen工具:

 为了不让一个任务意外中断
 nohup command &
 screen是一个虚拟终端
 yum install -y screen
 screen直接回车就进入了虚拟终端
 ctral a组合键再按d退出虚拟终端,但不是结束
 screen -ls 查看虚拟终端列表
 screen -r id 进入指定的终端
 screen -S aming
 screen -r aming

619d7e7bd7538eede8b7a95b268efb38b74.jpg

 

扩展

tcp三次握手四次挥手(重点)http://www.doc88.com/p-9913773324388.html

tshark几个用法:http://www.aminglinux.com/bbs/thread-995-1-1.html

https://blog.csdn.net/jyusun/article/details/71513086

http://www.cnblogs.com/chengmo/archive/2010/10/08/1846190.html

http://www.cnblogs.com/lixiaohui-ambition/archive/2012/12/11/2813419.html
1. Linux日志文件总管logrotate  http://linux.cn/article-4126-1.html
2. xargs用法详解 http://blog.csdn.net/zhangfn2011/article/details/6776925

46497078bfee63dd3527a11683f5320dcaf.jpg

 

转载于:https://my.oschina.net/u/3964315/blog/3036971

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值