为了网站的随时可以迁移或者负载均衡,必须保证web根目录的一致性,所以得实时同步

下面是我模拟迁移前的一个web同步:

用于迁移前的数据同步,主要利用rsync+lsync

客户端:192.168.1.135 (网站备份数据)

服务器:192.168.1.136 (网站源数据)

客户端安装rsync

yum install -y rsync xinetd

 

rsync添加配置文件

vi /etc/rsyncd.conf

[root@cm root]# cat /etc/rsyncd.conf

uid = nobody                      //启动服务的用户

gid = nobody                      //启动服务的组

use chroot = yes                   //限制笼环境

max connections = 10               //最大连接数

timeout = 300                     //超时时间

strict modes = yes                 

pid file = /var/run/rsync/rsyncd.pid     

#lock file = /var/run/rsync/rsyncd.lock

log file = /var/log/rsync/rsyncd.log

[data]                           //模块

#path =/usr/local/nginx-1.6.3/html/home/paixian/root

path = /usr/local/nginx/html/home/paixian/root     //模块路径

ignore errors = yes                             //忽略错误

read only = no                                //是否只读

write only = no                               //是否只写

hosts allow = *                               //访问限制

#hosts deny =

list = false                                   

uid = root

gid = root

auth users = min                                //认证用户

secrets file = /etc/rsyncd.passwd                  //认证密码文件

 

配置认证文件

vi /etc/rsyncd.passwd

[root@cm root]# cat /etc/rsyncd.passwd

min:min                                      //用户:密码

添加权限

chmod 600 /etc/rsyncd.passwd                    //授权

启动服务

service xinetd restart

检测服务是否启动

ss -tulnp|grep 873

 

 

服务器安装rsync

yum install -y rsync xinetd

添加认证文件

vi /etc/rsyncd.passwd

[root@min bin]# cat /etc/rsyncd.passwd

min

授权认证文件

chmod 600 /etc/rsyncd.passwd

测试客户端的rsync

rsync --list-only--password-file=/etc/rsyncd.passwd min@192.168.1.135::data

[root@min bin]# rsync --list-only --password-file=/etc/rsyncd.passwdmin@192.168.1.135::data

drwxrwxrwx        4096 2015/10/15 18:22:35 .

-rwxr-xr-x         404 2015/09/17 17:17:30 admin.php

-rwxr-xr-x         246 2015/09/17 22:14:00 config.php

-rwxr-xr-x         299 2015/09/17 17:15:37 index.php

-rwxr-xr-x          25 2015/09/17 17:17:30 phpinfo.php

-rwxr-xr-x        1414 2015/09/17 17:15:36product_list.phtml

-rwxr-xr-x        1998 2015/09/17 17:17:30 test.php

-rw-r--r--         114 2015/10/15 12:29:55 test1.php

-rw-r--r--           4 2015/10/15 18:22:17 test2.php

drwxrwxrwx        4096 2015/09/17 17:17:53 .cache

drwxrwxrwx        4096 2015/09/17 17:17:31 admin

drwxrwxrwx        4096 2015/09/17 17:15:36 data

drwxrwxrwx        4096 2015/09/17 17:17:30 demo

drwxrwxrwx        4096 2015/09/17 17:15:36 demo2

drwxrwxrwx        4096 2015/09/17 17:13:48phpdemo_boxcontroler

drwxrwxrwx        4096 2015/10/15 15:26:03 root

drwxrwxrwx        4096 2015/09/17 17:13:49 statics

drwxrwxrwx        4096 2015/09/17 17:17:30 test

drwxrwxrwx        4096 2015/09/17 17:15:44 web

安装lsyncd

cd /usr/local

unzip lsyncd-master.zip         //解压

cd lsyncd-master   

cmake-DCMAKE_INSTALL_PREFIX=/usr/local/lsyncd-2.1.5  //编译指定路径

make && make install

添加配置文件

cd /usr/local/lsyncd-2.1.5

mkdir etc  var                  //创建配置文件和日志文件

vi etc/lsyncd.conf                //添加配置文件

[root@min root]# cat/usr/local/lsyncd-2.1.5/etc/lsyncd.conf  

settings {

   logfile     ="/usr/local/lsyncd-2.1.5/var/lsyncd.log",

   statusFile  ="/usr/local/lsyncd-2.1.5/var/lsyncd.status",

    inotifyMode ="CloseWrite",

   maxProcesses = 7,

   -- nodaemon  =true,

}

sync {

   default.rsync,

   source     ="/usr/local/nginx-1.6.3/html/home/root", //源路径

   target     ="min@192.168.1.135::data",        //目标路径

   delete="running",

   exclude = {".*",".tmp"},                        //排除哪些文件

   delay = 0,                                   //推迟多少秒,一起发送

   init = false,

   rsync    ={

       binary = "/usr/bin/rsync",

       archive = true,

       compress = true,

       verbose  = true,

       password_file = "/etc/rsyncd.passwd",

       _extra        ={"--bwlimit=200"}

}

}

启动lrsyncd

cd bin/

./lsyncd -log Exec/usr/local/lsyncd-2.1.5/etc/lsyncd.conf

自行检测

mysql的实时同步:

http://10554846.blog.51cto.com/10544846/1693049

http://10554846.blog.51cto.com/10544846/1697185