歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Linux下架設rsync服務器

Linux下架設rsync服務器

日期:2017/3/1 16:30:56   编辑:關於Linux
Linux下架設rsync服務器 rsync 是一個Unix系統下的文件同步和傳輸工具。rsync是用 “rsync 算法”提供了一個客戶機和遠程文件服務器的文件同步的快速方法。 Some features of rsync include rsync 包括如下的一些特性: * can update whole directory trees and filesystems 能更新整個目錄和樹和文件系統; * optionally preserves symbolic links, hard links, file ownership, permissions, devices and times 有選擇性的保持符號鏈鏈、硬鏈接、文件屬於、權限、設備以及時間等; * requires no special privileges to install 對於安裝來說,無任何特殊權限要求; * internal pipelining reduces latency for multiple files 對於多個文件來說,內部流水線減少文件等待的延時; * can use rsh, ssh or direct sockets as the transport 能用rsh、ssh 或直接端口做為傳輸入端口; * supports anonymous rsync which is ideal for mirroring 支持匿名rsync 同步文件,是理想的鏡像工具; 安裝配置過程: 一。建相應的文件及文件夾 [root@estals60:~]#mkdir /etc/rsyncd --在/etc目錄下創建一個rsyncd的目錄,我們用來存放rsyncd.conf 和rsyncd.secrets文件; [root@estals60:~]#touch /etc/rsyncd/rsyncd.conf --創建rsyncd.conf ,這是rsync服務器的配置文件; [root@estals60:~]#touch /etc/rsyncd/rsyncd.secrets --創建rsyncd.secrets ,這是用戶密碼文件; [root@estals60:~]#chmod 600 /etc/rsyncd/rsyncd.secrets --為了密碼的安全性,我們把權限設為600; [root@estals60:~]#ls -lh /etc/rsyncd/rsyncd.secrets -rw------- 1 root root 14 2007-07-15 10:21 /etc/rsyncd/rsyncd.secrets [root@estals60:~]#touch /etc/rsyncd/rsyncd.motd 二。 修改 rsyncd.conf 和rsyncd.secrets 和rsyncd.motd rsyncd.conf 是rsync服務器主要配置文件,我們來個簡單的示例;比如我們要備份服務器上的 /nsn_talko_production/talko/var/www/html/Talko/talko.next/repository/ # Minimal configuration file for rsync daemon # See rsync(1) and rsyncd.conf(5) man pages for help # This line is required by the /etc/init.d/rsyncd script pid file = /var/run/rsyncd.pid port = 873 address = estals60 #uid = nobody #gid = nobody uid = root gid = root use chroot = yes read only = yes #limit access to private LANs hosts allow=* #192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0 #hosts deny=* max connections = 5 motd file = /etc/rsyncd/rsyncd.motd #This will give you a separate log file #log file = /var/log/rsync.log #This will log every file transferred - up to 85,000+ per user, per sync #transfer logging = yes log format = %t %a %m %f %b syslog facility = local3 timeout = 300 [P_repositor] path = /nsn_talko_production/talko/var/www/html/Talko/talko.next/repository/ list=yes --list 意思是把rsync 服務器上提供同步數據的目錄在服務器上模塊是否顯示列出來。默認是yes 。如果你不想列出來,就no ;如果是no是比較安全的,至少別人不知道你的服務器上提供了哪些目錄。你自己知道就行了 ignore errors --忽略IO錯誤 auth users = root --用戶賬號 (這個必須得是系統中已經存在的賬號) secrets file = /etc/rsyncd/rsyncd.secrets --存放密碼的地方 comment = P_repositor --相當於是一種接口名字,等服務跑起來了客戶端可以直接用這名字調用相關服務器的文件夾內容信息 #exclude = beinan/ samba/ --無視這兩個文件夾的內容 rsyncd.secrets的內容如下類似 root:123456 yofee:123456 rsyncd.motd 文件 它是定義rysnc 服務器信息的,也就是用戶登錄信息。比如讓用戶知道這個服務器是誰提供的等. +++++++++++++++++++++++++++ + Yofee Packages rsync + +++++++++++++++++++++++++++ 三、啟動rsync服務器 [root@estals60:~]#/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf 四、防火牆的設置 [root@estals60:~]#iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT [root@estals60:~]#iptables -L 查看一下防火牆是不是打開了 873端口; 五、執行同步命令 rsync -avzP root@estals60::P_repositor /nsn_talko/talko/var/www/html/Talko/talko.next/ 這時會要求輸入root的密碼,然後就沒啥問題了。 另外其實也可以考慮把他建在系統任務裡面定時運行。道理都是一樣的,用crontab,這裡就不再重述了。 ###################### uid = nobody gid = nobody use chroot = no read only = false max connections = 5 port = 873 motd file = /etc/rsyncd/rsyncd.motd pid file = /tmp/rsyncd.pid lock file = /tmp/rsync.lock log format = %t %a %m %f %b log file = /tmp/rsyncd.log timeout = 300 [update] path = /data/autoupdate/ ignore errors = yes list = false comment = update secrets file = /etc/rsyncd/rsyncd.secrets hosts allow = * #hosts deny = 0.0.0.0/32 ###########################################
Copyright © Linux教程網 All Rights Reserved