Step 4 of automated MySQL deployment

Source: Internet
Author: User

Step 4 of automated MySQL deployment

Step 4 of automated MySQL deployment

Preparations

First, you need to build ftpserver

Yum install vsftpd

Service vsftpd start

In this way, the ftp service is up. It is simple to use, so no configuration file is used. In this way, you only need to place the required files in the/var/ftp/pub/folder, and anonymous users can copy the files to the local machine.

Install rpm-build

Rpm-build is required for build. You can simply install it here.

Yum install rpm-build

Start rpm packaging below

Mget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.21.tar.gz
Mysql-5.6.21/cd/u01/
Mkdir rpm
Cd rpm

Modify mysql. spec

Name: mysql-rpm
Version: 5.6.21
Release: renfengjun
License: GPL
URL: http://dev.mysql.com/
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
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

Run the packaging command

Rpmbuild-bb./mysql. spec

Output:

Requires (pre):/bin/sh
Requires (post):/bin/sh
Requires (preun):/bin/sh
Checking for unpackaged file (s):/usr/lib/rpm/check-files/var/tmp/mysql-rpm-5.6.21-renfengjun-root
Warning: cocould not canonicalize hostname: CentOS511
Wrote:/usr/src/RedHat/RPMS/x86_64/mysql-rpm-5.6.21-renfengjun.x86_64.rpm
Executing (% clean):/bin/sh-e/var/tmp/rpm-tmp.62530
+ Umask 022
+ Cd/usr/src/redhat/BUILD
+ Rm-rf/var/tmp/mysql-rpm-5.6.21-renfengjun-root
+ Exit 0

The generated rpm package is here:

/Usr/src/redhat/RPMS/x86_64/mysql-rpm-5.6.21-renfengjun.x86_64.rpm

Packaging data templates

When packaging, remember to close mysql. Here we have written some test data:

Mysql> select * from dexdb. t;
+ ------ + ------------ +
| Id | name |
+ ------ + ------------ +
| 1 | renfengjun |
+ ------ + ------------ +
1 row in set (0.00 sec)

Pack the data template. Remember to package ibdata1

Cd/u01/mysql/data

Tar cf data.tar ibdata1 mysql/dexdb/performance_schema/test/

Modify my. cnf

My. cnf file content:

[Mysqld_safe]
Pid-file =/u01/mysql/run/mysqld. pid
# Malloc-lib =/u01/mysql/lib/libjemalloc. so
 
[Mysql]
Port = 3306
Prompt =\\ u \\ d \\ r :\\ m :\\ s>
Default-character-set = gbk
No-auto-rehash
 
[Client]
Port = 3306
Socket =/u01/mysql/run/mysql. sock
 
[Mysqld]
# Dir
Basedir =/u01/mysql
Datadir =/u01/mysql/data
Tmpdir =/tmp
Lc_messages_dir =/u01/mysql/share
Log-error =/u01/mysql/log/alert. log
Slow_query_log_file =/u01/mysql/log/slow. log
General_log_file =/u01/mysql/log/general. log
Socket =/u01/mysql/run/mysql. sock
 
# Innodb
Innodb_data_home_dir =/u01/mysql/data
Innodb_log_group_home_dir =/u01/mysql/data
Innodb_data_file_path = ibdata1: 12 M
Innodb_buffer_pool_size = 10G
Innodb_buffer_pool_instances = 4
Innodb_log_files_in_group = 2
Innodb_log_file_size = 1G
Innodb_log_buffer_size = 200 M
Innodb_flush_log_at_trx_commit = 1
Innodb_additional_mem_pool_size = 20 M
Innodb_max_dirty_pages_pct = 60
Innodb_io_capacity = 1000
Innodb_thread_concurrency = 16
Innodb_read_io_threads = 8
Innodb_write_io_threads = 8
Innodb_open_files = 60000
Innodb_file_format = Barracuda
Innodb_file_per_table = 1
Innodb_flush_method = O_DIRECT
Innodb_change_buffering = inserts
Innodb_adaptive_flushing = 1
Innodb_old_blocks_time = 1000
Innodb_stats_on_metadata = 0
Innodb_read_ahead = 0
Innodb_use_native_aio = 0
Innodb_lock_wait_timeout = 5
Innodb_rollback_on_timeout = 0
Innodb_purge_threads = 1
Innodb_strict_mode = 1
Transaction-isolation = READ-COMMITTED
 
# Myisam
Key_buffer = 64 M
Myisam_sort_buffer_size = 64 M
Concurrent_insert = 2
Delayed_insert_timeout = 300
 
# Replication
Master-info-file =/u01/mysql/log/master.info
Relay-log =/u01/mysql/log/relaylog
Relay_log_info_file =/u01/mysql/log/relay-log.info
Relay-log-index =/u01/mysql/log/mysqld-relay-bin.index
Slave_load_tmpdir =/u01/mysql/tmp
Slave_type_conversions = "ALL_NON_LOSSY"
Slave_net_timeout = 4
Skip-slave-start
Sync_master_info = 1000
Sync_relay_log_info = 1000
 
# Binlog
Log-bin =/u01/mysql/log/mysql-bin
# Server_id = 2552763370
Binlog_cache_size = 32 K
Max_binlog_cache_size = 2G
Max_binlog_size = 500 M
Binlog-format = ROW
Sync_binlog = 1000
Log-slave-updates = 1
Expire_logs_days = 0
 
