Atlas 是奇虎360 开源的一个数据库中间件,基于mysql-proxy,做了大量改造,是一个适合国情的高性能的mysql中间件。
官方提供源码下载和rpm下载,但是发现没有SRPM源码包,于是研究了一番,发现了不少问题,自行实现了spec文件,主要解决如下问题:
1、依赖包问题
2、实现了标准的init脚本,去掉了丑陋的mysql-proxyd
3、使用普通用户权限运行mysql-proxy
4、同时支持CentOS 6和CentOS 7
5、文件路径按照Linux 目录树标准FHS进行分布(/usr/local不符合rpm规范)
6、支持开发包(github上有人提问找不到头文件)
本着GPL精神,我希望将成果贡献给官方,以改进安装体验。Atlas.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
%global _enable_debug_package 0
%global debug_package %{nil}
%global __os_install_post /usr/lib/rpm/brp-compress %{nil}
Name: Atlas
Version: 2.2.1
Release: 2%{?dist}
Summary: A Proxy for the MySQL Client/Server protocol
License: GPL
URL: https://github.com/Qihoo360/Atlas
Source0: %{name}-%{version}.tar.gz
Source1: mysql-proxy.cnf
Source2: mysql-proxy.init
BuildRequires: flex,libtool
BuildRequires: glib2-devel >= 2.32.0
BuildRequires: jemalloc-devel
BuildRequires: libevent-devel
BuildRequires: lua-devel >= 5.1
BuildRequires: mysql-devel
BuildRequires: openssl-devel
BuildRequires: pkgconfig
Requires: openssl
Requires: jemalloc
Requires: mysql
Requires: lua >= 5.1
Requires: glib2
Conflicts: mysql-proxy
ExcludeArch: x86
%description
Atlas is a MySQL protocol-based database middleware project developed
and maintained by infrastructure team of the Web platform Department
in QIHU 360 SOFTWARE CO. LIMITED(NYSE:QIHU). It fixed lots of bugs and
added lot of new functions on the basis of MySQL-Proxy 0.8.2.
Currently the project has been widely applied in QIHU,
many MySQL business has connected to the Atlas platform.
The number of read and write requests forwarded by Atlas has reached billions.
%package devel
Summary: Development files for Atlas
Requires: Atlas = %{version}-%{release}
%description devel
Development files for Atlas
%prep
%setup -q
%build
%configure \
--with-lua \
CFLAGS="$CFLAGS -DHAVE_LUA_H" \
LDFLAGS="$LDFLAGS -lm -ldl -lcrypto -ljemalloc"
make %{?_smp_mflags}
%install
rm -rf $RPM_BUILD_ROOT
%{__make} DESTDIR=$RPM_BUILD_ROOT install
%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/log/mysql-proxy
%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/mysql-proxy
%{__mkdir} -p $RPM_BUILD_ROOT%{_initrddir}
%{__install} -m 644 -p %{SOURCE1} \
$RPM_BUILD_ROOT%{_sysconfdir}/mysql-proxy/mysql-proxy.cnf
%{__install} -m755 %{SOURCE2} \
$RPM_BUILD_ROOT%{_initrddir}/mysql-proxy
%clean
%{__rm} -rf $RPM_BUILD_ROOT
make -s clean
%pre
getent group mysql >/dev/null || groupadd -g 27 -o -r mysql
getent passwd mysql >/dev/null || \
useradd -u 27 -M -N -o -r -g mysql -s /bin/bash \
-d /var/lib/mysql mysql
exit 0
%post
ldconfig
chkconfig --add mysql-proxy || :
#fix lib path
%{__ln_s} -f %{_libdir}/mysql-proxy /usr/lib/mysql-proxy || :
%postun
ldconfig
chkconfig --del mysql-proxy || :
unlink /usr/lib/mysql-proxy || :
%files
%defattr(-,root,root,-)
%{_bindir}/mysql-proxy
%{_bindir}/encrypt
%{_bindir}/mysql-binlog-dump
%{_bindir}/mysql-myisam-dump
%exclude %{_bindir}/mysql-proxyd
%config(noreplace) %{_sysconfdir}/mysql-proxy/mysql-proxy.cnf
%{_initrddir}/mysql-proxy
%dir %attr(0755,mysql,mysql) %{_localstatedir}/log/mysql-proxy
%dir %{_libdir}/mysql-proxy
%{_libdir}/mysql-proxy/lua/*
%{_libdir}/mysql-proxy/plugins/*
%{_libdir}/libmysql-*
%{_libdir}/libsql-*
%doc examples/
%files devel
%defattr(-,root,root,-)
%{_includedir}/*.h
%{_libdir}/pkgconfig/mysql-chassis.pc
%{_libdir}/pkgconfig/mysql-proxy.pc
%changelog
* Thu Dec 3 2015 Purple Grape <purplegrape4@gmail.com> - 2.2.1-2
- fix lib path
* Thu Nov 26 2015 Purple Grape <purplegrape4@gmail.com> - 2.2.1-1
- fresh build
|
注:
1、官方只提供el6的rpm包,但是在CentOS 6上编译,会有依赖不足的问题,glib2版本必须大于2.32.0(CentOS 6官方自带的是2.28.8),于是我将cenots 7的glib2 (2.40.0版本)向下移植到了centos 6,用于解决依赖问题。具体见下面的链接。
本文转自 紫色葡萄 51CTO博客,原文链接:http://blog.51cto.com/purplegrape/1717054,如需转载请自行联系原作者