samba服務器端提供共享服務,同時做爲rsync客戶端將數據實時備份到rsync服務器端linux
samba服務器端:vim
yum install sambawindows
smb服務,nmb服務負責主機名解析centos
添加用戶,須要提早建立linux用戶bash
useradd –s /sbin/nologin smb1服務器
smbpasswd –a smb1app
smbpasswd smb1修改口令ide
smbpasswd –x smb1刪除用戶測試
pdbedit –L [-v] 查看用戶列表ui
windows匿名訪問
vim /etc/samba/smb.conf
[public]
map to guest = Bad User
共享文件夾配置下添加
public = yes
[pub]
comment = app
path = /data/bz2
valid user = smb1,@admins
writable = yes默認爲no
write list = smb2 writable 爲no時,只有smb2可寫 +或@admins表示組
public = yes
Linux客戶端
smbclient //ip/文件夾 –U user%pass
mount –o username=,password= //ip/文件夾 /mnt/smb
自動掛載
vim /etc/fstab
//ip/文件夾 /mnt/smb cifs username=,password= 0 0
或者//ip/文件夾 /mnt/smb cifs credentials=/etc/smbuser.txt 0 0
vim /etc/smbuser.txt
username=
password=
chmod 600 smbuser.txt
rsync服務器端
yum install rsync
vim /etc//etc/rsyncd.conf uid = root gid = root use chroot = no max connections = 0 ignore errors exclude = lost+found/ log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock reverse lookup = no hosts allow = 192.168.35.0/24 [backup] path = /data/share comment = backup read only = no auth users = rsyncuser secrets file = /etc/rsync.pass
echo "rsyncuser:centos" > /etc/rsync.pass
chmod 600 /etc/rsync.pass
rsync --daemon 可加入/etc/rc.d/rc.local實現開機啓動
rsync客戶端:
yum install inotify-tools rsync
echo "centos" > /etc/rsync.pass
chmod 600 /etc/rsync.pass
將本地share文件夾下文件(最後要加/否則會把文件夾一塊兒同步)同步到rsync服務器backup,真實路徑/data/share
測試rsync -avz --password-file=/etc/rsync.pass /data/share/ rsyncuser@192.168.35.128::backup
腳本
vim inotify.sh #!/bin/bash SRC='/data/share/' DEST='rsyncuser@192.168.35.128::backup' inotifywait -mrq --timefmt '%Y-%m-%d %H:%M' --format '%T %w %f' -e create,delete,moved_to,close_write,attrib ${SRC}\ |while read DATE TIME DIR FILE;do FILEPATH=${DIR}${FILE} rsync -az --delete --password-file=/etc/rsync.pass $SRC $DEST && echo "At ${TIME} on ${DATE}, file $FILEPATH was backuped up via rsync" >> /var/log/changelist.log done