有过MySQL运维的人应该都清楚,线上的MySQL一般都采用源码编译,因为这样才可以根据企业的各自需要选择要编译的功能,虽然MySQL的源码编译挺简单的,但是试想一下,如果你有几百台服务器同时要安装MySQL,难道你还一台台去手动编译、编写配置文件吗?这显然太低效了,本文讨论MySQL的自动化安装部署。
--------------------------------------分割线 --------------------------------------
Ubuntu 14.04下安装MySQL
Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL
Ubuntu 12.04 LTS 构建高可用分布式 MySQL 集群
Ubuntu 12.04下源代码安装MySQL5.6以及Python-MySQLdb
--------------------------------------分割线 --------------------------------------
1、制作符合自己需求的RPM包
我们要根据MySQL的源码编译符合企业需求的RPM包,源码获取命令如下:
wget
tar -zxvf mysql-5.6.16.tar.gz
cd mysql-5.6.16
mkdir rpm
cd rpm
在上面我们获取了源码,并在源码主目录下创建rpm目录,接着我们在该目录下创建mysql.spec文件:
Name: mysql
Version:5.6.16
Release: guahao
License: GPL
URL:
Group: applications/database
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: cmake
Packager: zhuxj@guahao.com
Autoreq: no
prefix: /opt/mysql
Summary: MySQL 5.6.16
%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
%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
%post
ln -s %{prefix}/lib %{prefix}/lib64
%preun
%changelog
有了这个spec文件之后,就可以执行如下命令生成我们自己的RPM包:
rpmbuild -bb ./mysql.spec