用rpmbuild打包mysql

Name: mysql
Version:5.5.25
Release: 1%{?dist}
License: GPL

Group: applications/database
URL: http://www.percona.com/redir/downloads/Percona-Server-5.6/LATEST/source/tarball/percona-server-5.6.19-67.0.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: cmake
Requires: coreutils,shadow-utils
Packager: [email protected]
Autoreq: no
Source: mysql-5.5.25.tar.gz
prefix: /usr/local/%{name}
Summary: percona server 5.6.19-67.0

%description
Percona Server is an enhanced, drop-in MySQL replacement which has been downloaded more than 1,000,000 times.
A free open source solution, Percona Server is a MySQL alternative which offers breakthrough performance, scalability, features, and instrumentation. Self-tuning algorithms and support for extremely high-performance hardware make it the clear choice for organizations that demand excellent performance and reliability from their MySQL database server.

%define MYSQL_USER mysql
%define MYSQL_GROUP mysql
%define __os_install_post %{nil}

%prep
%setup -n %{name}-%{version}

%build
CFLAGS="-O3 -g -fno-exceptions -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing"
CXX=g++
CXXFLAGS="-O3 -g -fno-exceptions -fno-rtti -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing"
export CFLAGS CXX CXXFLAGS

cmake .                                                  \
  -DSYSCONFDIR:PATH=%{prefix}                            \
  -DCMAKE_INSTALL_PREFIX:PATH=%{prefix}                  \
  -DWITH_ARCHIVE_STORAGE_ENGINE=1                       \
  -DWITH_INNOBASE_STORAGE_ENGINE=1             \
  -DDEFAULT_CHARSET=utf8                                 \
  -DDEFAULT_COLLATION=utf8_general_ci                    \
  -DENABLED_LOCAL_INFILE=0                             \
  -DWITH_DEBUG=0                                        \
  -DENABLE_DTRACE=0                     \
  -DEXTRA_CHARSETS=all                     \
  -DWITH_INNODB_MEMCACHED=1;

make -j `cat /proc/cpuinfo | grep processor| wc -l`

%install
rm -rf %{buildroot}
make DESTDIR=$RPM_BUILD_ROOT install
cp %{_sourcedir}/my.cnf $RPM_BUILD_ROOT%{prefix}/

%clean
#rm -rf $RPM_BUILD_ROOT
rm -rf $RPM_BUILD_DIR/*

%files
%defattr(-, %{MYSQL_USER}, %{MYSQL_GROUP})
%attr(755, %{MYSQL_USER}, %{MYSQL_GROUP}) %{prefix}/*

%pre
if ! id %{MYSQL_USER} > /dev/null 2>&1;then
useradd -M -s /sbin/nologin %{MYSQL_USER}
fi
mkdir -p /data/{mysql1,mysql2,mysql3,mysql4,mysql5}
chown -R mysql:mysql /data/{mysql1,mysql2,mysql3,mysql4,mysql5}
mkdir /usr/local/mysql

%post
if [ -f %{prefix}/support-files/mysql.server > /dev/null 2>&1 ]  && [ ! -f %{_initddir}/mysql > /dev/null 2>&1 ];then
cp %{prefix}/support-files/mysql.server %{_initddir}/mysql
chmod +x %{_initddir}/mysql
chkconfig --level 2345 %{_initddir}/mysql on
fi
#ln -s /usr/local/mysql/bin/* /usr/bin
#cp -rf /usr/local/mysql/lib/* /lib/
#cp -rf /usr/local/mysql/lib/* /lib64/
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql1 --user=mysql >/dev/null 2>&1
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql2 --user=mysql >/dev/null 2>&1
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql3 --user=mysql >/dev/null 2>&1
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql4 --user=mysql >/dev/null 2>&1
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql5 --user=mysql >/dev/null 2>&1
/usr/local/mysql/bin/mysqld_multi start 1-5

if [ ! -f %{_sysconfdir}/my.cnf ];then
mv %{prefix}/my.cnf %{_sysconfdir}/my.cnf
else
mv %{prefix}/my.cnf %{_sysconfdir}/my.cnf.rpmnew
fi

%preun
if [ -f %{_sysconfdir}/my.cnf ];then
mv %{_sysconfdir}/my.cnf %{_sysconfdir}/my.cnf.rpmold
fi

if [ -f %{_initddir}/mysql ];then
mv %{_initddir}/mysql %{_initddir}/mysql.rpmold
fi

%postun
rm -rf %{prefix}
#userdel -r %{MYSQL_USER} >/dev/null 2>&1

%changelog


你可能感兴趣的:(mysql,rpm,spec,rpmbuld)