1
|
[root@jie1 ~]
# yum -y install httpd nfs-utils
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@jie1 ~]
# vim /etc/httpd/conf/httpd.conf
########################################
ServerName 172.16.22.1:80
#DocumentRoot "/var/www/html" #提供虚拟主机,注释默认存放网页文件的路径
<VirtualHost *:80>
ServerName www.jie.com
DocumentRoot
/web/htdocs
<
/VirtualHost
>
#######################################
[root@jie1 ~]
# mkdir -pv /web/htdocs #创建存放网页的目录
[root@jie1 ~]
# cd /web/htdocs/
[root@jie1 htdocs]
# touch index.html test.html test.php
[root@jie1 htdocs]
# ls
index.html
test
.html
test
.php
[root@jie1 htdocs]
# echo "This is Jie1 Web+nfs Server" >index.html
[root@jie1 htdocs]
# httpd -t #检查web的配置文件是否有语法错误
Syntax OK
[root@jie1 htdocs]
# service httpd start #开启web服务
Starting httpd: [ OK ]
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
[root@jie1 htdocs]
# id apache #安装httpd软件后,系统会创建apache用户,查看apache的id号
uid=48(apache) gid=48(apache)
groups
=48(apache)
[root@jie1 htdocs]
# vim /etc/exports
######################################
/web/htdocs
172.16.22.3(rw,
sync
,root_squash,anonuid=48,anongid=48)
#nfs是以id号来确定是否能访问共享的文件的,因为两个服务器都安装了httpd软件,都会有apache用户,所以apache用户的id号能访问共享的文件
#/web/htdocs 共享的目录
#172.16.22.3 指定客户端能共享此文件,多个客户端用逗号隔开
#rw,读写权限
#sync,同步方式
#root_squash,压缩root用户的权限
#anonuid=48,指定此用户的id能访问共享文件
#anongid=48指定此组的id能访问共享文件
######################################
[root@jie1 htdocs]
# service nfs start #开启nfs服务
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Stopping RPC idmapd: [ OK ]
Starting RPC idmapd: [ OK ]
Starting NFS daemon: [ OK ]
[root@jie1 htdocs]
#
|
1
|
[root@jie3 /]
# yum -y install httpd
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
[root@jie3 /]
# vim /etc/httpd/conf/httpd.conf
########################################
ServerName 172.16.22.3:80
#DocumentRoot "/var/www/html"
<VirtualHost *:80>
ServerName www.jie.com
DocumentRoot
/website
#存放网页文件的路径
<
/VirtualHost
>
#######################################
[root@jie3 /]
# mkdir /website
[root@jie3 /]
# httpd -t
Syntax OK
[root@jie3 /]
# service httpd start
Starting httpd: [ OK ]
[root@jie3 ~]
# cd /website/
[root@jie3 website]
# ls #现在查看是没有任何文件
[root@jie3 website]
#
|
1
|
[root@jie1 htdocs]
#setfacl -R -m u:apache:rwx /web/ #设置apache用户对此中所有文件有读写可执行权限
|
1
2
3
4
5
6
7
|
[root@jie3 website]
#cd /root
[root@jie3 ~]
# mount -t nfs 172.16.22.1:/web/htdocs /website/ #通过nfs挂载服务器端的文件
[root@jie3 /]
#echo "172.16.22.1:/web/htdocs /website nfs defaults,_netdev 0 0" >>/etc/fstab #实现开机挂载
[root@jie3 ~]
# cd /website/
[root@jie3 website]
# ls #查看文件已经同步过来
index.html
test
.html
test
.php
[root@jie3 website]
#
|
1
2
3
4
5
6
|
[root@jie3 ~]
# cd /website/
[root@jie3 website]
# ls
index.html
test
.html
test
.php
[root@jie3 website]
# touch website.html #在客户端创建此文件
[root@jie3 website]
# ls
index.html
test
.html
test
.php website.html
|
1
2
|
[root@jie1 htdocs]
# ls #服务器端,可以查看来着客户端上传的文件
index.html
test
.html
test
.php website.html
|
1
2
|
[root@jie1 ~]
# yum -y install rsync xinetd httpd
#rsync服务通常基于超级守护进程xinetd管理的方式来实现,因此需要事先安装rysnc和xinetd
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@jie1 ~]
# vim /etc/httpd/conf/httpd.conf
########################################
ServerName 172.16.22.1:80
#DocumentRoot "/var/www/html"
<VirtualHost *:80>
ServerName www.jie.com
DocumentRoot
/web/htdocs
<
/VirtualHost
>
#######################################
[root@jie1 ~]
# mkdir -pv /web/htdocs
[root@jie1 ~]
# cd /web/htdocs #服务器端,没有任何的网页文件
[root@jie1 ~]
# ls
[root@jie1 ~]
#
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
[root@jie1 ~]
# vim /etc/rsyncd.conf
############vim /etc/rsyncd.conf########################################
uid = nobody
#备份以什么身份进行,用户ID
gid = nobody
#备份以什么身份进行,组ID
use chroot = no
#禁锢在源目录
max connections = 3
#最大连接数,0代表没有限制
strict modes =
yes
#是否检查口令文件的权限
pid
file
=
/var/run/rsyncd
.pid
#运行进程的pid文件
log
file
=
/var/log/rsyncd
.log
#日志记录文件
[htdocs]
#指定认证的备份模块名
path =
/web/htdocs
#需要备份的目录的路径
ignore errors =
yes
#忽略一些无关的IO错误
read
only = no
#设置为no,即可以传至服务器的相应目录。
write only = no
#设置为no,表示客户端可以下载文件
hosts allow = 172.16.22.3
#可以连接rsync服务器的主机的IP地址
hosts deny = *
#设置禁止连接rsync服务器的主机地址,*表示 拒绝所有除了hosts allow定义的
uid = root
gid = root
auth
users
= backuper
#连接模块的用户名
secrets
file
=
/etc/rsyncd
.
pwd
#连接模块用户名的密码文件存放路径
#####################################################################
[root@jie1 ~]
#vim /etc/rsyncd.pwd #用户的密码文件
#####################################################################
backuper:pwd123
#用户名:密码
#####################################################################
[root@jie1 ~]
# chmod 600 /etc/rsyncd.pwd #权限给600
[root@jie1 ~]
# chkconfig rsync on
[root@jie1 ~]
# chkconfig xinetd on
[root@jie1 ~]
# service xinetd start
Starting xinetd: [ OK ]
[root@jie1 ~]
# netstat -pant | grep 873
tcp 0 0 :::873 :::* LISTEN 19876
/xinetd
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
[root@jie3 ~]
#wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz #下载inotify-tools软件
[root@jie3 ~]
# ls
anaconda-ks.cfg
install
.log
inotify-tools-3.14.
tar
.gz
install
.log.syslog
[root@jie3 ~]
# tar xf inotify-tools-3.14.tar.gz #解压软件
[root@jie3 ~]
# cd inotify-tools-3.14
[root@jie3 inotify-tools-3.14]
# ./configure --prefix=/usr/local/inotify && make && make install #编译安装软件
[root@jie3 ~]
#cd /usr/local/inotify/
[root@jie3 inotify]
# echo "PATH=/usr/local/inotify/bin:$PATH" >>/etc/profile.d/inotify.sh #设置能与系统关联的path路径
[root@jie3 inotify]
# source /etc/profile.d/inotify.sh
[root@jie3 inotify]
# echo "/usr/local/inotify/lib" >/etc/ld.so.conf.d/inotify.conf #设置系统能识别软件的库文件
[root@jie3 inotify]
# ldconfig -v | grep inotify
/usr/local/inotify/lib
:
libinotifytools.so.0 -> libinotifytools.so.0.4.1
[root@jie3 inotify]
# ln -sv /usr/local/inotify/include/ /usr/include/inotify #链接头文件到系统能识别的路径下
`
/usr/include/inotify
' -> `/usr/local/inotify/include/'
[root@jie3 inotify]
#
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[root@jie3 /]
# vim /etc/httpd/conf/httpd.conf
########################################
ServerName 172.16.22.3:80
#DocumentRoot "/var/www/html"
<VirtualHost *:80>
ServerName www.jie.com
DocumentRoot
/website
<
/VirtualHost
>
#######################################
[root@jie3 /]
# mkdir /website
[root@jie3 /]
# httpd -t
Syntax OK
[root@jie3 /]
# service httpd start
Starting httpd: [ OK ]
[root@jie3 ~]
# cd /website/
[root@jie3 website]
# ls
[root@jie3 website]
#
[root@jie3 ~]
#
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[root@jie3 ~]
# vim /etc/rsyncd.pwd
#############################################
pwd123
#密码与rsync服务器的密码相同
###############################################
[root@jie3 ~]
# chmod 600 /etc/rsyncd.pwd
[root@jie3 ~]
# vim rsync.sh
#####################################################################
#!/bin/bash
host=172.16.22.1
src=
/website
des=htdocs
inotifywait -mrq --timefmt
'%d/%m/%y %H:%M'
--
format
'%T %w%f%e'
-e modify,delete,create,attrib $src \
|
while
read
files
do
/usr/bin/rsync
-vzrtopg --progress --password-
file
=
/etc/rsyncd
.secrets $src backuper@$host::$des
echo
"${files} was rsynced"
>>
/tmp/rsync
.log 2>&1
done
####################################################################
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
##1、先开启监控的脚本(inotify主机上)
[root@jie3 ~]
# bash -x rsync.sh &
#不放在后台可以查看同步的详细过程,生成环境中,建议把此脚本放到后台执行,此脚本会监控客户端数据是否方式变化,如果变化脚本就运行,数据不变化,脚本就会等待着用户的输入
##2、在开一个终端,在此目录创建文件(inotify主机上)
[root@jie3 ~]
# cd /website/
[root@jie3 website]
# touch index.html test.php testdb.php inotify.php
[root@jie3 website]
# ls
index.html testdb.php
test
.php inotify.php
[root@jie3 website]
#
##3、看服务器端,数据是否已经同步过去
[root@jie1 ~]
# cd /web/htdocs/
[root@jie1 htdocs]
# ls
index.html testdb.php
test
.php inotify.php
#数据已经被同步过来
[root@jie1 htdocs]
#
|
1
2
|
[root@jie1 ~]
# yum -y install rsync xinetd httpd
#rsync服务通常基于超级守护进程xinetd管理的方式来实现,因此需要事先安装rysnc和xinetd
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@jie1 ~]
# vim /etc/httpd/conf/httpd.conf
########################################
ServerName 172.16.22.1:80
#DocumentRoot "/var/www/html"
<VirtualHost *:80>
ServerName www.jie.com
DocumentRoot
/web/htdocs
<
/VirtualHost
>
#######################################
[root@jie1 ~]
# mkdir -pv /web/htdocs
[root@jie1 ~]
# cd /web/htdocs #服务器端,没有任何的网页文件
[root@jie1 ~]
# ls
[root@jie1 ~]
#
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
###====此配置文件的解释,在rsync+inotify中已经解释了=====####
[root@jie1 ~]
# vim /etc/rsyncd.conf
############vim /etc/rsyncd.conf###############
uid = nobody
gid = nobody
use chroot = no
max connections = 3
strict modes =
yes
pid
file
=
/var/run/rsyncd
.pid
log
file
=
/var/log/rsyncd
.log
[htdocs]
path =
/web/htdocs
ignore errors =
yes
readonly
= no
write only = no
hosts allow = 172.16.22.3
hosts deny = *
list =
false
uid = root
gid = root
auth
users
= backuper
secrets
file
=
/etc/rsyncd
.
pwd
##############################################
[root@jie1 ~]
#vim /etc/rsyncd.pwd
backuper:pwd123
[root@jie1 ~]
# chmod 600 /etc/rsyncd.pwd
[root@jie1 ~]
# chkconfig rsync on
[root@jie1 ~]
# chkconfig xinetd on
[root@jie1 ~]
# service xinetd start
Starting xinetd: [ OK ]
[root@jie1 ~]
# netstat -pant | grep 873
tcp 0 0 :::873 :::* LISTEN 19876
/xinetd
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
[root@jie3 ~]
#wget --no-check-certificate https://sersync.googlecode.com/files/sersync2.5_64bit_binary_stable_final.tar.gz
[root@jie3 ~]
# ls
anaconda-ks.cfg
install
.log.syslog
install
.log sersync2.5_64bit_binary_stable_final.
tar
.gz
mkdir
/usr/local/sersync
[root@jie3 ~]
#mkdir -pv /usr/local/sersync/{conf,bin,log}
mkdir
: created directory `
/usr/local/sersync
'
mkdir
: created directory `
/usr/local/sersync/conf
'
mkdir
: created directory `
/usr/local/sersync/bin
'
mkdir
: created directory `
/usr/local/sersync/log
'
[root@jie3 ~]
# tar xf sersync2.5_64bit_binary_stable_final.tar.gz
[root@jie3 ~]
# cd GNU-Linux-x86/
[root@jie3 GNU-Linux-x86]
# ls
confxml.xml sersync2
[root@jie3 GNU-Linux-x86]
# mv confxml.xml /usr/local/sersync/conf/
[root@jie3 GNU-Linux-x86]
# mv sersync2 /usr/local/sersync/bin/
[root@jie3 GNU-Linux-x86]
# cd /usr/local/sersync/
[root@jie3 sersync]
# echo "PATH=/usr/local/sersync/bin:$PATH" >>/etc/profile.d/sersync.sh
[root@jie3 sersync]
# source /etc/profile.d/sersync.sh
[root@jie3 sersync]
# echo "pwd123" >/usr/local/sersync/sersync.pwd
[root@jie3 sersync]
# chmod 600 /usr/local/sersync/sersync.pwd
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
[root@jie3 sersync]
# vim /usr/local/sersync/conf/confxml.xml
#########################################################################<?xml version="1.0" encoding="ISO-8859-1"?>
<
head
version=
"2.5"
>
#设置本地的ip地址和监听的端口
<host hostip=
"172.16.22.3"
port=
"8008"
><
/host
>
#debug模式是否开启
<debug start=
"false"
/>
#xfs文件系统是否开启
<fileSystem xfs=
"false"
/>
#同步时,是否支持正则表达式,默认关闭
<filter start=
"false"
>
<exclude expression=
"(.*)\.svn"
><
/exclude
>
<exclude expression=
"(.*)\.gz"
><
/exclude
>
<exclude expression=
"^info/*"
><
/exclude
>
<exclude expression=
"^static/*"
><
/exclude
>
<
/filter
>
# 设置要监控的事件
<inotify>
<delete start=
"true"
/>
<createFolder start=
"true"
/>
<createFile start=
"false"
/>
<closeWrite start=
"true"
/>
<moveFrom start=
"true"
/>
<moveTo start=
"true"
/>
<attrib start=
"false"
/>
<modify start=
"false"
/>
<
/inotify
>
#同步的设置
<sersync>
#同步的路径,本地的目录
<localpath
watch
=
"/website"
>
#rsync服务器的ip地址和rsync配置文件里面定义的模块
<remote ip=
"172.16.22.1"
name=
"htdocs"
/>
#<!-- -->括起来表示注释
<!--<remote ip=
"192.168.8.39"
name=
"tongbu"
/>-->
<!--<remote ip=
"192.168.8.40"
name=
"tongbu"
/>-->
<
/localpath
>
<
rsync
>
#rsync指令参数
<commonParams params=
"-artuz"
/>
#rsync同步认证设置的内容,user指定用户名,password指定存放密码的文件路径
<auth start=
"true"
users
=
"backuper"
passwordfile=
"/usr/local/sersync/sersync.pwd"
/>
#设置rsync远程服务端口
<userDefinedPort start=
"false"
port=
"874"
/><!-- port=874 -->
#设置超时时间
<timeout start=
"true"
time
=
"100"
/><!-- timeout=100 -->
#设置ssh加密传输模式,默认关闭
<
ssh
start=
"false"
/>
<
/rsync
>
#设置sersync传输失败日志脚本路径
<failLog path=
"/tmp/rsync_fail_log.sh"
timeToExecute=
"60"
/><!--default every 60mins execute once-->
#设置rsync+crontab定时传输,默认关闭
<
crontab
start=
"false"
schedule=
"600"
><!--600mins-->
<crontabfilter start=
"false"
>
<exclude expression=
"*.php"
><
/exclude
>
<exclude expression=\'
#\'" /*"></exclude>
<
/crontabfilter
>
<
/crontab
>
#设置sersync传输后调用name指定的插件脚本,默认关闭
<plugin start=
"false"
name=
"command"
/>
<
/sersync
>
#插件脚本范例
<plugin name=
"command"
>
<param prefix=
"/bin/sh"
suffix=
""
ignoreError=
"true"
/> <!--prefix
/opt/tongbu/mmm
.sh suffix-->
<filter start=
"false"
>
<include expression=
"(.*)\.php"
/>
<include expression=
"(.*)\.sh"
/>
<
/filter
>
<
/plugin
>
<
/head
>
#######################################################################
|
1
2
3
4
5
6
7
8
9
|
###sersync客户端的,开启同步机制,进行监控,然后创建文件
[root@jie3 website]
# sersync2 -r -d &
[root@jie3 ~]
# cd /website/
[root@jie3 website]
# touch index.html testdb.php test.html test.php
###rsync服务器端,查看可以来着sersync客户端的同步文件
[root@jie1 ~]
# cd /web/htdocs/
[root@jie1 htdocs]
# ls
index.html testdb.php
test
.html
test
.php
[root@jie1 htdocs]
#
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
[root@jie1 ~]
#wget ftp://distro.ibiblio.org/slitaz/sources/packages-2.0/o/ocaml-3.10.2.tar.gz
[root@jie1~]
#wget http://freebsd.ntu.edu.tw/FreeBSD/ports/distfiles/unison-2.32.52/unison-2.32.52.tar.gz
[root@jie1~]
#wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
[root@jie1 ~]
# ls
anaconda-ks.cfg
install
.log ocaml-3.10.2.
tar
.gz
inotify-tools-3.14.
tar
.gz
install
.log.syslog unison-2.32.52.
tar
.gz
[root@jie1 ~]
# tar xf inotify-tools-3.14.tar.gz
[root@jie1 ~]
# tar xf ocaml-3.10.2.tar.gz
[root@jie1 ~]
# tar xf unison-2.32.52.tar.gz
##编译安装inotify
[root@jie1 ~]
# cd inotify-tools-3.14
[root@jie1 inotify-tools-3.14]
# ./configure --prefix=/usr/local/inotify && make && make install
[root@jie1 inotify-tools-3.14]
# cd /usr/local/inotify/
##修改PATH环境变量
[root@jie1 inotify]
# echo "PATH=/usr/local/inotify/bin:$PATH" >/etc/profile.d/inotify.sh
[root@jie1 inotify]
# source /etc/profile.d/inotify.sh
##添加库文件到系统识别的路径
[root@jie1 inotify]
# echo "/usr/local/inotify/lib" >/etc/ld.so.conf.d/inotify.conf
[root@jie1 inotify]
# ldconfig -v | grep inotify
/usr/local/inotify/lib
:
libinotifytools.so.0 -> libinotifytools.so.0.4.1
##链接库文件到系统识别的路径
[root@jie1 inotify]
# ln -sv /usr/local/inotify/include/ /usr/include/inotify
`
/usr/include/inotify
' -> `/usr/local/inotify/include/'
##编译安装ocaml,unison依赖于ocaml
[root@jie1 inotify]
#cd /root/ocaml-3.10.2
[root@jie1 ocaml-3.10.2]
#./configure
[root@jie1 ocaml-3.10.2]
#make world opt
[root@jie1 ocaml-3.10.2]
#make install
##编译安装unison
[root@jie1 ocaml-3.10.2]
# cd /root/unison-2.32.52
##安装依赖性包
[root@jie1 unison-2.32.52]
#yum -y install ctags-etags
[root@jie1 unison-2.32.52]
# make UISTYLE=text
##make install会提示错误,此错误就是要你cp unison /usr/local/bin,复制即可
[root@jie1 unison-2.32.52]
# make install
[root@jie1 unison-2.32.52]
# cp unison /usr/local/bin
|
1
2
3
4
5
6
7
8
9
|
##把服务器A生成的公钥传到服务器B上####
[root@jie1 ~]
# ssh-keygen -t rsa #生成ssh的密钥对
[root@jie1 ~]
# scp ~/.ssh/id_rsa.pub 172.16.22.3:/root #生成的密钥在家目录的ssh文件中,ssh文件为隐藏文件,通过scp复制到服务器B上
[root@jie3 ~]
# mv id_rsa.pub .ssh/authorized_keys #在服务器B上把服务器A传来的公钥文件改名并存放到ssh目录下
[root@jie3 ~]
# chmod 600 .ssh/authorized_keys #给公钥文件改权限为600
[root@jie1 ~]
# service sshd restart #重启sshd服务
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
[root@jie1 ~]
#
|
1
2
3
4
5
6
7
8
9
|
##把服务器B生成的公钥传到服务器A上####
[root@jie3 ~]
# ssh-keygen -t rsa #生成ssh的密钥对
[root@jie3 ~]
# scp ~/.ssh/id_rsa.pub 172.16.22.1:/root #生成的密钥在家目录的ssh文件中,ssh文件为隐藏文件,通过scp复制到服务器B上
[root@jie1 ~]
# mv id_rsa.pub .ssh/authorized_keys #在服务器A上把服务器B传来的公钥文件改名并存放到ssh目录下
[root@jie1 ~]
# chmod 600 .ssh/authorized_keys #给公钥文件改权限为600
[root@jie3 ~]
# service sshd restart #重启sshd服务
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
[root@jie3 ~]
#
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
##服务器A搭建web的配置
[root@jie1 /]
# vim /etc/httpd/conf/httpd.conf
########################################
ServerName 172.16.22.1:80
#DocumentRoot "/var/www/html"
<VirtualHost *:80>
ServerName www.jie.com
DocumentRoot
/web/htdocs
<
/VirtualHost
>
#######################################
[root@jie1 ~]
# mkdir -pv /web/htdocs
[root@jie1 ~]
# cd /web/htdocs/
[root@jie1 htdocs]
# ls
[root@jie1 htdocs]
#
##服务器B搭建web的配置
[root@jie3 /]
# vim /etc/httpd/conf/httpd.conf
########################################
ServerName 172.16.22.3:80
#DocumentRoot "/var/www/html"
<VirtualHost *:80>
ServerName www.jie.com
DocumentRoot
/website
<
/VirtualHost
>
#######################################
[root@jie3 /]
# mkdir /website
[root@jie3 /]
# httpd -t
Syntax OK
[root@jie3 /]
# service httpd start
Starting httpd: [ OK ]
[root@jie3 ~]
# cd /website/
[root@jie3 website]
# ls
[root@jie3 website]
#
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
##服务器A的脚本
[root@jie1 ~]
# vim serA.sh
######################################################################
#/bin/bash
ipB=
"172.16.22.3"
srcA=
"/web/htdocs"
dstB=
"/website"
/usr/local/inotify/bin/inotifywait
-mrq -e create,delete,modify,move $srcA |
while
read
line;
do
/usr/local/bin/unison
-batch $srcA
ssh
:
//
$ipB/$dstB
echo
-n
"$line "
>>
/var/log/inotify
.log
echo
`
date
|
cut
-d
" "
-f1-4` >>
/var/log/inotify
.log
done
#####################################################################
##服务器B的脚本
[root@jie3 ~]
# vim serB.sh
#####################################################################
#/bin/bash
ipA=
"172.16.22.1"
srcB=
"/website"
dstA=
"/web/htdocs"
/usr/local/inotify/bin/inotifywait
-mrq -e create,delete,modify,move $srcB |
while
read
line;
do
/usr/local/bin/unison
-batch $srcB
ssh
:
//
$ipA/$dstA
echo
-n
"$line "
>>
/var/log/inotify
.log
echo
`
date
|
cut
-d
" "
-f1-4` >>
/var/log/inotify
.log
done
#####################################################################
##服务器A的测试
[root@jie1 ~]
# sh -x serA.sh #先运行unison同步脚本,查看过程
[root@jie1 ~]
# cd /web/htdocs/
[root@jie1 htdocs]
# touch serA.txt SerA.html SerA.php #然后创建文件
[root@jie1 htdocs]
# ls
SerA.html SerA.php serA.txt SerB.html SerB.php SerB.txt
##服务器B的测试
[root@jie3 ~]
# sh -x serB.sh
[root@jie3 ~]
# cd /website/
[root@jie3 website]
# touch SerB.txt SerB.html SerB.php
[root@jie3 website]
# ls
SerA.html SerA.php serA.txt SerB.html SerB.php SerB.txt
###=====可以把脚本设置开机自启,放到rc.local文件中,且放在后台运行
|