Mysql Linux
Mysql Linux
Double-Take, GeoCluster, Double-Take for Virtual Systems, and NSI are registered trademarks of Double-Take Software, Inc. Balance and Double-Take ShadowCaster are trademarks of Double-Take Software, Inc. TimeData is a registered trademark of Double-Take Software Canada, Inc. TimeData logo is a trademark of Double-Take Software Canada, Inc. Linux is the registered trademark of Linus Torvalds in the U.S. and other countries. Red Hat and Red Hat Enterprise Linux are registered trademarks of Red Hat, Inc. in the United States and other countries. MySQL is a registered trademark of MySQL AB in the United States, the European Union and other countries. Microsoft, Windows, and the Windows logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. VMware is a registered trademark or trademark of VMware, Inc. in the United States and/or other jurisdictions. All other trademarks are the property of their respective companies. 2008 Double-Take Software, Inc. All rights reserved. Revision 1.0.0 published June 2008
Table of Contents
Document Overview ............................................................................ 1
Audience ................................................................................................................ 1 Expectations ........................................................................................................... 1 Related documentation ............................................................................................. 1 Getting help ............................................................................................................ 2
Document Overview
This document is a Double-Take application note. An application note provides guidelines on the use of Double-Take in a specific environment. This document contains: Document OverviewExplains what an application note contains, how it should be used, what you need to know before trying to use the application note, and where you can go for more information. Solution OverviewExplains how the application works with Double-Take and describes the considerations that you must weigh when implementing your Double-Take solution. Review this section to make sure that you understand the theory involved with using Double-Take and your application. Includes both basics, such as system requirements, as well as configuration and environment-specific topics, such as interactions with specific clients or special considerations for WAN (Wide Area Network) environments. Pay special attention to those topics that are directly related to your environment. Sample ImplementationDescribes a specific example of how to use Double-Take for this solution. Use these procedures as a guideline for creating your own implementation. NOTE: Because no two environments or configurations are exactly the same, you will probably need to implement additional or different steps than what is documented here in order to make the solution work in your environment.
Audience
This document is written for network and application administrators who have a working understanding of the applications and environments where the Double-Take solution is to be deployed. You may need to expand on the documented information in order to customize the solution to fit your environment. Before you use this application note, you should have an understanding of: Double-Take MySQL
Expectations
Application notes are intended to provide a framework for configuring a Double-Take solution in a specific environment and to draw attention to decisions you will need to make when configuring your solution. Because there are an infinite number of possible configuration, network, and environment scenarios, application notes contain general configuration guidelines as well as an example configuration procedure that has been tested for a specific environment. This document assumes that you are comfortable working with your operating system, Double-Take, and MySQL.
Related documentation
Before you begin to configure your solution, make sure that you have complete documentation for your operating system, application, and Double-Take. This application note does not provide step-by-step instructions for using standard operating system, application, and Double-Take functionality. The following documents contain additional information that you may need while setting up this solution: Double-Take Users Guide or online documentation Reference guides or documentation for your version of MySQL
Getting help
Double-Take Software has application notes that describe how to configure Double-Take with a variety of popular third-party applications. These application notes are available on the Application Notes page of the Double-Take Software support web site (http://support.doubletake.com). Double-Take Software offers professional services on a fee basis to assist you in identifying the best practices for implementing a solution in your environment. Visit http://www.doubletake.com/what-we-offer/services/ for more information.
Solution Overview
MySQL is a scalable, reliable, flexible, and high-performance relational database management system for many server-based operating systems. Double-Take provides real-time enterprise data protection and replication. Double-Take can be used to provide high availability for MySQL. This document describes the steps necessary to configure Double-Take to provide high availability for Linux servers running MySQL. These procedures allow a secondary server to assume the identity and role of a failed primary MySQL server while maintaining the availability of MySQL services with minimal disruption or data loss. To complete these instructions, you will install MySQL and Double-Take, and configure Double-Take for replication and failover. NOTE: Due to the complexities of these applications, this document is intended for network administrators with experience installing, configuring, and maintaining network applications including Double-Take and MySQL.
Configuration
In this solution, a single server is configured to act as the primary MySQL server, and a second server is configured to act as the backup target server. Double-Take is used to replicate and failover the MySQL server database to a Double-Take target machine. In the event of a source failure, the clients are directed to the target server. Failed Source (Offline) Target
Target Name: Jersey and Indy Target IP: 125.7.82.67 and 125.7.82.43 MySQL Double-Take
MySQL client User and application requests are sent to the target by locating the sources original IP address or hostname NOTE: Double-Take allows you to configure one target to monitor and failover for one or more source machines. In a one-to-one configuration, you will want to replicate your MySQL data to the same location on the target so that failover is automatic. In a many-to-one configuration, the data will need to be replicated to a unique location and then renamed to the corresponding MySQL directory on the source before failover occurs. This application note focuses on a single MySQL server being replicated to a single target.
Requirements
For this scenario, your system must meet the following requirements: Two servers running Red Hat Enterprise Linux 4.5 or later NOTE: The two servers should both be running the same operating system.
Both servers must be connected to the same physical network MySQL server, version 5.0 or later Two licensed copies of Double-Take for Linux If you are using MySQL for Linux servers (64-bit), the following minimum versions are required: Two servers running Red Hat Enterprise Linux 4.5 or later (64-bit) NOTE: The two servers should both be running the same operating system.
Both servers must be connected to the same physical network MySQL server, version 5.0 or later Two licensed copies of Double-Take for Linux version 4.3.x or later The system hardware must support 64-bit applications
Permissions
The source and target machines must share the same user accounts that have the same GUID. Double-Take Software strongly recommends that customers use unified network accounts in order to facilitate transferring the database from the source to the target.
File Name
Ib_logfile# Ibdata#
NOTE:
The Listener service will not start on the target if mysql.sock is replicated from the source, but the target is not in a failed over state. This file contains configuration information that is not valid on the target unless it is in a failed over state. If you need to start MySQL on the target server without failing over, do not include mysql.sock in the replication set.
Sample Implementation
This section describes an example of how to configure Double-Take and MySQL. Use these procedures as a guideline for creating your own implementation. Because no two environments or configurations are exactly the same, you will probably need to implement additional or different steps than what is documented here in order to make the solution work in your environment.
creating will control the stopping and starting of the Mysql service. Make sure to set the services on the target to manual startup.
Create an /etc/init.d/mysqld script to start and stop the mysql service manually. An example init.d script is included in Configure failover and begin failure monitoring. Once configured properly in a Linux server, the Mysql service can be started or stopped by executing the command.
4.
# /etc/init.d/mysqld start / stop The command /etc/init.d/mysqld start/stop can be used inside a post-failover and
pre-failback script to start and stop Mysql services on the target server. Getting Started guide for details.
5. Install Double-Take on the target server using the installation defaults. See the Double-Take
2. Double-click your source machine to log on. 3. Right-click your source machine and select New, Replication Set and enter the desired name
4. Select the MySQL data you wish to protect. For more information about what you should include
5. Right-click the replication set name and select Save to save the replication set. 6. Right-click on the source and select Properties. 7. On the Source tab, enable Block Checksum All Files on a Difference Mirror and click OK. 8. Drag and drop the replication set onto the target. The Connection Manager dialog box opens. 9. The Source Server, Target Server, Replication Set, and Route fields will automatically be
populated. If you have multiple IP addresses on your target, verify the Route field is set to the correct network path. (For detailed information on connecting a source and target, see the Double-Take User's Guide.)
10. Select One to One to map the replication set data from the source to an identical
NOTE:
If you start MySQL and mount the replicated databases on the target, or if the data on the target is otherwise modified, the data on the source and target will no longer match. If the updated data on the target is not needed, perform a full or difference with block checksum mirror from the source to the target. If the updated data on the target is needed, restore the data from the target to the source.
automatically. To do this, create a shell script file called POST_FAILOVER.SH and save the file to the /usr/bin/ directory where the Double-Take commands are installed. The POST_FAILOVER.SH script should include the following contents
******************************************************** #!/bin/bash /etc/init.d/mysqld start ********************************************************
MySQL services.
Sample_Init.d
############***** BEGINING OF INIT.D SCRIPT FOR MySQL SERVICE ***** ############# #!/bin/bash # # mysqld This shell script takes care of starting and stopping # the MySQL subsystem (mysqld). # # chkconfig: - 64 36 # description:MySQL database server. # processname: mysqld # config: /etc/my.cnf # pidfile: /var/run/mysqld/mysqld.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network prog="MySQL" # extract value of a MySQL option from /etc/my.cnf # Usage: get_mysql_option FILE VARNAME DEFAULT # result is returned in $result get_mysql_option(){ result=`sed -n "s/^[ \t]*$2[ \t]*=[ \t]*//p" "$1" 2>/dev/null | tail -n 1` if [ -z "$result" ]; then # not found, use default result="$3" else # found, still have to deal with quoting and end-of-line comments dequoted=`echo "$result" | sed "s/^'\([^']*\)'.*$/\1/"` if [ x"$dequoted" != x"$result" ]; then result="$dequoted" else dequoted=`echo "$result" | sed 's/^"\([^"]*\)".*$/\1/'` if [ x"$dequoted" != x"$result" ]; then result="$dequoted" else result=`echo "$result" | sed 's/^\([^ \t#]*\).*$/\1/'` fi fi fi } get_mysql_option /etc/my.cnf datadir="$result" get_mysql_option /etc/my.cnf socketfile="$result" get_mysql_option /etc/my.cnf errlogfile="$result" get_mysql_option /etc/my.cnf mypidfile="$result" datadir "/var/lib/mysql" socket "$datadir/mysql.sock" err-log "/var/log/mysqld.log" pid-file "/var/run/mysqld/mysqld.pid"
start(){ touch "$errlogfile" chown mysql:mysql "$errlogfile" chmod 0640 "$errlogfile" [ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile" if [ ! -d "$datadir/mysql" ] ; then action $"Initializing MySQL database: " /usr/bin/mysql_install_db ret=$? chown -R mysql:mysql "$datadir" if [ $ret -ne 0 ] ; then return $ret fi fi chown -R mysql:mysql "$datadir" chmod 0755 "$datadir" # The reason for explicitly specifying --pid-file is that there may # be no such entry in my.cnf, and the default behavior will be to not # create it at all... /usr/bin/mysqld_safe --defaults-file=/etc/my.cnf --pid-file="$mypidfile" >/dev/null 2>&1 & ret=$? # Spin for a maximum of N seconds waiting for the server to come up. # Rather than assuming we know a valid username, accept an "access # denied" response as meaning the server is functioning. if [ $ret -eq 0 ]; then STARTTIMEOUT=30 while [ $STARTTIMEOUT -gt 0 ]; do RESPONSE=`/usr/bin/mysqladmin -uUNKNOWN_MYSQL_USER ping 2>&1` && break
echo "$RESPONSE" | grep -q "Access denied for user" && break sleep 1 let STARTTIMEOUT=${STARTTIMEOUT}-1 done if [ $STARTTIMEOUT -eq 0 ]; then echo "Timeout error occurred trying to start MySQL Daemon." action $"Starting $prog: " /bin/false else action $"Starting $prog: " /bin/true fi else action $"Starting $prog: " /bin/false fi [ $ret -eq 0 ] && touch /var/lock/subsys/mysqld return $ret } stop(){ MYSQLPID=`cat "$mypidfile" 2>/dev/null ` if [ -n "$MYSQLPID" ]; then /bin/kill "$MYSQLPID" >/dev/null 2>&1 ret=$? if [ $ret -eq 0 ]; then STOPTIMEOUT=60 while [ $STOPTIMEOUT -gt 0 ]; do /bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break sleep 1 let STOPTIMEOUT=${STOPTIMEOUT}-1 done if [ $STOPTIMEOUT -eq 0 ]; then echo "Timeout error occurred trying to stop MySQL Daemon." ret=1 action $"Stopping $prog: " /bin/false else rm -f /var/lock/subsys/mysqld rm -f "$socketfile" action $"Stopping $prog: " /bin/true fi else action $"Stopping $prog: " /bin/false fi else ret=1 action $"Stopping $prog: " /bin/false fi return $ret } restart(){ stop start } condrestart(){ [ -e /var/lock/subsys/mysqld ] && restart || : } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status mysqld ;; restart) restart ;; condrestart) condrestart ;; *) echo $"Usage: $0 {start|stop|status|condrestart|restart}" exit 1 esac exit $? ############# ***** END OF INIT.D SCRIPT FOR MYSQL SERVICE ***** #############
********************************************************************************************************* NOTE :--- Copy this script to the /etc/init.d/ directory of the linux server, and name it as "mysqld". chkconfig mysql on Please note that you can just use script directly, To start Mysql type command: $ /etc/init.d/mysqld start To stop Mysql type command: $ /etc/init.d/mysqld stop
3. After a failure is resolved, you will be ready to bring your source back online. At this time, you
will want to stop the MySQL services on the target automatically. To do this, create a shell script file called PREFAILBACK.SH and save the script file to the /usr/bin/ directory where the Double-Take commands are installed. The PREFAILBACK.SH script should include the following:
****************************************************************** #!/bin/bash /etc/init.d/mysqld stop ******************************************************************
4. Select Start, Programs, Double-Take, Failover Control Center. 5. Select the target machine from the list of available machines. If the target you need is not
displayed, click Add Target, enter the machine name, and click OK. machine and click OK. The Monitor Settings window will open.
6. To add a monitor for the selected target, click Add Monitor. Type the name of the source 7. In the Monitor Settings window, mark the IP address that is going to failover. 8. Click Scripts and specify the scripts that were created previously, using POST_FAILOVER.SH for the target post-failover script and PREFAILBACK.SH for the target pre-failback script. NOTE:
The scripts are processed using the same account running the Double-Take service.
9. Click OK to go back to the Monitor Settings dialog box. 10. Click OK to begin monitoring the source machine.
In the event of a source machine failure, your target machine is now ready to stand in for your source. For details on monitoring failover, see the Double-Take Users Guide.
NOTE:
If you must rebuild your hard drive, continue with step 3. If you do not need to rebuild your hard drive, verify that the Double-Take connection on the source has been disconnected (right-click the connection in the Double-Take Management Console and select Disconnect) and then continue with step 6.
3. Install your operating system. Since your source machine is not connected to the network, go
4. Install Double-Take using the installation defaults. 5. Install MySQL using the same installation settings as you did originally. 6. On the source, stop the MySQL service so that all MySQL files are closed on the source and the
Double-Take target can restore the changes back to the source. Depending on the type of failure, your services may be set to manual startup but could still be running. Stop any SQL services that are running.
10
8. Select the target machine that is currently standing in for the failed source. 9. Select the failed source and click Failback. The pre-failback script entered during the failover
configuration stops the MySQL services on the target so that no additional changes can be made.
10. You will be prompted to determine if you want to continue monitoring the source server. Do not
11. Stop the MySQL service on the source. 12. Delete the 13. Restart the Double-Take service (#service
14. Connect the source machine to the network. 15. After the source is back online, select whether or not you want to continue monitoring this
Verify that the Double-Take connection on the source has been disconnected. If it is not, right-click the connection in the Double-Take Management Console and select Disconnect.
16. Since the replication sets were deleted, you will need to re-create those replication sets. 17. To begin the restoration process, open the Double-Take Management Console and select Tools,
You can also run the Double-Take DTCL automated restoration script, which can be found in the Double-Take Users Guide, to complete the remaining steps in this section.
Original SourceThe name of the source machine where the data originally resided. Restore FromThe name of the target machine that contains the replicated data. Replication SetThe name of the replication set to be restored. Restore ToThe name of the machine where the data will be restored. This may or may not be the same as the original source machine.
19. Identify the correct drive mappings for the data and any other restoration options necessary. For
detailed information on the restoration options, see the Double-Take Users Guide.
20. Verify that the selections you have made are correct and click Restore. The restoration
procedure time will vary depending on the amount of data that you have to restore.
21. After the restoration is complete, start the MySQL services on the source machine. 22. Reestablish the Double-Take MySQL replication set connection.
At this time, your data is restored back to your source machine, the source machine is again the primary MySQL server, and, if you selected to continue failover monitoring, the target is available to stand in for the source in the event of a failure.
11