首页 > 代码库 > rsync数据备份解决方案
rsync数据备份解决方案
rsync命令是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件。rsync使用所谓的“rsync算法”来使本地和远程两个主机之间的文件达到同步,这个算法只传送两个文件的不同部分,而不是每次都整份传送,因此速度相当快。
一、项目规则:
1、系统环境
[root@zabbix-client ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@zabbix-client ~]# uname -r3.10.0-327.el7.x86_64
2、更改主机名和/etc/hosts文件 (客户端和服务端同时操作)
[root@zabbix-server etc]# tail -2 /etc/hosts192.168.30.137 zabbix-server192.168.30.136 zabbix-client
二、安装rsync软件
1、 安装rsync软件(客户端和服务端同时操作)
[root@zabbix-client ~]# yum install rsync -y[root@zabbix-client ~]# rpm -qa rsyncrsync-3.0.9-17.el7.x86_64
2、编辑rsyncd.conf配置文件
[root@zabbix-server ~]# vi /etc/rsyncd.conf#Rsync server#created by nulige 2017-7-8##rsyncd.conf start##uid = rsyncgid = rsyncuse chroot = nomax connections = 2000timeout = 600pid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.logignore errorsread only = falselist = falsehosts allow = 192.168.30.1/24hosts deny = 0.0.0.0/32auth users = rsync_backupsecrets file = /etc/rsync.password##################################################[backup]comment = backup server by nulige at 207-7-8path = /backup
3、添加用户并授权、更改所属组】
[root@zabbix-server etc]# useradd rsync -s /sbin/nologin -M[root@zabbix-server etc]# id rsyncuid=1000(rsync) gid=1000(rsync) groups=1000(rsync)[root@zabbix-server etc]# mkdir /backup[root@zabbix-server etc]# chown -R rsync /backup[root@zabbix-server etc]# ls -ld /backupdrwxr-xr-x 2 rsync root 6 Jun 24 10:18 /backup
4、创建密码文件
[root@zabbix-server etc]# echo "rsync_backup:nulige" >/etc/rsync.password[root@zabbix-server etc]# chmod 600 /etc/rsync.password[root@zabbix-server etc]# cat /etc/rsync.passwordrsync_backup:nulige
5、添加rsync启动脚本
[root@zabbix-client ~]# vi /etc/init.d/rsync#!/bin/bash #author:nulige#this script for start|stop rsync daemon service #date:2017/7/8 status1=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v ‘grep‘) pidfile="/var/run/rsyncd.pid" start_rsync="rsync --daemon --config=/etc/rsyncd.conf" function rsyncstart() { if [ "${status1}X" == "X" ];then rm -f $pidfile ${start_rsync} status2=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v ‘grep‘) if [ "${status2}X" != "X" ];then echo "rsync service start.......OK" fi else echo "rsync service is running !" fi } function rsyncstop() { if [ "${status1}X" != "X" ];then kill -9 $(cat $pidfile) status2=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v ‘grep‘) if [ "${statusw2}X" == "X" ];then echo "rsync service stop.......OK" fi else echo "rsync service is not running !" fi } function rsyncstatus() { if [ "${status1}X" != "X" ];then echo "rsync service is running !" else echo "rsync service is not running !" fi } function rsyncrestart() { if [ "${status1}X" == "X" ];then echo "rsync service is not running..." rsyncstart else rsyncstop rsyncstart fi } case $1 in "start") rsyncstart ;; "stop") rsyncstop ;; "status") rsyncstatus ;; "restart") rsyncrestart ;; *) echo echo "Usage: $0 start|stop|restart|status" echo esac
6、给脚本添加执行权限
[root@zabbix-client ~]# chmod a+x /etc/init.d/rsync
7、启动rsync服务
#启动[root@zabbix-client ~]# service rsync start#重启[root@zabbix-client ~]# service rsync restartrsync service is not running...#查看状态[root@zabbix-client ~]# service rsync statusrsync service is not running !
或
#启动rsync服务(没有用启动脚本的情况,系统默认的启动方法)
[root@zabbix-server etc]# rsync --daemon
8、查看启动端口
[root@zabbix-server etc]# netstat -lntup|grep rsynctcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 49936/rsync tcp6 0 0 :::873 :::* LISTEN 49936/rsync
9、加入开机自启动
[root@zabbix-server ~]#echo "#rsync boot start by nulige at 2017-7-8" >>/etc/rc.local[root@zabbix-server ~]#echo "rsync --daemon" >>/etc/rc.local[root@zabbix-server ~]# tail /etc/rc.local #rsync boot start by nulige at 2017-7-8rsync --daemon
三、安装客户端
rsync数据备份解决方案
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。