你的位置:首页 > 数据库

[数据库]屌炸天实战 Mysql 系列教程(五) 多实例、高可用生产环境实战


第一篇:屌炸天实战 MySQL 系列教程(一) 生产标准线上环境安装配置案例及棘手问题解决

第二篇:屌炸天实战 MySQL 系列教程(二) 史上最屌、你不知道的数据库操作

第三篇:屌炸天实战 MySQL 系列教程(三)你不知道的 视图、触发器、存储过程、函数、事物、索引、语句

第四篇:屌炸天实战 MySQL 系列教程(四) 主从复制、读写分离、模拟宕机、备份恢复方案生产环境实战

第五篇:屌炸天实战 Mysql 系列教程(五) 多实例、高可用生产环境实战

 

本章内容:

  • MySQL 多实例
  • 简介
  • 安装前的配置
  • 生产环境屌炸天的脚步
  • 初始化登录实现多实例
  • 要再增加一个多实例怎么办?解决
  • MySQL 高可用
  • 部署配置heardbeat
  • 部署配置drbd
  • heardbeat与drbdde 联合配置
  • 部署MySQL
  • 联合heardbeat配置MySQL

 

一、MySQL 多实例

1、简介

前几年一个朋友跟我说他们公司一台物理服务器上跑 3 到 5 个实例,我说你们公司得多穷啊,他说这个是合理规划,发挥服务器最大性能,你说呢?

别问小编公司跑几个,小编公司有钱不在乎,一台小型器最多跑 3 个实例,当然,每天的数据量还是很大的。

那什么使多实例呢,为什么用它?

多实例就是在一台机器上开启多个不同的服务端口(如:3306,3307);

运行多个MySQL服务进程,这些进程通过不同的socket监听不同的服务端口来提供各自的服务。

MySQL多实例共用一个 MySQL 的安装程序,使用不同(也可相同)的 my.cnf 配置文件,启动程序和数据文件。

在提供服务时,多实例 MySQL 在逻辑上是各自独立的,多个实例的本身是根据配置文件对应的设定值,来获得服务器的相关硬件资源多少。

2、安装配置前操作

安装配置前的一些配置少不了

文件的目录最好也规矩,这样才专业

#杀掉进程,避免冲突,删掉启动命令。pkill mysqldps -ef|grep mysqlrm -f /etc/init.d/mysqld# 创建目录,授权mkdir -p /data/{3306,3307}/datachown -R mysql.mysql /data/tree /data/  /data/   #总的多实例根目录├── 3306    #3306实例的目录│  └── data  #3306实例的数据文件目录└── 3307    #3307实例的目录  └── data  #3307实例的数据文件目录  4 directories, 0 files

3、配置文件

话不多说,直接上生产环境线上的配置文件:

[client]port      = 3306socket     = /data/3306/mysql.sock[mysql]no-auto-rehash[mysqld]user  = mysqlport  = 3306socket = /data/3306/mysql.sockbasedir = /application/mysqldatadir = /data/3306/dataopen_files_limit  = 1024back_log = 600max_connections = 800max_connect_errors = 3000table_cache = 614external-locking = FALSEmax_allowed_packet =8Msort_buffer_size = 1Mjoin_buffer_size = 1Mthread_cache_size = 100thread_concurrency = 2query_cache_size = 2Mquery_cache_limit = 1Mquery_cache_min_res_unit = 2k#default_table_type = InnoDBthread_stack = 192K#transaction_isolation = READ-COMMITTEDtmp_table_size = 2Mmax_heap_table_size = 2Mlong_query_time = 1#log_long_format#log-error = /data/3306/error.log#log-slow-queries = /data/3306/slow.logpid-file = /data/3306/mysql.pidlog-bin = /data/3306/mysql-binrelay-log = /data/3306/relay-binrelay-log-info-file = /data/3306/relay-log.infobinlog_cache_size = 1Mmax_binlog_cache_size = 1Mmax_binlog_size = 2Mexpire_logs_days = 7key_buffer_size = 16Mread_buffer_size = 1Mread_rnd_buffer_size = 1Mbulk_insert_buffer_size = 1M#myisam_sort_buffer_size = 1M#myisam_max_sort_file_size = 10G#myisam_max_extra_sort_file_size = 10G#myisam_repair_threads = 1#myisam_recoverlower_case_table_names = 1skip-name-resolveslave-skip-errors = 1032,1062replicate-ignore-db=mysqlserver-id = 1innodb_additional_mem_pool_size = 4Minnodb_buffer_pool_size = 32Minnodb_data_file_path = ibdata1:128M:autoextendinnodb_file_io_threads = 4innodb_thread_concurrency = 8innodb_flush_log_at_trx_commit = 2innodb_log_buffer_size = 2Minnodb_log_file_size = 4Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_file_per_table = 0[mysqldump]quickmax_allowed_packet = 2M[mysqld_safe]log-error=/data/3306/mysql3306.errpid-file=/data/3306/mysqld.pid

