0

0

自动化部署MySQL5.6步骤_MySQL

php中文网

php中文网

发布时间:2016-06-01 13:01:00

|

1204人浏览过

|

来源于php中文网

原创

准备工作

首先需要搭建ftpserver

yum install vsftpd
 
service vsftpd start

这样ftp服务就起来了,这里只是简单的使用,所以没有使用配置文件。这样我们只要将需要的文件置于/var/ftp/pub/文件夹下,匿名用户就可以copy文件到本机了。

安装rpm-build

build需要用到rpm-build,这里简单安装即可

yum install rpm-build

下面开始rpm打包

mget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.21.tar.gz
cd /u01/mysql-5.6.21
mkdir rpm
cd rpm

修改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 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

执行打包命令

rpmbuild -bb ./mysql.spec

输出:

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

生成的rpm包在这里:

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

打包数据模板

打包的时候记得关闭mysql。这里写了一点测试数据:

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

数据模板打包,记得ibdata1打包上

cd /u01/mysql/data

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

修改my.cnf

my.cnf文件内容:

[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:12M
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=/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=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

serverid在自动化安装脚本中自动生成。

将上面的data.tar 、my.cnf、生成的rpm包copy到ftp的pub目录下

PDFlux
PDFlux

PDF内容提取+智能问答神器,结合了科研级精准的非结构化文档解析能力,以及ChatGPT的智能问答能力。

下载

/var/ftp/pub/

自动化安装脚本

auto_install_mysql.sh:

#!/bin/sh
yum install -y cmake gcc g++ bisonncurses-devel zlib
 
ftp -n<

结束。

验证一下

[root@study2 ~]# service mysql start
Starting MySQL.......................[  OK  ]
 
 
[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, 2014, 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  ]

比较粗糙,还有需要改进的地方。慢慢完善吧。

相关专题

更多
苹果官网入口直接访问
苹果官网入口直接访问

苹果官网直接访问入口是https://www.apple.com/cn/,该页面具备0.8秒首屏渲染、HTTP/3与Brotli加速、WebP+AVIF双格式图片、免登录浏览全参数等特性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

115

2025.12.24

拼豆图纸在线生成器
拼豆图纸在线生成器

拼豆图纸生成器有PixelBeads在线版、BeadGen和“豆图快转”;推荐通过pixelbeads.online或搜索“beadgen free online”直达官网,避开需注册的诱导页面。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

82

2025.12.24

俄罗斯搜索引擎yandex官方入口地址(最新版)
俄罗斯搜索引擎yandex官方入口地址(最新版)

Yandex官方入口网址是https://yandex.com。用户可通过网页端直连或移动端浏览器直接访问,无需登录即可使用搜索、图片、新闻、地图等全部基础功能,并支持多语种检索与静态资源精准筛选。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

546

2025.12.24

JavaScript ES6新特性
JavaScript ES6新特性

ES6是JavaScript的根本性升级,引入let/const实现块级作用域、箭头函数解决this绑定问题、解构赋值与模板字符串简化数据处理、对象简写与模块化提升代码可读性与组织性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

150

2025.12.24

php框架基础知识汇总
php框架基础知识汇总

php框架是构建web应用程序的架构,提供工具和功能,以简化开发过程。选择合适的框架取决于项目需求和技能水平。实战案例展示了使用laravel构建博客的步骤,包括安装、创建模型、定义路由、编写控制器和呈现视图。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

20

2025.12.24

Word 字间距调整方法汇总
Word 字间距调整方法汇总

本专题整合了Word字间距调整方法,阅读下面的文章了解更详细操作。

47

2025.12.24

任务管理器教程
任务管理器教程

本专题整合了任务管理器相关教程,阅读下面的文章了解更多详细操作。

7

2025.12.24

AppleID格式
AppleID格式

本专题整合了AppleID相关内容,阅读专题下面的文章了解更多详细教程。

12

2025.12.24

csgo视频观看入口合集
csgo视频观看入口合集

本专题整合了csgo观看入口合集,阅读下面的文章了知道更多入口地址。

371

2025.12.24

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
【web前端】Node.js快速入门
【web前端】Node.js快速入门

共16课时 | 1.9万人学习

550W粉丝大佬手把手从零学JavaScript
550W粉丝大佬手把手从零学JavaScript

共1课时 | 0.2万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号