DRBD + HeartBeat + MySQL: Configuring the high availability of MySQL

DRBD+Heartbeat+Mysql: Configure mysql high availability

Description:

Today I will continue to study the second application of DRBD, using DRBD+Heartbeat+Mysql: configure mysql high availability

< p>

Environment:

[root@dbm137~]#cat /etc/issueCentOS release 6.4 (Final)Kernel\r on an\m[root@dbm137~]#uname-r2.6.32-358.el6.i686
< td height="18">vip
dbm137 192.168.186.137 dbm137. 51.com primary DRBD+Heartbeat+Mysql
dbm138 192.168.186.138

dbm138.51.com secondary DRBD+Heartbeat+Mysql
192.168.186.200

Preparation and installation of DRBD:

http://www.voidcn.com/article/p-ooztnnqb-qq.html

Install and configure mysql:

Install mysql: (dbm137,dbm138)

##Install dependent packages: [root@dbm~]#yum -y install gcc gcc- c++ autoconf automake bison ncurses-devel libtool-ltdl-devel* cmake make
[root@dbm~]# mkdir-p/opt/mysql/data# Create a temporary data directory for the database [root@dbm ~]# cd /usr/local/src/[root@dbm src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.22 .tar.gz[root@dbm src]# tar-zxf mysql-5.6.22.tar.gz[root@dbm src]# cd mysql-5.6.22[root@dbm mysql-5.6.22]#cmake-DCMAKE_INS TALL_PREFIX=/usr/local/mysql-DMYSQL_DATADIR=/opt/mysql/data-DSYSCONFDIR=/usr/local/mysql-DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_WITH_PAY=1-DWITH_MEMORY_STORAGE_lib-DWITH_MEMORY_STORAGE_lib-DWITH_MEMORY_STORAGE=1-DWITH_MEMORY_DDRAGE=1-SQL/ mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS:STRING=utf8,gbk-DWITH_DEBUG=0##Note-DCM_INSTALL_PREFIX=utf8-DDEFAULT_COLLATION=utf8_general_ci make #This process may take a long time[root@dbm mysql-5.6.22]#make install[root@dbm~]#groupaddmysql#Create a mysql user group[root@dbm~]#useradd-s/sbin/nologin-g mysql mysql[root@dbm~]#chown-R mysql.mysql/opt/mysql#Authorized data directory[root@dbm~]#/usr/local/mysql/scripts/mysql_install_db--basedir=/usr/local/mysql --datadir=/opt/mysql/data --defaults-file=/usr/local/mysql/my.cnf --user=mysql #Initialize the database

Configure mysql:

dbm137(Primary)

[root@dbm137~]#mount/dev/drbd0/ Before data / # DRBD first device configured to mount [root @ dbm137 ~] # df -hFilesystem Size Used Avail Use% Mounted on / dev / mapper / VolGroup-lv_root 19G 3.4G 14G 20% / tmpfs 58M 0 58M 0% / dev/shm/dev/sda1 477M 43M 409M 10% /boot/dev/drbd0 8.8G 21M 8.3G [root@dbm137] 1% /data[root@dbm137] 1% /data[root@dbm137/mysql]# mkdir_binary_bin_log @dbm137~]# mkdir -p /data/mysql/data #Create the data directory of the database[root@dbm137~]# cp -a/opt/mysql/data/*/data/mysql/data/#Copy data to the database Directory[root@dbm137~]#chown-R mysql.mysql/data/mysql/#Authorized mysql directory[root@dbm137~]#cd/data/mysql/data/[root@dbm137data]#lltotal110604-rw- rw---- 1 mysql mysql 12582912 July 2 12:00 ibdata1-rw-rw---- 1 mysql mysql 50331648 Jul 2 12:00 ib_logfile0-rw-rw---- 1 mysql mysql 50331648 Jul 2 12:00 ib_logfile1drwx 2 mysql mysql 4096 Jul 2 12:00 mysqldrwx 2 mysql mysql 4096 Jul 2 12:00 performance_schemadrwx 2 mysql mysql 2 12:00 test[ ro ot@dbm137~]#mv /usr/local/mysql/my.cnf /usr/local/mysql/my.cnf.old[root@dbm137~]#vi/usr/local/mysql/my.cnf#Modify configuration File[mysqld]basedir = /usr/local/mysql #installation path datadir = /data/mysql/data #data directory port = 3306server-id = 1 #Do not modify this value pid-file = /data/mysql/data/ mysql.pid #Process file socket = /var/lib/mysql/mysql.sockdefault_storage_engine = InnoDBlog-bin = /data/mysql/binlog/mysql-binlog #Binary file expire_logs_days = 14max_binlog_size = 5Gbinlog_cache_query_bin_low_log2_low_data_max_cache_size = 10M_long_file_cache_size = 20M /mysql/data/slow.log #slow log file open_files_limit = 65535innodb = FORCEinnodb_buffer_pool_size = 100M # Note that this parameter innodb_log_file_size = 1Gquery_cache_size = 0thread_cache_size = 64table_definition_cache = 512table_open_cache = 512max_connections = 200sort_buffer_size = 10Mmax_allowed_packet = 6Msql_mode = NO_ENGINE_SUBSTITUTION, STRICT_TRANS_TABLES [client] #socket = /var/lib/mysql/mysql.sock##Note: innodb_buffer_pool_size:##The main function is to cache the index, data, and insert data of the innodb table的Buffer##Default value: 128M## The size of this value set by the dedicated mysql server: 70%-80% of the system memory is the best##If your system memory is not large, check this parameter and set its value to be smaller (If the value is set too large, an error will be reported at startup)
[root@dbm137~]# cp-a/usr/local/mysql/support-files /mysql.server /etc/init.d/mysqld #copy start script[root@dbm137~]# /etc/init.d/mysqld start #Start mysql service Starting MySQL............ ........................ SUCCESS! ##Note:##Don’t, don’t set mysql to start automatically when booting, because the mysql service is started Unified management by heartbeat [root@dbm137~]# ps -ef| grep mysqlroot 16284 1 0 12:46 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe--datadir=/ data/mysql/data--pid-file=/data/mysql/data/mysql.pidmysql 16783 16284 6 12:46 pts/1 00:00:03 /usr/local/mysql/bin/mysqld--basedir=/ usr/local/mysql--datadir=/data/mysql/data--plugin-dir=/usr/local/mysql/lib/plugin--user=mysql--log-error=/var/log/mysqld.log --open-files-limit=65535 --pid-file=/data/mysql/data/mysql.pid --socket=/var/lib/mysql/mysql.sock --port=3306root 16878 1286 0 12:47 pts/1 00:00:00 grep mysql[root@dbm137~]# vi /etc/profile #Modify PATHPATH##Add at the end: export PATH=$PATH:/usr/local/mysql/bin[root@dbm137~]#source/etc/profile# Take effect immediately

dbm138(secondary)

##The following operations must watch carefully##First, perform the main backup of the DRBD device Switch, switch dbm137 to seocndary, and switch dbm138 to primary##Execute on the dbm137(primary) side [root@dbm137~]#/etc/init.d/mysqld stop#Stop the mysql service of 137 Shutting down MySQL. SUCCESS! [root@dbm137~]#umount /dev/drbd0 #Uninstall the DRBD device[root@dbm137~]#drbdadmsecondaryr0#Switch to secondary[root@dbm137~]#drocat/proc/d 8.3 .16 (api:88/proto:86-97) 0: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r-----
##Execute on the dbm138(secondary) side[root@dbm138~]#drbdadm primary r0#Switch 138 to primary[root@dbm138~]#cat /proc/drbd| grep roversion: 8.3.16 (api: 88/proto:86-97) 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----[root@dbm138~]#mount/dev/drbd0/data/#Mount DRBD device [root@dbm138~]#df -hFilesystem Size Used Avail Use% Mounted on / dev / mapper / VolGroup-lv_root 19G 3.4G 14G 20% / tmpfs 58M 0 58M 0% / dev / shm / dev / sda1 477M 43M 409M 10% / boot / dev / drbd0 8.8 G 2.1G 6.3G 25%/data[root@dbm138~]#cd/data/mysql/data/#View mysql data[root@dbm138data]#lltotal 2109468-rw-rw---- 1mysql mysql 56Jul 2 12:46 auto.cnf-rw-rw---- 1 mysql mysql 12582912 Jul 2 13:02 ibdata1-rw-rw---- 1 mysql mysql 1073741824 Jul 2 13:02 ib_logfile0-rw-rw--- -1 mysql mysql 1073741824 Jul 2 12:46 ib_logfile1drwx 2 mysql mysql 4096 Jul 2 12:00 mysqldrwx 2 mysql mysql 2 12:00 performance_schema-rw-rw-rw-rw -1 mysql mysql 185 Jul 2 12:46 slow.logdrwx 2 mysql mysql 4096 Jul 2 12:00 test[root@dbm138~]# cd/data/mysql/binlog/ View binary file[root @dbm138 binlog]# lltotal 8-rw-rw---- 1 mysql mysql 285 Jul 2 13:02 mysql-binlog.000001-rw-rw---- 1 mysql mys ql 39Jul 2 12:46 mysql-binlog.index[root@dbm138~]#mv/usr/local/mysql/my.cnf/usr/local/mysql/my.cnf.old[root@dbm138~]#vi /usr/local/mysql/my.cnf #Modify the configuration file[mysqld]basedir=/usr/local/mysql #Installation path datadir=/data/mysql/data #Data directory port=3306server-id= 1 #This value is not required To modify, because there is only one active and standby mysql at the same time pid-file = /data/mysql/data/mysql.pid #process file socket = /var/lib/mysql/mysql.sockdefault_storage_engine = InnoDBlog-bin = /data/ mysql / binlog / mysql-binlog # binaries expire_logs_days = 14max_binlog_size = 5Gbinlog_cache_size = 10Mmax_binlog_cache_size = 20Mslow_query_loglong_query_time = 2slow_query_log_file = /data/mysql/data/slow.log #slow log file open_files_limit = 65535innodb = FORCEinnodb_buffer_pool_size = 100M # Note that this parameter innodb_log_file_size = 1Gquery_cache_size = 0thread_cache_size = 64table_definition_cache = 512table_open_cache = 512max_connections = 200sort_buffer_size = 10Mmax_allowed_packet = 6Msql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES[client]#soc/var/var/var k##Note:##The active and standby nodes must ensure that the configuration file my.cnf is exactly the same on both sides to avoid problems [root@dbm138~]# cp-a/usr/local/mysql/support-files/mysql.server/etc/ init.d/mysqld #copy start script##Note:##Don’t, don’t set mysql to start automatically at boot, because the start of mysql service is managed by heartbeat [root@dbm138~]#/etc/init.d /mysqld start #Start mysql service Starting MySQL...SUCCESS! [root@ dbm137~]# ps -ef| grep mysqlroot 1 0 12:46 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/data-- pid-file=/data/mysql/data/mysql.pidmysql 16783 16284 6 12:46 pts/1 00:00:03 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql-- datadir=/data/mysql/data--plugin-dir=/usr/local/mysql/lib/plugin--user=mysql--log-error=/var/log/mysqld.log--open-files-limit =65535--pid-file=/data/mysql/data/mysql.pid--socket=/var/lib/mysql/mysql.sock--port=3306root 16878 1286 0 12:47 pts/1 00:00: 00 grep mysql[root@dbm138~]# cd /data/mysql/binlog/ #View this binary file[root@dbm138 binlog]#ll #Nextdbm137 Regenerate a .000002, normal total 12-rw-rw---- 1 mysql mysql 285 Jul 2 13:02 mysql-binlog.000001-rw-rw---- 1 mysql mysql 120 Jul 2 13:28 mysql -binlog.000002-rw-rw---- 1 mysql mysql 78 Jul 2 13:28 mysql-binlog.index[root@dbm138~]#vi/etc/profile #改PATH##Add at the end: export PATH =$PATH:/usr/local/mysql/bin[root@dbm138~]#source/etc/profile#Effect immediately

Install and configure HeartBeat:

Install HeartBeat: (dbm137,dbm138)

yum is used to install HeartBeat here (recommended)

Centos6.4 does not include the HeartBeat software package by default, and the epel source needs to be installed

[root@dbm~]# cd /usr/local/src /[root@dbm src]# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm[root@dbmsrc]# rpm-ivh epel- release-6-8.noarch.rpm [root@dbm src]# yum -y install heartbeatLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfileError: Can not retrieve metalink for repository: epel. Please verify its path and try again

Note: An error was reported during yum installation, the solution:

[root@dbm~]#vi/etc/yum.repos.d/epel .repo#to comment out all baseurl lines#Comment out all mirrorlist lines[root@dbm src]#yum-y install heartbeat

Configure HeartBeat: (dbm137,dbm138)

Note : At this time dbm138 is Primary

##Preparation work before configuration: ##stop the MySQL service of two nodes will be stopped by heartbeat Unified management [root@dbm~]# /etc/init.d/mysqld stopShutting down MySQL.. SUCCESS!##Uninstall the DRBD devices of the two nodes, which will be managed by heartbeat [root@dbm~]#umount/dev/ drbd0
Heartbeat configuration involves the following files: /etc/ha.d/ha.cf #Main configuration file/etc/ha.d/haresources #资源文件/etc/ha.d/authkeys #Authentication related/etc/ha.d/resource.d/mysqld #mysql startup script, managed by HeartBeat
Edit the main configuration file ha.cf[root@dbm137~]# vi /etc/ha.d/ha.cf (dbm137)logfile /var/log/ha-log# Define the log name and storage location of HA logfacility local0keepalive 2#The heartbeat sending interval is 2 seconds deadtime 10#The death time is 10 seconds, and the standby node does not detect the heartbeat of the host within 10 seconds, confirm the other party's failure ucast eth0 192.168.186.138#ucast xxx.xxx #xxx.eth1 xxx.xxx.xxx. The address is designated as the other party’s IP# Use two heartbeat lines, the internal network and the external network, to ensure the high availability of the heartbeat auto_failback off# After the server is normal, the new primary server will take over the resource, and the other server will give up the resource, because the cost of switching once is high node dbm137.51.com dbm138.51.com#Define the node and specify the hostname hostname
[root@dbm138~]# vi /etc/ha.d /ha.cf (dbm138)logfile /var/log/ha-log#Defines the log name and storage location of HA logfacility local0keepalive 2#The heartbeat sending interval is 2 seconds, deadtime 10 seconds, standby node 10 seconds The host’s heartbeat is not detected, and confirm that the other party is faulty ucast eth0 192.168.186.137#ucast eth1 xxx.xxx.xxx.xxx#IP address is designated as the other party’s IP# Use two heartbeat lines for the internal network and external network to ensure the high availability of the heartbeat auto_failback #After the server is normal, the new main server takes over the resource, and the other server gives up the resource because the cost of switching once is very high node dbm137.51.com dbm138.51.com#Define the node, specify the hostname hostname

Edit the two-machine interconnection verification file authkeys:(dbm137,dbm138) p>

[root@dbm ~]# vi /etc/ha.d/authkeysauth 11 crc
#Requires permission to set /etc/ha.d/authkeys to 600[root@dbm~]# chmod 600 /etc/ha.d/authkeys

Edit the cluster resource file haresources:(dbm137,dbm138)

[root@dbm~]#vi/etc/ha.d/haresourcesdbm138.51. com IPaddr::192.168.186.200/24/eth0 drbddisk::r0 Filesystem::/dev/drbd0::/data::ext4 mysqld##The contents of this file on the two hosts dbm137 and dbm138 are exactly the same. Do not modify dbm137 to dbm137.51.com##Host name is set to the host name of the primary node (Primary) at this time, that is, dbm138.51.com##Ipaddr: bind virtual ip and bind it on eth0##drbddisk: specify drbd ##Filesystem: Specify the drbd device /dev/drbd0, mount point /data, file system ext4, and mount the drbd device ##mysqld: Specify the mysql startup script, which is managed by heartbeat 

Edit the mysql script file mysqld:(dbm137,dbm138)

[root@dbm~]# cp-a/etc/init .d/mysqld/etc /ha.d/resource.d/

Start HeartBeat:(dbm137,dbm138)

Note:Start on the primary node first(dbm138 is primary)

dbm138(Primary)[root@dbm138~]# /etc/init.d/heartbeat startStarting High-Availability services: INFO: Resource is stoppedDone.[root@dbm138~]# chkconfig heartbeat on[root@dbm138~]# ps -ef| grep heartbeatroot 00:00 17255 1 0 14:39 00:00:00 heartbeat: master control processroot 17259 17255 0 14:39 17 260 255 0 14:39 heartbeat 17 255 0 00:00:00 heartbeat: 0 0 00:00:00 :00 heartbeat: write: ucast et h0root 17261 17255 0 14:39 00:00:00 heartbeat: read: ucast eth0 root 14:39 pts/0 0 14:39 pts/0 heartbeat[root@dbm138-ef#grep heartbeat[root@dbm138-~]# Check whether the mysql service has started root 17943 1 0 14:39 00: 00: 00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/data --pid-file=/ data/mysql/data/mysql.pidmysql 18437 17943 8 14:39 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/ data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --open-files-limit=65535 --pid-file =/data/mysql/data/mysql.pid --socket=/var/lib/mysql/mysql.sock --port=3306root 18470 1283 0 14:39 pts/0 00:00:00 grep mysql[root@dbm138 ~] # df -h # view DRBD apparatus mounted there Filesystem Size Used Avail Use% mounted on / dev / mapper / volGroup-lv_root 19G 3.4G 14G 20% / tmpfs 58M 0 58M 0% / dev / shm / dev / sda1 477M 4 3M 409M 10% /boot/dev/drbd0 8.8G 2.1G 6.3G 25% /data
dbm137(Secondary)[root@dbm137~]#/ etc/init.d/heartbeat startStarting High-Availability services: INFO: Resource is stoppedDone.[root@dbm137~]# chkconfig heartbeat on[root@dbm137~]# ps-ef|grep heartbeat root: 43 1 17508 0 :00:00 heartbeat: master control processroot 17512 17508 0 14:43 0 00: 00 heartbeat: FIFO reader 17513 17508 0 14:43 17508 0 14:43 0 14:43 0 14: 00:00 write 0 14:00:00 heartbeat: 0 14: 508 0 14:00:00 00:00:00 heartbeat: read: ucast eth0 root 17538 1271 0 14:43 pts/0 00:00:00 grep heartbeat[root@dbm137~]#ps -ef|grep mysql mysql service not started #root node 17540 1271 0 14:43 pts/0 00:00:00 grep mysql[root@dbm137~]# df -h The DRBD device of the standby node is not mounted on the Filesystem Used/Mounted/Avail%/root/Avail Volume 19G 3.4G 14G 20%/tmpfs 58M 0% 58M 0% /dev/shm/dev/sda1 477M 43M 409M 10% /boot

Test:

Test 1: Whether the client can successfully access the database

##Database primary (dbm138)[root@dbm138~]#cat /proc/drbd| grep ro #Confirm that it is the Primary node version: 8.3.16 (api:88/proto :86-97) 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----[root@dbm138~]#mysql-p123456#Login to the database Warning:Using a password on the interface can be insecure. Welcome to the MySQL monitor. Commands end with; or \g. Your MySQL connection id is 3Server version: 5.6.22-log Source distribution Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights .Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type'help;'or'\h'for help.Type'\c'to clear the current input statement.mysql> grant replication slave on *.* to'client'@'192.168.186.136' identified by '123456'; #Create a database account and authorize Query OK, 0 rows affected (0.03 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
##Client192.168.186.136[root@scj136~]#mysql-h192.168.186.200-uclient-p123456#Connect to the database, ip It is a virtual ip200Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with; or \g. Your MySQL connection id is 4Server version: 5.6.22-log Source (distribution) 2000 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type'help;' Type' or'\h' for help \c'to clear the current input statement.mysql>show databases;#Visit successful+--------------------+|Database|+------ --------------+| information_schema|| test|+--------------------+2 rows in set (0 .12 sec)

Test 2: The DRBD service of the master node is stopped

The DRBD service of the master node is stopped, and the secondary node changes, Whether the client can continue to access the database

Test 3: The mysql service of the master node is stopped

The mysql service of the master node is stopped, see If the secondary node changes, can the client continue to access the database

