port=873 //监听端口默认为873,也能够是别的端口 log file=/var/log/rsync.log //指定日志 pid file=/var/run/rsyncd.pid //指定pid address=192.168.202.130 #能够定义绑定的ip [test] #为模块名,自定义 path=/root/rsync // 指定该模块对应在哪一个目录下 use chroot=true //是否限定在该目录下,默认为true,当有软链接时,须要改成fasle,若是为true就限定为模块默认目录 max connections=4 //指定最大能够链接的客户端数 read only=no //是否为只读,若是是no的话,客服端推送给服务端的时候不成功,这时候要改为yes list=true //是否能够列出模块名 rsync --port 8730 172.16.37.139:: 若是为yes的话会列出客户端全部的模块名字。 uid=root //以哪一个用户的身份来传输 gid=root //以哪一个组的身份来传输 auth users=test //指定验证用户名,能够不设置,不设置默认不用密码,设置的话安全性更高点 secrets file=/etc/rsyncd.passwd //指定密码文件,若是设定验证用户,这一项必须设置,设定密码权限为400. hosts allow=192.168.133.132 1.1.1.1 2.2.2.2 192.168.133.0/24 //设置能够容许访问的主机,能够是网段,多个Ip地址用空格隔开
[root@hanfeng ~]# vim /etc/rsyncd.conf
port=873 #监听端口默认为873,也能够是别的端口 log file=/var/log/rsync.log pid file=/var/run/rsyncd.pid address=192.168.202.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.202.132
[root@hanfeng ~]# rsync --daemon [root@hanfeng ~]#
[root@hanfeng ~]# ps aux |grep rsync root 2473 0.0 0.0 114640 536 ? Ss 21:21 0:00 rsync --daemon root 2475 0.0 0.0 112656 988 pts/0 R+ 21:21 0:00 grep --color=auto rsyn [root@hanfeng ~]#
[root@hanfeng ~]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2033/master tcp 0 0 192.168.202.130:873 0.0.0.0:* LISTEN 2473/rsync tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1149/sshd tcp6 0 0 ::1:25 :::* LISTEN 2033/master tcp6 0 0 :::22 :::* LISTEN 1149/sshd [root@hanfeng ~]#
[root@hanfeng ~]# vim /etc/rsyncd.conf 将path=/root/rsync改成path=/tmp/rsync [root@hanfeng ~]# mkdir /tmp/rsync [root@hanfeng ~]#
[root@hanfeng ~]# chmod 777 /tmp/rsync [root@hanfeng ~]#
[root@hf-02 ~]# rsync -avP /tmp/hanfeng.txt 192.168.202.130::test/hanfeng-02.txt rsync: failed to connect to 192.168.202.130 (192.168.202.130): No route to host (113) rsync error: error in socket IO (code 10) at clientserver.c(122) [sender=3.0.9]
[root@hf-02 ~]# ping 192.168.202.130 PING 192.168.202.130 (192.168.202.130) 56(84) bytes of data. 64 bytes from 192.168.202.130: icmp_seq=1 ttl=64 time=18.3 ms 64 bytes from 192.168.202.130: icmp_seq=2 ttl=64 time=0.335 ms ^C --- 192.168.202.130 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1002ms rtt min/avg/max/mdev = 0.335/9.366/18.398/9.032 ms [root@hf-02 ~]#
[root@hf-02 ~]# telnet 192.168.202.130 873 Trying 192.168.202.130... telnet: connect to address 192.168.202.130: No route to host [root@hf-02 ~]#
[root@hf-02 ~]# iptables -nvL Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 2278 5435K ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 1 84 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 18 3551 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 1727 packets, 116K bytes) pkts bytes target prot opt in out source destination [root@hf-02 ~]#
[root@hf-02 ~]# systemctl stop firewalld [root@hf-02 ~]# iptables -nvL Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination [root@hf-02 ~]#
[root@hf-02 ~]# telnet 192.168.202.130 873 Trying 192.168.202.130... Connected to 192.168.202.130. Escape character is '^]'. @RSYNCD: 30.0 ^] telnet> quit Connection closed. [root@hf-02 ~]#
#auth users=test #secrets file=/etc/rsyncd.passwd
[root@hf-02 ~]# rsync -avP /tmp/hanfeng.txt 192.168.202.130::test/hanfeng-02.txt sending incremental file list hanfeng.txt 50 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/1) sent 125 bytes received 27 bytes 304.00 bytes/sec total size is 50 speedup is 0.33 [root@hf-02 ~]#
[root@hanfeng ~]# ls /tmp/rsync hanfeng-02.txt [root@hanfeng ~]#
[root@hf-02 ~]# rsync -avP 192.168.202.130::test/hanfeng-02.txt /tmp123.txt receiving incremental file list hanfeng-02.txt 50 100% 48.83kB/s 0:00:00 (xfer#1, to-check=0/1) sent 45 bytes received 159 bytes 408.00 bytes/sec total size is 50 speedup is 0.25 [root@hf-02 ~]#
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
[root@hanfeng ~]# cat /var/log/rsync.log 2017/12/06 21:16:31 [2445] rsyncd version 3.0.9 starting, listening on port 873 2017/12/06 21:16:31 [2445] bind() failed: Cannot assign requested address (address-family 2) 2017/12/06 21:16:31 [2445] unable to bind any inbound sockets on port 873 2017/12/06 21:16:31 [2445] rsync error: error in socket IO (code 10) at socket.c(555) [Receiver=3.0.9] 2017/12/06 21:21:22 [2473] rsyncd version 3.0.9 starting, listening on port 873 2017/12/06 23:10:53 [2619] name lookup failed for 192.168.202.132: Name or service not known
[root@hanfeng ~]# rsync --port=873 192.168.202.130:: test [root@hanfeng ~]#
[root@hanfeng ~]# rsync --port=873 192.168.202.130:: [root@hanfeng ~]#
rsync传输时设置密码html
在/etc/rsyncd.passwd文件中编辑node
而后修改权限为600linux
rsync -avP /tmp/test/ test@192.168.202.130::test/shell
在rsync传输文件的时候,在写shell脚本输入密码很差,好比天天凌晨半夜更新数据库文件啥的,那就会很麻烦数据库
[root@hf-01 ~]# [root@hf-01 ~]# ls /var/log/messages /var/log/messages [root@hf-01 ~]# less !$ less /var/log/messages [root@hf-01 ~]# du -sh !$ du -sh /var/log/messages 388K /var/log/messages
[root@hf-01 ~]# ls /var/log/messages* /var/log/messages /var/log/messages-20171120 /var/log/messages-20171203 /var/log/messages-20171112 /var/log/messages-20171127 [root@hf-01 ~]#
[root@hf-01 ~]# cat /etc/logrotate.conf # see "man logrotate" for details //会告诉你查看logrotate的帮助文档 # rotate log files weekly weekly //每周切割一次 # keep 4 weeks worth of backlogs rotate 4 //切割四个 # create new (empty) log files after rotating old ones create //建立一个新的文件 # use date as a suffix of the rotated file dateext //这是它的后缀名 # uncomment this if you want your log files compressed #compress //是否须要压缩,压缩成 .tar.gz # RPM packages drop log rotation information into this directory include /etc/logrotate.d //这个目录下还有一些文件 # no packages own wtmp and btmp -- we'll rotate them here /var/log/wtmp { //切割该文件,每月切割一次 monthly create 0664 root utmp minsize 1M rotate 1 } /var/log/btmp { //切割该文件,指定权限,属主,属组 missingok monthly create 0600 root utmp rotate 1 } # system-specific logs may be also be configured here. [root@hf-01 ~]#
[root@hf-01 ~]# ls /etc/logrotate.d ppp samba syslog wpa_supplicant yum [root@hf-01 ~]# cat /etc/logrotate.d/syslog /var/log/cron /var/log/maillog /var/log/messages /var/log/secure /var/log/spooler { sharedscripts postrotate /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true endscript } [root@hf-01 ~]#
[root@hf-01 ~]# last root pts/0 192.168.74.1 Thu Dec 7 01:41 still logged in reboot system boot 3.10.0-123.el7.x Thu Dec 7 01:36 - 05:38 (04:01) root pts/1 192.168.74.1 Wed Dec 6 05:11 - 05:13 (00:01) root pts/0 192.168.74.1 Wed Dec 6 01:27 - crash (1+00:09) reboot system boot 3.10.0-123.el7.x Wed Dec 6 01:26 - 05:38 (1+04:11) root pts/0 192.168.74.1 Tue Dec 5 01:38 - crash (23:48) reboot system boot 3.10.0-123.el7.x Tue Dec 5 01:37 - 05:38 (2+04:00) root pts/0 192.168.74.1 Mon Dec 4 03:23 - down (02:57) root pts/0 192.168.74.1 Sun Dec 3 17:42 - 03:23 (09:40) 等等等,只截取了一部分 [root@hf-01 ~]# ls /var/log/wtmp /var/log/wtmp
[root@hf-01 ~]# lastb btmp begins Sat Dec 2 04:25:01 2017 [root@hf-01 ~]# ls /var/log/btmp /var/log/btmp [root@hf-01 ~]#
[root@hf-01 ~]# ls /var/log/secure /var/log/secure [root@hf-01 ~]#
screen,虚拟的一个屏幕,也能够理解为一个虚拟的终端vim
需求,执行一个脚本,须要一天一晚上,并且脚本会输出一些东西出来,这就意味着这个脚本不能中途断开,保证脚本不中断,有两种方法:安全
安装screen包——>yum install -y screen服务器
[root@hf-01 ~]# screen 在虚拟终端下执行了vmstat 1,按 ctrl+a键 同时按,随后再按 d键 ,就把screen丢到后台了 [detached from 2841.pts-0.hf-01] [root@hf-01 ~]# screen -ls //列出当前全部的session There is a screen on: 2841.pts-0.hf-01 (Detached) 1 Socket in /var/run/screen/S-root. [root@hf-01 ~]# screen -r 2841 //从新回到虚拟终端——>若不须要screen了,直接杀死,按 exit 便可 [screen is terminating] [root@hf-01 ~]# screen -ls //再次查看,会发现没有screen No Sockets found in /var/run/screen/S-root. [root@hf-01 ~]#
[root@hf-01 ~]# screen [detached from 2880.pts-0.hf-01] [root@hf-01 ~]# screen [detached from 2903.pts-0.hf-01] [root@hf-01 ~]# screen [detached from 2926.pts-0.hf-01] [root@hf-01 ~]# screen -ls There are screens on: 2926.pts-0.hf-01 (Detached) 2903.pts-0.hf-01 (Detached) 2880.pts-0.hf-01 (Detached) 3 Sockets in /var/run/screen/S-root. [root@hf-01 ~]#