正在进行Blog搬家,这里看到的Blog暂时不完整。

由于Chinaunix的Blog主机不支持301跳转,所以只有麻烦大家访问的时候多点一下。

phanx 的博客空间,请访问这个地址 http://phanx.blog.chinaunix.net



##################### phanx.com #####################
Author: phanx
Updated: 2017-6-18
转载请保留作者信息
###################################################

两个主机有目录需要内容一样,NAS上的NFS没法用,直接export NFS也不太合适,上集群文件系统又有点过了,于是还是考虑用rsync来同步。
考虑到同步要求要“实时”,所以需要用inotify-tools来及时触发rsync的同步。

网上inotify + rsync的教程很多,但是确实都有些毛病。想用这个方案的同学请参考 真正的inotify+rsync实时同步 彻底告别同步慢

后来又研究了一下,决定用lsyncd + rsync来实现。
网上已经有一篇写的比较好的教程了,可以参考 seanlook 写的 lsyncd实时同步搭建指南——取代rsync+inotify
SegmentFault上也有 lsyncd实时同步搭建指南——取代rsync+inotify 内容一样。

我因为要在内部YUM上分发,因此需要编译成RPM。 新版本(写这个的时候版本为2.2.2)的lsyncd没有提供RPM编译所需的SPEC文件,所幸EPEL上有lsyncd-2.1.5的版本SRC RPM,里面提供了SPEC文件,但是新版本的编译前配置方式从configure改成了cmake,因此要调整一下2.1.5所提供的SPEC文件。

先为编译lsyncd的做一些准备:

gcc gcc-c++ 这些不用说了,编译环境必须要的,没有的话,先搞好,要不然cmake会出错。

由于编译lsyncd依赖 lua / lua-develasciidoc,lua 在 RHEL/CentOS 的安装DVD中可以找到,但 lua-devel 和 asciidoc 这两个包不在 RHEL 的 base-channel 里面,而是在 rhel-6-server-optional-rpms 中,因此需要提前下载安装好。

有redhat账号的同学可以直接从 redhat CUSTOMER PORTAL —–> DOWNLOADS —–> Tech Preview: New RPM Package Search 中找到并下载。

没有的就找 CentOS的RPM 来装: asciidoc-8.4.5-4.1.el6.noarch.rpm
lua-devel-5.1.4-4.1.el6.x86_64.rpm
asciidoc 安装的时候会依赖 docbook-style-xsl 包,如果配了安装DVD的YUM源, 用yum装 asciidoc 的时候会自动安装解决依赖,没有配YUM就手工装,安装DVD中有。

另外,由于需要 cmake,所以也需要提前安装好(同样在安装DVD里面有)。

这些准备完后,从EPEL上下载 lsyncd-2.1.5-0.el6.src.rpm,从GITHUB上下载 lsyncd-master.zip 后,就可以开始构建新版RPM了。

先安装 lsyncd-2.1.5 的源码包
1
rpm -ivh lsyncd-2.1.5-0.el6.src.rpm


然后在 rpmbuild的SPEC目录会有 lsyncd.spec

