规模化部署mysql5.6

Mysql有时需要大规模部署时,我们可以使用之前的数据库做为模板然后通过rpm打包工具传递到其它主机进行批量部署。

1、首先,下载rpmbuild
yum install rpm-build -y
它是Red Hat用于打RPM包的工具。我们在编辑打包程序时,可以看到/root/rpmbuild目录下有如下文件夹。

BUILD  BUILDROOT  RPMS  SOURCES  SPECS  SRPMS

2、然后,下载源码包
http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.20.tar.gz
并将其复制到指定的目录/root/rpmbuild/SOURCES/mysql-5.6.20.tar.gz

3、安装编译MySQL需要的依赖包
yum -y install make gcc-c++ cmake bison-devel  ncurses-devel

4、编写spec脚本

其实编写spec文件本质上是在写一个回调函数,rpmbuild根据spec的回调函数,生成一个Shell脚本,打包的过程就是执行Shell脚本的过程。我们在脚本中使用CFLAGS将源码包转变为二进制安装包。

5、生成rpm包

Tar zxvf mysql-5.6.20.tar.gz

Cd mysql_5.6.20

mkdir  5.6.20_mysql/rpm

cp mysql.spec  5.6.20_mysql/rpm

rpmbuild –bb ./rpm/mysql.spec    编译安装打包

执行结束后生成的rpm包就在RPMS/x86_64下了

定义配置模板,需要生成唯一的server_id

6、配置ftp

Yum install vsftp

Vi /etc/vsftpd/vsftpd.conf

userlist_enable=NO

将root从user_list中去掉

将root从/etc/vsftpdftpusers中去掉

Service vsftpd start

7、准备所需数据

需要的数据有rpm包、my.cnf和data文件。

Tar cf data.tar ibdata1 mysql/ performance_schema/  test/   准备数据包

将mysql_5.6.20.tar.gz包、my.cnf包和data.tar包放在/var/ftp/pub目录供其它server下载。

8、配置自动化脚本

自动化脚本主要包括rpm包安装,ftp下载,mysql’用户和组添加、文件夹赋权、数据包解压、rpm包安装和服务配置。

9、拷贝到目标服务器执行

Scp auto_mysql.txt ip:/root/

Chmod 755 auto.sh

./auto.sh &

注脚本文件:

mysql.spec

Name: mysql
Version:5.6.20
Release: %(echo $RELEASE)%{?dist}
License: GPL
URL: http://downloads.mysql.com/archives/get/file/mysql-5.5.37.tar.gz
Group: applications/database
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: cmake
Packager: [email protected]
Autoreq: no
#Source: %{name}-%{version}.tar.gz
prefix: /usr/local/mysql
Summary: MySQL 5.6.20

%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

my.cnf

[mysqld_safe]
pid-file=/usr/local/mysql/run/mysqld.pid
#malloc-lib=/usr/local/mysql/lib/libjemalloc.so

[mysql]
port=3306
prompt=\\[email protected]\\d \\r:\\m:\\s>
default-character-set=gbk
no-auto-rehash

[client]
port=3306
socket=/usr/local/mysql/run/mysql.sock

[mysqld]
#dir
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
tmpdir=/tmp
lc_messages_dir=/usr/local/mysql/share
log-error=/usr/local/mysql/log/alert.log
slow_query_log_file=/usr/local/mysql/log/slow.log
general_log_file=/usr/local/mysql/log/general.log
socket=/usr/local/mysql/run/mysql.sock

#innodb
innodb_data_home_dir=/usr/local/mysql/data
innodb_log_group_home_dir=/usr/local/mysql/data
innodb_data_file_path=ibdata1:2G;ibdata2:16M:autoextend
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=200M
innodb_flush_log_at_trx_commit=1
innodb_additional_mem_pool_size=20M
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=64M
myisam_sort_buffer_size=64M
concurrent_insert=2
delayed_insert_timeout=300

#replication
master-info-file=/usr/local/mysql/log/master.info
relay-log=/usr/local/mysql/log/relaylog
relay_log_info_file=/usr/local/mysql/log/relay-log.info
relay-log-index=/usr/local/mysql/log/mysqld-relay-bin.index
slave_load_tmpdir=/usr/local/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=/usr/local/mysql/log/mysql-bin
server_id=2552763370
binlog_cache_size=32K
max_binlog_cache_size=2G
max_binlog_size=500M
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=1M
query_cache_min_res_unit=1K

table_definition_cache=65536
#table_cache=65536

thread_stack=512K
thread_cache_size=256
read_rnd_buffer_size=128K
sort_buffer_size=256K
join_buffer_size=128K
read_buffer_size=128K

port=3306
skip-name-resolve
skip-ssl
max_connections=4500
max_user_connections=4000
max_connect_errors=65536
max_allowed_packet=128M
connect_timeout=8
net_read_timeout=30
net_write_timeout=60
back_log=1024

server_id=1921681201

# vi mysql_install.sh

