Linux531rsync定时同步 再回忆

rsync定时同步

环境配置

关闭防火墙,selinux

systemctl stop firewalld
systemctl disable firewall
setenforce 0
cat /etc/selinux/configpei
SELINUX=disable

设置主机名

systemctl set-hostname code
systemctl set-hostname backup

设置静态IP

rsync由于要设置定时同步,所以要配置DNS,时钟完全同步

cd /etc/sysconfig/network-scirpts
ls
cat ifcfg-ens33
vim ifcfg-ens33

ROUTERPUTE=none
IPADDR=192.168.235.6
GATEWAY=192.168.235.254
#和虚拟机网关一致
DNS1=8.8.8.8

在这里插入图片描述

关闭NetworkManager

systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl status NetworkManager

配置YUM源

#备份
cd /etc/yum.repos.d
tar -zcf repo.tar.gz *repo
rm -rf *.repo
#挂载
rm rf /mnt/*
mount -o ro /dev/sr0 /mnt
lsblk
chmod +x /etc/rc.local
echo 'mount -o ro /dev/sr0 /mnt'>>/etc/rc.local
#

配置时钟同步

ntpdate cn.ntp.org.cn

192.168.235.10

Last login: Sat May 31 19:35:10 2025 from 192.168.235.1
[code@code ~]$ systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service;                                                                  disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[code@code ~]$ hostname
code.itcast.cn
[code@code ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state U                                                                 NKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pf                                                                 ifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:d6:84:b3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.235.10/24 brd 192.168.235.255 scope global e                                                                 ns33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed6:84b3/64 scope link
       valid_lft forever preferred_lft forever
3: virbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state                                                                  DOWN group default qlen 1000
    link/ether 52:54:00:d1:59:30 brd ff:ff:ff:ff:ff:ff
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fas                                                                 t master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:d1:59:30 brd ff:ff:ff:ff:ff:ff
[code@code ~]$ systemctl status NetworkManager
● NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.ser                                                                 vice; disabled; vendor preset: enabled)
   Active: inactive (dead) since 四 2025-05-15 19:14:49 CST;                                                                  2 weeks 2 days ago
     Docs: man:NetworkManager(8)
 Main PID: 937 (code=exited, status=0/SUCCESS)
[code@code ~]$ yum repolist
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                     源名称                       状态
!local1                    local yum                    4,070
repolist: 4,070
[code@code ~]$ ntpdate
31 May 20:15:17 ntpdate[103622]: no servers can be used, exit                                                                 ing

192.168.235.100

Last login: Sat May 31 19:34:59 2025 from 192.168.235.1
[backup@backup ~]$ systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service;                                                                  disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[backup@backup ~]$ hostname
backup.itcast.cn
[backup@backup ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state U                                                                 NKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pf                                                                 ifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:04:f5:98 brd ff:ff:ff:ff:ff:ff
    inet 192.168.235.100/24 brd 192.168.235.255 scope global                                                                  ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe04:f598/64 scope link
       valid_lft forever preferred_lft forever
3: virbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state                                                                  DOWN group default qlen 1000
    link/ether 52:54:00:53:dd:1d brd ff:ff:ff:ff:ff:ff
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fas                                                                 t master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:53:dd:1d brd ff:ff:ff:ff:ff:ff
[backup@backup ~]$ systemctl status NetworkManager
● NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.ser                                                                 vice; disabled; vendor preset: enabled)
   Active: inactive (dead) since 四 2025-05-15 19:12:39 CST;                                                                  2 weeks 2 days ago
     Docs: man:NetworkManager(8)
 Main PID: 902 (code=exited, status=0/SUCCESS)
[backup@backup ~]$ yum repolist
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                    源名称                        状态
!lcoal                    local yum                     4,070
repolist: 4,070
[backup@backup ~]$ ntpdate
31 May 20:15:18 ntpdate[89896]: no servers can be used, exiti                                                                 ng

定时同步

创建文件夹

code:

mkdir -p /app/java_project
cd /app/java_project
touch file{10..13}.java
touch aa{3..6}

在这里插入图片描述
在这里插入图片描述

配置/etc/rsyncd.conf

vim /etc/rsyncd.conf
PATH=/app/java_project
log file=/var/log/rsync.log

backup:

创建备份文件夹

mkdir -p /backup/app1_java

测试rsyncd服务 ‘’/''r5

rsync -a root@192.168.235.10::
[root@backup backup]# rsync -a root@192.168.235.10::
app

测试备份语句

rsync -av root@192.168.235.10::/backup/app1_java

在这里插入图片描述

编写定时程序

crontab -l
crontab -e

分 时 日 月 周 /root/rsync.sh
10 21 * * * /root/rsync.sh

编写rsync.sh

vim /rsync.sh
rsync -av root@192.168.235.10::app /backup/app1_java &&/dev/null

设置rsync.sh权限

chmod +x rsync.sh

源码

192.168.235.10

Session stopped
    - Press <Return> to exit tab
    - Press R to restart session
    - Press S to save terminal output to file
    ┌──────────────────────────────────────────────────────────────────────┐
    │                 • MobaXterm Personal Edition v23.2 •                 │
    │               (SSH client, X server and network tools)               │
    │                                                                      │
    │ ⮞ SSH session to code@192.168.235.10                                 │
    │   • Direct SSH      :  ✓                                             │
    │   • SSH compression :  ✓                                             │
    │   • SSH-browser     :  ✓                                             │
    │   • X11-forwarding  :(remote display is forwarded through SSH)  │
    │                                                                      │
    │ ⮞ For more info, ctrl+click on help or visit our website.            │
    └──────────────────────────────────────────────────────────────────────┘

Last login: Sat May 31 19:35:10 2025 from 192.168.235.1
[code@code ~]$ systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service;                                                                              disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[code@code ~]$ hostname
code.itcast.cn
[code@code ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state U                                                                             NKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pf                                                                             ifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:d6:84:b3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.235.10/24 brd 192.168.235.255 scope global e                                                                             ns33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed6:84b3/64 scope link
       valid_lft forever preferred_lft forever
3: virbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state                                                                              DOWN group default qlen 1000
    link/ether 52:54:00:d1:59:30 brd ff:ff:ff:ff:ff:ff
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fas                                                                             t master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:d1:59:30 brd ff:ff:ff:ff:ff:ff
[code@code ~]$ systemctl status NetworkManager
● NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.ser                                                                             vice; disabled; vendor preset: enabled)
   Active: inactive (dead) since 四 2025-05-15 19:14:49 CST;                                                                              2 weeks 2 days ago
     Docs: man:NetworkManager(8)
 Main PID: 937 (code=exited, status=0/SUCCESS)
[code@code ~]$ yum repolist
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                     源名称                       状态
!local1                    local yum                    4,070
repolist: 4,070
[code@code ~]$ ntpdate
31 May 20:15:17 ntpdate[103622]: no servers can be used, exit                                                                             ing
[code@code ~]$ su - caozx26
密码:
上一次登录:六 517 17:37:28 CST 2025pts/2 上
[caozx26@code ~]$ ls
app  inotify.sh  公共  模板  视频  图片  文档  下载  音乐  桌面
[caozx26@code ~]$ ll app
总用量 0
drwxrwxr-x. 2 caozx26 caozx26 90 524 13:35 java
[caozx26@code ~]$ sudo su
[sudo] caozx26 的密码:
[root@code caozx26]# ssh 192.168.235.100
The authenticity of host '192.168.235.100 (192.168.235.100)' can't be established.
ECDSA key fingerprint is SHA256:PbCAj5CjyP8yLyHMKdEPFFA4planWCr8FpxrrOp3d+I.
ECDSA key fingerprint is MD5:5b:0a:38:81:36:32:b6:38:d1:d8:3b:61:12:39:5a:fc.
Are you sure you want to continue connecting (yes/no)?
Host key verification failed.
[root@code caozx26]# ssh 192.168.235.100
The authenticity of host '192.168.235.100 (192.168.235.100)' can't be established.
ECDSA key fingerprint is SHA256:PbCAj5CjyP8yLyHMKdEPFFA4planWCr8FpxrrOp3d+I.
ECDSA key fingerprint is MD5:5b:0a:38:81:36:32:b6:38:d1:d8:3b:61:12:39:5a:fc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.235.100' (ECDSA) to the list of known hosts.

Last login: Sat May 31 20:18:59 2025

[root@backup ~]#
[root@backup ~]# exit
登出
Connection to 192.168.235.100 closed.
[root@code caozx26]# ls /
app  boot  dir1   dir12  dir2  etc   lib    media  opt   root  sbin  srv  tmp  var
bin  dev   dir11  dir13  dir3  home  lib64  mnt    proc  run   shop  sys  usr
[root@code caozx26]# cd app
[root@code app]# ls
java
[root@code app]# cd java
[root@code java]# ls
1.java  2.java  3.java  4.java  5.java  6.java
[root@code java]# cd
[root@code ~]#
[root@code ~]# ll java
ls: 无法访问java: 没有那个文件或目录
[root@code ~]# ll /app
总用量 0
drwxr-xr-x. 5 root root 215 515 21:30 java_project
[root@code ~]# cd /app
[root@code app]# ls
java_project
[root@code app]# ll java_project
总用量 6144
-rw-r--r--. 1 root root 6291456 515 21:30 2.java
drwxr-xr-x. 2 root root       6 515 20:51 aa1
drwxr-xr-x. 2 root root       6 515 20:51 aa2
drwxr-xr-x. 2 root root       6 515 20:51 aa3
-rw-r--r--. 1 root root       0 515 20:54 file1.java
-rw-r--r--. 1 root root       0 515 20:54 file2.java
-rw-r--r--. 1 root root       0 515 20:54 file3.java
-rw-r--r--. 1 root root       0 515 20:54 file4.java
-rw-r--r--. 1 root root       0 515 20:54 file5.java
-rw-r--r--. 1 root root       0 515 20:54 file6.java
-rw-r--r--. 1 root root       0 515 20:54 file7.java
-rw-r--r--. 1 root root       0 515 20:54 file8.java
-rw-r--r--. 1 root root       0 515 20:54 file9.java
[root@code app]# cd
[root@code ~]#
[root@code ~]# touch -p /app/java_project/{file10..file12}.java
touch:无效选项 -- p
Try 'touch --help' for more information.
[root@code ~]# touch --help
用法:touch [选项]... 文件...
Update the access and modification times of each FILE to the current time.

A FILE argument that does not exist is created empty, unless -c or -h
is supplied.

A FILE argument string of - is handled specially and causes touch to
change the times of the file associated with standard output.

Mandatory arguments to long options are mandatory for short options too.
  -a                    只更改访问时间
  -c, --no-create       不创建任何文件
  -d, --date=字符串     使用指定字符串表示时间而非当前时间
  -f                    (忽略)
  -h, --no-dereference          会影响符号链接本身,而非符号链接所指示的目的地
                                (当系统支持更改符号链接的所有者时,此选项才有用)
  -m                    只更改修改时间
  -r, --reference=FILE   use this file's times instead of current time
  -t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time
      --time=WORD        change the specified time:
                           WORD is access, atime, or use: equivalent to -a
                           WORD is modify or mtime: equivalent to -m
      --help            显示此帮助信息并退出
      --version         显示版本信息并退出

请注意,-d 和-t 选项可接受不同的时间/日期格式。

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
请向<http://translationproject.org/team/zh_CN.html> 报告touch 的翻译错误
要获取完整文档,请运行:info coreutils 'touch invocation'
[root@code ~]# cd /app/java_project
[root@code java_project]# ls
2.java  aa2  file1.java  file3.java  file5.java  file7.java  file9.java
aa1     aa3  file2.java  file4.java  file6.java  file8.java
[root@code java_project]# touch file{10..12}.java
[root@code java_project]# ls
2.java  aa2  file10.java  file12.java  file2.java  file4.java  file6.java  file8.java
aa1     aa3  file11.java  file1.java   file3.java  file5.java  file7.java  file9.java
[root@code java_project]# touch aa{4..9}
[root@code java_project]# ls
2.java  aa2  aa4  aa6  aa8  file10.java  file12.java  file2.java  file4.java  file6.java  file8.java
aa1     aa3  aa5  aa7  aa9  file11.java  file1.java   file3.java  file5.java  file7.java  file9.java
[root@code java_project]# cd
[root@code ~]# cat /etc/rsync.conf
cat: /etc/rsync.conf: 没有那个文件或目录
[root@code ~]# cat /etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]
#        path = /home/ftp
#        comment = ftp export area
#
 [app]
path=/app/java_project
log file=/var/log/rsync.log
auth users = user1,user2,user3
secrets file=/etc/rsyncd.secrets
[root@code ~]# vim /etc/rsyncd.conf
[root@code ~]# ls /etc/rsyncd.conf
/etc/rsyncd.conf
[root@code ~]# cat /etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]
#        path = /home/ftp
#        comment = ftp export area
#
 [app]
path=/app/java_project
log file=/var/log/rsync.log
auth users = user1,user2,user3
secrets file=/etc/rsyncd.secrets
[root@code ~]# ]cd /app
bash: ]cd: 未找到命令...
[root@code ~]# cd /app
[root@code app]# cd java_project
[root@code java_project]# ls
2.java  aa3  aa6  aa9          file12.java  file3.java  file6.java  file9.java
aa1     aa4  aa7  file10.java  file1.java   file4.java  file7.java
aa2     aa5  aa8  file11.java  file2.java   file5.java  file8.java
[root@code java_project]# rm -rf aa{3..6}
[root@code java_project]# ls
2.java  aa7  file10.java  file1.java  file4.java  file7.java
aa1     aa8  file11.java  file2.java  file5.java  file8.java
aa2     aa9  file12.java  file3.java  file6.java  file9.java
[root@code java_project]# rm -rf file{6..9}.java
[root@code java_project]#
Network error: Software caused connection abort

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Session stopped
    - Press <Return> to exit tab
    - Press R to restart session
    - Press S to save terminal output to file
    ┌──────────────────────────────────────────────────────────────────────┐
    │                 • MobaXterm Personal Edition v23.2 •                 │
    │               (SSH client, X server and network tools)               │
    │                                                                      │
    │ ⮞ SSH session to code@192.168.235.10                                 │
    │   • Direct SSH      :  ✓                                             │
    │   • SSH compression :  ✓                                             │
    │   • SSH-browser     :  ✓                                             │
    │   • X11-forwarding  :  ✓  (remote display is forwarded through SSH)  │
    │                                                                      │
    │ ⮞ For more info, ctrl+click on help or visit our website.            │
    └──────────────────────────────────────────────────────────────────────┘

Last login: Sat May 31 20:08:16 2025 from 192.168.235.1
[code@code ~]$ crontab -l
no crontab for code
[code@code ~]$ su - caozx26
密码:
上一次登录:六 5月 31 20:18:07 CST 2025pts/1 上
[caozx26@code ~]$ sudo su
[sudo] caozx26 的密码:
[root@code caozx26]# ls /
app  boot  dir1   dir12  dir2  etc   lib    media  opt   root  sbin  srv  tmp  var
bin  dev   dir11  dir13  dir3  home  lib64  mnt    proc  run   shop  sys  usr
[root@code caozx26]# cd app
[root@code app]# ls
java
[root@code app]# cd java
[root@code java]# ls
1.java  2.java  3.java  4.java  5.java  6.java
[root@code java]# cd /app
[root@code app]# ls
java_project
[root@code app]# cd java_project
[root@code java_project]# ls
2.java  aa2  aa8  file10.java  file12.java  file2.java  file4.java
aa1     aa7  aa9  file11.java  file1.java   file3.java  file5.java
[root@code java_project]# cat /etc/sshd
cat: /etc/sshd: 没有那个文件或目录
[root@code java_project]# cat /etc/sshd/sshd_config
cat: /etc/sshd/sshd_config: 没有那个文件或目录
[root@code java_project]# cat /etc/ssh/sshd_config
#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile      .ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
#GSSAPIEnablek5users no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
# WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several
# problems.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation sandbox
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

# override default of no subsystems
Subsystem       sftp    /usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
[root@code java_project]# cat /etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody
# gid = nobody
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]
#        path = /home/ftp
#        comment = ftp export area
#
 [app]
path=/app/java_project
log file=/var/log/rsync.log
auth users = user1,user2,user3
secrets file=/etc/rsyncd.secrets
[root@code java_project]# cat /etc/rsyncd.secrets
user1:123
user2:123
user3:
[root@code java_project]#

192.168.235.100

   ┌──────────────────────────────────────────────────────────────────────┐
    │                 • MobaXterm Personal Edition v23.2 •                 │
    │               (SSH client, X server and network tools)               │
    │                                                                      │
    │ ⮞ SSH session to backup@192.168.235.100                              │
    │   • Direct SSH      :  ✓                                             │
    │   • SSH compression :  ✓                                             │
    │   • SSH-browser     :  ✓                                             │
    │   • X11-forwarding  :(remote display is forwarded through SSH)  │
    │                                                                      │
    │ ⮞ For more info, ctrl+click on help or visit our website.            │
    └──────────────────────────────────────────────────────────────────────┘

Last login: Sat May 31 19:34:59 2025 from 192.168.235.1
[backup@backup ~]$ systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service;                                                                  disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[backup@backup ~]$ hostname
backup.itcast.cn
[backup@backup ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state U                                                                 NKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pf                                                                 ifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:04:f5:98 brd ff:ff:ff:ff:ff:ff
    inet 192.168.235.100/24 brd 192.168.235.255 scope global                                                                  ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe04:f598/64 scope link
       valid_lft forever preferred_lft forever
3: virbr0: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state                                                                  DOWN group default qlen 1000
    link/ether 52:54:00:53:dd:1d brd ff:ff:ff:ff:ff:ff
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fas                                                                 t master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:53:dd:1d brd ff:ff:ff:ff:ff:ff
[backup@backup ~]$ systemctl status NetworkManager
● NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.ser                                                                 vice; disabled; vendor preset: enabled)
   Active: inactive (dead) since 四 2025-05-15 19:12:39 CST;                                                                  2 weeks 2 days ago
     Docs: man:NetworkManager(8)
 Main PID: 902 (code=exited, status=0/SUCCESS)
[backup@backup ~]$ yum repolist
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                    源名称                        状态
!lcoal                    local yum                     4,070
repolist: 4,070
[backup@backup ~]$ ntpdate
31 May 20:15:18 ntpdate[89896]: no servers can be used, exiti                                                                 ng
[backup@backup ~]$ su - caozx26
密码:
上一次登录:六 524 13:19:48 CST 2025pts/0 上
[caozx26@backup ~]$ sudo su
[sudo] caozx26 的密码:
[root@backup caozx26]# cat /etc/ssh/sshd_config
#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile      .ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
#GSSAPIEnablek5users no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
# WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several
# problems.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation sandbox
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

# override default of no subsystems
Subsystem       sftp    /usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
[root@backup caozx26]# ls /
2010  backup  bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@backup caozx26]# cd /backup
[root@backup backup]# ls
app1_java
[root@backup backup]# ls app1_java
1.java  2.java  3.java  4.java  5.java  6.java
[root@backup backup]# rsync -a root@192.168.235.10::
app
[root@backup backup]# rsync -av root@192.168.235.10::/backup/app1_java
ERROR: The remote path must start with a module name not a /
rsync error: error starting client-server protocol (code 5) at main.c(1649) [Re                                               ceiver=3.1.2]
[root@backup backup]# rsync -av root@192.168.235.10::app /backup/app1_java
Password:
@ERROR: auth failed on module app
rsync error: error starting client-server protocol (code 5) at main.c(1649) [Re                                               ceiver=3.1.2]
[root@backup backup]# rsync -av user1@192.168.235.10::app /backup/app1_java
Password:
receiving incremental file list
./
2.java
aa4
aa5
aa6
aa7
aa8
aa9
file1.java
file10.java
file11.java
file12.java
file2.java
file3.java
file4.java
file5.java
file6.java
file7.java
file8.java
file9.java
aa1/
aa2/
aa3/

sent 404 bytes  received 6,294,184 bytes  1,798,453.71 bytes/sec
total size is 6,291,456  speedup is 1.00
[root@backup backup]# cribtab -l
bash: cribtab: 未找到命令...
[root@backup backup]# crontab -l
50 17 * * * /root/rsync_java.sh

[root@backup backup]# crontab -e
crontab: installing new crontab
[root@backup backup]# crontab -l
10 21 * * * /root/rsync_java.sh

[root@backup backup]# cd
[root@backup ~]# cat /rsync.sh
cat: /rsync.sh: 没有那个文件或目录
[root@backup ~]# cat /rsync_java.sh
cat: /rsync_java.sh: 没有那个文件或目录
[root@backup ~]# cat rsync_java.sh
!/bin/bash
rsync -av user3@192.168.235.10::app /backup/app1_java &&/dev/null
[root@backup ~]# ls
2010    aa2              file2.java  file6.java  initial-setup-ks.cfg  shop
23.txt  aa3              file3.java  file7.java  linux.txt
2.java  anaconda-ks.cfg  file4.java  file8.java  q
aa1     file1.java       file5.java  file9.java  rsync_java.sh
[root@backup ~]# cd /
[root@backup /]# ls
2010    bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
backup  boot  etc  lib   media  opt  root  sbin  sys  usr
[root@backup /]# cd backup
[root@backup backup]# ls
app1_java
[root@backup backup]# cd app1_java
[root@backup app1_java]# ls
1.java  4.java  aa1  aa4  aa7  file10.java  file1.java  file4.java  file7.java
2.java  5.java  aa2  aa5  aa8  file11.java  file2.java  file5.java  file8.java
3.java  6.java  aa3  aa6  aa9  file12.java  file3.java  file6.java  file9.java
[root@backup app1_java]#
Network error: Software caused connection abort

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Session stopped
    - Press <Return> to exit tab
    - Press R to restart session
    - Press S to save terminal output to file
    ┌──────────────────────────────────────────────────────────────────────┐
    │                 • MobaXterm Personal Edition v23.2 •                 │
    │               (SSH client, X server and network tools)               │
    │                                                                      │
    │ ⮞ SSH session to backup@192.168.235.100                              │
    │   • Direct SSH      :  ✓                                             │
    │   • SSH compression :  ✓                                             │
    │   • SSH-browser     :  ✓                                             │
    │   • X11-forwarding  :(remote display is forwarded through SSH)  │
    │                                                                      │
    │ ⮞ For more info, ctrl+click on help or visit our website.            │
    └──────────────────────────────────────────────────────────────────────┘

Last login: Sat May 31 20:09:23 2025 from 192.168.235.1
[backup@backup ~]$ cd /backup/app1_java
[backup@backup app1_java]$ ls
1.java  4.java  aa1  aa4  aa7  file10.java  file1.java  file4.java  file7.java
2.java  5.java  aa2  aa5  aa8  file11.java  file2.java  file5.java  file8.java
3.java  6.java  aa3  aa6  aa9  file12.java  file3.java  file6.java  file9.java
[backup@backup app1_java]$ crontab -l
no crontab for backup
[backup@backup app1_java]$ cd
[backup@backup ~]$ crontab -l
no crontab for backup
[backup@backup ~]$ cd
[backup@backup ~]$ su - caozx26
密码:
上一次登录:六 531 20:18:55 CST 2025pts/1 上
[caozx26@backup ~]$ sudo su
[sudo] caozx26 的密码:
[root@backup caozx26]# crontab -l
10 21 * * * /root/rsync_java.sh

[root@backup caozx26]# cd app
bash: cd: app: 没有那个文件或目录
[root@backup caozx26]# cd /app
bash: cd: /app: 没有那个文件或目录
[root@backup caozx26]# ls
公共  模板  视频  图片  文档  下载  音乐  桌面
[root@backup caozx26]# cd
[root@backup ~]# cd /
[root@backup /]# ls
2010  backup  bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@backup /]# cd backup
[root@backup backup]# ls
app1_java
[root@backup backup]# cd app1_java
[root@backup app1_java]# ls
1.java  4.java  aa1  aa4  aa7  file10.java  file1.java  file4.java  file7.java
2.java  5.java  aa2  aa5  aa8  file11.java  file2.java  file5.java  file8.java
3.java  6.java  aa3  aa6  aa9  file12.java  file3.java  file6.java  file9.java
[root@backup app1_java]# cd
[root@backup ~]# la
bash: la: 未找到命令...
[root@backup ~]# ls
2010    aa1  anaconda-ks.cfg  file3.java  file6.java  file9.java            q
23.txt  aa2  file1.java       file4.java  file7.java  initial-setup-ks.cfg  rsync_java.sh
2.java  aa3  file2.java       file5.java  file8.java  linux.txt             shop
[root@backup ~]# cd /
[root@backup /]# cd /backup
[root@backup backup]# cd app1_java
[root@backup app1_java]# ls
1.java  4.java  aa1  aa4  aa7  file10.java  file1.java  file4.java  file7.java
2.java  5.java  aa2  aa5  aa8  file11.java  file2.java  file5.java  file8.java
3.java  6.java  aa3  aa6  aa9  file12.java  file3.java  file6.java  file9.java
[root@backup app1_java]# cd
[root@backup ~]# crontab -e
crontab: installing new crontab
[root@backup ~]# cat rsync_java.sh
!/bin/bash
rsync -av user3@192.168.235.10::app /backup/app1_java &&/dev/null
[root@backup ~]# rsync -av user3@192.168.235.10::app /backup/app1_java && /dev/null
Password:
@ERROR: auth failed on module app
rsync error: error starting client-server protocol (code 5) at main.c(1649) [Receiver=3.1.2]
[root@backup ~]# rsync -av user3@192.168.235.10::app /backup/app1_java && /dev/null
Password:
receiving incremental file list

sent 22 bytes  received 311 bytes  222.00 bytes/sec
total size is 6,291,456  speedup is 18,893.26
bash: /dev/null: 权限不够
[root@backup ~]# ls /backup/app1_java
1.java  4.java  aa1  aa4  aa7  file10.java  file1.java  file4.java  file7.java
2.java  5.java  aa2  aa5  aa8  file11.java  file2.java  file5.java  file8.java
3.java  6.java  aa3  aa6  aa9  file12.java  file3.java  file6.java  file9.java
[root@backup ~]#


在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值