Use Ruby's FPM module for binary mysql RPM package creation for one-click installation

Source: Internet
Author: User
Tags fpm install perl

With the development of the Internet, some Internet enterprises, even the traditional enterprise servers are more and more. One of the challenges that will be faced is automated operations management. Suppose we need to automate the deployment of a lot of applications, and these applications are complex, many processes, and require source installation. Even if you can do this with automation, it's pretty cumbersome to configure. So now there is a technology can be installed in the source code of the application package as RPM package, or Deb package, complete one-click installation, this method is used to be a powerful

There are a lot of packaging methods for RPM packages, and here's a relatively simple way to do this using Ruby's FPM module. Low learning cost, convenient, fast


experimental Environment : Minimized installation of CentOS7 system

Achieving the goal : package MySQL for binary deployment as RPM package for one-click installation


Ruby Environment Preparation:

Installing the ruby Environment

Yum-y Install RubyGems ruby-devel rubygems-devel

Add Taobao gem Source, delete default source (Install module fast)

View Gem Source

Gem Sources-l

Add a source and delete the default

Gem sources--add https://gems.ruby-china.org/--remove https://rubygems.org/

Update Gem Software

Gem Install json_puregem update--system

Installing the FPM Module

To view installed modules

Gem List

Installing the FPM Module

Gem Install FPM

Specify the version number when installing the module, and the output details

Cases:

Gem Install json-v 1.8.3–v

Small V for the specified version number, large v output detailed installation information


FPM Common Options Introduction

-C #指定fpm去哪个目录查找打包的文件-s #指定源的类型, such as Dir-t #指定目标类型, such as RPM package, or Deb package--vendor #指定包的vendor名字-N #指定包的名字-V #指定包的版本号-D #指定依赖包--prefix #指定安装路径--post-install #包安装后要运行的脚本, equivalent to--before-install- -pre-install #包安装前要运行的脚本, equivalent to--after-install--post-uninstall #包卸载后要运行的脚本, is equivalent to--before-remove--pre-uninstall #包卸载前要运 Line of script, equivalent to--after-remove

Binary installation MySQL5.6 steps

Create a MySQL user group

Groupadd mysqluseradd-m-G mysql-s/sbin/nologin MySQL

Create MySQL Data Catalog

Mkdir-p/data/mysql

Unpack the binary package and copy it to/usr/local/mysql

Tar-xvzf MYSQL-5.6.31-LINUX-GLIBC2.5-X86_64.TAR.GZMV Mysql-5.6.31-linux-glibc2.5-x86_64/usr/local/mysql

Set permissions

Chown-r Mysql:mysql/data/mysqlchown-r Mysql:mysql/usr/local/mysql

To initialize and install a dependent package:

Yum-y Install Perl-module-install
/usr/local/mysql/scripts/mysql_install_db--user=mysql--datadir=/data/mysql

Modifying a configuration file

Sed-i '/^datadir=/[email protected][email protected]=/data/[email protected] '/usr/local/mysql/support-files/ Mysql.server/bin/cp/usr/local/mysql/support-files/my-default.cnf/etc/my.cnf

Configure the Startup service

Ln/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqldchkconfig--add mysqld

Configuring Environment variables

echo "Export path= $PATH:/usr/local/mysql/bin" >/etc/profile.d/mysql.shsource/etc/profile.d/mysql.sh

Making RPM schemes

    1. Specify RPM to package the directory as/usr/local/mysql

    2. Specify the installation dependency package Perl-module-install

    3. Specify scripts to execute before installation: Create user groups, create directories, configure permissions

    4. Specify post-installation script execution: Initialize, modify configuration files, configure startup services, configure environment variables

    5. Specify the script to execute after uninstallation: Delete the installation directory, delete the environment variables, delete the service

Steps to make RPM package

Execute script before installation: install_mysql_post.sh

#!/bin/bashgroup=mysqluser=mysql#create group if not  existsegrep  "^ $group"  /etc/group >& /dev/nullif [ $? -ne  0 ];then    groupadd  $GROUPFI #create user if not existsegrep   "^ $user"  /etc/passwd >& /dev/nullif [ $? -ne 0 ];then     useradd -g  $group  -M -s /sbin/nologin  $userfi #create  datadir if not existsif [ ! -d /data/mysql ];then     mkdir -p /data/mysqlelse    echo  "/data/mysql dir is  exists "    exit 2fiif [ -d /usr/local/mysql ];then     echo  "/usr/local/mysql directory is exists"     exit  2fi 

Execute script after installation: install_mysql_pre.sh

#!/bin/bashhomedir=/usr/local/mysqldatadir=/data/mysql#set permissionschown-r mysql:mysql $datadirchown-R MySQL: MySQL $homedir #add my.cnf/bin/cp $homedir/support-files/my-default.cnf/etc/my.cnf#add servicechkconfig--add mysqld

Execute script after uninstallation: uninstall_mysql_pre.sh

#!/bin/bashrm-rf/usr/local/mysqlecho "Delete complete, but my.cnf and DataDir are not delete"

Execute the following command to create the RPM package

Installing a production package requires a dependency package:

Yum-y Install rpm-buildfpm-s dir-t rpm-v 5.6.31-n mysql--before-install install_mysql_post.sh--after-install instal l_mysql_pre.sh--after-remove uninstall_mysql_pre.sh-d ' Perl-module-install '/usr/local/mysql/data/mysql/etc/ init.d/mysqld/etc/profile.d/mysql.sh

Command execution is a bit long, after the completion of the current directory will be generated in the MYSQL-5.6.31-1.X86_64.RPM package, this time you can copy this package to other CENTOS7 system for testing, if it is CentOS6 system, but some dependent package is not the same, the others are the same

For some other options, such as the author, the platform and other information can find more information, use the following command to view the RPM execution script information:

RPM-QP--scripts mysql-5.6.31-1.x86_64.rpm


The introduction of the RPM package has been completed, if you like the article or blog can be collected or attention, will not regularly update some technical blog

This article is from the "Blue _ Storm" blog, make sure to keep this source http://270142877.blog.51cto.com/12869137/1954881

Use Ruby's FPM module for binary mysql RPM package creation for one-click 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.