3306_my.cnf
#!/bin/sh#Nick Suo#email:630571017@qq.com#blog:http://www.cnblogs.com/suoning#initport=3306mysql_user="root"mysql_pwd="suoning"CmdPath="/application/mysql/bin"mysql_sock="/data/${port}/mysql.sock"#startup functionfunction_start_mysql(){  if [ ! -e "$mysql_sock" ];then   printf "Starting MySQL...\n"   /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &  else   printf "MySQL is running...\n"   exit  fi}#stop functionfunction_stop_mysql(){  if [ ! -e "$mysql_sock" ];then    printf "MySQL is stopped...\n"    exit  else    printf "Stoping MySQL...\n"    ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown  fi}#restart functionfunction_restart_mysql(){  printf "Restarting MySQL...\n"  function_stop_mysql  sleep 2  function_start_mysql}case $1 instart)  function_start_mysql;;stop)  function_stop_mysql;;restart)  function_restart_mysql;;*)  printf "Usage: /data/${port}/mysql {start|stop|restart}\n"esac

3306_mysql
[client]port      = 3307socket     = /data/3307/mysql.sock[mysql]no-auto-rehash[mysqld]user  = mysqlport  = 3307socket = /data/3307/mysql.sockbasedir = /application/mysqldatadir = /data/3307/dataopen_files_limit  = 1024back_log = 600max_connections = 800max_connect_errors = 3000table_cache = 614external-locking = FALSEmax_allowed_packet =8Msort_buffer_size = 1Mjoin_buffer_size = 1Mthread_cache_size = 100thread_concurrency = 2query_cache_size = 2Mquery_cache_limit = 1Mquery_cache_min_res_unit = 2k#default_table_type = InnoDBthread_stack = 192K#transaction_isolation = READ-COMMITTEDtmp_table_size = 2Mmax_heap_table_size = 2M#long_query_time = 1#log_long_format#log-error = /data/3307/error.log#log-slow-queries = /data/3307/slow.logpid-file = /data/3307/mysql.pid#log-bin = /data/3307/mysql-binrelay-log = /data/3307/relay-binrelay-log-info-file = /data/3307/relay-log.infobinlog_cache_size = 1Mmax_binlog_cache_size = 1Mmax_binlog_size = 2Mexpire_logs_days = 7key_buffer_size = 16Mread_buffer_size = 1Mread_rnd_buffer_size = 1Mbulk_insert_buffer_size = 1M#myisam_sort_buffer_size = 1M#myisam_max_sort_file_size = 10G#myisam_max_extra_sort_file_size = 10G#myisam_repair_threads = 1#myisam_recoverlower_case_table_names = 1skip-name-resolveslave-skip-errors = 1032,1062replicate-ignore-db=mysqlserver-id = 3innodb_additional_mem_pool_size = 4Minnodb_buffer_pool_size = 32Minnodb_data_file_path = ibdata1:128M:autoextendinnodb_file_io_threads = 4innodb_thread_concurrency = 8innodb_flush_log_at_trx_commit = 2innodb_log_buffer_size = 2Minnodb_log_file_size = 4Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_file_per_table = 0[mysqldump]quickmax_allowed_packet = 2M[mysqld_safe]log-error=/data/3307/mysql3307.errpid-file=/data/3307/mysqld.pid

