静态文件迁移有以下两种方式 1、手动执行rsync 命令 2、通过crontab 来执行定时作业 执行rsync命令把redhat237 = /apache/htdocs目录下的所有文件及文件夹 复制到目标服务器的 /var/www/html/文件夹下。 rsync -avz --progress apache@192.168.8.131::apacheimg /root/test/ --password-file=/root/test/rsyncd.secrets 配置步骤: 在源端: [root@fmw1 xinetd.d]# vi /etc/xinetd.d/rsync # default: off # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync { disable = no socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } [root@fmw1 ~]# vi /etc/rsyncd.conf uid = nobody gid = nobody use chroot = no max connections = 50 pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock log file = /var/log/rsyncd.log [apacheimg] path = /app/apache/ ignore errors read only = no list = yes auth users = apache secrets file = /etc/rsyncd.secrets [root@fmw1 log]# vi /etc/rsyncd.secrets apache:apache [root@fmw1 log]# ll /etc/rsync* -rw-r--r-- 1 root root 286 Jun 8 07:01 /etc/rsyncd.conf -rw-r--r-- 1 root root 14 Jun 8 05:08 /etc/rsyncd.secrets [root@fmw1 log]# chmod 600 /etc/rsyncd.* 启动 [root@fmw1 log]# ps -ef|grep rsync |grep -v grep [root@fmw1 log]# rsync --daemon --config=/etc/rsyncd.conf [root@fmw1 log]# ps -ef|grep rsync |grep -v grep root 5618 1 0 07:06 ? 00:00:00 rsync --daemon --config=/etc/rsyncd.conf [root@fmw1 log]# 设置开机启动: [root@fmw1 log]# vi /etc/rc.local #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local /etc/init.d/vsftpd start /usr/bin/rsync --daemon --config=/etc/rsyncd.conf ~ 客户端安装 建立密码文件 [root@fmw1 ~]# vi /etc/rsyncd.secrets apache [root@fmw1 ~]# chmod 600 /etc/rsyncd.secrets 测试:【注意远程主机的格式是“用户名@主机::配置文件中的栏名”,如果不加用户名,默认同当前用户,不要用单冒号】 上传:[root@c62slave ~]# rsync -av /root/pwd mysql@192.168.1.218::mysql 下载:[root@c62slave ~]# rsync -av mysql@192.168.1.218::mysql /root/mysqldata 不需手动输入密码: 上传:[root@c62slave ~]# rsync -av /root/pwd mysql@192.168.1.218::mysql --password-file=/etc/rsyncd.pwd 下载:[root@c62slave ~]# rsync -vzrtopg --progress mysql@192.168.1.218::mysql /root/mysqldata/ --password-file=/etc/rsyncd.pwd 仅列出远程主机的文件清单: # rsync -v rsync://wolf2012@192.168.1.218:873/test --password-file=/etc/rsyncd.pwd仅列出远程主机的文件列表。 test是远程主机的/etc/rsyncd.conf中配置组名。 rsync -avz --progress apache@192.168.8.131::apacheimg /app/bak/ --password-file=/etc/rsyncd.secrets (责任编辑:IT) |