centos8環境安裝配置rsync


一,查看本地centos的版本:

[root@localhost lib]# cat /etc/redhat-release 
CentOS Linux release 8.1.1911 (Core) 

 

說明:劉宏締的架構森林是一個專注架構的博客,地址:https://www.cnblogs.com/architectforest

         對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/

 說明:作者:劉宏締 郵箱: 371125307@qq.com

 

二,查看是否已安裝rsync程序包?

[root@localhost source]# rpm -qa | grep rsync
rsync-3.1.3-6.el8.x86_64

 

三,如果沒安裝,用下面的命令安裝:

[root@localhost yum.repos.d]# dnf install rsync

 

四,創建目錄和密碼文件:

[root@localhost dest]# mkdir /data/rsync
[root@localhost dest]# cd /data/rsync/
[root@localhost rsync]# mkdir run
[root@localhost rsync]# chmod 777 run
[root@localhost rsync]# mkdir log
[root@localhost rsync]# chmod 777 log
[root@localhost rsync]# mkdir conf
[root@localhost rsync]# chmod 777 conf
[root@localhost rsync]# cd conf/
[root@localhost conf]# vi server.pass

說明:server.pass的內容:pusher:123456

         pusher是訪問rsync服務時的用戶名

         123456是pusher對應的密碼

 

五,配置rsync服務的配置文件

[root@localhost yum.repos.d]# vi /etc/rsyncd.conf

編輯內容為:

uid = root
gid = root
port = 873
#use chroot = no            #是否可以改變同步的根目錄
#read only = yes            #只讀或者可以上傳文件
#hosts allow=192.168.1.220
#hosts deny=*
# transfer logging = yes
#motd file = /data/rsync/conf/motd
# log format = %t %a %m %f %b
# syslog facility = local3
# timeout = 300
max connections = 200
pid file = /data/rsync/run/rsyncd.pid
lock file = /data/rsync/run/rsync.lock
log file = /data/rsync/log/rsyncd.log

[wwwroot]
path         = /data/nfs/dest
comment      = lg69_rsync
#read only    = yes
read only    = no
auth users   = pusher
secrets file = /data/rsync/conf/server.pass
hosts allow  = 127.0.0.1,192.168.1.0/24,59.151.1.0/24,211.151.133.0/24,58.221.35.0/24,125.76.249.0/24
# list=yes
# ignore errors
# exclude = test/ test.php

 

六,生成rsync客戶端密碼文件及配置各密碼文件權限

1,生成rsync客戶端密碼文件

[root@localhost conf]# vi client.pass

說明:內容與服務端中pusher的密碼相同,內容設置為:123456

 

2,密碼文件的權限一律切換為 600

[root@localhost conf]# ll
總用量 8
-rw-r--r-- 1 root root 7 2月  24 16:51 client.pass
-rw-r--r-- 1 root root 7 2月  24 16:47 server.pass
[root@localhost conf]# chmod 600 *
[root@localhost conf]# ll
總用量 8
-rw------- 1 root root 7 2月  24 16:51 client.pass
-rw------- 1 root root 7 2月  24 16:47 server.pass

 

七,查看rsync的版本

[root@localhost conf]# rsync --version
rsync  version 3.1.3  protocol version 31

 

八,用systemctl管理rsync服務

1,創建一個配置文件

[root@localhost conf]# vi /etc/sysconfig/rsyncd

說明:內容為:

OPTIONS=""

2,創建service文件

[root@localhost conf]# vi /lib/systemd/system/rsyncd.service

說明:service文件內容為:

[Unit]
Description=fast remote file copy program daemon
ConditionPathExists=/etc/rsyncd.conf

[Service]
EnvironmentFile=/etc/sysconfig/rsyncd
ExecStart=/usr/bin/rsync --daemon --no-detach "$OPTIONS"

[Install]
WantedBy=multi-user.target

 

3,測試啟動:

[root@localhost conf]# systemctl start rsyncd

 

九,啟動rsync服務后,客戶端測試同步一個目錄到本地

[root@localhost conf]# rsync -vzrtopg --progress --password-file=/data/rsync/conf/client.pass pusher@127.0.0.1::wwwroot /data/nfs/test

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM