centos-rhel服务器相关 / 未分类 · 2015年4月2日

mysql从源码打包rpm之关键mysql.spec

因为mysql 用cmake 安装太慢了 所以打包一下rpm 虽然%post 得还不够完善 可以慢慢改
code 的结果是有框框 所以只好这些发一下而已
[root@localhost ~]# cat rpmbuild/SPECS/mysql.spec
#rpm包的包名,而不是文件名,不能包含空格
Name: mysql
#rpm的版本号,不允许出现连接符 –
Version:5.5.25
Release: 1.0
License: GPL
#需要在一个存在的组中,通过/usr/share/doc/rpm-*/GROUPS查看完整的组列表
Group: applications/database
URL: a.com
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: cmake
Requires: coreutils,shadow-utils
Packager: evan886@gmail.com
Autoreq: no
Source: mysql-5.5.25.tar.bz2
prefix: /apps/%{name}
Summary: mysql server 5.5.25
%description
evan_mysql
%define MYSQL_USER mysql
%define MYSQL_GROUP mysql
%define __os_install_post %{nil}
%prep
%setup -n %{name}-%{version}
#%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} \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DENABLE_PROFILING:BOOL=ON \
-DWITH_DEBUG:BOOL=OFF \
-DWITH_VALGRIND:BOOL=OFF \
-DENABLE_DEBUG_SYNC:BOOL=OFF \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DWITH_SSL:STRING=bundled \
-DWITH_UNIT_TESTS:BOOL=OFF \
-DWITH_ZLIB:STRING=bundled \
-DWITH_PARTITION_STORAGE_ENGINE:BOOL=ON \
-DWITH_INNOBASE_STORAGE_ENGINE:BOOL=ON \
-DWITH_ARCHIVE_STORAGE_ENGINE:BOOL=ON \
-DWITH_BLACKHOLE_STORAGE_ENGINE:BOOL=ON \
-DWITH_PERFSCHEMA_STORAGE_ENGINE:BOOL=ON \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE:BOOL=ON \
-DWITH_EMBEDDED_SERVER=0 \
-DINSTALL_LAYOUT:STRING=STANDALONE \
-DCOMMUNITY_BUILD:BOOL=ON \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_NDBCLUSTER_STORAGE_ENGINE=1 \
-DENABLED_PROFILING=1 \
-DINNODB_PAGE_ATOMIC_REF_COUNT=1 \
-DWITH_INNODB_MEMCACHED=1;
make -j `cat /proc/cpuinfo | grep processor| wc -l`
%install
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}
mkdir -p apps/mysql/
chown -R mysql:mysql /apps/mysql
fi
##这个post 的好像全部没有效果
%post
if [[ ! -f %{_sysconfdir}/my.cnf ]];then
yes|cp -f %{prefix}/my.cnf %{_sysconfdir}/my.cnf
else
yes|cp -f %{prefix}/my.cnf %{_sysconfdir}/my.cnf.rpmnew
fi
cd /apps/mysql/
scripts/mysql_install_db –user=mysql –datadir=/data/apps/mysql/data/ > /dev/null 2>&1
cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld
#cp %{prefix}/support-files/mysql.server %{_initddir}/mysqld
chmod +x %{_initddir}/mysqld
chkconfig mysqld on
#chkconfig –level 2345 %{_initddir}/mysqld on
#/etc/init.d/mysqld start
echo ‘export PATH=apps/mysql/bin/:$PATH’ >> /etc/profile
source /etc/profile
/etc/init.d/mysqld start
/apps/mysql/bin/mysqladmin password evan;
rm -rf /apps/mysql/data/test;
#%{_sysconfdir} /etc
#%{_initddir} %{_sysconfdir}/rc.d/init.d
#if [ ! -f %{_sysconfdir}/my.cnf ];then
#cp %{prefix}/my.cnf %{_sysconfdir}/my.cnf
#else
#cp %{prefix}/my.cnf %{_sysconfdir}/my.cnf.rpmnew
#fi
%preun
/etc/init.d/mysqld stop
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}
rm -rf /etc/rc.d/init.d/mysqld
userdel -r %{MYSQL_USER} >/dev/null 2>&1
%changelog