3307_my.cnf
#!/bin/sh#Nick Suo#email:630571017@qq.com#blog:http://www.cnblogs.com/suoning#initport=3307mysql_user="root"mysql_pwd="suoning"CmdPath="/application/mysql/bin"mysql_sock="/data/${port}/mysql.sock"#startup functionfunction_start_mysql(){  if [ ! -e "$mysql_sock" ];then   printf "Starting MySQL...\n"   /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &  else   printf "MySQL is running...\n"   exit  fi}#stop functionfunction_stop_mysql(){  if [ ! -e "$mysql_sock" ];then    printf "MySQL is stopped...\n"    exit  else    printf "Stoping MySQL...\n"    ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown  fi}#restart functionfunction_restart_mysql(){  printf "Restarting MySQL...\n"  function_stop_mysql  sleep 2  function_start_mysql}case $1 instart)  function_start_mysql;;stop)  function_stop_mysql;;restart)  function_restart_mysql;;*)  printf "Usage: /data/${port}/mysql {start|stop|restart}\n"esac

3307_mysql
#上传及拷贝配置文件cd /home/oldsuo/tools/rz data.zipunzip data.zip  Archive: data.zip      creating: data/      creating: data/3306/     inflating: data/3306/my.cnf         inflating: data/3306/mysql          creating: data/3307/     inflating: data/3307/my.cnf         inflating: data/3307/mysqlcp data/3306/my.cnf /data/3306/cp data/3307/my.cnf /data/3307/tree /data/

#拷贝启动文件,加执行权限cp data/3306/mysql /data/3306/cp data/3307/mysql /data/3307/chmod +x /data/3306/mysqlchmod +x /data/3307/mysqltree /data/      /data/├── 3306│  ├── data│  ├── my.cnf│  └── mysql└── 3307  ├── data  ├── my.cnf└── mysql# 多实例启动文件的启动mysql服务实质:mysqld_safe --defaults-file=/data/3306/my.cnf 2>&1 > /dev/null &mysqld_safe --defaults-file=/data/3307/my.cnf 2>&1 > /dev/null &# 多实例启动文件的停止mysql服务实质:mysqladmin -u root -poldsuo -S /data/3306/mysql.sock shutdownmysqladmin -u root -poldsuo -S /data/3307/mysql.sock shutdown

4、初始化启动登录

此时就算完成了,可以初始化并启动了,so easy

#初始化数据库,存放数据路径,自己放自己的目录下cd /application/mysql/scripts/./mysql_install_db --basedir=/application/mysql/ --datadir=/data/3306/data --user=mysql./mysql_install_db --basedir=/application/mysql/ --datadir=/data/3307/data --user=mysql#启动mysql,并检查端口/data/3306/mysql start/data/3307/mysql startnetstat -lntup|grep 330[6-7]  tcp    0   0 0.0.0.0:3307        0.0.0.0:*          LISTEN   27896/mysqld    tcp    0   0 0.0.0.0:3306        0.0.0.0:*          LISTEN   27174/mysqld#授权,并检查(批量)find /data/ -type f -name "mysql"/data/3306/mysql/data/3307/mysqlfind /data/ -type f -name "mysql" -exec chmod 700 {} \;find /data/ -type f -name "mysql" -exec chown root.root {} \;find /data/ -type f -name "mysql" -exec ls -l {} \;#设置mysql登陆密码,为nick。mysqladmin -u root -S /data/3306/mysql.sock password 'nick'mysqladmin -u root -S /data/3307/mysql.sock password 'nick'#修改密码mysqladmin -uroot -pnick password 'oldsuo' -S /data/3306/mysql.sock#多实例数据库的登陆方法,需要参数-S、并指定sock。mysql -S /data/3306/mysql.sock    #不设置密码登陆mysql -S /data/3307/mysql.sockmysql -uroot -p -S /data/3306/mysql.sock    #设置密码登陆mysql -uroot -p -S /data/3307/mysql.sock mysql -uroot -p –hlocalhost -S /data/3306/mysql.sock    #远程登陆mysql -uroot -p –hlocalhost -S /data/3307/mysql.sockmysql -uroot -p –h 192.168.200.98 -P 3306mysql -uroot -p –h 192.168.200.98 -P 3307#创建库,名为d3306、d3307。并检查。create database d3306;create database d3307;show databases;

5、增加一个mysql实例

问题又来了,要增加一个实例怎么弄呢?

其实不难,只需按上面步骤,创建目录,在修改相应配置文件,初始化就ok

