MySQL Automated installation

Source: Internet
Author: User
Tags rpmbuild

MySQL installation generally uses RPM or the source code installation method.
The advantages of RPM installation are fast and convenient. The disadvantage is that you cannot customize the installation directory. If you need to adjust the location of data files and log files, some manual adjustments are required.
The advantage of source installation is that you can customize the installation directory, the drawback is that the compilation time is long, the process is complex

In fact, there is a way to customize the RPM package.
It is equivalent to the installation of the source code to customize a RPM package. Once packaged, can be used multiple times
It can customize the path, automatically create account during installation, automatically configure the service, environment variables and so on, and the installation process is quick and simple.
In a large-scale deployment scenario, the advantages are outstanding.
The disadvantage is to make RPM packages, you need to write your own Red Hat definition of the spec file. The learning curve written by spec file is rather steep.

Requirements are as follows
1. Create user MySQL
2. Database software installed in the/home/mysql/mysql-5.6.14 directory
3. Data files are stored in the/data directory
4. Configure the service to start automatically

First, download Rpmbuild
Yum Install Rpm-build-y
It is a tool used by Red Hat to play RPM packages.
After installation, restart the computer, you can see the following folder in the/root/rpmbuild directory

The process of packaging this tool is roughly the following,
Writing spec Specifies the process of packaging
Place the source tarball in the sources directory,
Unzip the source code to the build directory and execute the make command
Place the results of make install in the BuildRoot directory.
Finally, the buildroot compiled binary files are made into RPM packages.
And you can specify the commands that are executed before the RPM installation, after installation, and so on.

First, download the source package
Http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.14.tar.gz
and copy it to the specified directory
/root/rpmbuild/sources/mysql-5.6.14.tar.gz

Install the dependency packages required to compile MySQL
Yum-y install make gcc-c++ cmake bison-devel ncurses-devel

Writing spec Scripts
Vim Mysql.spec

Name:mysql
version:5.6.14
Release:1%{?dist}
summary:mysql-5.6.14 RPM

Group:applications/database
License:gpl
Url:http://www.mysql.com
Source0:mysql-5.6.14.tar.gz
BuildRoot:% (Mktemp-ud%{_tmppath}/%{name}-%{version}-%{release}-xxxxxx)
Buildrequires:cmake

Autoreqprov:no
%description
MySQL 5.6.14

%define Mysql_user MYSQL
%define Mysql_group MYSQL

%prep
%setup-n Mysql-%{version}

%build
CMake \
-dcmake_install_prefix=/home/mysql/mysql-5.6.14 \
-dmysql_datadir=/data \
-DSYSCONFDIR=/ETC \
-dwith_myisam_storage_engine=1 \
-dwith_innobase_storage_engine=1 \
-dwith_memory_storage_engine=1 \
-dwith_readline=1 \
-dmysql_unix_addr=/data/mysql.sock \
-dmysql_tcp_port=3306 \
-denabled_local_infile=1 \
-dwith_partition_storage_engine=1 \
-dextra_charsets=all \
-ddefault_charset=utf8 \
-ddefault_collation=utf8_general_ci
Make-j ' Cat/proc/cpuinfo | grep processor| Wc-l '


%install
RM-RF%{buildroot}
Make install Destdir=%{buildroot}


%pre
Mkdir-p/data
Useradd-m-s/bin/bash MySQL
Chown-r Mysql:mysql/data


%post
/home/mysql/mysql-5.6.14/scripts/mysql_install_db--basedir=/home/mysql/mysql-5.6.14--datadir=/data--user=mysql
Cp/home/mysql/mysql-5.6.14/support-files/mysql.server/etc/init.d/mysql
Chkconfig MySQL on
Service MySQL Start
echo "Export path=.: $PATH:/home/mysql/mysql-5.6.14/bin;" >>/HOME/MYSQL/.BASHRC
Source/home/mysql/.bashrc

%preun
Service MySQL Stop
Chkconfig--del MySQL
Userdel MySQL
Rm-rf/home/mysql
Rm-rf/data
Rm-rf/etc/init.d/mysql

%clean
RM-RF%{buildroot}


