PHP和Python都是跨平台的語言,所以理論上系統應該可以支持在不同的平台上運行。但是由於時間和精力以及資源有限,目前天兔系統只測試完善了Centos/RedHat系統的支持。我們目前提供的技術支持也是只針對於Centos/RedHat系統,其他系統暫不支持技術服務。
安裝需求
1.MySQL5.1
及以上(必須,用來存儲監控系統采集的數據)
2.Apache 2.2
及以上 (必須,WEB服務器運行服務器)
3.PHP 5.3
以上 (必須,提供WEB界面支持,不支持PHP7
)
4.Python2
(必須,推薦2.6及以上
版本,執行數據采集和報警任務,不支持Python3
)
5.Python
連接和監控數據庫的相關驅動模塊包
:
MySQLdb
for python (Python連接MySQl的接口,用於監控MySQL,此模塊必須安裝)cx_oracle
for python (Python連接Oracle的接口,非必須,如果需要監控oracle此模塊必須安裝)Pymongo
for python (Python連接MongoDB的接口,非必須,如果需要監控MongoDB此模塊必須安裝)redis-py
for python (Python連接Redis的接口,非必須,如果需要監控Redis此模塊必須安裝)
安裝LAMP基礎環境
配置LAMP基礎環境的方式有很多種,最簡單的方式有yum安裝、RPM包安裝等方式、安裝集成環境包(例如lampp/xampp等)。您也可以手動編譯安裝相關軟件。這里我們不推薦使用YUM進行安裝,YUM安裝的PHP環境可以因為缺少某些依賴包導致500錯誤
。如果你有能力,可以進行編譯安裝,按照需要的模塊編譯PHP和MYSQL數據庫,這種方式也是目前大型WEB推薦的方式。如果你無法進行編譯安裝,我們推薦你使用Xampp
集成環境包進行安裝,xampp是一個可靠的穩定的lamp套件,目前已被諸多公司用於生產服務器的部署,目前Lepus的開發環境,測試環境以及線上官網的WEB環境,都是運行在xampp環境下面,並且一直都是穩定的。
Xampp下載地址:https://www.apachefriends.org/download.html
Xampp幫助文檔:https://www.apachefriends.org/faq_linux.html
官方推薦版本:xampp-linux-x64-1.8.2-5-installer.run
,該版本在下列安裝部署中會提供下載地址連接,或者進入Lepus常用軟件下載專貼進行下載:http://www.dba-china.com/topic/226。
安裝Xampp步驟示例
安裝過程非常簡單,通過我們提供的CDN地址下載軟件后,直接運行即可
[root@ebs-cloud software]# wget http://cdn.lepus.cc/cdncache/software/xampp-linux-x64-1.8.2-5-installer.run
[root@ebs-cloud software]# chmod +x xampp-linux-x64-1.8.2-5-installer.run
[root@ebs-cloud software]# ./xampp-linux-x64-1.8.2-5-installer.run
—————————————————————————-
Welcome to the XAMPP Setup Wizard.
—————————————————————————-
Select the components you want to install; clear the components you do not want
to install. Click Next when you are ready to continue.
XAMPP Core Files : Y (Cannot be edited)
XAMPP Developer Files [Y/n] :y
Is the selection above correct? [Y/n]: y
—————————————————————————-
Installation Directory
XAMPP will be installed to /opt/lampp
Press [Enter] to continue :
—————————————————————————-
Setup is now ready to begin installing XAMPP on your computer.
Do you want to continue? [Y/n]: y
—————————————————————————-
Please wait while Setup installs XAMPP on your computer.
Installing
0% ______________ 50% ______________ 100%
#########################################
—————————————————————————-
Setup has finished installing XAMPP on your computer.
其他問題:
1.如果遠程訪問xampp報下面錯誤
Access forbidden! New XAMPP security concept:
Access to the requested object is only available from the local network.
This setting can be configured in the file “httpd-xampp.conf”.
打開文件extra/httpd-xampp.conf
注釋掉下面一行
#Require local
2.配置啟用虛擬目錄
打開下面的注釋
# Virtual hosts Include etc/extra/httpd-vhosts.conf
3.默認WEB代碼上傳目錄:
/opt/lampp/htdocs/
關於xampp的詳細使用,包括啟動關閉、以及安全特性,都可以在官網幫助里面找到的,這里不重復寫了,大家可以去查看:https://www.apachefriends.org/faq_linux.html
安裝Python基礎模塊
首先安裝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!
安裝Lepus采集器
注:在安裝Lepus系統之前,請先根據前面內容安裝LAMP和Python運行基礎環境。
1)下載軟件安裝包
# cd /usr/local
# git clone https://github.com/ruzuojun/lepus.git
2)對可執行文件授權,並創建軟連接
# cd lepus
# chmod +x lepus*
# ln -s /usr/local/lepus/lepus /usr/local/sbin/lepus
# ln -s /usr/local/lepus/lepus_monitor /usr/local/sbin/lepus_mointor
3).在監控機創建監控數據庫,並授權。
mysql> create database lepus default character set utf8;
mysql> grant select,insert,update,delete,create on lepus.* to 'lepus_user'@'localhost' identified by 'xxxxxx';
mysql> flush privileges;
4)導入SQL文件夾里的初始化SQL文件(表結構和數據文件)
# mysql -uroot –p lepus < sql/lepus_table.sql
# mysql -uroot –p lepus < sql/lepus_data.sql
5) 修改配置文件
進入到安裝目錄/usr/local/lepus
# cd /usr/local/lepus/
# vim etc/config.ini
監控機MySQL數據庫連接地址
[monitor_server]
host="127.0.0.1"
port=3306
user=" lepus_user "
passwd="xxxxxx"
dbname="lepus"
6) 啟動Lepus (可選)
此時,你可以執行啟動命令啟動lepus采集進程
[root@ebs-cloud lepus]# lepus start
lepus server start success!
[root@ebs-cloud lepus]# ps -ef|grep lepus
root 11553 1 0 14:40 pts/0 00:00:00 /bin/bash /usr/local/sbin/lepus start
root 11555 11553 0 14:40 pts/0 00:00:00 python lepus.py
root 11571 11555 0 14:40 pts/0 00:00:00 python lepus.py
root 11590 1851 0 14:40 pts/0 00:00:00 grep lepus
但是因為沒有添加主機,所以查看日志會看到如下提示,屬於正常提示。您也可以在部署完Lepus WEB控制台后再進行啟動。
[root@ebs-cloud lepus]# tail -f logs/lepus.log
2015-08-03 13:09:09 [WARNING] check mongodb: not found any servers
2015-08-03 13:09:09 [INFO] check mongodb controller finished.
2015-08-03 13:09:12 [INFO] check redis controller started.
2015-08-03 13:09:12 [WARNING] check redis: not found any servers
2015-08-03 13:09:12 [INFO] check redis controller finished.
2015-08-03 13:09:15 [INFO] check os controller started.
2015-08-03 13:09:15 [WARNING] check os: not found any servers
2015-08-03 13:09:15 [INFO] check os controller finished.
2015-08-03 13:09:38 [INFO] alarm controller started.
2015-08-03 13:09:38 [INFO] alarm controller finished.
如果啟動失敗,可以通過記錄的日志信息查看錯誤,通過log信息我們可以定位啟動失敗的問題:
# tail -f logs/lepus.log
import functions as func
File "./include/functions.py", line 285, in <module>
mail_host = get_option('smtp_host')
File "./include/functions.py", line 242, in get_option
conn=MySQLdb.connect(host=host,user=user,passwd=passwd,port=int(port),connect_timeout=5,charset='utf8')
File "/usr/lib64/python2.6/site-packages/MySQL_python-1.2.4-py2.6-linux-x86_64.egg/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib64/python2.6/site-packages/MySQL_python-1.2.4-py2.6-linux-x86_64.egg/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
`_mysql_exceptions.OperationalError: (1045, "Access denied for user 'lepus'@'localhost' (using password: YES)")`
到這里,Lepus采集程序安裝完畢!
安裝WEB管理台
復制lepus/web文件夾里的文件到Apache對應的網站虛擬目錄(備注:根據不同的安裝方式,這個目錄是不一樣的,如果采用xampp
安裝的Apache環境,則默認程序目錄為/opt/lampp/htdocs/
), 當然,為了更好的維護項目,通常我們會為每個項目配置一個獨立的虛擬主機目錄。具體步驟如下:
修改/opt/lampp/etc/httpd.conf
文件,將下面的denied修改為granted
<Directory />
AllowOverride none
Require all granted
</Directory>
取消這一行的注釋
Include etc/extra/httpd-vhosts.conf
修改/opt/lampp/etc/extra/httpd-vhosts.conf
文件,配置虛擬目錄,示例如下:
<VirtualHost *:80>
ServerAdmin demo.lepus.cc
DocumentRoot "/usr/local/lepus/web"
ServerName demo.lepus.cc
ServerAlias demo.lepus.cc
ErrorLog "logs/demo.lepus.cc-error_log"
CustomLog "logs/demo.lepus.cc-access_log" common
</VirtualHost>
修改完成后重啟
apache服務
打開application\config\database.php
文件,修改PHP連接監控服務器的數據庫信息
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'lepus_user';
$db['default']['password'] = 'xxxxxx';
$db['default']['database'] = lepus;
$db['default']['dbdriver'] = 'mysql';
登錄進行添加主機和監控
通過瀏覽器輸入IP地址或域名打開監控界面,即可登錄系統。.默認管理員賬號密碼admin/Lepusadmin
登錄后請修改管理員密碼,增加普通賬號。
登錄界面如下所示:
啟動和關閉Lepus
啟動和關閉監控系統
執行以下命令啟動系統采集進程
# lepus start
執行以下命令關閉系統采集進程
# lepus stop
執行以下命令監控系統是否正常運行
# lepus status
lepus server is running…
查看啟動關閉幫助命令
# lepus –help
lepus help:
support-site: www.lepus.cc
====================================================================
start Start lepus monitor server; Command: #lepus start
stop Stop lepus monitor server; Command: #lepus stop
status Check lepus monitor run status; Command: #lepus status
查看運行日志
當Lepus啟動時,Lepus提供了標准的日志輸出功能,可以通過日志查詢監控系統是否正在工作。
# cd /usr/local/lepus/
# tail -f logs/lepus.log
2015-01-07 18:24:42 [WARNING] check os: not found any servers
2015-01-07 18:24:42 [INFO] check os controller finished.
2015-01-07 18:25:15 [INFO] alarm controller started.
2015-01-07 18:25:15 [INFO] alarm controller finished.
2015-01-07 18:25:37 [INFO] check mysql controller started.
2015-01-07 18:25:37 [WARNING] check mysql: `not found any servers`
2015-01-07 18:25:37 [INFO] check mysql controller finished.
2015-01-07 18:25:42 [INFO] check os controller started.
2015-01-07 18:25:42 [WARNING] check os: `not found any servers`
2015-01-07 18:25:42 [INFO] check os controller finished.
文章名稱 | 文章地址 | 作者 |
---|---|---|
天兔(Lepus)監控系統快速安裝部署 | http://suifu.blog.51cto.com/9167728/1770493 | 歲扶 |
天兔(Lepus)監控系統慢查詢分析平台配置 | http://suifu.blog.51cto.com/9167728/1770672 | 歲扶 |
天兔(Lepus)監控操作系統(OS)配置 | http://suifu.blog.51cto.com/9167728/1770703 | 歲扶 |
天兔(Lepus)監控郵件推送安裝配置 | http://suifu.blog.51cto.com/9167728/1795014 | 歲扶 |
天兔(lepus)容器版本安裝部署 | https://bjddd192.github.io/mysql/2017/03/25/lepus.html | 乖乖龍 |