使用rmpbuild製做AliSQL數據庫rpm軟件包


環境:REHL6.5

軟件:rpmbuildhtml

使用到的文件:ALiSQL-Mastermysql

1、安裝所須要的軟件

[root@alisql ~]# yum install rpm* rpm-build rpmdev* –y
[root@alisql ~]# rpmdev-setuptree
[root@alisql ~]# tree rpmbuild/  
rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS

5 directories, 0 filesc++

2、將軟件源碼包上傳到SOURCE目錄

3、編寫配置文件

在rpmbuild/SPECS目錄下執行rpmdev-newspec -o alisql.spec,會在當前目錄下生成名爲alisql.spec的模板文件git

[root@alisql SPECS]# rpmdev-newspec -o alisql.spec

根據修改alisql.spec文件,修改後的內容以下github

Name:           alisql
Version:        5.6.3
Release:        1%{?dist}
Summary:        AliSQL

Group:          Applications/Databases
License:        GPL
URL:            https://github.com/alibaba/AliSQL
Source0:        %{name}-%{version}.tar.gz
BuildRequires:  gcc gcc-c++
Requires:       ncurses-devel bison perl

%define MYSQL_USER mysql
%define MYSQL_GROUP mysql


%description    
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.


%prep
%setup -q
useradd mysql
mkdir -p /usr/local/mysql
mkdir -p /data/mysqldb

%build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8   -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1

make %{?_smp_mflags}


%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT
find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';'

%pre
id mysql  &>/dev/null||useradd -m -s /bin/bash mysql &>/dev/null
mkdir -p /data/mysqldb
chown -R mysql: /data/mysqldb

%clean
rm -rf $RPM_BUILD_ROOT


%post 
/usr/local/mysql/scripts/mysql_install_db  --basedir=/usr/local/mysql --user=mysql  --datadir=/data/mysqldb &>/dev/null
cp -f /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf 
sed -i 's/^# basedir.*/basedir=\/usr\/local\/mysql/g' /etc/my.cnf
sed -i 's/^# datadir.*/datadir=\/data\/mysqldb/g' /etc/my.cnf
sed -i 's/^# socket.*/socket= \/tmp\/mysql.sock/g' /etc/my.cnf
cp -f /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
echo export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH >> /etc/profile
source /etc/profile
chkconfig --add mysqld &>/dev/null
chkconfig mysqld on &>/dev/null


%preun
chkconfig --del mysqld &>/dev/null
rm -rf /etc/init.d/mysqld &>/dev/null

%postun 
userdel -r mysql &>/dev/null
rm -fr /data/mysqldb &>/dev/null
rm -fr /usr/local/mysql &>/dev/null

%files
%defattr(-,mysql,mysql,-)
/usr/local/mysql/bin
/usr/local/mysql/data
/usr/local/mysql/include
/usr/local/mysql/lib
/usr/local/mysql/scripts
/usr/local/mysql/share
/usr/local/mysql/support-files
/usr/local/mysql/README
/usr/local/mysql/docs
/usr/local/mysql/man
%exclude /usr/local/mysql/COPYING
%exclude /usr/local/mysql/mysql-test 
%exclude /usr/local/mysql/sql-bench


%changelog
4、安裝打包編譯須要的軟件

一、安裝編譯所須要的軟件sql

[root@alisql ~]# yum install gcc gcc-c++ ncurses-devel perl -y

二、安裝cmake軟件(點此下載bash

將cmake源碼包上傳到家目錄進行解壓 app

[root@alisql ~]# tar -xf cmake-2.8.8.tar.gz 
[root@alisql ~]# cd cmake-2.8.8
[root@alisql cmake-2.8.8]# ./configure 
[root@alisql cmake-2.8.8]# make && make install

三、安裝bisonsocket

[root@alisql ~]# yum install bison -y

5、在rpmbuild/SPECS目錄下執行打包編譯

[root@alisql SPECS]# rpmbuild -bb alisql.spec

等待軟件打包成功,此時會在rpmbuild/RPMS/x86_64文件夾下生成rpm軟件包。post

參考文章

一、http://blog.chinaunix.net/uid-23069658-id-3944462.html

二、http://laoguang.blog.51cto.com/6013350/1103628

三、http://blog.csdn.net/kouyanqiu/article/details/53103249

相關文章
相關標籤/搜索