#增加一个mysql实例mkdir -p /data/3308/datacp /data/3306/my.cnf /data/3308/cp /data/3306/mysql /data/3308/ chown -R mysql.mysql /data/3308/cd /data/3308/vim my.cnf:g/3306/s//3308/g    #批量替换命令vi mysql:g/3306/s//3308/g#初始化数据库cd /application/mysql/scripts/./mysql_install_db --basedir=/application/mysql/ --datadir=/data/3308/data --user=mysql#启动数据库,并检查端口/data/3308/mysql startnetstat -lntup|grep 330#设置密码为nick。mysqladmin -u root -S /data/3308/mysql.sock password 'nick'#登陆mysqlmysql -uroot -p -S /data/3308//mysql.sock

 

二、MySQL 高可用双机热备

小编啥也不说了,直接把公司得环境搬上来吧

本文采用 heartbeat + drbd + MySQL 实现MySQL的高可用。

其原理图如下:

 

1、部署heartbeat3.0

heartbeat 是一个高可用集群架构,它最核心的两个部分为:心跳监测和资源接管,心跳监测是通过HA心跳实时监测,机器之间相互发送报文来告诉对方自己当前的状态,如果在指定的时间内未收到对方发送的报文,那就认为对方以宕机等,这时启动资源接管,使备份服务器变为主服务器,使服务器正常运行。

1.1.配置主机名与hosts

一惯的,需先改主机名与hosts文件

1>  data-1-1hostname data-1-1sed -i 's#HOSTNAME=localhost.localdomain#HOSTNAME=data-1-1#g' /etc/sysconfig/networktail -1 /etc/sysconfig/network/sbin/route add -host 192.168.1.5 dev eth1echo '/sbin/route add -host 192.168.1.5' >>/etc/rc.localroute -n#退出重新登录查看修改后主机名2>  data-1-2hostname data-1-2sed -i 's#HOSTNAME=localhost.localdomain#HOSTNAME=data-1-2#g' /etc/sysconfig/networktail -1 /etc/sysconfig/network/sbin/route add -host 192.168.1.3 dev eth1echo '/sbin/route add -host 192.168.1.3' >>/etc/rc.localroute -n

[root@localhost ~]# hostname data-1-2[root@localhost ~]# sed -i 's#HOSTNAME=localhost.localdomain#HOSTNAME=data-1-2#g' /etc/sysconfig/network[root@localhost ~]# tail -1 /etc/sysconfig/networkHOSTNAME=data-1-2[root@localhost ~]# /sbin/route add -host 192.168.1.6 dev eth1[root@localhost ~]# echo '/sbin/route add -host 192.168.1.6' >>/etc/rc.local [root@localhost ~]# route -nKernel IP routing tableDestination   Gateway     Genmask     Flags Metric Ref  Use Iface192.168.1.6   0.0.0.0     255.255.255.255 UH  0   0    0 eth1192.168.1.0   0.0.0.0     255.255.255.0  U   0   0    0 eth1192.168.200.0  0.0.0.0     255.255.255.0  U   0   0    0 eth0169.254.0.0   0.0.0.0     255.255.0.0   U   1002  0    0 eth0169.254.0.0   0.0.0.0     255.255.0.0   U   1003  0    0 eth10.0.0.0     192.168.200.6  0.0.0.0     UG  0   0    0 eth0

View Code

1.2.下载安装epel包

yum 安装前需先安装 epel 包

mkdir -p /home/oldsuo/toolscd /home/oldsuo/tools/sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.confwget http://mirrors.opencas.cn/epel/6/i386/epel-release-6-8.noarch.rpmrpm -ivh epel-release-6-8.noarch.rpmrpm -qa |grep epel

1.3.安装heartbeat

yum 安装,简单快捷

yum install heartbeat –y

1.4.配置heartbeat

安装完配置,以下是快速配置文档

