试用了一下Lepus监控系统,感觉不错。记录一下安装过程,留个备份。
搭建的环境:
<pre>
CentOS release 6.6 (Final)
</pre>
我这里是用root帐号登录搭建环境的。
首先Lepus监控环境是通过bs提供服务的,使用的是php的ci框架。这里需要在linux上搭建一个LAMP环境。(需要骚等片刻)
<pre>
yum install mysql-server httpd php -y
</pre>
设置2个守护进程开机自启动
<pre>
chkconfig httpd on
chkconfig mysqld on
</pre>
安装相关依赖包(喝杯茶,休息一下。)
<pre>
yum install gcc python-devel mysql-devel net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml -y
</pre>
安装unzip(如果没有unzip的话,后面会用到)
<pre>
yum install unzip
</pre>
这个时候,apache已经安装好了。由于服务器在外网,不能随便在80端口发布web站,所以我们把端口默认改成8080。
<pre>
vim /etc/httpd/conf/httpd.conf
修改
Listen 80
Listen 8080
</pre>
启动http服务先:
<pre>service httpd start</pre>
网络访问一下:http://xx.xx.xx.xx:8080 ,发现不能访问。嗯,防火墙开着呢。
开启一下8080端口,顺便把3306端口也开了。
<pre>
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
service iptables save
</pre>
然后检查一下iptables文件,看看
<pre>
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
</pre>
这里要注意一下,3306和8080的数据必须在-A INPUT -j REJECT --reject-with icmp-host-prohibited的前面。修改一下顺序,如下:
<pre>
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [5:660]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
</pre>
备注:vim中,yy复制一行,p粘贴,dd删除一行
改完之后,策略并没有直接生效,需要关闭重开一下
<pre>
service iptables stop
service iptables start
</pre>
此时再网络访问一下:http://xx.xx.xx.xx:8080,发现了可爱的apache。
配置一下PHP:
<pre>
[root@localhost ~]# sed -i "s/;date.timezone =/date.timezone = Asia/Shanghai/g" /etc/php.ini
[root@localhost ~]# sed -i "s#max_execution_time = 30#max_execution_time = 300#g" /etc/php.ini
[root@localhost ~]# sed -i "s#post_max_size = 8M#post_max_size = 32M#g" /etc/php.ini
[root@localhost ~]# sed -i "s#max_input_time = 60#max_input_time = 300#g" /etc/php.ini
[root@localhost ~]# sed -i "s#memory_limit = 128M#memory_limit = 128M#g" /etc/php.ini
[root@localhost ~]# sed -i "/;mbstring.func_overload = 0/ambstring.func_overload = 2\n" /etc/php.ini
[root@localhost ~]#
</pre>
安装python2.7
<pre>
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# wget https://www.python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2
[root@localhost src]# tar jxf Python-2.7.2.tar.bz2
[root@localhost src]# cd Python-2.7.2
[root@localhost Python-2.7.2]# ./configure --prefix=/usr/local/python2.7
[root@localhost Python-2.7.2]# make && make install
</pre>
查看一下python版本号:
<pre>
[root@localhost Python-2.7.2]# python
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
exit()
</pre>
咦?怎么还是系统自带的2.66版本?我们先看一下系统中有哪些python可执行文件
<pre>
[root@localhost bin]# find / -name "python"
/usr/local/python2.7/bin/python
/usr/local/src/Python-2.7.2/python
/usr/bin/python
</pre>
可以看到,在/usr/bin/目录下,有一个系统自带的旧版python。我们把旧版本用重命名备份一下,然后把新版本连接到该bin目录下。
<pre>
[root@localhost bin]# mv /usr/bin/python /usr/bin/python_2_6_6
[root@localhost bin]# ln -s /usr/local/python2.7/bin/python /usr/bin/python
[root@localhost bin]# python
Python 2.7.2 (default, Jan 16 2017, 16:21:48)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
</pre>
升级完python,发现yum指令不能用了。
<pre>
[root@localhost src]# yum
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.2 (default, Jan 16 2017, 16:21:48)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
</pre>
因为yum默认使用的pythom不支持2.7.2。咋办?
我们要修改一下yum文件里面的python,指定到我们刚才备份的那个版本(python_2_6_6)。
<pre>
vi /usr/bin/yum
修改
!/usr/bin/python
变成
!/usr/bin/python_2_6_6
</pre>
接下来安装MySQLdb-python库
<pre>
[root@localhost bin]# cd /usr/local/src/
[root@localhost src]# wget http://cdn.lepus.cc/cdncache/software/MySQLdb-python.zip
[root@localhost src]# unzip MySQLdb-python.zip
[root@localhost src]# cd MySQLdb1-master/
</pre>
这里需要把mysql_config配置一下
先看一下系统中的mysql的这个文件在哪。
<pre>
[root@localhost MySQLdb1-master]# find / -name "mysql_config"
/usr/lib64/mysql/mysql_config
/usr/bin/mysql_config
</pre>
修改site.cfg文件,把当前mysql_config的文件路径写对。
<pre>
[root@localhost MySQLdb1-master]# cat site.cfg |grep "mysql_config"
The path to mysql_config.
Only use this if mysql_config is not on your PATH, or you have some weird
mysql_config = /usr/bin/mysql_config
</pre>
然后启动py的安装脚本
<pre>
[root@localhost MySQLdb1-master]# python setup.py build
[root@localhost MySQLdb1-master]# python setup.py install
</pre>
接下来安装Lepus采集器
先从官网上下载安装包。我这里下载的最新测试版(3.8beta),下面的下载地址根据当前版本替换。
<pre>
[root@localhost src]# wget http://www.lepus.cc/soft/download/18
[root@localhost src]# unzip 18
[root@localhost src]# ls
18 Lepus_v3.8_beta MySQLdb1-master MySQLdb-python.zip Python-2.7.2 Python-2.7.2.tar.bz2
</pre>
在当前机器上mysql中,创建支持lepus系统需要的数据库,以及导入表结构等等。(先将mysql初始化帐号root密码123456)
<pre>
已经配置过的mysql不需要这句初始化密码命令
[root@localhost src]# mysqladmin -u root password '123456'
创建数据库
[root@localhost src]# mysql -uroot -p123456 -e "create database lepus default character set utf8;"
[root@localhost src]# mysql -uroot -p123456 -e "grant select,insert,update,delete,create on lepus.* to 'lepus'@'localhost' identified by 'lepus';"
[root@localhost src]# mysql -uroot -p123456 -e "grant select,insert,update,delete,create on lepus.* to 'lepus'@'127.0.0.1' identified by 'lepus';"
[root@localhost src]# mysql -uroot -p123456 -e "flush privileges"
</pre>
导入表结构,初始化数据
<pre>
[root@localhost sql]# pwd
/usr/local/src/Lepus_v3.8_beta/sql
[root@localhost sql]# mysql -uroot -p123456 lepus < lepus_table.sql
[root@localhost sql]# mysql -uroot -p123456 lepus < lepus_data.sql
</pre>
环境好了,接下来运行安装脚本。到安装包的python目录。
<pre>
[root@localhost python]# pwd
/usr/local/src/Lepus_v3.8_beta/python
[root@localhost python]# sh install.sh
[note] lepus will be install on basedir: /usr/local/lepus
[note] /usr/local/lepus directory does not exist,will be created.
[note] /usr/local/lepus directory created success.
[note] wait copy files.......
[note] change script permission.
[note] create links.
[note] install complete.
[root@localhost python]#
</pre>
给脚本可执行权限,修改数据库配置文件
<pre>
[root@localhost python]# cd /usr/local/lepus/
[root@localhost lepus]# chmod +x *.sh
[root@localhost lepus]# chmod +x *.py
[root@localhost lepus]# vim etc/config.ini
监控机MySQL数据库连接地址###
[monitor_server]
host="localhost"
port=3306
user="lepus"
passwd="lepus"
dbname="lepus"
</pre>
启动lepus服务
<pre>
[root@localhost lepus]# lepus start
</pre>
现在基本安装完毕。剩下的是安装web管理系统。把php文件夹(/usr/local/src/Lepus_v3.8_beta/php)整个移动到apache发布目录下。(新版是php文件夹,旧版好像是www文件夹。)
<pre>
[root@localhost www]# cp -rf /usr/local/src/Lepus_v3.8_beta/php/* /var/www/html/
</pre>
修改php的数据库配置文件。
<pre>
[root@localhost html]# cd /var/www/html/application/config/
[root@localhost config]# vim database.php
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['port'] = '3306';
$db['default']['username'] = 'lepus';
$db['default']['password'] = 'lepus';
$db['default']['database'] = 'lepus';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
</pre>
配置完毕之后,打开http://xx.xx.xx.xx:8080,发现系统已经部署好了。
默认管理员账号密码admin/Lepusadmin
登录一下,体验吧!!!
搭建过程参照:http://www.cnblogs.com/xuanzhi201111/p/5200757.html