准备环境
首先安装Python环境(Python版本要求为Python2.6以上,不支持Python3)
安装数据库连接Python的驱动包
1.安装 MySQLdb for python (必须安装)
MySQLdb为Python连接和操作MySQL的类库,如果您准备使用lepus系统监控MySQL数据库,那么该模块必须安装。
安装步骤如下:
#wget http://cdn.lepus.cc/cdncache/software/MySQLdb-python.zip
# unzip MySQLdb-python.zip
# cd MySQLdb1-master/
# which mysql_config
/usr/local/mysql/bin/mysql_config
# vim site.cfg 修改如下:
mysql_config = /usr/local/mysql/bin/mysql_config
# python setup.py build
# python setup.py install
常见错误解决:
1).如果编译python出现如下问题
/usr/bin/ld: cannot find -lpython2.7
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
请按如下步骤处理:
A.检查并安装python-devel
包
# yum -y install python-devel
B.将libpython2.7.so
库文件建立软连接到/usr/lib
下
32位服务器下执行
# ln -s /usr/local/Python2.7/lib/libpython2.7.so /usr/lib/libpython2.7.so
64位服务器下执行
# ln -s /usr/local/Python2.7/lib/libpython2.7.so /usr/lib64/libpython2.7.so
C.检查下/etc/ld.so.conf
是否包含/usr/local/Python2.7/lib
#vi /etc/ld.so.conf 添加/usr/local/Python2.7/lib
#/sbin/ldconfig
2.安装cx_oracle for python (如果需要监控Oracle则必须安装)
下载安装oracle instant client
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
如果是64位的,请选择.*x86_64.rpm
,否则是.*i386.rpm
如果是oracle 9i或更高,请选择Instant Client 11
,如果是8或8i,请选择Instant Client 10
[root@westserver software]# rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
Preparing… ########################################### [100%]
1:oracle-instantclient11.########################################### [100%]
[root@westserver software]# rpm -ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm
Preparing… ########################################### [100%]
1:oracle-instantclient11.########################################### [100%]
[root@westserver software]# rpm -ivh oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
Preparing… ########################################### [100%]
1:oracle-instantclient11.########################################### [100%]
[root@westserver home]# vim /root/.bash_profile
ORACLE_HOME="/usr/lib/oracle/11.2/client64"
PATH=$PATH:$ORACLE_HOME/bin
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH
修改完成后重新加载bash_profile文件
[root@westserver cx_Oracle-5.1.2]# source ~/.bash_profile
[root@westserver software]# vim /etc/ld.so.conf 加入
/usr/lib/oracle/11.2/client64/lib
执行ldconfig生效
[root@westserver software]# ldconfig
安装cx_oracle
# wget http://cdn.lepus.cc/cdncache/software/cx_Oracle-5.1.2.tar.gz
# tar zxvf cx_Oracle-5.1.2.tar.gz
# cd cx_Oracle-5.1.2
# python setup.py build
# python setup.py install
3.安装Pymongo for python (如果需要监控Mongodb则必须安装)
pymongo为Python连接和操作MongoDB的类库,如果您准备使用lepus系统监控MongoDBs数据库,那么该模块必须安装。
安装步骤如下:
# wget http://cdn.lepus.cc/cdncache/software/pymongo-2.7.tar.gz
# tar zxvf pymongo-2.7.tar.gz
# cd pymongo-2.7
# python setup.py install
4.安装Redis 驱动 (如果需要监控Redis则必须安装)
# wget http://cdn.lepus.cc/cdncache/software/redis-py-2.10.3.tar.gz
# tar zxvf redis-py-2.10.3.tar.gz
# cd redis-2.10.3/
# python setup.py install
5.安装SQLServer驱动 (如果需要监控SQLServer则必须安装)
安装pymssql需要的包:
freetds(http://www.filewatcher.com/m/freetds-0.82.tar.gz.1596755-0.html)
setuptools(https://pypi.python.org/pypi/setuptools)
pymssql(https://pypi.python.org/pypi/pymssql/)
安装步骤:
A. 安装freetds
#tar zxvf freetds-0.82.tar.gz
#cd freetds-0.82
#./configure –prefix=/usr/local/freetds –with-tdsver=8.0 –enable-msdblib –enable-dbmfix –with-gnu-ld –enable-shared –enable-static
#make && make install
#echo "/usr/local/freetds/lib" » /etc/ld.so.conf.d/freetds.conf
#ldconfig -v
B. 安装setuptools
#tar zxvf setuptools-3.5.1.tar.gz
#cd setuptools-3.5.1
# python setup.py install
C. 安装pymssql
#tar zxvf pymssql-2.1.0.tar.gz
#cd pymssql-2.1.0
#python setup.py install
注:如果不安装freetds,会报如下错误:
error: command ‘gcc’ failed with exit status 1
6.测试各个驱动是否正常运行(非必须)
在lepus的安装文件包python目录中,你可以找到如下测试文件,测试上述驱动是否安装正确。
# python test_driver_mysql.py
MySQL python drivier is ok!
# python test_driver_oracle.py
Oracle python drivier is ok!
# python test_driver_mongodb.py
MongoDB python drivier is ok!
# python test_driver_redis.py
Redis python drivier is ok!
[root@host-10-100-38-78 ~]# wget http://cdn.lepus.cc/cdncache/software/MySQLdb-python.zip
–2018-05-11 12:11:24– http://cdn.lepus.cc/cdncache/software/MySQLdb-python.zip
Resolving cdn.lepus.cc… failed: Name or service not known.
wget: unable to resolve host address “cdn.lepus.cc” 下载失败,wget: unable to resolve host address “cdn.lepus.cc”地址换了吗?
@1452912296 可以加下群,群里有文件的哦。这个地址目前失效了。
@NiceRu 好的,那个群啊?怎么加入呢。
@1452912296 请加天兔数据库监控QQ群:149648217 。