cd /etc/ha.d/cp ha.cf ha.cf.oricp authkeys authkeys.oricp haresources haresources.orichmod 600 authkeysvim ha.cfdebugfile   /var/log/ha-debuglogfile     /var/log/ha-loglogfacility   local1keepalive   2deadtime   30warntime   10initdead    60#bcast eth1mcast  eth1  225.0.0.1 694 1 0auto_failback    onnode      data-1-1node      data-1-2crm       novim authkeysauth 11 sha1 sui1bian2xie3duo4dian5suibianxieduodianvim haresources#192.168.1.3  data-1-1    IPaddr::192.168.200.91/24/eth0#data-1-1   IPaddr::192.168.200.91/24/eth0  httpd#192.168.1.5data-1-2    IPaddr::192.168.200.94/24/eth0#mysql master#picdata-1-1  IPaddr::192.168.1.3/24/eth1   mysqld#picdata-1-1  IPaddr::192.168.1.3/24/eth1#mysql slave#picdata-1-2  IPaddr::192.168.1.5/24/eth1

1.5.配置hosts

检查 hosts,一定要做

#!!!主机名必须与uname -n 显示一致!cat >>/etc/hosts<<eof192.168.1.3 data-1-1192.168.1.5 data-1-2eoftail -2 /etc/hostsping data-1-1ping data-1-2

[root@data-1-2 heartbeat-3.0.4]# cat >>/etc/hosts<<eof> 192.168.1.3 data-1-1> 192.168.1.5 data-1-2> eof[root@data-1-2 heartbeat-3.0.4]# tail -2 /etc/hosts192.168.1.6 data-1-1192.168.1.7 data-1-2[root@data-1-2 heartbeat-3.0.4]# ping data-1-164 bytes from data-1-1 (192.168.1.3): icmp_seq=1 ttl=64 time=1.98 ms[root@data-1-2 heartbeat-3.0.4]# ping data-1-264 bytes from data-1-2 (192.168.1.5): icmp_seq=1 ttl=64 time=0.040 ms

View Code

1.6.启动heartbeat服务

可以启动啦,啦

/etc/init.d/iptables stopsetenforce 0/etc/init.d/heartbeat startps -ef |grep hear

[root@data-1-1 ha.d]# /etc/init.d/iptables stop[root@data-1-1 ha.d]# setenforce 0setenforce: SELinux is disabled[root@data-1-1 ha.d]# /etc/init.d/heartbeat startStarting High-Availability services: INFO: Resource is stoppedINFO: Resource is stoppedDone.[root@data-1-1 ha.d]# ps -ef |grep hearroot   5282   1 0 14:17 ?    00:00:00 heartbeat: master control processroot   5286 5282 0 14:17 ?    00:00:00 heartbeat: FIFO reader    root   5287 5282 0 14:17 ?    00:00:00 heartbeat: write: mcast eth1 root   5288 5282 0 14:17 ?    00:00:00 heartbeat: read: mcast eth1  root   5298 1763 0 14:18 pts/0  00:00:00 grep hear

View Code

 

2、部署 DRBD

DRBD 是一个用软件实现、不共享、服务器之间镜像块块的存储复制解决方案。

在高可用(HA)环境中使用 DRBD,可以代替一个共享的盘阵。

2.1.环境准备

#!!!双网卡,双硬盘

2.2.对磁盘分区

超过2T的磁盘,一般是 parted 分区,支持更好

#parted分区##data-1-1和data-1-2操作一样!fdisk –lparted /dev/xvdb mklabel gptparted /dev/xvdb mkpart primary 0 1024parted /dev/xvdb pparted /dev/xvdb mkpart primary 1025 2146parted /dev/xvdb p

[root@data-1-1 ~]# fdisk -lDisk /dev/xvdb: 2147 MB, 2147483648 bytes[root@data-1-1 ~]# parted /dev/xvdb mklabel gpt信息: You may need to update /etc/fstab.                 [root@data-1-1 ~]# parted /dev/xvdb mkpart primary 0 1024警告: The resulting partition is not properly aligned for best performance.忽略/Ignore/放弃/Cancel? Ignore                      信息: You may need to update /etc/fstab.                 [root@data-1-1 ~]# parted /dev/xvdb pNumber Start  End   Size  File system Name   标志 1   17.4kB 1024MB 1024MB        primary[root@data-1-1 ~]# parted /dev/xvdb mkpart primary 1025 2146警告: The resulting partition is not properly aligned for best performance.忽略/Ignore/放弃/Cancel? Ignore                      信息: You may need to update /etc/fstab.                 [root@data-1-1 ~]# parted /dev/xvdb p1   17.4kB 1024MB 1024MB        primary2   1025MB 2146MB 1121MB        primary