按照以下差异修改 lsyncd.spec 文件:

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
Name: lsyncd
-Version: 2.1.5
+Version: 2.2.2
Release: 0%{?dist}
Summary: File change monitoring and synchronization daemon
Group: Applications/Internet
License: GPLv2+
-URL: http://code.google.com/p/lsyncd/
+URL: https://github.com/axkibe/lsyncd/
-Source0: http://lsyncd.googlecode.com/files/%{name}-%{version}.tar.gz
+Source0: %{name}-%{version}.tar.gz
-# https://github.com/axkibe/lsyncd/issues/220
-Patch0: 0001-Sanitize-mv-arguments.patch
Source1: %{name}.init
Source3: %{name}.sysconfig
Source4: %{name}.logrotate
Source5: %{name}.conf
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires: lua-devel >= 5.1.3
BuildRequires: asciidoc
Requires: lua
Requires: rsync, openssh-clients
Requires(post): chkconfig
Requires(preun): chkconfig
Requires(preun): initscripts
Requires(postun): initscripts
%description
Lsyncd watches a local directory trees event monitor interface (inotify).
It aggregates and combines events for a few seconds and then spawns one
(or more) process(es) to synchronize the changes. By default this is
rsync.
Lsyncd is thus a light-weight live mirror solution that is comparatively
easy to install not requiring new file systems or block devices and does
not hamper local file system performance.
%prep
%setup -q
-%patch0 -p1
%build
-export CFLAGS="$RPM_OPT_FLAGS -fPIE"
-export LDFLAGS="-pie -Wl,-z,relro -Wl,-z,now"
-%configure
-make %{?_smp_mflags}
+cd build
+cmake ..
+make
%install
rm -rf $RPM_BUILD_ROOT
-make install DESTDIR=$RPM_BUILD_ROOT
+mkdir -p $RPM_BUILD_ROOT/usr/bin
+install -c build/lsyncd $RPM_BUILD_ROOT/usr/bin
+mkdir -p $RPM_BUILD_ROOT/usr/share/doc/lsyncd/
+install -c -m 644 examples/lbash.lua examples/lecho.lua examples/lgforce.lua examples/limagemagic.lua examples/lpostcmd.lua examples/lrsync.lua examples/lrsyncssh.lua $RPM_BUILD_ROOT/usr/share/doc/lsyncd/
+mkdir -p $RPM_BUILD_ROOT/usr/share/man/man1/
+install -c -m 644 doc/manpage/lsyncd.1 $RPM_BUILD_ROOT/usr/share/man/man1/
install -d 0755 %{buildroot}%{_initrddir}
install -p -m 0755 %{SOURCE1} %{buildroot}%{_initrddir}/lsyncd
install -p -D -m 0644 %{SOURCE3} %{buildroot}%{_sysconfdir}/sysconfig/%{name}
install -d -m 0755 %{buildroot}%{_localstatedir}/run/%{name}
install -d -m 0755 %{buildroot}%{_localstatedir}/log/%{name}
install -p -D -m 0644 %{SOURCE4} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
install -p -D -m 0644 %{SOURCE5} %{buildroot}%{_sysconfdir}/
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%{_mandir}/man1/lsyncd.1*
%doc COPYING ChangeLog examples
%config(noreplace) %{_sysconfdir}/%{name}.conf
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
%attr(0755,root,root) %{_initrddir}/%{name}
%dir %{_localstatedir}/run/%{name}
%dir %{_localstatedir}/log/%{name}
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%{_bindir}/lsyncd
%exclude %{_docdir}/lsyncd
%post
/sbin/chkconfig --add %{name}
%preun
if [ "$1" -eq 0 ]; then
/sbin/service %{name} stop >/dev/null 2>&1
/sbin/chkconfig --del %{name}
fi
%postun
if [ "$1" -ge "1" ]; then
/sbin/service %{name} condrestart >/dev/null 2>&1 || :
fi
%changelog
+* Sun Jun 18 2017 Phanx Lee <phanx#sina.com> - 2.2.2-0
+- Update to 2.2.2.


再把 lsyncd-master.zip 放到rpmbuild的SOURCES目录,解压 修改目录名,创建build空目录,再打包。
1
2
3
4
5
6
unzip lsyncd-master.zip
mkdir lsyncd-master/build
mv lsyncd-master lsyncd-2.2.2
tar czf lsyncd-2.2.1.tar.gz lsyncd-2.2.2
cd ../SPEC
rpmbuild -bb lsyncd.spec


完成后会生成两个RPM,一般只需要 lsyncd-2.2.2-0.el6.x86_64.rpm 。

如果有内部的RPM包签名,那么加上签名就可以在内部YUM源发布了。

rpm --addsign lsyncd-2.2.2-0.el6.x86_64.rpm

以上,lsyncd的RPM的编译制作就完成了,现在开始安装配置 lsyncd 。


———-


先按照常规配置好rsync daemon模式
目标端:

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
mkdir /etc/rsyncd
echo "phanx:PasswordforPhanx" > /etc/rsyncd/rsyncd.secret
sed -i 's/\= yes/\= no/g' /etc/xinetd.d/rsync
vim /etc/rsyncd.conf
# =============rsyncd.conf =======================
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid
port = 873
address = target.phanx.com
uid = root
gid = root
use chroot = yes
read only = false
#limit access to private LANs
hosts allow=source.phanx.com
#hosts deny=*
max connections = 5
#motd file = /etc/rsyncd/rsyncd.motd
#This will give you a separate log file
log file = /var/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
#transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
[target1]
path = /home/phanx/data/
list=yes
auth users = phanx
secrets file = /etc/rsyncd/rsyncd.secret
comment = rsyncServer
service xinetd restart


