RHEL5.5下安装mycheckpoint
以下是在RHEL5.5下安装mycheckpoint,需要安装python,并且版本大于2.4。需要安装Mysql-Python模块,版本必须大于或等于1.2.3,否则会出现bug。这个已经过查证。
官网及下载:
mysql-python 1.2.3下载:
wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download
rpm -qa|grep -i mysql-python
查看mysql-python版本,rhel5.5的的是1.2.2,需要将其卸载。
rpm -e --nodeps xxxxxx
欢迎转载,请注明作者、出处。
作者:张正
blog:http://space.itpub.net/26355921
QQ:176036317
如有疑问,欢迎联系。
(提前已经装好了mysql)
[root@host3 ~]# python
Python 2.4.3 (#1, Jun 11 2009, 14:09:58)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit
[root@host3 ~]# ls
anaconda-ks.cfg install.log.syslog package2.sh vmware-tools-distrib
Desktop mycheckpoint-231.tar.gz package.sh
install.log MySQL-python-1.2.3.tar.gz rlwrap
[root@host3 ~]# tar -zxf mycheckpoint-231.tar.gz
[root@host3 ~]# rm mycheckpoint-231.tar.gz
rm: remove regular file `mycheckpoint-231.tar.gz'? y
[root@host3 ~]# cd mycheckpoint-231/
[root@host3 mycheckpoint-231]# sudo python setup.py install
/usr/lib/python2.4/distutils/dist.py:236: UserWarning: Unknown distribution option: 'requires'
warnings.warn(msg)
running install
running build
running build_scripts
creating build
creating build/scripts-2.4
copying and adjusting scripts/mycheckpoint -> build/scripts-2.4
changing mode of build/scripts-2.4/mycheckpoint from 644 to 755
running install_scripts
copying build/scripts-2.4/mycheckpoint -> /usr/bin
changing mode of /usr/bin/mycheckpoint to 755
[root@host3 mycheckpoint-231]# cd ..
[root@host3 ~]# tar -zxf MySQL-python-1.2.3.tar.gz
[root@host3 ~]# rm MySQL-python-1.2.3.tar.gz
rm: remove regular file `MySQL-python-1.2.3.tar.gz'? y
[root@host3 ~]# ls
anaconda-ks.cfg install.log.syslog package2.sh vmware-tools-distrib
Desktop mycheckpoint-231 package.sh
install.log MySQL-python-1.2.3 rlwrap
[root@host3 ~]# cd MySQL-python-1.2.3/
[root@host3 MySQL-python-1.2.3]# ls
doc _mysql.c pymemcompat.h setup.py
ez_setup.py MySQLdb README setup_windows.py
HISTORY _mysql_exceptions.py setup.cfg site.cfg
MANIFEST.in MySQL_python.egg-info setup_common.py tests
metadata.cfg PKG-INFO setup_posix.py
[root@host3 MySQL-python-1.2.3]# locate mysql_config
/usr/local/bin/mysql_config
[root@host3 MySQL-python-1.2.3]# vi site.cfg
[options]
# embedded: link against the embedded server library
# threadsafe: use the threadsafe client
# static: link against a static library (probably required for embedded)
embedded = False
threadsafe = True
static = False
# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
mysql_config = /usr/local/bin/mysql_config
# The Windows registry key for MySQL.
# This has to be set for Windows builds to work.
# Only change this if you have a different version.
registry_key = SOFTWARE\MySQL AB\MySQL Server 5.0
[root@host3 MySQL-python-1.2.3]# python setup.py install
Traceback (most recent call last):
File "setup.py", line 5, in ?
from setuptools import setup, Extension
ImportError: No module named setuptools
[root@host3 MySQL-python-1.2.3]# yum -y install python-setuptools
[root@host3 MySQL-python-1.2.3]# python setup.py install
running install
.............
Installed /usr/lib/python2.4/site-packages/MySQL_python-1.2.3-py2.4-linux-i686.egg
Processing dependencies for MySQL-python==1.2.3
[root@host3 MySQL-python-1.2.3]# yum -y install mysql-devel
[root@host3 MySQL-python-1.2.3]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.2-m2-log MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database mycheckpoint;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on mycheckpoint.* to 'moni_user'@'%' identified by 'moni_passwd';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exitr
-> Bye
[root@host3 MySQL-python-1.2.3]# vi /etc/mycheckpoint.cnf
[mycheckpoint]
#smtp_host = mail.my-server-company.com
#smtp_from = monitor@my-server-company.com
#smtp_to = dba@my-server-company.com
monitored_port = 3306
purge_days = 60
#... Any command line option can go here; replace dash ("-") with underscored ("_")
[client]
user=moni_user
password=moni_passwd
socket=/tmp/mysql.sock
port=3306
[root@host3 MySQL-python-1.2.3]# mycheckpoint deploy
Traceback (most recent call last):
File "/usr/bin/mycheckpoint", line 23, in ?
import MySQLdb
File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", line 19, in ?
File "build/bdist.linux-i686/egg/_mysql.py", line 7, in ?
File "build/bdist.linux-i686/egg/_mysql.py", line 6, in __bootstrap__
ImportError: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
[root@host3 MySQL-python-1.2.3]# updatedb
[root@host3 MySQL-python-1.2.3]# locate libmysqlclient_r.so.16
/opt/mysql/lib/libmysqlclient_r.so.16
/opt/mysql/lib/libmysqlclient_r.so.16.0.0
[root@host3 MySQL-python-1.2.3]# vi /etc/ld.so.conf
include ld.so.conf.d/*.conf
/opt/mysql/lib/
[root@host3 MySQL-python-1.2.3]# ldconfig -v
..............................
[root@host3 MySQL-python-1.2.3]# python setup.py install
running install
............
Installed /usr/lib/python2.4/site-packages/MySQL_python-1.2.3-py2.4-linux-i686.egg
Processing dependencies for MySQL-python==1.2.3
[root@host3 MySQL-python-1.2.3]# python
Python 2.4.3 (#1, Jun 11 2009, 14:09:58)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
/usr/lib/python2.4/site-packages/MySQL_python-1.2.3-py2.4-linux-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib/python2.4/site-packages/MySQL_python-1.2.3-py2.4-linux-i686.egg/_mysql.pyc, but /root/MySQL-python-1.2.3 is being added to sys.path
>>> exit
[root@host3 MySQL-python-1.2.3]# mycheckpoint deploy
-- ERROR: Cannot connect to database
-- ERROR: Failed sending email
(1045, "Access denied for user 'moni_user'@'host3' (using password: YES)")
--
-- Make sure `mycheckpoint` schema exists, e.g.
-- CREATE DATABASE `mycheckpoint`
-- Make sure the user has ALL PRIVILEGES on the `mycheckpoint` schema. e.g.
-- GRANT ALL ON `mycheckpoint`.* TO 'my_user'@'my_host' IDENTIFIED BY 'my_password'
-- The user will have to have the SUPER privilege in order to disable binary logging
-- - Otherwise, use --skip-disable-bin-log (but then be aware that slaves replicate this server's status)
-- In order to read master and slave status, the user must also be granted with REPLICATION CLIENT or SUPER privileges
-- - Otherwise, use --skip-check-replication
--
[root@host3 MySQL-python-1.2.3]# mysql -u moni_user -pmoni_passwd
ERROR 1045 (28000): Access denied for user 'moni_user'@'localhost' (using password: YES)
[root@host3 MySQL-python-1.2.3]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.2-m2-log MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> select user,host,password from mysql.user;
+-----------+-----------+-------------------------------------------+
| user | host | password |
+-----------+-----------+-------------------------------------------+
| root | localhost | |
| root | host3 | |
| root | 127.0.0.1 | |
| | localhost | |
| | host3 | |
| moni_user | % | *B0F4A3678A0500187C67F54F1013BB4AE6069FFB |
+-----------+-----------+-------------------------------------------+
6 rows in set (0.09 sec)
mysql> delete from mysql.user where user='';
Query OK, 2 rows affected (0.06 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@host3 MySQL-python-1.2.3]# mycheckpoint deploy
-- ERROR: Cannot show master & slave status. Skipping
如果使用mycheckpoint发邮件,报错:
[root@mysql-monitor ~]#mycheckpoint email_alert_pending_report -v --debug
-- ERROR: Failed sending email
Traceback (most recent call last):
File "/usr/bin/mycheckpoint", line 4337, in send_email_message
s = smtplib.SMTP(smtp_host)
File "/usr/lib64/python2.6/smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib64/python2.6/smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib64/python2.6/smtplib.py", line 273, in _get_socket
return socket.create_connection((port, host), timeout)
File "/usr/lib64/python2.6/socket.py", line 567, in create_connection
raise error, msg
error: [Errno 111] Connection refused
查看端口:
[root@mysql-monitor ~]# netstat -antl|grep 25
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 1 0 127.0.0.1:25 127.0.0.1:35088 CLOSE_WAIT
tcp 1 0 127.0.0.1:25 127.0.0.1:35089 CLOSE_WAIT
tcp 1 0 127.0.0.1:25 127.0.0.1:35374 CLOSE_WAIT
tcp 1 0 127.0.0.1:25 127.0.0.1:35242 CLOSE_WAIT
tcp 0 0 127.0.0.1:25 127.0.0.1:35509 ESTABLISHED
tcp 7 0 127.0.0.1:25 127.0.0.1:35239 CLOSE_WAIT
tcp 0 0 ::1:25 :::* LISTEN
tcp 0 0 ::ffff:127.0.0.1:35509 ::ffff:127.0.0.1:25 ESTABLISHED
是因为:127.0.0.1:25 ,只允许使用端口号为25的IP为127.0.0.1,因此会出现Connection refused
服务器重启后,重新配置/etc/mail/sendmail.mc ,然后m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
再查看端口:
[mysql@mysql-monitor ~]$ netstat -antl|grep 25
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN
这样既可。
[mysql@mysql-monitor ~]$ mycheckpoint email_alert_pending_report -v --debug
-- Using /etc/mycheckpoint.cnf as defaults file
-- mycheckpoint rev 231, build 201305231510. Copyright (c) 2009-2013 by Shlomi Noach
-- database is mycheckpoint
-- Will not monitor the database
-- Sending HTML alert pending report message from mysql@mysql-monitor.com to: zhangzheng2040@126.com via: mysql-monitor.com
-- + Sent
发送成功
[root@host3 MySQL-python-1.2.3]# crontab -e
*/5 * * * * mycheckpoint --skip-check-replication
[root@host3 MySQL-python-1.2.3]#service crond restart
Stopping crond: [ OK ]
Starting crond: [ OK ]
[root@host3 MySQL-python-1.2.3]# mycheckpoint http
read databases
started httpserver on port 12306...
本地ip:192.168.83.130
用网页访问:
http://192.168.83.130:12306/mycheckpoint