这个项目是刚开始上班的时候遇见的,项目和广电合作,所以数据不能直接从外网进入到广电内部,必须用广电的服务器,广电内部服务器有两个网段
一个是外网网段,一个是内网网段,另外一个网段就是我们服务器阿里云外网。
网站数据要从阿里云上穿过外网网段进入内网网段,我们客户的数据都在阿里云上。
当时用的就是rsync做的增量备份。
当时是这么解决的。
1,部署rsync 以阿里服务为主 同步 模拟天津广电服务器
yum -y install xinetd yum -y install rsync*
网上下载源码包也可以
iptables -A INPUT -p tcp --dport 873 -j ACCEPT vi /etc/xinetd.d/rsync #编辑xinetd 进程配置文件 允许开启 rsync disable = no chkconfig rsync on #设置开机自启动
创建rsync 配置文件
vi /etc/rsyncd.conf #配置文件信息 uid = root //运行RSYNC守护进程的用户 gid = root //运行RSYNC守护进程的组 use chroot = no //不使用chroot max connections = 4 // 最大连接数为4 strict modes =yes //是否检查口令文件的权限 port = 873 //默认端口873 [backup] //指定同步文件模块名称 path = /home/backup/ //镜像文件的路径 comment = This is a test //这个模块的注释信息 ignore errors //可以忽略一些无关的IO错误 read only = yes // 只读 list = no //不允许列文件 auth users = hening //认证的用户名,如果没有这行则表明是匿名,此用户与系统无关 secrets file = /etc/rsync.pas //密码和用户名对比表,密码文件自己生成 hosts allow = 115.29.48.231 //允许主机 hosts deny = 0.0.0.0/0 //禁止主机 #transfer logging = yes pid file = /var/run/rsyncd.pid //pid文件的存放位置 lock file = /var/run/rsync.lock //锁文件的存放位置 log file = /var/log/rsyncd.log //日志记录文件的存放位置
服务器端 rsyncd.conf uid = root gid = root use chroot = no max connections = 4 strict modes =yes port = 873 hosts allow = 106.120.175.154 list = no pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log [kuaijia] path = /home/webroot/newkuaijia comment = rsync files ignore errors read only = yes list = no auth users = rsync secrets file = /etc/rsync.pas
_______________________________________________________________________________
手动创建密码文件
touch /etc/rsync.pas root:password #服务器端密码文件
修改文件权限
chown root:root rsync.pas chmod 600 rsync.pas #设置权限 vi /etc/rsyncd.motd #配置欢迎信息文件
启动xinetd 服务
service xinetd restart
启动 rsync 服务
之前有启动程序 先kill
/usr/bin/rsync --daemon 后台启动
或者 /etc/rc.d/init.d/xinetd reload 重新加载xinetd 超级进程启动
查看 rsync是否启动
/etc/init.d/xinetd reload lsof -i:873 #查看进程id netstat -a | grep rsync
/etc/rsync.pas 为密码配置文件 客户端密码文件只需要写密码就好
chmod 600 rsync.pas #设置权限,密码正确也无法登陆
最后一部 连接服务器
向server 获取文件
/usr/bin/rsync -vzrtopg --progress --delete hening@192.168.0.217::backup /home/backup --password-file=/etc/rsync.pas
客户端上执行脚本命令:
/usr/bin/rsync -vzrtopg --delete --update --progress rsync@115.29.48.231::kuaijia /test --password-file=/etc/rsync.pas
--update 增量备份
--progress 显示备份过程
脚本自动化执行部分
手动部分启动服务
/usr/bin/rsync --daemon #启动rsync /etc/init.d/xinetd restart #重新启动xinetd 守护进程 重新加载也可以
手动关闭rsync 进程
shell 路径
/usr/sh/rsync.sh 备份路径可以手动执行
rsync.sh
#!/bin/bash /usr/bin/rsync -vzrtopg --delete --update --progress rsync@115.29.48.231::kuaijia /var/www/html --password-file=/etc/rsync.pas >> /var/log/rsync_backup.log date >> /var/log/rsync_backup.log chown -R root:root /var/www/html chmod -R 777 /var/www/html
/usr/sh/stop_rsync.sh 停止自动备份
启动自动备份
/etc/init.d/crond start
chkconfig crond on 开机自启动
service crond start
crontab -l
crontab -e
*/5 * * * * /usr/sh/rsync.sh >> /var/log/rsync_backup.log
5分钟执行一次 追加日志文件
2,修改阿里数据库用户表 标识用户所属地区
======================================================================
3,数据库同步问题
阿里云服务器导出数据 new_kuaijia阿里云限制 这边虚拟天津服务器 不能直接mysqldump
脚本路径 /usr/sh/kuaijia_mysqldump.sh
客户端服务器 rsync 同步文件 mysql_backup 模块
客户端脚本路径
/usr/sh/mysql_down.sh
客户端导入数据库脚本
/usr/sh/mysql.sh
set names utf8;
解决乱码问题
4,天津广电 电视端操作,同时插入两个数据库