然后源端配置lsyncd

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
mkdir /etc/rsyncd
echo "PasswordforPhanx" > /etc/rsyncd/rsyncd.passwd
vim /etc/lsyncd.conf
----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync, but executing moves through on the target.
--
-- For more examples, see /usr/share/doc/lsyncd*/examples/
--
-- sync{default.rsyncssh, source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"}
sync {
default.rsync,
source = "/home/phanx/data/",
target = "phanx@target.phanx.com::target1",
delay = 1,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
password_file = "/etc/rsyncd/rsyncd.passwd"
}
}
chkconfig lsyncd on
service lsyncd start


如果目标端有防火墙或者iptables,那么记得在防火墙和iptables中放开目标端的TCP 873,就可以了。
更详细的介绍,还是请参考前面提到的 seanlook 的文章 或者 lsyncd 的文档。



##################### phanx.com #####################
Author: phanx
Updated: 2011-5-8
转载请保留作者信息
###################################################


在使用Openfiler连接EMC存储的时候,由于Openfiler是基于rPath Linux版本的,EMC的PowerPath没有对rPath提供支持,所以无法使用。
但是,在linux发行版中,一般都自带了Device Mapper Multipath,可以采用dm-mutipath来替代PowerPath提供的多路径功能。

首先建立一个/etc/multipath.conf文件
1
2
3
defaults {
user_friendly_names yes
}


然后启动multpathd服务,加载dm_multipath模块,这样就可以看到多路径聚合后的psudo device了。

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
[root@localhost ~]# chkconfig --level 345 multipathd on
[root@localhost ~]# service multipathd start
[root@localhost ~]# modprobe dm_multipath
[root@localhost ~]# service multipathd restart
[root@localhost ~]# lsmod | grep multi
dm_multipath 17476 3 dm_round_robin
dm_mod 76610 16 dm_multipath,dm_mirror,dm_log
[root@localhost ~]# multipath
[root@localhost ~]# ll /dev/mapper/
total 0
crw-rw---- 1 root
root 10, 57 2011-05-07 00:46 control
brw-rw---- 1 root disk 253, 0 2011-05-07 00:46 mpathb
brw-rw---- 1 root disk 253, 1 2011-05-07 00:46 mpathc
[root@localhost ~]# multipath -ll
mpathc (360060160ef501d003eed32b4c26be011) dm-1 DGC,RAID 10
size=180G features='1 queue_if_no_path' hwhandler='1 emc' wp=rw
|-+- policy='round-robin 0' prio=1 status=active
| |- 3:0:0:0 sdb 8:16 active ready running
| `- 4:0:0:0 sdf 8:80 active ready running
`-+- policy='round-robin 0' prio=0 status=enabled
|- 3:0:1:0 sdd 8:48 active ready running
`- 4:0:1:0 sdh 8:112 active ready running
mpathb (360060160ef501d00a6ececc4c26be011) dm-0 DGC,RAID 10
size=120G features='1 queue_if_no_path' hwhandler='1 emc' wp=rw
|-+- policy='round-robin 0' prio=1 status=active
| |- 3:0:0:1 sdc 8:32 active ready running
| `- 4:0:0:1 sdg 8:96 active ready running
`-+- policy='round-robin 0' prio=0 status=enabled
|- 3:0:1:1 sde 8:64 active ready running
`- 4:0:1:1 sdi 8:128 active ready running


由于Openfiler的/opt/openfiler/sbin/list-disks.pl脚本不能识别Device Mapper的设备,所以无法直接在Web界面中通过Block Device创建PV和VG。但是可以通过在CLI下手工的创建。
使用fdisk对LUN划分区,直接创建一个主分区,类型为 8e 的Linux LVM。
完成后即可看到mpathbp1和mpathcp1两个设备了,再把这两个设备定义为PV,然后创建VG就可以
在Openfiler中使用了。

1
2
3
4
5
6
7
8
9
[root@localhost ~]# fdisk /dev/mapper/mpathb
[root@localhost ~]# fdisk /dev/mapper/mpathc
[root@localhost ~]# pvcreate /dev/mapper/mpathbp1
[root@localhost ~]# pvcreate /dev/mapper/mpathcp1
[root@localhost ~]# vgcreate nasdatavg /dev/mapper/mpathbp1
[root@localhost ~]# vgcreate naslogvg /dev/mapper/mpathcp1