系统:Centos 7.2
1、安装依赖包
yum install make gcc rpm-build rpmdevtools -y yum install make cmake gcc gcc-c++ bison libaio ncurses-devel perl perl-DBI perl-DBD-MySQL perl-Time-HiRes readline-devel numactl zlib-devel curldevel
2、rpm工具相关路径
mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} [root@A01-R21-I102-44-A000324 soft]# cd /root/rpmbuild/ [root@A01-R21-I102-44-A000324 rpmbuild]# ll total 0 drwxr-xr-x 2 root root 6 Aug 29 14:03 BUILD drwxr-xr-x 2 root root 6 Aug 29 14:03 RPMS drwxr-xr-x 2 root root 6 Aug 29 14:03 SOURCES drwxr-xr-x 2 root root 6 Aug 29 14:03 SPECS drwxr-xr-x 2 root root 6 Aug 29 14:03 SRPMS
3、MySQL 源码包
将MySQL源码包拷贝到my.cnf文件也要拷贝放到 /root/rpmbuild/SOURCES 目录下
[root@A01-R21-I102-44-A000324 SOURCES]# pwd /root/rpmbuild/SOURCES [root@A01-R21-I102-44-A000324 SOURCES]# ll total 52056 -rw-r--r-- 1 root root 3702 Aug 29 14:08 my.cnf -rw-r--r-- 1 root root 53298645 Aug 29 14:07 mysql-boost-5.7.44.tar.gz
4、boost依赖包
将boost包拷贝到 /root/rpmbuild/BUILD 目录下,并进行解压 (源码包中的boost解压后才能用,即手动安装时才不需要单独下载)
[root@A01-R21-I102-44-A000324 BUILD]# pwd /root/rpmbuild/BUILD [root@A01-R21-I102-44-A000324 BUILD]# ll total 81756 drwx------ 8 501 20 4096 Aug 12 2015 boost_1_59_0 -rw-r--r-- 1 root root 83709983 Aug 29 14:10 boost_1_59_0.tar.gz
5、spec文件
在路径 /root/rpmbuild/SPECS 下创建spec配置文件
[root@A01-R21-I102-44-A000324 SPECS]# pwd /root/rpmbuild/SPECS [root@A01-R21-I102-44-A000324 SPECS]# cat mysql.5.7.44.spec Name: mysql Version: 5.7.44 Release: 1%{?dist} License: GPL URL: http://downloads.mysql.com/archives/get/file/mysql-5.7.44.tar.gz Group: applications/database Source: %{name}-boost-%{version}.tar.gz BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) BuildRequires: cmake Packager: [email protected] Autoreq: no prefix: /export/servers/mysql Summary: MySQL 5.7.44 %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. %define MYSQL_USER mysql %define MYSQL_GROUP mysql # 准备构建环境的脚步,通常用于解压源代码 %prep %setup -n mysql-%{version} # 构建软件包脚本,通常用于编译源代码 %build cmake \ -DCMAKE_INSTALL_PREFIX=/export/servers/mysql \ -DMYSQL_DATADIR=/export/data/mysql/data \ -DSYSCONFDIR=/export/servers/mysql/etc \ -DMYSQL_UNIX_ADDR=/export/data/mysql/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8mb4 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DMYSQL_TCP_PORT=3358 \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST=../boost_1_59_0 make -j `cat /proc/cpuinfo | grep processor| wc -l` # 安装软件包脚本 %install rm -rf %{buildroot} make install DESTDIR=%{buildroot} cp %{_sourcedir}/my.cnf $RPM_BUILD_ROOT%{prefix}/ # 安装前执行脚本 %pre groupadd mysql useradd -g mysql -s /bin/nologin -M mysql >/dev/null 2>&1 mkdir -p /export/servers/mysql/etc mkdir -p /export/data/mysql/data mkdir -p /export/data/mysql/dumps mkdir -p /export/data/mysql/log mkdir -p /export/data/mysql/tmp mkdir -p /export/data/mysql/undo chown -R mysql:mysql /export/data/mysql # 安装后执行脚本 %post /bin/cp %{prefix}/support-files/mysql.server /etc/init.d/mysql /bin/mv %{prefix}/my.cnf /export/servers/mysql/etc/my.cnf chkconfig mysql on %{prefix}/bin/mysqld --defaults-file=/export/servers/mysql/etc/my.cnf --initialize-insecure --user=mysql service mysql start echo "export PATH=$PATH:/export/servers/mysql/bin;" >> /etc/profile source /etc/profile # 卸载前执行脚本 %preun service mysql stop chkconfig --del mysql userdel -r mysql >/dev/null 2>&1 rm -rf %{prefix} >/dev/null 2>&1 rm -rf /export/data/mysql >/dev/null 2>&1 rm -rf /etc/init.d/mysql >/dev/null 2>&1 %files %defattr(-, %{MYSQL_USER}, %{MYSQL_GROUP}) %attr(755, %{MYSQL_USER}, %{MYSQL_GROUP}) %{prefix}/* %changelog
上述配置文件对应的rpm包,在centos7上安装卸载都ok,配置文件中关于设置mysql服务和开机启动相关操作,也可以参考下面
# 复制服务脚本 cp /export/servers/mysql/support-files/mysql.server /etc/init.d/mysql # 添加此服务到系统服务 chkconfig --add mysql # 添加服务后,就可以使用systemctl命令进行管理了 # 启动服务 systemctl start mysql # 停止服务 systemctl stop mysql # 设置服务为开机自启动 systemctl enable mysql # 查看服务运行状态 systemctl status mysql
6 打包
cd /root rpmbuild -bb rpmbuild/SPECS/mysql.5.7.44.spec # 打包完毕,会在RMPS目录下看到2个rpm包 [root@A01-R21-I102-44-A000324 x86_64]# pwd /root/rpmbuild/RPMS/x86_64 [root@A01-R21-I102-44-A000324 x86_64]# ll total 232408 -rw-r--r-- 1 root root 75295324 Aug 29 15:04 mysql-5.7.44-1.el7.centos.x86_64.rpm -rw-r--r-- 1 root root 162688444 Aug 29 15:05 mysql-debuginfo-5.7.44-1.el7.centos.x86_64.rpm
标签:Centos,5.7,--,RPM,44,rpmbuild,export,mysql,root From: https://www.cnblogs.com/broadway/p/18390163