• Lepus监控之安装部署


    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服务

    打开applicationconfigdatabase.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登录后请修改管理员密码,增加普通账号。

    登录界面如下所示:

    20170427_cdd92d21-c68a-45c3-a5d2-8af731fa3efe

    启动和关闭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 乖乖龙
  • 相关阅读:
    Docker简介,安装,配置
    Centos7给 root 账户开通ssh权限
    [转载]Hyper-v 安装CentOS 7
    软件开发_六大原则
    php函数名后冒号(:)+数据类型(返回值类型限制/php新特性)
    MySQL--事务介绍
    MySQL存储引擎
    leetcode刷题笔记300题 最长上升子序列
    leetcode刷题笔记299题 猜数字游戏
    **leetcode刷题笔记四 两个有序序列的中位数**
  • 原文地址:https://www.cnblogs.com/EikiXu/p/10019904.html
Copyright © 2020-2023  润新知