您的位置:首页 > 运维架构 > Linux

【编译打包】Atlas-2.2.1-2.el7.centos.src.rpm

2015-11-26 13:25 423 查看
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文件内容如下:
%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,用于解决依赖问题。具体见下面的链接。

百度网盘地址:http://pan.baidu.com/s/1pJpJzo3
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Atlas