View Code

2.3.安装配置DRBD

以下是快速安装配置文档

1>  安装epel包mkdir -p /home/oldsuo/toolscd /home/oldsuo/tools/sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.confwget http://mirror.ventraip.net.au/elrepo/elrepo/el6/x86_64/RPMS/elrepo-release-6-5.el6.elrepo.noarch.rpmrpm -ivh elrepo-release-6-5.el6.elrepo.noarch.rpm2>  安装drbd,并加载到内核yum install drbd kmod-drbd84 -yrpm -qa |grep drbdcd /home/oldsuo/tools/export LC_ALL=Clsmod |grep drbdmodprobe drbdlsmod |grep drbdecho "modprobe drbd >/dev/null 2>&1" >/etc/sysconfig/modules/drbd.modulestail -1 /etc/sysconfig/modules/drbd.modules#!!!报错FATAL: Module drbd not found.http://blog.sina.com.cn/s/blog_702bd5360101h84d.html[root@data-1-2 ~]# modprobe drbdFATAL: Module drbd not found.解决方法:yum install kernel* -y    重启服务器!

2.4.配置drbd.conf文件

一惯需改配置文件

vim /etc/drbd.confglobal { usage-count no;}common { syncer {  rate 330M;  verify-alg crc32c; }}resource data { protocol C; disk  {  on-io-error detach; } on data-1-1 {  device /dev/drbd0;  disk /dev/xvdb1;  address 192.168.1.6:7788;  meta-disk /dev/xvdb2;  } on data-1-2 {  device /dev/drbd0;  disk /dev/xvdb1;  address 192.168.1.7:7788;  meta-disk /dev/xvdb2;  }}

2.5.初始化

启动前需初始化

drbdadm create-md data[root@data-1-2 tools]# drbdadm create-md datainitializing activity logNOT initializing bitmapWriting meta data...New drbd meta data block successfully created.

2.6.启动、关闭及查看状态

启动啦,啦,啦,检查状态

drbdadm up datacat /proc/drbddrbdadm down data  关闭[root@data-1-1 tools]# drbdadm up data[root@data-1-1 tools]# cat /proc/drbdversion: 8.4.6 (api:1/proto:86-101)GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-09 14:35:00 0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----  ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:999984

2.7.同步

配置同步

#!!!主上操作!drbdadm -- --overwrite-data-of-peer primary datacat /proc/drbdPrimary/Secondary

[root@data-1-1 ~]# drbdadm -- --overwrite-data-of-peer primary data[root@data-1-1 ~]# cat /proc/drbdversion: 8.4.4 (api:1/proto:86-101)GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@data-1-1, 2015-12-11 20:06:46 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----  ns:58112 nr:0 dw:0 dr:58784 al:0 bm:3 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:490464    [=>..................] sync'ed: 11.2% (490464/548576)K    finish: 0:00:08 speed: 58,112 (58,112) K/sec[root@data-1-1 ~]# cat /proc/drbdversion: 8.4.4 (api:1/proto:86-101)GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@data-1-1, 2015-12-11 20:06:46 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----  ns:517248 nr:0 dw:0 dr:517920 al:0 bm:31 lo:0 pe:146 ua:0 ap:0 ep:1 wo:f oos:34420    [=================>..] sync'ed: 94.1% (34420/548576)K    finish: 0:00:00 speed: 36,724 (36,724) K/sec[root@data-1-1 ~]# cat /proc/drbdversion: 8.4.4 (api:1/proto:86-101)GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@data-1-1, 2015-12-11 20:06:46 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----  ns:548576 nr:0 dw:0 dr:549248 al:0 bm:34 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0[root@data-1-1 ~]# cat /proc/drbdversion: 8.4.4 (api:1/proto:86-101)GIT-hash: 74402fecf24da8e5438171ee8c19e28627e1c98a build by root@data-1-1, 2015-12-11 20:06:46 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----  ns:548576 nr:0 dw:0 dr:549248 al:0 bm:34 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

View Code

2.8.挂载磁盘

挂载磁盘

#主!!!mkfs.ext4 /dev/drbd0mkdir /datamount /dev/drbd0 /data/df -HTmount /dev/xvdb2 /mnt/#从!!!mkdir /data