#!/bin/bash
# mysql auto-install script

yum install -y cmake gcc g++ bison ncurses-devel zlib

#Step 2: Create group & user
group=$(more /etc/group|grep mysql)
if [ "$group" != "" ]; then
   echo "group already created!"
else
   groupadd mysql
fi

user=$(more /etc/passwd|grep mysql)
if [ "$user" != "" ]; then
   echo "user already created!"
else
   useradd -g mysql mysql
fi

#Step 3: Get source
ftp -n<<EOF
open 10.243.29.65
user root test!2013
binary
cd /var/ftp/pub
mget *
EOF

#Step 3: Install
unique_id=`ifconfig | grep ‘inet addr:‘| grep -v ‘127.0.0.1‘ | cut -d: -f2 | awk ‘{ print $1}‘ | sed -e ‘s/\.//g‘`
echo ‘server_id=‘$unique_id >> my.cnf
rpm -ivh mysql-5.6.20-.el6.x86_64.rpm
cp my.cnf /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql

tar xvf data.tar -C /usr/local/mysql/data/
chown -R mysql:mysql /usr/local/mysql

mkdir -p /usr/local/mysql/log
chown -R mysql:mysql /usr/local/mysql/log

#step 4: Start MySQL
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig mysqld on

/etc/init.d/mysqld start

时间: 2024-10-12 14:59:09

规模化部署mysql5.6的相关文章

3分钟内快速部署MySQL5.6.35数据库实践

3分钟内快速部署MySQL5.6.35数据库实践 1.下载软件 wget -q http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz 2.解压移动 tar xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz  mkdir -p /application mv mysql-5.6.35-linux-glibc2.5-x86_64 /applicatio

部署MySQL5.7时的权限问题

本周部署MySQL5.7的时候遇到这样的问题,在初始化的时候,总是失败,并且报错: 2019-01-09T09:47:13.957685Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.2019-01-09T09:47:13.957703Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the d

CentOS7.X安装部署mysql5.7主从环境

生产搭建环境:操作系统:CentOS7.5内存大小:32GB硬盘:500G主库IP:192.168.8.129 hostname:master从库IP:192.168.8.130 hostname:slave 涉及主从都需要执行的地方,文中只写主库的操作指使,从库请自觉执行相同的命令 目录:1.环境准备与清理2.参数调优3.安装部署 1.系统初始化1.1.1. 主从库环境关闭selinux [[email protected]]# sed -i 's/SELINUX=enforcing/SELI

快速部署MySQL5.6.34数据库实践

第一章 MySQL介绍 1.1 什么是MySQL 简单来说,数据库(英文Database)就是一个存放计算机数据的仓库,这个仓库是按照一定的数据结构(数据库结构是指数据库的组织形式或数据之间的联系)来对数据进行组织和存储的,我们可以通过数据库提供的多种方法来管理期中的数据. 2.2 为什么选择MySQL数据库 毫无疑问,即成事实,绝大多数的使用linux操作系统的大中小互联网网站都在使用MySQL做为其后端的数据库存储,从大型的BAT门户,到电商平台,分类门户登无一例外都是用MySQL数据库.那

centos6.7 64位环境下部署MySQL-5.7.13

系统环境: [[email protected] ~]# cat /etc/redhat-release CentOS release 6.7 (Final) [[email protected] tools]# uname -a Linux localhost 2.6.32-573.22.1.el6.x86_64 #1 SMP Wed Mar 23 03:35:39 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux [[email protected] tools

Centos6 源码部署MySQL5.6

mysql从5.5版本开始,不再使用./configure编译,而是使用cmake编译器,具体的cmake编译参数可以参考mysql官网文档(※ 非常重要) http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html mysql-5.6.16.tar.gz源码包下载地址: http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15.tar.gz 我的mys

centos6上安装部署MySQL5.5详细配置

刚工作不久,按捺不住一颗骚动的心,2333333 总结在安装数据库过程中遇到的错误与解决方法 目的:搭建lamp或lnmp架构,系统使用的是centos6,mysqld版本是5.5的 首先安装需要编译的库文件: yum install gcc cpp glibc glibc-devel gcc-c++ yum -y install gcc make libtool automake autoconf rrdtool-devel libpcap-devel gdbm-devel zlib-deve

快速部署MySQL5.6.36数据库实践

1.创建用户安装依赖包上传软件包[[email protected] ~]# useradd -s /sbin/nologin -M mysql #<==创建用户[[email protected] app]# yum install libaio* perl-devel -y #<==安装依赖包[[email protected] app]# mkdir -p /home/app #<==创建软件存放目录[[email protected] app]# cd /home/app #&l

Linux服务器部署mysql5.7.x 二进制包

mysql5.7的安装相对于5.6还是有点区别,本章主要介绍二进制的安装方法. mysql 5.7下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads 安装 我下载的是版本是mysql5.7.22社区版 解压拷贝 mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql 先创建mysql用户 groupadd mysql useradd -r -g mysql -s /bi