##After stopping the primary node’s mysql service, the Secondary node has no change and 192.168. 186.136 I can’t access the database normally
##Solution:## Both primary and secondary nodes must write [root@dbm~]#vi/opt/monitor/ mysql/monitormysql.sh#!/bin/bash#Monitor the operation of mysql service while truedo drbdstatus=`cat /proc/drbd 2> /dev/null| grep ro| tail -n1|awk -F':''{ print $4}'|awk -F'/'{print $1}'#Judging the status of drbd mysqlstatus=`/etc/init.d/mysqld status| grep -c SUCCESS#Judge whether mysql is running if[-z $drbdstatus];then init sleep 10 elif[$drbdstatus=='Primary'];then #If drbd is Primary status/mysql if not start/mysql#theneq if[$0mysqlstatus] &> /dev/null #Start mysql service /etc/init.d/mysqld start &> /dev/null newmysql status=`/etc/init.d/mysqld status| grep -c SUCCESS# again judge whether mysql started successfully if [$newmysqlstatus -eq 0]; then. If mysql is not running, it cannot be started./etc/ d/heartbeat stop &> /dev/null #stop the heartbeat service, the purpose is to automatically switch to another backup machine /etc/init.d/heartbeat stop &> /dev/null #stop After the heartbeat service is stopped, it will Uninstall the DRBD device, stop the mysql service, switch between active and standby fi fi sleep 5done
##Note: Do not put this monitoring script in the /data/ directory When the drbd device is mounted, this script will be overwritten [root@dbm~]#chmod u+x/opt/monitor/mysql/monitormysql.sh[root@dbm~]#nohupbash/opt/monitor/mysql /monitormysql.sh&#Place background operation##Don’t forget to set automatic startup when booting

Test 4: The heartbeat service of the master node is stopped or restarted

Stop or restart the heartbeat service of the primary node to see if the Secondary node changes and whether the client can continue to access the database

##Master node ( primary) dbm138[root@dbm138~]#/etc/init.d/heartbeatMovie BD%restart size[root@dbm138~]#df -h Uninstallation System# unted on / dev / mapper / VolGroup-lv_root 19G 3.4G 14G 20% / tmpfs 58M 0 58M 0% / dev / shm / dev / sda1 477M 43M 409M 10% / boot [root @ dbm138 ~] # ps -ef | grep mysql #mysql service is closed root 20784 1283 0 05:27 pts/0 00:00:00 grep mysql
##Backup node(secondary)dbm137[ root @ dbm137 ~] # df -h #DRBD device mounted Filesystem Size Used Avail Use% mounted on / dev / mapper / volGroup-lv_root 19G 3.4G 14G 20% / tmpfs 58M 0 58M 0% / dev / shm / dev /sda1 Main switch 477M 43M 409M 10% /boot/dev/drbd0 8.8G 2.1G 6.3G 25% /data (root@dbm137~)# 8.3#cat /proc/drbd api: 16# proto:86-97)GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build32R6, 2014-11-24 14:49:06 0:cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C ns----- :119303 28 nr:1408dw:2494876 dr:9454779al:633bm:576lo:0pe:0ua:0ap:0ep:1wo:foos:0[root@dbm137~]#ps -ef|grepmysql #mysql service has started root 20633 1 0 05:26 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/data--pid-file=/data /mysql/data/mysql.pidmysql 21127 20633 3 05:26 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysqld.log --open-files-limit=65535 --pid-file= /data/mysql/data/mysql.pid--socket=/var/lib/mysql/mysql.sock--port=3306root 21440 1271 0 05:26 pts/0 00:00:00 grep mysql

< pre class="brush:bash;toolbar:false">##Client 192.168.186.136[root@scj136~]#mysql-h192.168.186.200-uclient-p123456Warning:Using a password on the command line interface can be insecure .Welcome to the MySQL monitor. Commands end with; or \g. Your MySQL connection id is 2Server version: 5.6.22-log Sour ce distributionCopyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective helpers. h’for help.Type’\c’to clear the current input statement.mysql>show databases;#Access is still normal+——————–+|Database |+——————–+| information_schema|| test|+——————– +2 rows in set (0.07 sec)

Test 5: Shut down or restart the master node server

Shut down or restart the primary node server to see the changes of the Secondary node and whether 192.168.186.136 can still access the database; after the primary node restarts, look at the Secondary node (new primary node) ) Changes

##After the primary node is shut down, the primary and standby nodes switch normally, and client access is normal##After the primary node returns to normal, the primary and standby nodes will not Then switch, the Secondary node (new master node) will continue to provide services to the outside world

Leave a Comment

Your email address will not be published.