Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change / etc/init.d/mysql and let HeartBeat just monitor the status of MYSQL

2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to change / etc/init.d/mysql and let HeartBeat just monitor the status of MYSQL, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Based on HA, when switching occurs, it will do STOP native resources, and then START each other's resources.

There are two resources in our real environment:

One is IPaddr, which is used to manage VIP

One is mysql, which is used to manage MYSQL resources

In practical application, we find that MYSQL can not be turned off at once (flush dirty pages), or it takes a long time to start (recovery). This greatly prolongs the switching time of HA.

So we were wondering if HA could only manage the state of MYSQL, but not the startup and STOP of MYSQL?

We know that when HA manages a resource of type lsb, it calls the resource-related command in the / etc/init.d/ or. / resource.d/ directory plus the parameter start/stop/status.

For example, there are mysql resources

Start mysql: service mysql start

Stop mysql: service mysql stop

Status mysql: service mysql status

To achieve this, 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 could not be found"

Exit 4

Fi

Fi

= >

This paragraph is changed to:

=

'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

#-Modi-1

. / root/.bash_profile

MYSQLPID=$$

STAT_FILE=/home/mysql/ mysql.`date +% Y% m% d% H% M% S`.$ MYSQLPID

Mysql-uroot-h227.0.0.1-s-e "select" aliyun.mysql ";" > $STAT_FILE 2 > & 1 &

CNT=1

MYSQLSTATUS=UNKNOWN

While ["$MYSQLSTATUS" = "UNKNOWN"]

Do

If test-f $STAT_FILE

Then

Read CONTENT

< $STAT_FILE if [ "$CONTENT" = "aliyun.mysql" ] then MYSQLSTATUS=OK log_success_msg "MySQL running ($mysqld_pid)" rm -f $STAT_FILE exit 0 elif [ "$CONTENT" != "" ]; then ERROR_CNT=`grep -i "error" $STAT_FILE | grep -v "using password" | wc -l` if [ "$ERROR_CNT" -ge "1" ];then log_failure_msg "MySQL status Warning in logfile $STAT_FILE " fi exit 0 fi fi sleep $CNT CNT=`expr $CNT + 2` if [ $CNT -gt 5 ]; then MYSQLSTATUS=ERROR log_failure_msg "MySQL running ($mysqld_pid),But no respond" echo "ERROR: MySQL running ($mysqld_pid),But no respond" >

> / var/log/messages

Exit 1

Fi

Done

#-/ Modi-1

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 could not be found"

Exit 4

Fi

Fi

=

The above changes mean that when running service msyql status

If the host HANG resides and the MYSQL process is still there, but the MYSQL cannot respond to the query, we set the status to FAILED.

(if the temporary file mysql.`date +% Y% m% d% H% M% S. $MYSQLPID exists within 10 seconds, and the content must be "aliyun.mysql", then MYSQL is normal.)

If the above conditions are true and MYSQL is in an unresponsive state, the program will also write information to the file: / home/mysql/aliyun.mysql

If HEARTBEAT detects that MYSQL has failed. Will Stop/Start mysql resources N times (N is determined according to the configuration of cib.xml)

During the restart process, we return the stop/start status directly to 0. Do not actually shut down or start mysql.

This is done so that the next time MYSQL detects the status, an error is returned directly. It can be switched quickly.

So we need to change a few more areas in / etc/init.d/mysql:

0) change the parameter start/stop of the original mysql to startup/stopdown

'start')-& gt' startup')

'stop')-& gt' stopdown')

1) add new start segment

=

'start')

# Start daemon

Log_success_msg "Mysql Start failed with / etc/init.d/mysql in HA Mode!"

Exit 0

=

2) add a new stop segment

=

'stop')

# Stop daemon.

Log_success_msg "Mysql Stop failed with / etc/init.d/mysql in HA Mode!"

Exit 0

=

Test:

Start mysql: service mysql startup

Close mysql: service mysql stopdown

Status mysql: service mysql status

Service mysql start/stop

These two sentences do nothing, and I will send you a message!

Summary:

After doing so, no matter how HEARTBEAT restarts / shuts down, it will only affect VIP. Will not operate directly on MYSQL.

On the one hand, MYSQL will not be affected because HEARTBEAT is not working properly.

On the other hand, you can make HEARTBEAT switch faster (because it saves time to start and shut down MYSQL)

But there is one small drawback to this:

When HEARTBEAT starts, MYSQL does not start automatically.

HEARTBEAT will find that MYSQL is invalid after startup. Then a switch occurs.

So you have to make sure that at least one NODE MYSQL STATUS is normal before HEARTBEAT starts!

Thank you for reading this article carefully. I hope the article "how to change / etc/init.d/mysql and let HeartBeat just monitor the status of MYSQL" shared by the editor will be helpful to you. At the same time, I hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report