Installation of MySQL automated O & M

Source: Internet
Author: User
Tags rpmbuild

Installation of MySQL automated O & M

MySQL is usually installed using RPM or source code.
RPM installation is fast and convenient. the disadvantage is that the installation directory cannot be customized. if you need to adjust the storage location of data files and log files, you also need to manually adjust the source code installation to customize the installation directory. The disadvantage is that the compilation time is long and the process is complex.

In fact, there is another way to customize the RPM package.
It is equivalent to using the source code to install a customized RPM package. One package can be used multiple times.
It can customize the path, automatically create an account during installation, automatically configure services, environment variables, and so on, and the installation process is fast and simple.
In large-scale deployment scenarios, the advantages are outstanding.
The disadvantage is that when creating an RPM package, you need to write the spec file defined by Red Hat. The learning curve of the spec file is steep.

The requirements are as follows:
1. Create a user mysql
2. database software installed in/home/mysql/mysql-5.6.14 directory
3. Store data files in the/data Directory
4. Configure the service and start it automatically

First, download rpmbuild
Yum install rpm-build-y
It is a tool used by Red Hat to pack RPM.
After the installation, restart the computer. The/root/rpmbuild directory contains the following folders:

The tool packaging process is roughly as follows,
Specify the spec packaging process.
Put the source code compressed package under the SOURCES directory,
Decompress the source code to the BUILD directory and execute the make command.
Put the result of make install in the BUILDROOT directory,
Finally, compile the compiled binary file under BUILDROOT into an RPM package.
In addition, you can specify the commands executed during the process, such as detaching and executing, before and after RPM installation.

First, download the source code 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 dependent packages required for MySQL Compilation
Yum-y install make gcc-c ++ cmake bison-devel ncurses-devel

Write spec script
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

Where
Source0: mysql-5.6.14.tar.gz
This compressed file needs to be placed in the specified directory (/root/rpmbuild/SOURCES)
During automatic decompression, the file will be found in the specified directory


AutoReqProv: no
This parameter must be set. Otherwise, the missing dependency package is displayed during installation.

% Setup-n mysql-% {version}
After extracting the source code package, you will go to the directory to execute build. By default, it is based on the directory that is spliced by % {name} and % {version.
Take MySQL as an example. The name written in spec is MySQL, and the version is 5.6.14.
Then it will go into the MySQL-5.6.14 directory,
But the directory after the source package is extracted is mysql-5.6.14 (lower case)
Therefore, use the-n parameter in the setup section to match the directory (that is, the default setting is not working and you need to match the directory yourself)

Make-j 'cat/proc/cpuinfo | grep processor | wc-l'
Check that the computer has several cores and then multi-thread Compilation

The script process is as follows:
First extract the source code package
% Prep
% Setup-n mysql-% {version}

Then execute the % build process and make the compilation.

Then execute % install
Install the compiled code 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 we specified is/home/mysql/mysql-5.6.14/, it is equivalent to installing it again in a sandbox.
It will pack the files installed in the sandbox into an RPM package.

% Files indicates which files in the sandbox are imported into the RPM package.
% Files the specified file is a relative path and the absolute path should be % {buildroot}/home/mysql/mysql-5.6.14
By default, % {buildroot} is/root/rpmbuild/BUILDROOT/MySQL-5.6.14-1.el6.i386/

This % {buildroot} is set by BuildRoot of the spec file.
BuildRoot: % (mktemp-ud % {_ tmppath}/% {name}-% {version}-% {release}-XXXXXX)

% Pre is the command executed before RPM Installation
Here, we mainly create directories and accounts for data files.
Mkdir-p/data
Useradd-m-s/bin/bash mysql
Chown-R mysql: mysql/data

% Post is the command executed after RPM installation.
Here we mainly create database instances, configure services, and configure 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 for uninstalling the RPM package and is mainly used for cleaning
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 generates a Shell script based on the spec callback function. The packaging process is the process of executing the Shell script.

The customized RPM installation package can meet the needs of large-scale automated deployment.
Because it can
Custom configuration file (put the configuration file on ftp or http and download the configuration file in the % post segment under/etc)
Customize the installation directory, data file, and log file directory (different mount points in the production system may be different physical devices at the underlying layer)
Automatically create accounts and configure services and environment variables

These features are small in size,
For example, for R & D and testing and installation, people think you have something wrong. Obviously, an rpm can be done, and you are still so complicated, isn't it stupid?
I have installed a database in the production environment for several years. When I installed it again, I guess I forgot where to put this RPM...
However, once the scale is up, ten or eight servers need to be installed in one day, the advantages of this automated installation will be apparent.

-------------------------------------- Split line --------------------------------------

Install MySQL in Ubuntu 14.04

MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF

Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL

Build a MySQL Master/Slave server in Ubuntu 14.04

Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS

Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04

MySQL-5.5.38 universal binary Installation

-------------------------------------- Split line --------------------------------------

This article permanently updates the link address:

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.