데몬이 루트로 시작되고 있습니다.
[root@uhspaastream02 etc]# systemctl status -l UHS_FolderMonitor.service
● UHS_FolderMonitor.service - Starts the folder monitoring/logging script
Loaded: loaded (/etc/systemd/system/UHS_FolderMonitor.service; static; vendor preset: disabled)
Active: inactive (dead) since Fri 2018-02-02 15:42:49 EST; 41s ago
Docs: man:systemd.service
Process: 11491 ExecStart=/usr/etc/UHS_FolderMonitor.ksh (code=exited, status=0/SUCCESS)
Main PID: 11491 (code=exited, status=0/SUCCESS)
Feb 02 15:42:49 uhspaastream02.corp.uhsinc.biz systemd[1]: Starting Starts the folder monitoring/logging script...
Feb 02 15:42:49 uhspaastream02.corp.uhsinc.biz rsyncd[11492]: rsync: failed to open log-file /var/log/rsync_activity.log: Permission denied (13)
Feb 02 15:42:49 uhspaastream02.corp.uhsinc.biz rsyncd[11492]: Ignoring "log file" setting.
Feb 02 15:42:49 uhspaastream02.corp.uhsinc.biz rsyncd[11492]: building file list
Feb 02 15:42:49 uhspaastream02.corp.uhsinc.biz rsyncd[11492]: rsync: link_stat "/nfs/client_fs/NFSPRODW/UHS_FolderMonitor.ksh" failed: Permission denied (13)
Feb 02 15:42:49 uhspaastream02.corp.uhsinc.biz rsyncd[11492]: rsync: ERROR: cannot stat destination "/NFSPRODW": Permission denied (13)
Feb 02 15:42:49 uhspaastream02.corp.uhsinc.biz rsyncd[11492]: rsync error: errors selecting input/output files, dirs (code 3) at main.c(565) [Receiver=3.0.9]
Feb 02 15:42:49 uhspaastream02.corp.uhsinc.biz systemd[1]: Started Starts the folder monitoring/logging script.
콘텐츠 /etc/rsyncd.conf
:
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
#pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
#log file = /var/log/samba/uhsrsync.log
uid = root
gid = root
use chroot = yes
max connections = 8
exclude = lost+found/
transfer logging = yes
timeout = 900
ignore nonreadable = yes
#log format = %o %h [%a] %m %b %f %l
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
# [ftp]
# path = /home/ftp
# comment = ftp export area
콘텐츠 /etc/systemd/system/UHS_FolderMonitor.service
:
[Unit]
Description= Starts the folder monitoring/logging script
Documentation= man:systemd.service
[Service]
Type=oneshot
ExecStart=/usr/etc/UHS_FolderMonitor.ksh
출력 ksh /usr/etc/UHS_FolderMonitor.ksh
:
[root@uhspaastream02 NFSPRODW]$ ksh /usr/etc/UHS_FolderMonitor.ksh
sending incremental file list
rsync: link_stat "/nfs/client_fs/NFSPRODW/*.*" failed: No such file or
directory (2)
sent 12 bytes received 12 bytes 48.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors)
(code 23) at main.c(1052) [sender=3.0.9]
콘텐츠 /var/log/rsync_activity.log
:
[root@uhspaastream02 NFSPRODW]$ cat /var/log/rsync_activity.log
2018/02/02 13:30:03 [3422] building file list
2018/02/02 13:30:03 [3422] >f+++++++++ HHN Center_COWIN, JUSTIN
TYME_HHN8026539_HHN0005000372168_9.14.2017_p152w-258306975.pdf
2018/02/02 13:30:03 [3422] sent 130.00K bytes received 31 bytes 260.06K
bytes/sec
2018/02/02 13:30:03 [3422] total size is 149.91K speedup is 1.15
2018/02/02 17:06:22 [13342] building file list
2018/02/02 17:06:22 [13342] >f+++++++++ RTMS Project Update.docx
2018/02/02 17:06:22 [13342] sent 11.17K bytes received 31 bytes 22.40K
bytes/sec
2018/02/02 17:06:22 [13342] total size is 14.00K speedup is 1.25
2018/02/12 09:33:22 [8120] building file list
2018/02/12 09:33:22 [8120] rsync: link_stat "/nfs/client_fs/NFSPRODW/*.*"
failed: No such file or directory (2)
2018/02/12 09:33:22 [8120] sent 12 bytes received 12 bytes 48.00
bytes/sec
2018/02/12 09:33:22 [8120] total size is 0 speedup is 0.00
2018/02/12 09:33:22 [8120] rsync error: some files/attrs were not
transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9]
2018/02/12 09:37:02 [8206] building file list
2018/02/12 09:37:02 [8206] rsync: link_stat "/nfs/client_fs/NFSPRODW/*.*"
failed: No such file or directory (2)
2018/02/12 09:37:02 [8206] sent 12 bytes received 12 bytes 48.00
bytes/sec
2018/02/12 09:37:02 [8206] total size is 0 speedup is 0.00
2018/02/12 09:37:02 [8206] rsync error: some files/attrs were not
transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9]
2018/02/12 09:37:35 [8218] building file list
2018/02/12 09:37:35 [8218] rsync: link_stat "/nfs/client_fs/NFSPRODW/*.*"
failed: No such file or directory (2)
2018/02/12 09:37:35 [8218] sent 12 bytes received 12 bytes 48.00
bytes/sec
2018/02/12 09:37:35 [8218] total size is 0 speedup is 0.00
2018/02/12 09:37:35 [8218] rsync error: some files/attrs were not
transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9]
라이센스 NFSPRODW
:
[root@uhspaastream02 NFSPRODW]$ ls -ld /nfs/client_fs/NFSPRODW/
drwxrwxrwx. 2 root root 4096 Feb 12 09:37 /nfs/client_fs/NFSPRODW/
라이센스 UHS_FolderMonitor.ksh
:
[root@uhspaastream02 NFSPRODW]$ ls -ld /usr/etc/UHS_FolderMonitor.ksh
-rwxrwxrwx. 1 root root 724 Feb 2 16:31 /usr/etc/UHS_FolderMonitor.ksh
코드 UHS_FolderMonitor.ksh
:
[root@uhspaastream02 NFSPRODW]$ cat /usr/etc/UHS_FolderMonitor.ksh
#!/bin/ksh
# Description: Script that moves files to Windows NFS share via the systemd
UHS_FolderMonitor service file
# Service Filename is
/etc/systemd/system/UHS_FolderMonitor.service
# Service file above relies on the
/etc/systemd/system/UHS_FolderMonitor.path file
#
# Scriptname: /usr/etc/UHS_FolderMonitor.ksh
#
# Owner:
# Version 1.0
# Last Updated: 01/24/18
#
#Change Log: Initial Create 01/24/18
#
# mv /nfs/client_fs/NFSPRODW/*.* /NFSPRODW
/usr/bin/rsync --chmod=u=rwx,g=rwx,o=rwx --remove-source-files -r -zvh --
log-file=/var/log/rsync_activity.log /nfs/client_fs/NFSPRODW/*.* /NFSPRODW
echo `date` ' Rsync - File(s) moved to NFS Share' >>
/usr/etc/UHS_FolderMonitor.log
수동으로 실행된 명령이 제대로 작동하기 rsyncd
때문에 데몬을 실행하는 사용자에게 이 문제를 일으키는 권한이 있어야 한다고 생각합니다 .rsync
감사해요.
답변1
먼저 로컬 버전입니다.
테스트 스크립트에서 "--remove-source-files"를 생략했습니다.
[root@centos7 rsync_task]# pwd
/root/rsync_task
[root@centos7 rsync_task]# ls -la backup.sh
-rw-r--r-x 1 root root 259 Feb 13 01:15 backup.sh
[root@centos7 rsync_task]# cat backup.sh
#!/bin/sh
echo "List files in src: "$(ls /mnt/backup_src)
/usr/bin/rsync --chmod=u=rwx,g=rwx,o=rwx -r -zvh --log-file=/var/log/rsync_activity.log /mnt/backup_src/* /mnt/backup_dst
echo `date` ' Rsync - File(s) moved to NFS Share' >> /var/log/rsync_backup.log
서비스 파일:
[root@centos7 rsync_task]# ls -lah /etc/systemd/system/rsync_backup.service
-rw-r--r-- 1 root root 160 Feb 13 00:52 /etc/systemd/system/rsync_backup.service
[root@centos7 rsync_task]# cat /etc/systemd/system/rsync_backup.service
[Unit]
Description= Starts the folder monitoring/logging script
Documentation= man:systemd.service
[Service]
Type=oneshot
ExecStart=/root/rsync_task/backup.sh
서비스를 시작하기 전에 확인해야 할 몇 가지 사항은 다음과 같습니다.
[root@centos7 mnt]# pwd
/mnt
[root@centos7 mnt]# ls -lad backup_*
drwxr-xr-x 2 root root 6 Feb 13 01:15 backup_dst
drwxr-xr-x 2 root root 71 Feb 13 01:12 backup_src
[root@centos7 mnt]# ls backup_src/
file1 file2 file3 file4 file5
[root@centos7 mnt]# ls backup_dst
서비스를 시작합니다:
[root@centos7 yurij]# systemctl start rsync_backup.service
[root@centos7 yurij]# systemctl status rsync_backup.service
● rsync_backup.service - Starts the folder monitoring/logging script
Loaded: loaded (/etc/systemd/system/rsync_backup.service; static; vendor preset: disabled)
Active: inactive (dead)
Docs: man:systemd.service
Feb 13 01:24:11 centos7.localdomain backup.sh[2714]: List files in src: file1 file2 file3 file4 file5
Feb 13 01:24:11 centos7.localdomain backup.sh[2714]: sending incremental file list
Feb 13 01:24:11 centos7.localdomain backup.sh[2714]: file1
Feb 13 01:24:11 centos7.localdomain backup.sh[2714]: file2
Feb 13 01:24:11 centos7.localdomain backup.sh[2714]: file3
Feb 13 01:24:11 centos7.localdomain backup.sh[2714]: file4
Feb 13 01:24:11 centos7.localdomain backup.sh[2714]: file5
Feb 13 01:24:11 centos7.localdomain backup.sh[2714]: sent 236 bytes received 107 bytes 686.00 bytes/sec
Feb 13 01:24:11 centos7.localdomain backup.sh[2714]: total size is 0 speedup is 0.00
Feb 13 01:24:11 centos7.localdomain systemd[1]: Started Starts the folder monitoring/logging script.
백업을 확인해 보겠습니다.
[root@centos7 mnt]# ls backup_dst
file1 file2 file3 file4 file5
NFS 공유에 복사합니다("debian9"는 NFS 서버로 사용됩니다).
NFS 서버 구성:
root@debian9:~/backups# pwd
/root/backups
root@debian9:~/backups# ls -ld ./
drwxrwxrwx 2 root root 4096 Feb 13 01:35 ./
root@debian9:~/backups# cat /etc/exports
/root/backups 192.168.56.0/24(rw,sync,no_subtree_check,no_root_squash,insecure)
root@debian9:~/backups# systemctl status nfs-server
● nfs-server.service - NFS server and services
Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled)
Active: active (exited) since Tue 2018-02-13 01:32:10 MSK; 6min ago
Process: 1631 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)
Process: 1628 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS)
Process: 1625 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)
Process: 1645 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
Process: 1643 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Main PID: 1645 (code=exited, status=0/SUCCESS)
Feb 13 01:32:10 debian9 systemd[1]: Starting NFS server and services...
Feb 13 01:32:10 debian9 systemd[1]: Started NFS server and services.
백업한 첫 번째 호스트의 상태:
[root@centos7 mnt]# pwd
/mnt
[root@centos7 mnt]# ls backup_src
file1 file2 file3 file4 file5
[root@centos7 mnt]# ls backup_dst
[root@centos7 mnt]# mount|grep nfs
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
[root@centos7 mnt]# mount -t nfs 192.168.56.4:/root/backups backup_dst/
[root@centos7 mnt]# ls backup_dst
[root@centos7 mnt]# mount|grep nfs
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
192.168.56.4:/root/backups on /mnt/backup_dst type nfs4 (rw,relatime,vers=4.1,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.56.5,local_lock=none,addr=192.168.56.4)
서비스를 시작해 보겠습니다.
[root@centos7 yurij]# systemctl start rsync_backup.service
[root@centos7 yurij]# systemctl status rsync_backup.service
● rsync_backup.service - Starts the folder monitoring/logging script
Loaded: loaded (/etc/systemd/system/rsync_backup.service; static; vendor preset: disabled)
Active: inactive (dead)
Docs: man:systemd.service
Feb 13 01:43:25 centos7.localdomain backup.sh[2874]: List files in src: file1 file2 file3 file4 file5
Feb 13 01:43:25 centos7.localdomain backup.sh[2874]: sending incremental file list
Feb 13 01:43:25 centos7.localdomain backup.sh[2874]: file1
Feb 13 01:43:25 centos7.localdomain backup.sh[2874]: file2
Feb 13 01:43:25 centos7.localdomain backup.sh[2874]: file3
Feb 13 01:43:25 centos7.localdomain backup.sh[2874]: file4
Feb 13 01:43:25 centos7.localdomain backup.sh[2874]: file5
Feb 13 01:43:26 centos7.localdomain backup.sh[2874]: sent 236 bytes received 107 bytes 228.67 bytes/sec
Feb 13 01:43:26 centos7.localdomain backup.sh[2874]: total size is 0 speedup is 0.00
Feb 13 01:43:26 centos7.localdomain systemd[1]: Started Starts the folder monitoring/logging script.
[root@centos7 mnt]# ls backup_dst
file1 file2 file3 file4 file5
NFS 서버를 확인하십시오.
root@debian9:~/backups# pwd
/root/backups
root@debian9:~/backups# ls
file1 file2 file3 file4 file5
마지막으로 "debian9" 호스트에서 실행될 "rsyncd"를 사용해 보십시오:
root@debian9:~/backups# cat /etc/rsyncd.conf
log file=/var/log/rsyncd
[Backups]
comment = backups
path = /root/backups/
use chroot = yes
lock file = /var/lock/rsyncd
read only = no
write only = yes
list = yes
uid = root
gid = root
strict modes = yes
hosts allow = 192.168.56.5 #it's my 'centos7'
ignore errors = no
ignore nonreadable = yes
transfer logging = no
timeout = 600
refuse options = checksum dry-run
dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz
root@debian9:~/backups# systemctl status rsync
● rsync.service - fast remote file copy program daemon
Loaded: loaded (/lib/systemd/system/rsync.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2018-02-13 02:06:42 MSK; 33s ago
Main PID: 2327 (rsync)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/rsync.service
└─2327 /usr/bin/rsync --daemon --no-detach
Feb 13 02:06:42 debian9 systemd[1]: Stopped fast remote file copy program daemon.
Feb 13 02:06:42 debian9 systemd[1]: Started fast remote file copy program daemon.
"debian9"의 백업 디렉터리를 확인하세요:
root@debian9:~/backups# pwd
/root/backups
root@debian9:~/backups# ls
백업 스크립트를 약간 변경합니다.
[root@centos7 rsync_task]# cat backup.sh
#!/bin/sh
echo "List files in src: "$(ls /mnt/backup_src)
/usr/bin/rsync --chmod=u=rwx,g=rwx,o=rwx -r -zvh --log-file=/var/log/rsync_activity.log /mnt/backup_src/* rsync://192.168.56.4/Backups
echo `date` ' Rsync - File(s) moved to NFS Share' >> /var/log/rsync_backup.log
소스 파일을 체크인합니다:
[root@centos7 mnt]# pwd
/mnt
[root@centos7 mnt]# ls backup_src/
file1 file2 file3 file4 file5
서비스를 시작해 보겠습니다.
[root@centos7 yurij]# systemctl start rsync_backup.service
[root@centos7 yurij]# systemctl status rsync_backup.service
● rsync_backup.service - Starts the folder monitoring/logging script
Loaded: loaded (/etc/systemd/system/rsync_backup.service; static; vendor preset: disabled)
Active: inactive (dead)
Docs: man:systemd.service
Feb 13 02:10:13 centos7.localdomain backup.sh[3021]: List files in src: file1 file2 file3 file4 file5
Feb 13 02:10:13 centos7.localdomain backup.sh[3021]: sending incremental file list
Feb 13 02:10:13 centos7.localdomain backup.sh[3021]: file1
Feb 13 02:10:13 centos7.localdomain backup.sh[3021]: file2
Feb 13 02:10:13 centos7.localdomain backup.sh[3021]: file3
Feb 13 02:10:13 centos7.localdomain backup.sh[3021]: file4
Feb 13 02:10:13 centos7.localdomain backup.sh[3021]: file5
Feb 13 02:10:13 centos7.localdomain backup.sh[3021]: sent 232 bytes received 103 bytes 670.00 bytes/sec
Feb 13 02:10:13 centos7.localdomain backup.sh[3021]: total size is 0 speedup is 0.00
Feb 13 02:10:13 centos7.localdomain systemd[1]: Started Starts the folder monitoring/logging script.
서버에서 백업(rsynd) 파일을 체크인합니다.
root@debian9:~/backups# pwd
/root/backups
root@debian9:~/backups# ls
file1 file2 file3 file4 file5
답변2
그만한 가치가 있는지 알아보려면 스크립트 파일 /usr/etc/UHS_FolderMonitor.ksh에서 SELinux 컨텍스트를 확인하겠습니다. rsync를 사용하는 시스템 단위 파일과 비슷한 문제가 발생했습니다.
유용한 부울 값은 man 8 rsync_selinux(selinux-policy-doc 패키지)를 참조하세요.