欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

制作MySQL RPM安装包Spec

程序员文章站 2022-05-31 21:45:41
适用环境: 数据库版本:MySQL 5.7.26 操作系统:CentOS 7 制作思路: 将数据库初始化和配置工作放到安装脚本中方便定制: 1、打包MySQL应用目录 2、不自动生成配置文件 3、不自动生成数据目录 4、不自动初始化数据 Spec代码: # # # MySQL参数配置 # mysql ......

适用环境:

数据库版本:mysql 5.7.26
操作系统:centos 7 

 

制作思路:

将数据库初始化和配置工作放到安装脚本中方便定制:
1、打包mysql应用目录
2、不自动生成配置文件
3、不自动生成数据目录
4、不自动初始化数据

 

spec代码:

# ========================================= #
# mysql参数配置
# mysql源码路径
# 源码包版本
%global src_base              mysql
%global version                  5.7.26
%global src_dir               %{src_base}-%{version}
%global cmake_bin              /home/rpmbuilder/cmake-3.16.2-linux-x86_64/bin/cmake

name:        %{src_base}
version:    %{version}

# 安装版本
release:    1

# 安装包介绍
summary:    mysql server        

# 遵循协议
license:    gplv2

# 打包需要
# buildrequires:  cmake /sbin/useradd /sbin/groupadd /bin/bash /bin/sh /bin/chown

# 安装需要
# requires:    ncurses ncurses-devel pcre numactl-libs numactl bison libaio libaio-devel

# 安装的虚拟环境,在rpmbuild/buildroot目录下
buildroot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}-xxxxxx)


# sorce信息
source0:        %{name}-%{version}.tar.gz
source10:       boost_1_59_0.tar.bz2
source90:       filter-provides.sh
source91:       filter-requires.sh



%if 0%{?rhel} > 6
# for rpm => 4.9 only: https://fedoraproject.org/wiki/packaging:autoprovidesandrequiresfiltering
%global __requires_exclude ^perl\\((gd|hostnames|lib::mtr|lib::v1|mtr_|my::)
%global __provides_exclude_from ^(/usr/share/(mysql|mysql-test)/.*|%{_libdir}/mysql/plugin/.*\\.so)$
%else
# https://fedoraproject.org/wiki/epel:packaging#generic_filtering_on_epel6
%global __perl_provides %{source90}
%global __perl_requires %{source91}
%endif


# mysql安装目录
%define     mysql_server_path     /data0/software/mysql/server
# mysql数据目录
%define     mysql_data_path     /data0/software/mysql/data

%define     mysql_user             mysql 
%define     mysql_group         mysql 

# mysql配置文件目录
%define        mysql_conf_path        /data0/software/mysql/server/etc/my.cnf

# mysql描述
%description
the mysql(tm) software delivers a very fast, multi-threaded, multi-user, 
and robust sql (structured query language) database server. mysql server 
is intended for mission-critical, heavy-load production systems as well 
as for embedding into mass-deployed software. 
 
 
 
# ========================================= #
# 环境准备
%prep
rm -rf $rpm_build_root/%{name}-%{version}
# setup把boost和mysql压缩包解压到下面路径
# ./rpmbuild/build/mysql-5.7.28/mysql-5.7.28/
# ./rpmbuild/build/mysql-5.7.28/boost_1_59_0/

%setup -q -t -a 0 -a 10 -c -n %{src_dir}

groupadd %{mysql_group} >/dev/null 2>&1 || :
useradd -g %{mysql_group} %{mysql_user} -s /bin/nologin >/dev/null 2>&1 || :


# ========================================= #
# 编译
%build
%{cmake_bin} ./%{src_dir} \
-dcmake_install_prefix=%{mysql_server_path} \
-dmysql_datadir=%{mysql_data_path} \
-dsysconfdir=%{mysql_server_path}/etc \
-ddefault_charset=utf8 \
-ddefault_collation=utf8_general_ci \
-dmysql_unix_addr=%{mysql_data_path}/tmp/mysql.sock \
-dmysql_tcp_port=3306 \
-dmysql_user=mysql \
-dwith_myisam_storage_engine=1 \
-dwith_innobase_storage_engine=1 \
-dwith_archive_storage_engine=1 \
-dwith_blackhole_storage_engine=1 \
-denable_downloads=1 \
-ddownload_boost=1 \
-dwith_boost=.

make -j3 %{?_smp_mflags}

# ========================================= #
# 安装
%install
rm -rf %{buildroot}
make destdir=%{buildroot} install

# ========================================= #
# 制作rpm包
%files 
%defattr(-, %{mysql_user}, %{mysql_group}) 
%attr(755, %{mysql_user}, %{mysql_group}) %{mysql_server_path}/* 

%changelog