centos6下mysql5.7.13制作rpm包
一、安装依赖
yum -y install gperf zlib-devel time ncurses-devel gcc* cmake libaio-devel rpm-build
二、创建打包的用户和目录
## 创建打包用户 ##
useradd rpmbuilder
## 切换到 rpmbuilder用户 ##
su rpmbuilder
## 使用rpmbuild创建相关文件夹 ##
rpmbuild ~
三、相关脚本
1、alterpassword.sh重置密码脚本
#/bin/bash mysqlpasswd=`tail -n 1 /tmp/mysqllog | awk -F":" '{print $NF}'|awk '{gsub(/^\s+|\s+$/, "");print}'` /usr/local/mysql/bin/mysqladmin -uroot -p$mysqlpasswd password 'mysql#147' >/dev/null 2>&1
2、my.cnf配置文件
[mysqld] port=3307 datadir=/data/mysql socket=/var/run/mysqld/mysql.sock table_open_cache=128 binlog_cache_size=1M max_heap_table_size=8M tmp_table_size=16M read_buffer_size=2M [mysqld_safe] log-error=/var/log/mysql/mysqld.log pid-file=/var/run/mysqld/mysqld.pid symbolic-links=0 [client] default-character-set=utf8 socket=/var/run/mysqld/mysql.sock [mysql] default-character-set=utf8 socket=/var/run/mysqld/mysql.sock
3、source_profile.sh环境变量生效脚本
#!/bin/bash
source /etc/profile
4、mysql.spec剧本
Name: mysql Version: 5.7.13 Release: 1%{?dist} License: GPL URL: http://downloads.mysql.com/archives/get/file/mysql-5.7.13.tar.gz Group: applications/database Source: mysql-5.7.13.tar.gz BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) BuildRequires: cmake Packager: hrg@zbj.com Autoreq: no #Source: %{name}-%{version}.tar.gz prefix: /usr/local/mysql Summary: MySQL 5.7.13 %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 #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 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/data/mysql \ -DSYSCONFDIR=/etc \ -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysqld.sock \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DENABLED_PROFILING=1 \ -DMYSQL_TCP_PORT=3307 \ -DWITH_DEBUG=0 \ -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}/ cp %{_sourcedir}/source_profile.sh $RPM_BUILD_ROOT%{prefix}/ cp %{_sourcedir}/alterpassword.sh $RPM_BUILD_ROOT%{prefix}/ %pre mkdir -p /data/mysql useradd -s /bin/nologin -M mysql >/dev/null 2>&1 %post /bin/cp %{prefix}/support-files/mysql.server /etc/init.d/mysqld mkdir -p /data/mysql && chown mysql.mysql /data/mysql; mkdir -p /var/log/mysql && touch /var/log/mysql/mysqld.log && chown mysql.mysql /var/log/mysql; mkdir -p /var/run/mysqld && touch /var/run/mysqld/mysql.sock && touch /var/run/mysqld/mysqld.pid && chown mysql.mysql /var/run/mysqld; rm -rf /etc/my.conf rm -rf /etc/my.cnf.d/ /bin/cp %{prefix}/my.cnf %{_sysconfdir}/my.cnf echo "export PATH=.:\$PATH:/usr/local/mysql/bin;" >> /etc/profile source /usr/local/mysql/source_profile.sh rm -rf /usr/local/mysql/source_profile.sh chkconfig mysqld on %{prefix}/bin/mysqld --initialize --basedir=%{prefix} --datadir=/data/mysql --user=mysql &>/tmp/mysqllog chown -R mysql:mysql /usr/local/mysql chown -R mysql:mysql /data/mysql service mysqld start /bin/bash /usr/local/mysql/alterpassword.sh rm -rf /usr/local/mysql/alterpassword.sh echo """ 1、datadir:/data/mysql 2、errlogdir:/var/log/mysql/mysqld.log 3、default password:mysql#147 """ %preun service mysql stop chkconfig --del mysql userdel -r mysql >/dev/null 2>&1 rm -rf /usr/local/mysql >/dev/null 2>&1 rm -rf /data/mysql >/dev/null 2>&1 rm -rf /etc/init.d/mysqld >/dev/null 2>&1 %files %defattr(-, %{MYSQL_USER}, %{MYSQL_GROUP}) %attr(755, %{MYSQL_USER}, %{MYSQL_GROUP}) %{prefix}/* %changelog
四、上传制作rpm相关素材
1、BUILD目录素材
上传解压后的boost_1_59_0和mysql-5.7.13到BUILD目录
2、SOURCES目录素材
[root@linux SOURCES]# pwd /home/hrg/rpmbuild/SOURCES [root@linux SOURCES]# ll total 49348 -rw-r--r-- 1 hrg hrg 205 Aug 27 13:12 alterpassword.sh -rw-rw-r-- 1 hrg hrg 419 Aug 26 19:05 my.cnf -rw-r--r-- 1 hrg hrg 50516207 Aug 21 15:39 mysql-5.7.13.tar.gz -rw-r--r-- 1 hrg hrg 32 Aug 27 12:47 source_profile.sh
3、SPECS素材
[root@linux SPECS]# pwd /home/hrg/rpmbuild/SPECS [root@linux SPECS]# ll total 4 -rw-rw-r-- 1 hrg hrg 3315 Aug 27 13:18 mysql.spec
五、制作RPM包
cd /home/rpmbuilder/rpmbuild/SPECS
rpmbuild -bb mysql.spec
作者:凉生墨客
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。