[root@data-1-1 tools]# mkfs.ext4 /dev/drbd0     mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks62592 inodes, 249995 blocks12499 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=2600468488 block groups32768 blocks per group, 32768 fragments per group7824 inodes per groupSuperblock backups stored on blocks:     32768, 98304, 163840, 229376Writing inode tables: done              Creating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 23 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[root@data-1-1 tools]# mkdir /md1[root@data-1-1 tools]# mount /dev/drbd0 /md1/[root@data-1-1 tools]# df -HTFilesystem          Type  Size Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root ext4  49G 6.4G  40G 14% /tmpfs            tmpfs 187M   0 187M  0% /dev/shm/dev/xvda1          ext4  500M  85M 389M 18% /boot/dev/drbd0          ext4  992M 1.3M 939M  1% /data[root@data-1-1 data]# mount /dev/xvdb2 /mnt/mount: you must specify the filesystem type

View Code

 

3:配合heartbeat调试drbd服务配置

联合 heartbeat 调试配置 DRBD 服务,两者结合

#两台操作!/etc/init.d/heartbeat stop#后面加入内容,不能换行vim /etc/ha.d/haresourcesdata-1-1    IPaddr::192.168.200.91/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext4/etc/init.d/heartbeat start###!!!/etc/ha.d/resource.d/IPaddr!!!###!!!/etc/ha.d/resource.d/drbddisk!!!

 

4: 部署MySQL

快速安装 MySQL 文档

4.1.解压配置

mkdir -p /home/oldsuo/tools/cd /home/oldsuo/tools/rz 上传免编译安装包ls mysql-5.5.47-linux2.6-x86_64.tar.gztar zxf mysql-5.5.47-linux2.6-x86_64.tar.gzmkdir -p /application/mv mysql-5.5.47-linux2.6-x86_64 /application/mysql-5.5.47ln -s /application/mysql-5.5.47/ /application/mysqlls -l /application/#检查[root@data-1-1 tools]# ls -l /application/lrwxrwxrwx  1 root root    26 Dec 13 13:25 mysql -> /application/mysql-5.7.10/drwxr-xr-x  9 7161 wheel   4096 Nov 30 03:54 mysql-5.7.10

4.2.创建用户

groupadd mysqluseradd -g mysql -M mysql

4.3.多实例配置

#杀掉进程,避免冲突,删掉启动命令。pkill mysqldps -ef|grep mysqlrm -f /etc/init.d/mysqld#上传及拷贝配置文件cd /home/oldsuo/tools/rz data.zipunzip data.zip  Archive: data.zip      creating: data/      creating: data/3306/     inflating: data/3306/my.cnf         inflating: data/3306/mysql          creating: data/3307/     inflating: data/3307/my.cnf         inflating: data/3307/mysqlcp data/3306/my.cnf /data/3306/cp data/3307/my.cnf /data/3307/tree /data/#拷贝启动文件,加执行权限cp data/3306/mysql /data/3306/cp data/3307/mysql /data/3307/chmod +x /data/3306/mysqlchmod +x /data/3307/mysqltree /data/      /data/        #总的多实例根目录├── 3306      #3306实例的目录│  ├── my.cnf  #3306实例的配置文件│  └── mysql    #3306实例的启动文件└── 3307      #3307实例的目录  ├── my.cnf  #3307实例的配置文件└── mysql    #3307实例的启动文件

4.3.初始化数据库,启动单实例

#初始化数据库cd /application/mysql/scripts/./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql[root@data-1-1 ~]# /application/mysql/bin/mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql2015-12-13 13:53:25 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2015-12-13 13:53:33 [WARNING] The bootstrap log isn't empty:2015-12-13 13:53:33 [WARNING] 2015-12-13T05:53:26.040946Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead2015-12-13T05:53:26.076433Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)2015-12-13T05:53:26.076465Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)#授权,并做替换find /data –name mysql.mysql /datased -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe#启动单实例,并检查/data/3306/mysql startsleep 6lsof -i :3306

 

5: 配合heartbeat调试MySQL

#两边操作,添加mysql。cp /data/3306/mysql /etc/ha.d/resource.d/chmod +x /etc/ha.d/resource.d/vim /etc/ha.d/haresourcesdata-1-1    IPaddr::192.168.200.91/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/md1::ext4 mysql