# Server
Default-storage-engine = INNODB
Character-set-server = gbk
Lower_case_table_names = 1
Skip-external-locking
Open_files_limit = 65536
Safe-user-create
Local-infile = 1
# Sqlmod = "STRICT_ALL_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE"
Performance_schema = 0
 
Log_slow_admin_statements = 1
Log_warnings = 1
Long_query_time = 1
Slow_query_log = 1
General_log = 0
 
Query_cache_type = 0
Query_cache_limit = 1 M
Query_cache_min_res_unit = 1 K
 
Table_definition_cached = 65536
# Table_cache = 65536
 
Thread_stack = 512 K
Thread _ cache_size = 256
Read_rnd_buffer_size = 128 K
Sort_buffer_size = 256 K
Join_buffer_size = 128 K
Read_buffer_size = 128 K
 
Port = 3306
Skip-name-resolve
Skip-ssl
Max_connections = 4500
Max_user_connection= 4000
Max_connect_errorrs = 65536
Max_allowed_packet = 128 M
Connect_timeout = 8
Net_read_timeout = 30
Net_write_timeout = 60
Back_log = 1024

Serverid is automatically generated in the automated installation script.

Copy the existing data.tar, my. cnf, and generated rpm packages to the ftp pub directory.

/Var/ftp/pub/

Automated installation script

Auto_install_mysql.sh:

#! /Bin/sh
Yum install-y cmake gcc g ++ bisonncurses-devel zlib
 
Ftp-n <EOF
Open 192.168.0.33
User anonymous dexter
Binary
Cd pub
Prompt
Mget *
EOF
 
Rpm-ivh mysql-rpm-5.6.21-renfengjun.x86_64.rpm
Tar-xvf data.tar-C/u01/mysql/data/
Chown-R mysql: mysql/u01/mysql/
 
Unique_id = 'date "+ % Y % m % d % M % S "'
Echo 'server _ id = '$ unique_id> my. cnf
 
Cp my. cnf/u01/mysql/

Run the remote automatic installation command

Execute remote copy (the dcli command is the script I took out from the all-in-one machine, which is written in py. In fact, it is similar to scp and can send emails if necessary)

For batch installation, use the-k option to initialize ssh.

Copy the script to a remote device

[Root @ centos511 ~] #./Dcli-l root-c192.168.0.36-f./auto_install_mysql.sh

Attackers can execute remote commands in the background.

[Root @ centos511 ~] #./Dcli-l root-c192.168.0.36/root/auto_install_mysql.sh

Output:

[[Root @ centos511 ~] #./Dcli-l root-c192.168.0.36/root/get_rpm.sh
Root@192.168.0.36's password:
192.168.0.36: Address 192.168.0.36 maps tolocalhost, but this does not map back to the address-POSSIBLE BREAK-INATTEMPT!
192.168.0.36: Loaded plugins: fastestmirror, security
192.168.0.36: Loading mirror speeds from cachedhostfile
192.168.0.36: * base: mirrors.btte.net
192.168.0.36: * extras: mirrors.btte.net
192.168.0.36: * updates: mirrors.yun-idc.com
192.168.0.36: Setting up Install Process
192.168.0.36: The Packagecmake-2.6.4-5.el5.4.x86_64 already installed and latest version
192.168.0.36: Package gcc-4.1.2-55.el5.x86_64already installed and latest version
192.168.0.36: No package g ++ available.
192.168.0.36: Package bison-2.3-2.1.x86_64already installed and latest version
192.168.0.36: The Packagencurses-devel-5.5-24.20060715.x86_64 already installed and latest version
192.168.0.36: The Packagencurses-devel-5.5-24.20060715.i386 already installed and latest version
192.168.0.36: Package zlib-1.2.3-7.el5.x86_64already installed and latest version
192.168.0.36: Package zlib-1.2.3-7.el5.i386already installed and latest version
192.168.0.36: Nothing to do
192.168.0.36: Please login with USER and PASS.
192.168.0.36: Please login with USER and PASS.
192.168.0.36: KERBEROS_V4 rejected as anauthentication type
192.168.0.36: Interactive mode off.
192.168.0.36: Preparing... ######################################## ##########
192.168.0.36: mysql-rpm ##################################### #############
.......

End.

Verify

[Root @ study2 ~] # Service mysql start
Starting MySQL...
 
 
[Root @ study2 ~] # Su-mysql
Mys [mysql @ study2 ~] $ Mysql
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 1
Server version: 5.6.21-r5436-log Sourcedistribution
 
Copyright (c) 2000,201 4, Oracle and/or itsaffiliates. All rights reserved.
 
Oracle is a registered trademark of OracleCorporation and/or its
Affiliates. Other names may be trademarks oftheir respective
Owners.
 
Type 'help; 'or' \ H' for help. type' \ C' toclear the current input statement.
 
Root @ (none) 12:29:11> show databases;
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Dexdb |
| Mysql |
| Performance_schema |
| Test |
+ -------------------- +
5 rows in set (0.37 sec)
 
Root @ (none) 12:29:14> use dexdb;
Database changed
Root @ dexdb 12:29:17> select * from t;
+ ------ + ------------ +
| Id | name |
+ ------ + ------------ +
| 1 | renfengjun |
+ ------ + ------------ +
1 row in set (0.19 sec)
 
Root @ dexdb 12:29:19> quit
Bye
 
[Root @ study2 ~] # Service mysql stop
Shutting down MySQL. [OK]

It's rough and there's something to improve. Complete it slowly.

-------------------------------------- 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:

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.