When ha switches, it will stop the local resources and then start the resources of the other party.
Our actual environment has two resources:
One is ipaddr, which is used to manage VIP;
MySQL is used to manage MySQL resources;
In the actual application process, we found that MySQL cannot be flush dirty pages or it takes a long time to start (recovery). This greatly prolongs the HA switching time. So we are wondering if HA can only manage the MySQL status, rather than MySQL start and stop? We know that when ha manages resources of the LSB type, it calls/etc/init. d/or. /resource. d/Add the start/stop/status parameter to the resource-related commands in the directory.
For example, there are MySQL resources,
Start MYSQL: Service MySQL start
Stop MYSQL: Service MySQL stop
MySQL: Service MySQL status for the purpose, we can modify the shell script:/etc/init. d/MySQL
==========================================
'Status ')
# First, check to see if PID file exists
If test-s "$ server_pid_file"; then
Read mysqld_pid <$ server_pid_file
If kill-0 $ mysqld_pid 2>/dev/NULL; then
Log_success_msg "MySQL running ($ mysqld_pid )"
Exit 0
Else
Log_failure_msg "MySQL is not running, but PID file exists"
Exit 1
Fi
Else
# Try to find appropriate mysqld Process
Mysqld_pid = 'pidof $ sbindir/mysqld'
If test-Z $ mysqld_pid; then
If test "$ use_mysqld_safe" = "0"; then
Lockfile =/var/lock/subsys/mysqlmanager
Else
Lockfile =/var/lock/subsys/MySQL
Fi
If test-F $ lockfile; then
Log_failure_msg "MySQL is not running, but lock exists"
Exit 2
Fi
Log_failure_msg "MySQL is not running"
Exit 3
Else
Log_failure_msg "MySQL is running but PID file cocould not be found"
The above changes mean that when the service msyql status is run,
If the host hang is running, the MySQL process is still running, but MySQL cannot respond to the query. We also set the status to failed.
(If the temporary file MySQL is in 10 seconds. 'date + % Y % m % d % H % m % s '. $ mysqlpid exists, and the content must be "aliyun. mySQL ", then MySQL is normal .)
If the above condition is true, MySQL is in the unresponsive state, and the program will write information to the file:/home/MySQL/aliyun. mysqlheartbeat if MySQL fails to be checked. it will stop/start MySQL resources n times (N is based on CIB. xml configuration ),
During the restart process, the Stop/start status is directly returned to 0. Do not really close or start MySQL.
In this way, an error is returned directly when MySQL detects the status next time. Quick Switch. Therefore, in/etc/init. d/MySQL, we need to change the following:
0) change the original MySQL parameter start/stop to startup/stopdown.
Status MYSQL: Service MySQL statusservice MySQL start/stop
If neither of the two statements does anything, send a message to you! Summary:
After this is done, no matter how heartbeat restarts/closes, it will only affect the VIP. MySQL is not directly operated.
On the one hand, it will not affect MySQL because heartbeat is not working properly;
On the other hand, heartbeat switching can be made faster (because it saves time to start and stop MySQL), but there is a small drawback in doing so:
MySQL is not automatically started when heartbeat is started.
After heartbeat is started, MySQL becomes invalid. Then a switchover occurs.
Therefore, you must ensure that at least one node's MySQL status is normal before heartbeat is started!
The above script has been successfully tested in Linux rhel5.3 and heartbeat 2.1.4 environments.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.