rsync服务器
2022-07-25 本文已影响0人
lzj01231
配置yum源
vim /etc/yum.repos.d/cdrom.repo #redhat8
[BaseOS]
name=BaseOS
baseurl=file:///mnt/BaseOS
enable=1
gpgcheck=0
[AppStream]
name=AppStream
baseurl=file:///mnt/AppStream
enable=1
gpgcheck=0
vim /etc/yum.repos.d/cdrom.repo #redhat7
[cdrom]
name=cdrom
baseurl=file:///mnt
gpgcheck=0
enable=1
安装软件
mount /dev/sr0 /mnt
yum install -y bash-completion vim wget
201、202两台都安装rsync
yum install -y rsync
201创建rsync-a用户,编辑rsync配置文件,创建rsync用户认证文件
useradd -M -s /sbin/nologin rsync-a
chown rsync-a:rsync-a /folder-a
vim /etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
# configuration example:
uid = rsync-a
gid = rsync-a
use chroot = yes
max connections = 100
pid file = /var/run/rsyncd.pid
# exclude = lost+found/
read only = no
fake super = yes
transfer logging = yes
timeout = 900
# ignore nonreadable = yes
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
# [ftp]
# path = /home/ftp
# comment = ftp export area
[module-a]
path = /folder-a
comment = md5 vg-a lv-a mount
auth users = rsync_a
secrets file = /etc/rsyncd.secrets
echo "rsync_a:123" > /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.secrets
201、202配置服务相关
systemctl enable --now rsyncd
firewall-cmd --add-service=rsyncd --permanent
firewall-cmd --reload
setsebool -P rsync_full_access on
202配置自动上传
vim shell202.sh
#!/bin/bash
host=$(hostname)
data=$(date +%F-%H-%M)
back=/boot/grub2
tar -czf ~/${host}_${data}.tar.gz /boot/grub2
export RSYNC_PASSWORD=123
rsync -av ~/${host}_${data}.tar.gz rsync_a@192.168.26.201::module-a
echo "*/3 * * * * sh /root/shell202.sh" | crontab