phpstudy建设网站教程,微信小程序开发需要什么,灵山建设局网站,国外炫网站最近公司要求将IDC的APP日志备份到公司办公网内部#xff0c;思前想后#xff0c;结合以前学过的知识#xff0c;决定用rsync直接推送#xff0c;即从APP服务器上直接将日志推送到公司内网。这样避免了在生产服务器上额外安装更多软件而且只需要进行简单的配置#xff0c;… 最近公司要求将IDC的APP日志备份到公司办公网内部思前想后结合以前学过的知识决定用rsync直接推送即从APP服务器上直接将日志推送到公司内网。这样避免了在生产服务器上额外安装更多软件而且只需要进行简单的配置从运维的角度看简化了排错步骤同时降低了安全风险简要网络拓扑图如下 提示:办公区服务器192.168.1.202上的rsync服务端口为873映射到公网10.0.0.10上的端口为51873实验环境IDC机房内网服务器:[rootserver101 ~]# cat /etc/redhat-release
CentOS release 6.4 (Final)
[rootserver101~]# uname -m
x86_64
[rootFabric-64 ~]
[rootserver101 ~]# uname -r
2.6.32-358.el6.x86_64
[rootserver101 ~]#
[rootserver101 ~]#ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:50:56:90:A1:DA inet addr:192.168.168.101 Bcast:192.168.168.255 Mask:255.255.255.0公司办公区机房内部服务器:[rootserver202 ~]# cat /etc/redhat-release
CentOS release 6.4 (Final)
[rootserver202~]# uname -m
x86_64
[rootFabric-64 ~]
[rootserver202 ~]# uname -r
2.6.32-358.el6.x86_64
[rootserver202 ~]#
[rootserver202 ~]#ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:50:56:90:A1:DA inet addr:192.168.1.202 Bcast:192.168.168.255 Mask:255.255.255.0说明:这里规定公司办公区服务器作为rsync的服务端所以rsync的主服务程序运行在192.268.1.202上,数据流向是从IDC机房内部服务器到办公网内部服务器rsync服务端进行配置①rsync服务配置文件如下:[rootserver1-202 ~]# vim /etc/rsyncd.conf
#rsync_config
uid www
gid www
use chroot no
max connections 200
timeout 300
pid file /var/run/rsyncd.pid
lock file /var/run/rsync.lock
log file /var/log/rsyncd.log
[datacenter]
path /data/datacenter/apps/approval
ignore errors
read only false
list false
#hosts allow 0.0.0.0/24
#hosts deny 0.0.0.0/32
auth users rsync_backup
secrets file /etc/rsync.password
[rootserver1-202 ~]#②密码文件内容如下:[rootserver1-202 ~]# cat /etc/rsync.password
rsync_backup:123456
[rootserver1-202 ~]#③密码文件权限设置为600:[rootserver1-202 ~]# chmod 600 /etc/rsync.password
[rootserver1-202 ~]# ll /etc/rsync.password
-rw------- 1 root root 23 Nov 6 10:57 /etc/rsync.password
[rootserver1-202 ~]#④以守护进程的模式启动rsync(daemon模式)[rootserver1-202 ~]# rsync --daemon --config/etc/rsyncd.conf
[rootserver1-202 ~]#
[rootserver1-202 ~]#ps -ef|grep rsync
root 18170 1 0 12:27 ? 00:00:00 rsync --daemon --config
/etc/rsyncd.conf
root 19989 19916 0 16:51 pts/0 00:00:00 grep rsync
[rootserver1-202 ~]#客户端安装配置配置之前查看是否安装rsync[rootserver101 ~]# rpm -q rsync
rsync-3.0.6-9.el6.x86_64
[rootserver101 ~]#创建密码文件因为客户端只需要指定登录密码即可该密码与服务端的密码配置文件中的密码要一致[rootserver101 ~]# echo 123456 /etc/rsync.password
[rootserver101 ~]#同时给密码文件授权600[rootserver101 ~]# chmod 600 /etc/rsync.password
[rootserver101 ~]# ll /etc/rsync.password
-rw------- 1 root root 10 11月 6 10:58 /etc/rsync.password
[rootserver101 ~]#测试同步结果:[rootserver101 ~]#rsync -avz /etc/hosts --port51873 rsync_backup20.0.0.20
::datacenter --password-file/etc/rsync.password sending incremental file list
hosts
sent 734 bytes received 27 bytes 1522.00 bytes/sec
total size is 3117 speedup is 4.10
[rootserver101 ~]# 服务端202上查看同步结果:[rootserver1-202 approval]# pwd
/data/datacenter/apps/approval
[rootserver1-202 approval]#
[rootserver1-202 approval]# ll
-rw-r--r-- 1 www www 3117 Oct 29 14:13 hosts
[rootserver1-202 approval]# 发现文件hosts已经同步到rsync服务器的目录/data/datacenter/apps/approval,至此数据同步完成解析来做定时任务设置定时任务,让该任务在每天晚上凌晨1点开始执行同步前一天的数据:[rootserver101 ~]#mkdir /server/scripts
[rootserver101 ~]#cd /server/scripts
[rootserver101 ~]#vim rsync-log.sh
#!/bin/bash
rsync -avz /usr/local/nginx/logs/app_$(date -d 1 day ago %Y-%m-%d).log --port
51873 rsync_backup20.0.0.20::datacenter --password-file/etc/rsync.password
[rootserver101 ~]#注意:这里不要忘记了给rsync-log.sh赋予可执行权限[rootserver101 ~]#chmod x rsync-log.sh
[rootserver101 ~]#
[rootserver101 ~]#crontab -e
#rsync app logs to datacenter every 01:00:00
* 01 * * * /bin/sh /server/scripts/rsync-log.sh /dev/null 21
[rootserver101 ~]#保存重启crontab服务[rootserver101 ~]#
[rootserver101 ~]# /etc/init.d/crond restart
停止 crond [确定]
正在启动 crond [确定]
[rootserver101 ~]#cp 与 rsync 同名目录同步覆盖关系 同名目录同步覆盖方法1、cp -rp dir1/* dir2/同名不覆盖不提示yes no| cp -rp dir1/* dir2/同名覆盖不提示\cp -rp dir1/* dir2/2、rsync -avz dir1/ dir2/ or rsync -avz dir1/* dir2/同名同步后不删除rsync -avz dir1/* dir2/同名同步后删除dir1同步过去的原文件 rsync -avz dir1/* dir2/ --remove-sent-files至此rsync实现远程日志文件同步实验配置完成如有不妥请各位多多指点 转载于:https://blog.51cto.com/ucode/1710413