%files
%defattr (-,%{mysql_user},%{mysql_group})
%attr (755,%{mysql_user},%{mysql_group})/home/mysql/mysql-5.6.14/*


%changelog

Please refer to the function of each segment of this script.
http://machael.blog.51cto.com/829462/213477

which
Source0:mysql-5.6.14.tar.gz
This compressed file needs to be placed in the specified directory (/root/rpmbuild/sources)
This file will be found in the specified directory when auto-extracting.


Autoreqprov:no
This parameter must be set, otherwise it will show the missing of the dependent package when it is installed. Actually, it's not needed.

%setup-n Mysql-%{version}
After extracting the source package, it enters the directory execution build, which by default is the directory that is spliced according to%{name} and%{version}.
In MySQL, for example, the name written in spec is mysql,version to 5.6.14
Then it will go into the MySQL-5.6.14 directory,
But the directory after the source package decompression is mysql-5.6.14 (lowercase)
So in Setup This section uses the-n parameter to match the directory. (That is, the default settings do not work, you need to match the directory)

Make-j ' Cat/proc/cpuinfo | grep processor| Wc-l '
Check that the computer has several cores and then multithreaded compilation

The process of this script is like this
First unpack the source package
%prep
%setup-n Mysql-%{version}

Then execute the%build process, make compile

Then execute%install
The compiled code is actually installed once,
The directory it installs is/root/rpmbuild/buildroot/mysql-5.6.14-1.el6.i386/home/mysql/mysql-5.6.14/
Because the installation directory that we specified is/home/mysql/mysql-5.6.14/, it is equivalent to installing it in a sandbox.
It will make the files after installation in the sandbox into RPM packages

%files is specifying which sandbox files to enter into the RPM package
%files The specified file is a relative path, the absolute path should be%{buildroot}/home/mysql/mysql-5.6.14
The default%{buildroot} is/root/rpmbuild/buildroot/mysql-5.6.14-1.el6.i386/

This%{buildroot} is set by the buildroot of the spec file.
BuildRoot:% (Mktemp-ud%{_tmppath}/%{name}-%{version}-%{release}-xxxxxx)

%pre is the command executed before RPM installation
Here is the main creation of data files directory and account
Mkdir-p/data
Useradd-m-s/bin/bash MySQL
Chown-r Mysql:mysql/data

%post is a command that is executed after RPM installation
This is mainly to create a database instance, configure the service, configure the environment variables
/home/mysql/mysql-5.6.14/scripts/mysql_install_db--basedir=/home/mysql/mysql-5.6.14--datadir=/data--user=mysql
Cp/home/mysql/mysql-5.6.14/support-files/mysql.server/etc/init.d/mysql
Chkconfig MySQL on
Service MySQL Start
echo "Export path=.: $PATH:/home/mysql/mysql-5.6.14/bin;" >>/HOME/MYSQL/.BASHRC
Source/home/mysql/.bashrc

%preun is the command that unloads the RPM package and is used primarily to clean up
Service MySQL Stop
Chkconfig--del MySQL
Userdel MySQL
Rm-rf/home/mysql
Rm-rf/data
Rm-rf/etc/init.d/mysql

In fact, writing a spec file is essentially writing a callback function, Rpmbuild, based on the spec's callback function, generates a shell script, which is the process of executing the shell script.

Custom RPM installation packages for scenarios where large-scale automated deployments are available
Because it can
Custom configuration file (place the configuration file on FTP or HTTP, download the configuration file in the%post section and place it in/etc)
Custom installation directories and data files, directory of log files (different mount points of the production system, the underlying may be different physical devices)
Automatically create accounts, configure service and environment variables

These features are negligible in scale,
For example, to research and development and test installation, people still think you have a problem. Obviously a rpm can be done, you are still so complex, not smelly?
Production environment for a library to run for several years, and then, when the RPM estimates have forgotten where to put ...
But once the scale comes up, a day needs to install 10 units of 8, the advantages of this automated installation is revealed



Reference:
Source installation MySQL
Http://www.cnblogs.com/xiongpq/p/3384681.html

Rpmbuild Spec File Detailed
http://machael.blog.51cto.com/829462/213477
Http://www.worldhello.net/2011/04/02/2405.html

Explanation of Autoreqprov parameters
http://blog.csdn.net/peng_zhou/article/details/3530230

MySQL Automated installation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.