自动化部署MySQL 5.6 步骤
准备工作
首先需要搭建ftpserver
yum install vsftpd
service vsftpd start
这样ftp服务就起来了,这里只是简单的使用,所以没有使用配置文件。这样我们只要将需要的文件置于/var/ftp/pub/文件夹下,匿名用户就可以copy文件到本机了。
安装rpm-build
build需要用到rpm-build,这里简单安装即可
yum install rpm-build
下面开始rpm打包
mget
cd /u01/mysql-5.6.21
mkdir rpm
cd rpm
修改mysql.spec
Name: mysql-rpm
Version:5.6.21
Release: renfengjun
License: GPL
URL:
Group: applications/database
BuildRoot:%{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: cmake
Packager: dexter.ren.jl@gmail.com
Autoreq: no
prefix: /u01/mysql
Summary: mysql-5.6.21.tar.gz
%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-loadproduction systems as well
as for embedding into mass-deployed software.
%define MYSQL_USER mysql
%define MYSQL_GROUP mysql
%define __os_install_post %{nil}
%build
cd $OLDPWD/../
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 \
-DWITH_EXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE:BOOL=ON \
-DWITH_EMBEDDED_SERVER=0 \
-DINSTALL_LAYOUT:STRING=STANDALONE \
-DCOMMUNITY_BUILD:BOOL=ON \
-DMYSQL_SERVER_SUFFIX='-r5436';
make -j `cat /proc/cpuinfo | grep processor| wc-l`
%install
cd $OLDPWD/../
make DESTDIR=$RPM_BUILD_ROOT install
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-, %{MYSQL_USER}, %{MYSQL_GROUP})
%attr(755, %{MYSQL_USER}, %{MYSQL_GROUP})%{prefix}/*
%pre
mkdir -p /u01/mysql/data
mkdir -p /u01/mysql/run
mkdir -p /u01/mysql/log
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql /u01/mysql/data
chown -R mysql:mysql /u01/mysql/log
chown -R mysql:mysql /u01/mysql/run
echo "exportPATH=$PATH:/u01/mysql/bin" >> /home/mysql/.bash_profile
%post
ln -s %{prefix}/lib %{prefix}/lib64
cp /u01/mysql/support-files/mysql.server/etc/init.d/mysql
chkconfig mysql on
%preun
chkconfig --del mysql
rm -rf /u01
userdel mysql
rm -rf /var/spool/mail/mysql
rm -rf /etc/init.d/mysql
rm -rf /home/mysql
%changelog
执行打包命令
rpmbuild -bb ./mysql.spec
输出: