1. 程式人生 > >Linux 檔案級實時複製技術

Linux 檔案級實時複製技術

一、專案描述

Linux 檔案級實時複製技術

二、系統環境(linux)天翼雲

 

原機(/opt/david)

目標機(/opt/david)

彈性IP

49.75.185.142 837

14.18.106.217 837

作業系統使用者名稱

root

Root

作業系統密碼

Jiangs

[email protected]

登入方式

 

ssh

賬號/密碼

N/A

N/A

三、遷移步驟

服務端:

linux下檢查rsync是否安裝命令:

rpm -qa|grep rsync

a. 編輯配置檔案

# vi /etc /rsyncd.conf

[[email protected] etc]# cd /etc

[[email protected] etc]# vi rsyncd.conf

# 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

# GLOBAL OPTIONS

uid = root

gid = root

use chroot = no

read only = yes

#limit access to private LANs

hosts allow=49.75.185.142

hosts deny=*

max connections = 5

pid file = /var/run/rsyncd.pid

secrets file = /etc/rsyncd/rsyncd.secrets

# GLOBAL OPTIONS

uid = root

gid = root

use chroot = no

read only = yes

#limit access to private LANs

hosts allow=49.75.185.142

hosts deny=*

max connections = 5

pid file = /var/run/rsyncd.pid

secrets file = /etc/rsyncd.secrets

# Minimal configuration file for rsync daemon

uid = root

gid = root

use chroot = no

read only = yes

#limit access to private LANs

hosts allow=49.75.185.142

pid file = /var/run/rsyncd.pid

secrets file = /etc/rsyncd.secrets

#lock file = /var/run/rsync.lock

motd file = /etc/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

# MODULE OPTIONS

[davidhome]

path = /opt/david/

list=yes

ignore errors

auth users = rsync

comment = David home

exclude = important/

[chinatmp]

path = /opt/china/

list=no

ignore errors

auth users =

comment = tmp_china

b. 建立/etc/ rsyncd.secrets檔案

#cat /etc/ rsyncd.secrets

rsync:123456

c. 為了密碼的安全性,我們必須把許可權設為600

# chown root:root /etc/ rsyncd.secrets

# chmod 600 /etc/rsyncd.secrets

d. 建立連線到伺服器的客戶端看到的歡迎資訊檔案/etc/rsyncd.motd

# vim /etc/rsyncd.motd

[[email protected] rsyncd]# more rsyncd.motd

+++++++++++++++++++++++++++ + wuzy Camp

服務啟動方式

對於負荷較重的 rsync 伺服器應該使用獨立執行方式

# yum install rsync xinetd --服務安裝

# /usr/bin/rsync –daemon(service xinetd restart)

# chkconfig rsync on

# netstat -ntpl | grep 873 --檢視服務是否啟動

測試

1、客戶端

環境:14.18.106.217

# yum -y install rsync

# mkdir /opt/davie /opt/china

# [[email protected] david]#

rsync -avzP --delete [email protected]::davidhome /opt/david/--讓客戶端與伺服器保持完全一致, --delete

-a --引數,相當於-rlptgoD,

-r --是遞迴

-l --是連結檔案,意思是拷貝連結檔案

-i --列出 rsync 伺服器中的檔案

-p --表示保持檔案原有許可權

-t --保持檔案原有時間

-g --保持檔案原有使用者組

-o --保持檔案原有屬主

-D --相當於塊裝置檔案

-z --傳輸時壓縮

-P --傳輸進度

-v --傳輸時的進度等資訊,和-P有點關係

3、通過密碼檔案同步

# echo "123456"> /etc/rsync.password

# chmod 600 /etc/rsync.password

# rsync -avzP --delete --password-file=/etc/rsync.password [email protected]::davidhome /opt/david/ --呼叫密碼檔案

4、客戶端自動同步

# crontab -e

10 0 * * * rsync -avzP --delete --password-file=/etc/rsync.password [email protected]::davidhome /opt/david/

# crontab -l