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

Monitoring mha masterha_manager processes using supervisor

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

When we use the masterha_manager script that comes with mha to automatically switch over the main mysql library, we need to consider how to keep the masterha_manager monitoring process running normally. Supervisor can solve this problem very well, it can change an ordinary command line process into background daemon, monitor the process status, and restart automatically when an exception exits.

Here is a list of deployment points and management commands

First, supervisor installation:

Sudo pip install supervisor

Second, supervisor configuration:

Mkdir-p / etc/supervisor/conf.d/

Generate configuration file

# echo_supervisord_conf > / etc/supervisor/supervisord.conf

You may encounter the following error in this step

Traceback (most recent call last): File "/ usr/bin/echo_supervisord_conf", line 5, in from pkg_resources import load_entry_point File "/ usr/lib/python2.6/site-packages/pkg_resources.py", line 2655, in working_set.require (_ _ requires__) File "/ usr/lib/python2.6/site-packages/pkg_resources.py", line 648 In require needed = self.resolve (parse_requirements (requirements)) File "/ usr/lib/python2.6/site-packages/pkg_resources.py", line 546, in resolve raise DistributionNotFound (req) pkg_resources.DistributionNotFound: meld3 > = 0.6.5

Check the reason on the Internet, probably related to the python or pip version. Install meld3 once through the source code, and get it done in three simple steps:

Git clone https://github.com/Supervisor/meld3cd meld3python setup.py install

View configuration fil

Cat / etc/supervisor/supervisord.conf

[unix_http_server]

File=/tmp/supervisor.sock; the path to the socket file

[supervisord]

Logfile=/tmp/supervisord.log; main logfile; default $CWD/supervisord.log

Logfile_maxbytes=50MB; max main logfile bytes b4 rotation; default 50MB

Logfile_backups=10; # of main logfile backups; 0 means none, default 10

Loglevel=info; loglevel; default info; others: debug,warn,trace

Pidfile=/tmp/supervisord.pid; supervisord pidfile; default supervisord.pid

Nodaemon=false; start in foreground if true; default false

Minfds=1024; min. Avail startup file descriptors; default 1024

Minprocs=200; min. Avail process descriptors;default 200

User=dbadmin; default is current user, required if root

[rpcinterface:supervisor]

Supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]

Serverurl=unix:///tmp/supervisor.sock; use a unix:// URL for a unix socket

[include]

Files = / etc/supervisor/conf.d/*.conf

Key points of configuration:

1. Other configurations will be able to use the generated default configuration, but user needs to be changed to a password-free login user, such as dbadmin here, otherwise masterha_manager startup will make an error, because mha password-free login is all based on the dbadmin account.

2. The configuration of the management process can be placed directly in the [program:xxx] section of the main configuration file of supervisor, but it is best for each process to prepare a configuration file for easy management. Specify the configuration file directory through the file configuration of the [include] section.

Third, take masterha_manager monitoring test as an example to see the operation of supervisor, and prepare the configuration file of masterha_manager monitoring test.

Cat / etc/supervisor/conf.d/masterha_manager_test.conf

[program:masterha_manager_test]

Command=masterha_manager-- conf=/etc/mha/test.cnf-- ignore_last_failover; start command

Stdout_logfile=/tmp/manager.log; stdout log output location

Stderr_logfile=/tmp/manager.log; stderr log output location

Autostart=true; automatically starts when supervisord starts

Autorestart=true; restarts automatically when the program exits abnormally

Startsecs=10; if there is no abnormal exit after 10 seconds of startup, it is deemed to have been started normally

2. Start the supervisord process

# supervisord-c / etc/supervisor/supervisord.conf

# ps-ef | grep super

Dbadmin 11892 1 0 02:56? 00:00:00 / usr/bin/python / usr/bin/supervisord

Root 13340 31610 0 02:56 pts/0 00:00:00 grep super

3. Check the status of the monitored process

# supervisorctl status

Masterha_manager_test RUNNING pid 11912, uptime 0:03:08

# ps-ef | grep master

Root 1343 31610 0 02:59 pts/0 00:00:00 grep master

Root 3228 1 0 2016? 00:01:33 / usr/libexec/postfix/master

Dbadmin 11912 11892 0 02:56? 00:00:00 perl / usr/local/bin/masterha_manager-conf=/etc/mha/test.cnf-ignore_last_failover

You can see that masterha_manager has been started.

4, test

Directly kill the masterha_manager process to simulate the abnormal exit of masterha_manager:

# ps-ef | grep master

Root 1343 31610 0 02:59 pts/0 00:00:00 grep master

Root 3228 1 0 2016? 00:01:33 / usr/libexec/postfix/master

Dbadmin 11912 11892 0 02:56? 00:00:00 perl / usr/local/bin/masterha_manager-conf=/etc/mha/test.cnf-ignore_last_failover

# kill-9 11912

# ps-ef | grep master

Dbadmin 1707 11892 5 03:30? 00:00:00 perl / usr/local/bin/masterha_manager-conf=/etc/mha/test.cnf-ignore_last_failover

Root 2054 31610 0 03:30 pts/0 00:00:00 grep master

Root 3228 1 0 2016? 00:01:33 / usr/libexec/postfix/master

You can see that supervisor restarted the masterha_manager monitoring process.

5. Common management commands

Supervisord: initially starts Supervisord, starts and manages the processes set in the configuration

Supervisorctl stop (start, restart) xxx, stop (start, restart) a process (xxx)

Supervisorctl reread: load only the latest configuration files and do not restart any processes

Supervisorctl reload: load the latest configuration file, stop all the original processes and start and manage all processes according to the new configuration

Supervisorctl update: according to the latest configuration file, start processes with new configuration or changes, and processes with no changes in configuration will not be affected and restart

6. Add supervisord to serve the Linux system, and boot automatically.

Prepare to start the script supervisord.sh

# chmod + x supervisord.sh# mv supervisord.sh / etc/init.d/supervisord# chkconfig-- add supervisord# chkconfig-- level 345 supervisord oncat / etc/rc.d/init.d/supervisord #! / bin/sh## / etc/rc.d/init.d/supervisord # # Supervisor is a client/server system that# allows its users to monitor and control a # number of processes on UNIX-like operating# systems.## chkconfig:-64 3 hours description: Supervisor Server# processname: supervisord# Source init functions. / etc/rc.d/init.d/functionsprog= "supervisord" prog_bin= "/ usr/bin/supervisord" PIDFILE= "tmp/supervisord.pid" CONFILE= "/ etc/supervisor/supervisord.conf" start () {echo-n $"Starting $prog:" daemon $prog_bin-c $CONFILE-- pidfile $PIDFILE [- f $PIDFILE] & & success $"$prog startup" | failure $"$prog startup" echo} stop () {echo-n $"Shutting down $prog:" [- f $PIDFILE] & & killproc $prog | | success $"$prog shutdown" echo} case "$1" in start) start ; stop) stop;; status) status $prog;; restart) stop start;; *) echo "Usage: $0 {start | stop | restart | status}";; esac

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