2020年8月2日 星期日

2.rsyncd --centos 7

yum install rsync -y
systemctl start rsyncd
systemctl status rsyncd
systemctl enable rsyncd
firewall-cmd --permanent --zone=public --add-service=rsyncd

server 端的設定很簡單,只有兩個檔要寫入
1. /etc/rsyncd.conf

2. /etc/rsyncd.secrets

client 檔的設定更簡單

1. /root/rsyncd.secrets

root@b2d:~# cat /root/rsyncd.secrets
123456 #就只要存在密碼即可
然後下一個指令,讓 client 吐資料給 server 就行了,B2D 已經把指令寫成一個 shell,定排程去執行,如下

root@b2d:~# cat /root/bk-b2d.sh
#! /bin/sh

# IP 為遠端備份主機的 IP
# 格式:
# rsync 選項 密碼檔 欲備份的檔案目錄之絕對路徑 帳號@主機IP::備份區段
# 用例:
# /usr/bin/rsync -avHS --numeric-ids --password-file=/root/rsyncd.secrets /var/www my_backup@192.168.1.186::mybk
# 若要增加備份目錄, 請自行複製新增一列來修改要備份的檔案目錄即可
#------------------------------------------------------------

/usr/bin/rsync -avHS --numeric-ids --password-file=/root/rsyncd.secrets /etc my_backup@127.0.0.1::mybk
/usr/bin/rsync -avHS --numeric-ids --password-file=/root/rsyncd.secrets /home my_backup@127.0.0.1::mybk
/usr/bin/rsync -avHS --numeric-ids --password-file=/root/rsyncd.secrets /var my_backup@127.0.0.1::mybk



vim /etc/rsyncd.conf

#####################################
uid = root
gid = wheel
use chroot = yes
max connections = 4
syslog facility = local5

[w1]
path = /home/_backup
comment = backup_www
ignore errors
secrets file = /usr/local/etc/rsync/rsync.passwd
auth users = www
read only = no

[163.17.209.248]
path = /163.17.209.248
comment = backup_www
ignore errors
secrets file = /etc/r.p
auth users = etc1
read only = no

[homelia]
path = /home/lia
auth users = home
secrets file = /etc/r.p
read only = no
comment = backup_www
ignore errors

[html]
path = /var/www/html
auth users = html
secrets file = /etc/r.p
read only = no
comment = backup_www
ignore errors

[www]
path = /var/www
auth users = www
secrets file = /etc/r.p
read only = no
comment = backup_www

ignore errors
#####################################

systemctl restart rsyncd.service
firewall-cmd --permanent --zone=public --add-service=rsyncd
vim /etc/r.p

#######################################
home:home
mail:mail
public:public
mysql:mysql
html:html
ftp:ftp
etc1:etc1
etc6:etc6
www:www
lib:lib
#######################################

#####/etc/r.p##############
chown root.root /etc/r.p
chmod 600 /etc/r.p
############################################
mkdir /163.17.209.1
mkdir /163.17.209.5
mkdir /public
mkdir /home/teacher
mkdir /home/office
###################

mkdir /163.17.209.242
systemctl restart rsyncd.service
firewall-cmd --permanent --zone=public --add-service=rsyncd
firewall-cmd --reload
reboot

將本地端的檔案傳到rsync server

rsync -avlHpogDtS --delete --password-file=/etc/rsync.etc1.pwd /etc etc1@163.17.209.236::163.17.209.242
/usr/bin/rsync -avHpogDtS --delete --password-file=/etc/rsync.home.pwd /home/lia/sfs3 home@163.17.209.236::homelia
/usr/bin/rsync -avHpogDtS --delete --password-file=/etc/rsync.html.pwd /var/www/html/sfs3 html@163.17.209.236::html

沒有留言:

張貼留言