RHEL 6.5----rsync+inotify数据同步服务
Rsync特性:
可以镜像保存整个目录树和文件系统;
可以保持原文件的权限、时间、软硬链接等;
安装简单。
传输特点:
速度快:rsync首次同步会复制同步全部内容,以后只传输修改过的文件;
压缩传输:rsync传输数据时,采用压缩解压缩的的方式,因此可以大大节省带宽。
安全:可以使用scp、ssh等方式传输文件,当然也可以通过直接的socket连接。
支持匿名传输,便于进行网站镜像;
选择性保持:符号连接、硬链接、文件属性、权限、时间等。
主机名 | IP | 安装的软件 |
master | 192.168.30.130 | xinetd、rsync |
slave | 192.168.30.131 |
[root@master ~]# yum install -y xinetd rsync
[root@master ~]# vim /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
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
[root@master ~]# /etc/init.d/xinetd restart
Stopping xinetd: [FAILED]
Starting xinetd: [ OK ]
[root@master ~]# netstat -antup | grep 873 //rsync的工作端口是873
tcp ::: :::* LISTEN /xinetd
以root用户同步测试
[root@slave ~]# mkdir /data-back
[root@slave ~]# rsync -azP root@192.168.30.130:/var/www/html/ /data-back/
The authenticity of host '192.168.30.130 (192.168.30.130)' can't be established.
RSA key fingerprint is :d7:::df:f3:::b4:b5:8e:6d:bc:4f::.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.30.130' (RSA) to the list of known hosts.
root@192.168.30.130's password:
receiving incremental file list
./
group
% .38kB/s :: (xfer#, to-check=/)
hosts
% .28kB/s :: (xfer#, to-check=/)
passwd
% .95MB/s :: (xfer#, to-check=/)
shadow
% .10MB/s :: (xfer#, to-check=/) sent bytes received bytes 393.09 bytes/sec
total size is speedup is 2.10
对比文件权限
[root@master html]# getfacl group
# file: group
# owner: root
# group: root
user::rw-
group::r--
other::r-- 可以看出master和slave上的两个文件权限相同
[root@slave ~]# getfacl /data-back/group
getfacl: Removing leading '/' from absolute path names
# file: data-back/group
# owner: root
# group: root
user::rw-
group::r--
other::r--
基于系统用户的备份
创建上传和下载用户
[root@master ~]# useradd rget01
[root@master ~]# echo "rget01:123456" | chpasswd
[root@master ~]# useradd rput01
[root@master ~]# echo "rput01:123456" | chpasswd
[root@master ~]# setfacl -R -m user:rput01:rwx /var/www/html/
[root@master ~]# setfacl -R -m default:user:rput01:rwx /var/www/html/
[root@master ~]# getfacl /var/www/html/
getfacl: Removing leading '/' from absolute path names
# file: var/www/html/
# owner: root
# group: root
user::rwx
user:rput01:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:rput01:rwx
default:group::r-x
default:mask::rwx
default:other::r-x [root@master ~]# setfacl -R -m user:rget01:rwx /var/www/html/
[root@master ~]# setfacl -R -m default:user:rget01:rwx /var/www/html/
[root@master ~]# getfacl /var/www/html/
getfacl: Removing leading '/' from absolute path names
# file: var/www/html/
# owner: root
# group: root
user::rwx
user:rget01:rwx
user:rput01:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:rget01:rwx
default:user:rput01:rwx
default:group::r-x
default:mask::rwx
default:other::r-x [root@master ~]# getfacl /var/www/html/passwd //之前存在的文件权限
getfacl: Removing leading '/' from absolute path names
# file: var/www/html/passwd
# owner: root
# group: root
user::rw-
user:rget01:rwx
user:rput01:rwx
group::r--
mask::rwx
other::r-- [root@master ~]# cp -r /root/install.log /var/www/html/
[root@master ~]# getfacl /var/www/html/install.log //新建文件的权限
getfacl: Removing leading '/' from absolute path names
# file: var/www/html/install.log
# owner: root
# group: root
user::rw-
user:rget01:rwx #effective:r-- //如果在后面的试验中同步不到客户端,注意看这里是否有生效的读取的权限
user:rput01:rwx #effective:r--
group::r-x #effective:r--
mask::r--
other::r-- [root@slave ~]# rsync -azP --delete rget01@192.168.30.130:/var/www/html /data-back //注意这里加 / 和不加 /的区别;不加 / 会把目录同步过去
rget01@192.168.30.130's password:
receiving incremental file list
html/
html/group
% .38kB/s :: (xfer#, to-check=/)
html/hosts
% .82kB/s :: (xfer#, to-check=/)
html/install.log
% .82MB/s :: (xfer#, to-check=/)
html/passwd
% .50kB/s :: (xfer#, to-check=/)
html/shadow
% .15kB/s :: (xfer#, to-check=/) sent bytes received bytes 4616.29 bytes/sec
total size is speedup is 4.11 [root@slave ~]# cd /data-back/
[root@slave data-back]# ll
total
-rw-r--r-- root root May : group
-rw-r--r-- root root May : hosts
drwxrwxr-x root root May : html
-rw-r--r-- root root May : passwd
---------- root root May : shadow
[root@slave data-back]# cd /data-back/html/
[root@slave html]# getfacl install.log
# file: install.log
# owner: root
# group: root
user::rw-
group::r--
other::r--
[root@master ~]# rm -rf /var/www/html/install.log
[root@slave ~]# ssh-copy-id rget01@192.168.30.130
rget01@192.168.30.130's password:
Now try logging into the machine, with "ssh 'rget01@192.168.30.130'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. [root@slave ~]# rsync -azP --delete rget01@192.168.30.130:/var/www/html /tmp
receiving incremental file list sent bytes received bytes 2668.00 bytes/sec
total size is speedup is 71.24
[root@slave ~]# rsync -azP --delete rget01@192.168.30.130:/var/www/html /tmp
receiving incremental file list
deleting html/install.log
html/ sent bytes received bytes 2618.00 bytes/sec
total size is speedup is 25.39
定时任务的时候,设置免密码登陆,写个简单的脚本即可。
[root@slave ~]# rsync -azP root@192.168.30.130:/var/www/html /tmp
root@192.168.30.130's password:
receiving incremental file list
html/
html/install.log
% .94MB/s :: (xfer#, to-check=/) sent bytes received bytes 5609.20 bytes/sec
total size is speedup is 4.41
[root@slave ~]# getfacl /tmp/html/install.log
getfacl: Removing leading '/' from absolute path names
# file: tmp/html/install.log
# owner: root
# group: root
user::rw-
group::r--
other::r-- [root@slave ~]# rsync -azp --delete rget01@192.168.30.130:/var/www/html /tmp //小写的p不打印传输过程,--delete会删除之前备份的文件,可以看出现当前只有html目录,没有之前的install.log文件了
rget01@192.168.30.130's password:
[root@slave ~]# ll /tmp/
total
drwxrwxr-x root root May : html
-rw-------. root root May : yum.log 注意有些文件,rget01和rput01并没有有效权限
[root@master ~]# cp -r /boot/grub /var/www/html/
[root@master ~]# ll /var/www/html/
total
drwxr-xr-x+ root root May : grub
-rw-rwxr--+ root root May : install.log
drwxr-xr-x+ root root May : pam.d
drwxr-xr-x+ root root May : pango
-rw-r--r--+ root root May : passwd
-rw-r--r--+ root root May : passwd-
[root@master ~]# getfacl /var/www/html/grub/
getfacl: Removing leading '/' from absolute path names
# file: var/www/html/grub/
# owner: root
# group: root
user::rwx
user:rget01:rwx #effective:r-x
user:rput01:rwx #effective:r-x
group::r-x
mask::r-x
other::r-x
default:user::rwx
default:user:rget01:rwx
default:user:rput01:rwx
default:group::r-x
default:mask::rwx
default:other::r-x [root@master ~]# getfacl /var/www/html/grub/
device.map grub.conf minix_stage1_5 stage2
e2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 ufs2_stage1_5
fat_stage1_5 jfs_stage1_5 splash.xpm.gz vstafs_stage1_5
ffs_stage1_5 menu.lst stage1 xfs_stage1_5
[root@master ~]# getfacl /var/www/html/grub/grub.conf
getfacl: Removing leading '/' from absolute path names
# file: var/www/html/grub/grub.conf
# owner: root
# group: root
user::rw-
user:rget01:rwx #effective:---
user:rput01:rwx #effective:---
group::r-x #effective:---
mask::---
other::--- [root@slave ~]# rsync -azP --delete rget01@192.168.30.130:/var/www/html /tmp
rget01@192.168.30.130's password:
receiving incremental file list
html/
html/grub/
html/grub/device.map
% .52kB/s :: (xfer#, to-check=/)
html/grub/e2fs_stage1_5
% .19MB/s :: (xfer#, to-check=/)
html/grub/fat_stage1_5
% .01MB/s :: (xfer#, to-check=/)
html/grub/ffs_stage1_5
% .87MB/s :: (xfer#, to-check=/)
rsync: send_files failed to open "/var/www/html/grub/grub.conf": Permission denied () //这种错误是rget01没有有效的读取权限
html/grub/iso9660_stage1_5
% .02MB/s :: (xfer#, to-check=/)
html/grub/jfs_stage1_5
% .69kB/s :: (xfer#, to-check=/)
html/grub/menu.lst -> ./grub.conf
html/grub/minix_stage1_5
% .14kB/s :: (xfer#, to-check=/)
html/grub/reiserfs_stage1_5
% .30kB/s :: (xfer#, to-check=/)
html/grub/splash.xpm.gz
% .54kB/s :: (xfer#, to-check=/)
html/grub/stage1
% .71kB/s :: (xfer#, to-check=/)
html/grub/stage2
% .01MB/s :: (xfer#, to-check=/)
html/grub/ufs2_stage1_5
% .69kB/s :: (xfer#, to-check=/)
html/grub/vstafs_stage1_5
% .83kB/s :: (xfer#, to-check=/)
html/grub/xfs_stage1_5
% .49kB/s :: (xfer#, to-check=/) sent bytes received bytes 59957.20 bytes/sec
total size is speedup is 2.34
rsync error: some files/attrs were not transferred (see previous errors) (code ) at main.c() [generator=3.0.]
在master上执行
[root@master ~]# chmod /var/www/html/grub/grub.conf
然后在slave上再次执行
[root@slave ~]# rsync -azP --delete rget01@192.168.30.130:/var/www/html /tmp
rget01@192.168.30.130's password:
receiving incremental file list
html/grub/grub.conf
% .27kB/s :: (xfer#, to-check=/) sent bytes received bytes 629.71 bytes/sec
total size is speedup is 158.96
在master上删除一些文件测试同步
[root@master ~]# rm -rf /var/www/html/grub/
在slave上同步测试
[root@slave ~]# rsync -azP --delete rget01@192.168.30.130:/var/www/html /tmp
rget01@192.168.30.130's password:
receiving incremental file list
deleting html/grub/xfs_stage1_5
deleting html/grub/vstafs_stage1_5
deleting html/grub/ufs2_stage1_5
deleting html/grub/stage2
deleting html/grub/stage1
deleting html/grub/splash.xpm.gz
deleting html/grub/reiserfs_stage1_5
deleting html/grub/minix_stage1_5
deleting html/grub/menu.lst
deleting html/grub/jfs_stage1_5
deleting html/grub/iso9660_stage1_5
deleting html/grub/grub.conf
deleting html/grub/ffs_stage1_5
deleting html/grub/fat_stage1_5
deleting html/grub/e2fs_stage1_5
deleting html/grub/device.map
deleting html/grub/
html/ sent bytes received bytes 536.00 bytes/sec
total size is speedup is 70.92
自动定时备份简单脚本
[root@slave ~]# vim /root/rsync_auto.sh
#!/bin/bash
rsync -az --delete rget01@192.168.30.130:/var/www/html /web-back
tar -czvf data-back-`date +%Y-%m-%d`.tar.gz /data-back/*
[root@slave ~]# chmod +x /root/rsync_auto.sh
[root@slave ~]# echo "0 3 * * * sh /root/rsync-auto.sh &" > /var/spool/cron/root
基于非系统用户的数据备份实例
在master上建立rsyncd.conf文件
[root@master ~]# vim /etc/rsyncd.conf
uid = nobody
gid = nobody
address = 192.168.30.130
port =
hosts allow = 192.168.30.131
use chroot = yes
max connections =
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
motd file = /etc/rsyncd.motd [rsync-data]
path = /var/www/html
comment = used for web-data root
read only = yes
list = yes
auth users = rsyncuser
secrets file = /etc/rsync.passwd
建立欢迎信息文件
[root@master ~]# echo ""Welcome to Rsync data back" > /etc/rsyncd.motd
[root@master ~]# cat !$
cat /etc/rsyncd.motd
<h1>Welcome to Rsync data back</h1>
建立rsync用户密码文件
[root@master ~]# vim /etc/rsync.passwd
rsyncuser:admin123
修改密码文件权限
[root@master ~]# chmod /etc/rsync.passwd
重启rsync服务(两种方式)
[root@master ~]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[root@master ~]# netstat -antup | grep
tcp ::: :::* LISTEN /xinetd
[root@master ~]# service xinetd stop
Stopping xinetd: [ OK ]
[root@master ~]# mv /etc/rsync.conf /etc/rsyncd.conf
[root@master ~]# rsync --daemon --config=/etc/rsyncd.conf
[root@master ~]# netstat -antup | grep
tcp 192.168.30.130: 0.0.0.0:* LISTEN /rsync
在slave端同步测试
[root@slave ~]# rsync -azP rsyncuser@192.168.30.130::backdata /data-back/
Welcome to Rsync data back //这是我们设置的欢迎信息 Password: #输入admin123,回车
receiving incremental file list
./
passwd
% .77MB/s :: (xfer#, to-check=/)
rsync: send_files failed to open "/shadow" (in backdata): Permission denied () sent bytes received bytes 175.54 bytes/sec
total size is speedup is 2.71
rsync error: some files/attrs were not transferred (see previous errors) (code ) at main.c() [generator=3.0.]
在master上更改权限重试即可
[root@master ~]# chmod /var/www/html/shadow
[root@slave ~]# rsync -azP rsyncuser@192.168.30.130::backdata /data-back/
Welcome to Rsync data back Password:
receiving incremental file list
shadow
% .17MB/s :: (xfer#, to-check=/) sent bytes received bytes 175.11 bytes/sec
total size is speedup is 3.92
实现自动备份的脚本
[root@slave ~]# vim /root/auto-rsync-passwd.sh
#!/bin/bash
export RSYNC_PASSWORD=admin123
rsync -avz rsyncuser@191.168.30.130::backdata /data-back
生产环境下,开启iptables,然后放行873端口
[root@master ~]# iptables -A INPUT -p tcp --dport -j ACCEPT
Rsync命令
rsync命令和scp命令很相似
-a, --archive archive mode 权限保存模式,相当于 -rlptgoD 参数,存档,递归,保持属性等
-r, --recursive 复制所有下面的资料,递归处理
-p, --perms 保留档案权限 ,文件原有属性
-t, --times 保留时间点,文件原有时间
-g, --group 保留原有属组
-o, --owner 保留档案所有者(root only)
-D, --devices 保留device资讯(root only)
-l, --links 复制所有的连接 ,拷贝连接文件
-z, --compress 压缩模式, 当资料在传送到目的端进行档案压缩. –azP
-H, --hard-links 保留硬链接文件
-A, --acls 保留ACL属性文件,需要配合--perms
-P,-P参数和 --partial --progress 相同.只是为了把参数简单化,表示传进度
--version, 输出rsync版本
-v , --verbose 复杂的输出信息
-u, --update 仅仅进行更新,也就是跳过已经存在的目标位置,并且文件时间要晚于要备份的文件,不覆盖新的文件
--port=PORT, 定义rsyncd(daemon)要运行的port(预设为tcp )
--delete, 删除那些目标位置有的文件而备份源没有的文件
--password-file=FILE ,从 FILE 中得到密码
--bwlimit=KBPS, 限制 I/O 带宽
--filter “-filename”,需要过滤的文件
--exclude=filname,需要过滤的文件
--progress,显示备份过程
inotify实时同步测试
inotify下载地址:
https://sourceforge.net/projects/inotify-tools/files/latest/download
Linux 内核从 2.6.13 版本开始提供了 inotify 通知接口,用来监控文件系统的各种变化情况,如文件存取、删除、移动等。利用这一机制,可以非常方便地实现文件异动告警、增量备份,并针对目录或文件的变化及时作出响应。使用 rsync 工具与 inotify 机制相结合,可以实现触发式备份(实时同步),只要原始位置的文档发生变化,则立即启动增量备份操作,否则处于静态等侍状态,这样一来,就避免了按固定周期备份进存在的延迟性、周期过密等问题。
[root@slave ~]# uname -r
2.6.-.el6.x86_64
[root@slave ~]# ls /proc/sys/fs/inotify/
max_queued_events max_user_instances max_user_watches max_queued_events #监控时间队列
max_user_instances #最多监控实例数
max_user_watches #每个实例最多监控的文件数
[root@slave ~]# cat /proc/sys/fs/inotify//max_queued_events [root@slave ~]# cat /proc/sys/fs/inotify//max_user_
max_user_instances max_user_watches
[root@slave ~]# cat /proc/sys/fs/inotify//max_user_instances [root@slave ~]# cat /proc/sys/fs/inotify//max_user_watches [root@slave ~]# vim /etc/sysctl.conf
#末尾添加三行内容
fs.inotify.max_queued_events =
fs.inotify.user_instances =
fs.inotify.max_user_watches =
使立即生效并查看
[root@slave ~]# sysctl -p
net.ipv4.ip_forward =
net.ipv4.conf.default.rp_filter =
net.ipv4.conf.default.accept_source_route =
kernel.sysrq =
kernel.core_uses_pid =
net.ipv4.tcp_syncookies =
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key
kernel.msgmnb =
kernel.msgmax =
kernel.shmmax =
kernel.shmall =
fs.inotify.max_queued_events =
error: "fs.inotify.user_instances" is an unknown key
fs.inotify.max_user_watches =
[root@slave ~]# cat /proc/sys/fs/inotify/max_user_watches
安装inotify-tools
[root@slave ~]# tar -xf inotify-tools-3.13.tar.gz -C /usr/local/src/
[root@slave ~]# cd /usr/local/src/inotify-tools-3.13/
[root@slave inotify-tools-3.13]# ./configure --prefix=/usr/local/inotify-tools;make;make install
[root@slave ~]# ln -s /usr/local/inotify-tools/bin/* /usr/bin/
使用同样方法在master上也安装inotify-tools
inotifywait常用参数:
-e 用来指定要监控哪些事件。这些事件包括: create 创建,move 移
动,delete 删除,modify 修改文件内容,attrib 属性更改。
-m 表示持续监控
-r 表示递归整个目录
-q 表示简化输出信息。
测试
首先打开两个终端
在第一个终端内输入
[root@master ~]# ln -s /usr/local/inotify-tools/bin/* /usr/bin/
[root@master ~]# inotifywait -mrq -e create.move,delete,modify
在另外一个终端内输入
[root@master ~]# cp install.log.syslog /var/www/html/
[root@master ~]# mkdir /var/www/html/inotify
然后在第一个中可以看到
[root@master ~]# ln -s /usr/local/inotify-tools/bin/* /usr/bin/
[root@master ~]# inotifywait -mrq -e create.move,delete,modify /var/www/html/
'create.move,delete,modify' is not a valid event! Run with the '--help' option to see a list of events.
[root@master ~]# inotifywait -mrq -e create,move,delete,modify /var/www/html/
/var/www/html/ CREATE install.log.syslog
/var/www/html/ MODIFY install.log.syslog
/var/www/html/ CREATE,ISDIR inotify
如果配置自动备份脚本
[root@master ~]# vim /root/inotify.sh
#!/bin/bash
SRC=/var/www/html
DST=root@192.168.30.130:/data-back
inotifywait -mrq -e modify,delete,create,attrib ${SRC} | while read D E F
do
/usr/bin/rsync -ahqzt --delete $SRC $DST
done
#D E F 分别对应前面的三个变量,因为前面输出三段内容
~
RHEL 6.5----rsync+inotify数据同步服务的更多相关文章
- Rsync+inotify数据同步
安装环境 备份服务器端:CentOS7,IP:192.168.1.100 备份客户端:CentOS7,IP:192.168.1.200 服务器端Rsync服务部署 1.安装程序包 # yum –y i ...
- Rsync+inotify 数据同步应用指南
Rsync+Inotify-tools (1):Inotify-tools 只能记录下被监听的目录发生了变化(包括增加.删除.修改),并没有 把具体是哪个文件或者哪个目录发生了变化记录下来: (2): ...
- rsync与inotify 数据同步
发布:thebaby 来源:脚本学堂 [大 中 小] 本文介绍下,在linux系统中,使用rsync与inotify实现数据同步的一个实例,有研究文件同步的朋友可以作个参考.本文转自:ht ...
- 2-3-2 rsync+inotify备份同步数据
RSYNC = Remote Sync 远程同步 高效,一定要结合shell 官网:https://rsync.samba.org Author: Andrew Tridgell, Wayne Dav ...
- centos 配置rsync+inotify数据实时同步2
一.Rsync服务简介 1. 什么是Rsync 它是一个远程数据同步工具,它在同步文件的同时,可通过LAN/WAN快速同步多台主机间的文件.Rsync使用所谓的“rsync算法”来使本地和远程两个主机 ...
- centos 配置rsync+inotify数据实时同步
何为rsync? 定义: rsync是一个开源的快速备份工具,可以在不同主机之间镜像同步整个目录树,支持增量备份,保持链接和权限,非常适用于异地备份 何为源端和发起端? 在远程同步过程中,负责发起rs ...
- 【linux运维】rsync+inotify与sersync+rsync实时数据同步笔记
Rsync(remote sync)远程同步工具,通过rsync可以实现对远程服务器数据的增量备份通过,但rsync自身也有缺陷,同步数据时,rsync采用核心算法对远程服务器的目标文件进行对比,只进 ...
- Rsync数据同步服务
Rsync数据同步服务 Rsync软件适用与unix/linux/windows等多种操作系统平台 Rsync是一款开源的,快速的,多功能的,可实现全量及增量的本地或远程数据同步备份的优秀工具,可以实 ...
- rsync+inotify实时同步环境部署记录
随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求,rsync在高端业务系统中也逐渐暴露出了很多不足.首先,rsync在同步数据时,需要扫描所有文件后进行比对,进行差量传输.如果文件 ...
随机推荐
- LOJ#139. 树链剖分
LOJ#139. 树链剖分 题目描述 这是一道模板题. 给定一棵$n$个节点的树,初始时该树的根为 1 号节点,每个节点有一个给定的权值.下面依次进行 m 个操作,操作分为如下五种类型: 换根:将一个 ...
- NOIP2016总结
Day1: T1:模拟: #include<iostream> #include<cstdio> #include<cstdlib> #include<cst ...
- SpringBoot快速HelloWorld入门
1.新建maven项目 2.pom.xml 里添加SpringBoot所依赖的jar包 <parent> <groupId>org.springframework.boot&l ...
- HihoCoder1705: 座位问题(STL)
描述 HIHO银行等待区有一排N个座位,从左到右依次编号1~N.现在有M位顾客坐在座位上,其中第i位坐在编号Ai的座位上. 之后又陆续来了K位顾客,(K + M ≤ N) 他们都会选择坐在最" ...
- 【NOIP2012】 国王游戏
[题目链接] 点击打开链接 [算法] 按ai * bi升序排序,贪心即可 [代码] #include<bits/stdc++.h> using namespace std; #define ...
- bzoj3270博物馆——期望概率DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3270 设计一个状态表示两个人分别在两个点的状态,带个标号num[i][j]: 据此得到状态之 ...
- 将svn的项目转移到另外一个仓库中
前几天在做一个项目的时候,因为需要,需要将Server A 上SVN仓库 repos1中的项目pro1迁移到Server B 上的SVN仓库中,首先想到的是:通过复制,但是仔细一想,这样是不可能的:然 ...
- C++语言中的static关键字的作用是什么?
在函数体,一个被声明为静态的变量在这一函数被调用过程中维持其值不变.在模块内(但在函数体外),一个被声明为静态的变量可以被模块内所用函数访问,但不能被模块外其它函数访问.它是一个本地的全局变量.在模块 ...
- Codeforces 702B【二分】
题意: 给一个a数组,输出有多少对相加是等于2^x的.1<=a[i]<=1e9,n<=1e5 思路: a[i]+a[j]=2^x 对于每个a[i],枚举x,然后二分查找a[j]; p ...
- hdoj1272【并查集】
因为是第二遍,所以题目也没怎么看,然后一开始的思路就是如果每次输入两个点的时候判断是不是同一个集合,如果同一个就是No,然后就wa了,想想也是,然后瞄了一下题解,还要判连通-真是蠢死了-多个集合都想不 ...