您的位置:首页 > 运维架构 > Linux

64位linux环境下编译安装cacti

2013-08-05 12:55 253 查看
首先安装apache
# tar zxvf httpd-2.2.6.tar.gz
# cd httpd-2.2.6
# ./configure --prefix=/usr/local/apache22 --enable-module=so--with-mpm=worker --enable-module=rewrite
# make && make install
启动apache:
# /usr/local/apache22/bin/apachectl start
IE访问http://ip/出现”It works!”,说明apache安装成功。


mysql
# tar zxvf mysql-5.0.22.tar.gz
# cd mysql-5.0.22
# ./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data/--without-innodb --without-debug --with-extra-charsets=gbk--with-extra-charsets=all --enable-assembler --with-pthread--enable-thread-safe-client --with-client-ldflags=-all-static
配置成功出现“Thank you forchoosing MySQL!”提示。
# make &&make install
Mysql配置
# cp ./support-files/mysql.server /etc/init.d/mysql
# groupadd mysql
# useradd –g mysql mysql
# chmod 777 /etc/init.d/mysql
# /usr/local/mysql/bin/mysql_install_db
# chown -R mysql:mysql /usr/local/mysql/data/
启动Mysql
# service mysql start
# /usr/local/mysql/bin/mysqladmin –u root –p password '123456'      //设置密码为rootpw
Enterpassword:                //默认密码为空,所以直接回车
# /usr/local/mysql/bin/mysql –u root –p
Enterpassword:                //输入新密码后,登录成功
mysql安装配置完毕。


第二部分:安装GD库及相关插件

编译安装libxml# wget http://xmlsoft.org/sources/libxml2-2.7.2.tar.gz# tar zxvflibxml2-2.7.2.tar.gz# cd libxml2-2.7.2# ./configure --prefix=/usr/local/libxml2/# make && make install
编译安装zlib# wget http://google-desktop-for-linux-mirror.googlecode.com/files/zlib-1.2.3.tar.gz# tar zxvf zlib-1.2.3.tar.gz# cd zlib/1.2.3/# ./configure --prefix=/usr/local/zlib2/# make && make install
编译安装jpeg这个版本jpeg在make install时会出现目录error。手动创建这些目录,然后再重新makeinstall就可以了,我这把缺失的命令都加上了,应该不会出这个error了。# wget ftp://ftp.aai.ee/pub/unix/jpegsrc.v6b.tar.gz# mkdir /usr/local/jpeg6# mkdir /usr/local/jpeg6/include# mkdir /usr/local/jpeg6/lib# mkdir /usr/local/jpeg6/bin# mkdir/usr/local/jpeg6/man/man1 -p# tar zxvfjpegsrc.v6b.tar.gz# cd jpeg-6b# ./configure --prefix=/usr/local/jpeg6# make# make install-lib# make install
编译安装libpng# wget http://oss.oetiker.ch/rrdtool/pub/libs/libpng-1.2.18.tar.gz# tar zxvflibpng-1.2.18.tar.gz# cd libpng-1.2.18# cp scripts/makefile.gcmmx makefile# ./configure --disable-shared--prefix=/usr/local/libpng2/# make && make install
编译安装freetype# wget http://oss.oetiker.ch/rrdtool/pub/libs/freetype-2.3.5.tar.gz# tar zxvf freetype-2.3.5.tar.gz# cd freetype-2.3.5# ./configure --disable-shared--prefix=/usr/local/freetype2/# make && make install
编译安装libart_lgpl# wget http://oss.oetiker.ch/rrdtool/pub/libs/libart_lgpl-2.3.17.tar.gz# tar zxvf libart_lgpl-2.3.17.tar.gz# cd libart_lgpl-2.3.17# ./configure --disable-shared--prefix=/usr/local/libart/# make && make install
编译安装gettext# wget http://ftp.gnu.org/pub/gnu/gettext/gettext-0.16.1.tar.gz# tar zxvf gettext-0.16.1.tar.gz# cd gettext-0.16.1# ./configure --prefix=/usr/local/gettext/# make && make install //这个编译时间好长啊。。。
上面全部安装完成后,开始编译安装gd,此处注意configure时各个插件的地址是否正确:
# wget http://google-desktop-for-linux-mirror.googlecode.com/files/gd-2.0.35.tar.gz # tar zxvfgd-2.0.35.tar.gz
# cd gd/2.0.35/
# ./configure --prefix=/usr/local/gd2--with-zlib=/usr/local/zlib2/ --with-png=/usr/local/libpng2/--with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype2/--with-libart=/usr/local/libart/ --with-gettext=/usr/local/gettext/--with-libxml=/usr/local/libxml2
# cp /usr/lib/libattr.* /lib/ //如果没执行这步,make时会出现下面的error信息
# make && make install
安装GD2时出错提示:
cd . &&/bin/sh /tmp/cacti/gd/2.0.35/config/missing --run aclocal-1.9 -I config
aclocal:configure.ac:64:warning: macro `AM_ICONV' not found in library
cd .&& /bin/sh /tmp/cacti/gd/2.0.35/config/missing --run automake-1.9--foreign
cd . &&/bin/sh /tmp/cacti/gd/2.0.35/config/missing --run autoconf
configure.ac:64:error: possibly undefined macro: AM_ICONV
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
make: ***[configure] error 1

解决方法:
# cp /usr/lib/libattr.*/lib/ //有两个libattr开头文件,有一个/lib里有,另一个复制过去就行了

编译安装Curl支持
# wget http://dl.ambiweb.de/mirrors/curl.haxx.se/curl-7.15.0.tar.gz # tar zxvfcurl-7.15.0.tar.gz
# cd curl-7.15.0
# ./configure --prefix=/usr/local/curl
# make && make install

第三部分:编译安装并配置PHP
# wget http://us3.php.net/distributions/php-5.2.16.tar.bz2 # tar jxvf php-5.2.16.tar.bz2
# cd php-5.2.16
# ./configure --prefix=/usr/local/php--with-apxs2=/usr/local/apache22/bin/apxs --with-jpeg-dir=/usr/local/jpeg6/--with-png-dir=/usr/local/libpng2/ --with-gd--with-freetype-dir=/usr/local/freetype2/ --with-zlib-dir=/usr/local/zlib2/--with-mysql=/usr/local/mysql --with-curl=/usr/local/curl--with-gettext=/usr/local/gettext --enable-sockets
我第一次安装时,编译PHP出错了,出错信息提示GD有问题:“configure: error: Unable to findgd.h anywhere under”上网查了下说:“系统中已经有GD了,把--with-gd后面留空,就可以顺利configure了,上面的命令,我已经去掉了—with-gd的值,所以应该不会出这个error了。仔细想想好像我装系统时确实把图形那个组件给点上了!嘿嘿~~~
Configure成功后提示”Thankyou for using PHP.”.

# make
# make test

Make test时出错了,不过感觉这个错误影响不是很大,暂时也没找到原因,可能是版本问题,因为上次安装时,我用的不同版本,所以遇到的错误信息也不一样,有点忘了,上次试用了三四个版本,头都搞大了。所以这次也没管它,直接继续安装了~还好后面都成功了,php好用~~~所以暂时就这样吧,如果有高手知道原因,望告之~呵呵~~即使后面不成功的话,这里也可以重编译再装:)换版本或想别的办法解决!!!
ob_start(): Ensure unerasable buffer cannot be flushed by ob_flush(). [tests/output/ob_start_basic_unerasable_005.phpt]
SPL: ArrayObject::exchangeArray() basic usage with object as underlyingdata store. [ext/spl/tests/arrayObject_exchangeArray_basic3.phpt]

继续:
# make install
# cp php.ini-dist/usr/local/php/lib/php.ini //拷贝php配置文件

修改apache配置文件httpd.conf
# vi/usr/local/apache22/conf/httpd.conf
在#AddType application/x-tar.tgz下加一行:
AddTypeapplication/x-httpd-php .php
在#LoadModule foo_module modules/mod_foo.so下加一行: 如果原来有就去掉#号
LoadModulephp5_module modules/libphp5.so
找到DirectoryIndexindex.html在后面添加index.php
保存httpd.conf文件.
重启动apache

# /usr/local/apache22/bin/apachectl stop
# /usr/local/apache22/bin/apachectl start

会出现报错,重启不成功:
*** httpd: Syntaxerror on line 53 of /usr/local/apache22/conf/httpd.conf: Cannot load /usr/local/apache22/modules/libphp5.sointo server: /usr/local/apache22/modules/libphp5.so: cannot restore segmentprot after reloc: Permission denied
# setenforce 0
# chcon -c -v -R -u system_u -r object_r -ttextrel_shlib_t /usr/local/apache22/modules/libphp5.so
# /usr/local/apache-2.2.17/bin/apachectlrestart
# setenforce 1

执行了之后还是会报错:
*** httpd: Could not reliably determine theserver's fully qualified domain name, using 220.250.64.24 for ServerName
在http.conf这个文件里面找到#ServerName www.example.com:80这一行,取掉前面的注释,然后保存退出就可以成功的重启apache服务了

第四部分:编译安装rrdtool及安装配置snmp
编译安装rrdtools
# wget ftp://ftp.pucpr.br/rrdtool/rrdtool-1.2.27.tar.gz # tarzxvf rrdtool-1.2.27.tar.gz
# cdrrdtool-1.2.27
#./configure --prefix=/usr/local/rrdtool
# make && make install

安装SNMP(或者采用源码方式安装SNMP,这里为了方便才使用的yum安装)
# yum -y install net-snmp*

配置SNMP
#vi /etc/snmp/snmpd.conf
com2sec notConfigUser default public
改为:com2sec notConfigUser127.0.0.1 public
access notConfigGroup "" anynoauth exact systemview none none
改为:access notConfigGroup"" any noauth exact all none none
#view all included .1 80
将前面的#注释去掉。
保存退出:wq
4.重新启动snmp服务
# service snmpd restart
用这个snmpwalk -v 2c -cpublic 127.0.0.1 if 测试SNMP是否有问题

第五部分:安装/配置cacti
# wget http://www.cacti.net/downloads/cacti-0.8.7g.tar.gz # tar zxvf cacti-0.8.7g.tar.gz
# mv cacti-0.8.7g/usr/local/apache22/htdocs/cacti
# chown -R root:root/usr/local/apache22/htdocs/cacti

在Mysql中创建新的database,导入cacti目录中的cacti.sq创建表:
# /usr/local/mysql/bin/mysql –u root –p
Enter Password:123456 //安装mysql时设置的密码,默认为空
mysql> create database cacti;
mysql> use cacti;
mysql> source/usr/local/apache22/htdocs/cacti/cacti.sql;

设置数据库用户权限:
grant all on cacti.* to root;
grant all on cacti.* to root@localhost;
grant all on cacti.* to cactiuser;
grant all on cacti.* tocactiuser@localhost;
set password forcactiuser@localhost=password('123456');

编辑cacti的数据库配置文件,与上一步中的用户对应。
# vi /usr/local/apache22/htdocs/cacti/include/config.php
$database_type=“mysql”;
$database_default=“cacti”;
$database_hostname=“localhost”;
$database_username=“cactiuser”;
$database_password=“123456”;

打开浏览器http://IP地址/cacti
这里可能出现的error信息如下:You have created anew database, but have not yet imported the 'cacti.sql …
解决方法:出现这个错误是因为数据库用户的权限问题。如果按照我上面的用户创建及设置应该是不会出现这个error的。如果把$database_hostname换成IP,就会出现这个错误。当然如果给这个IP地址grant给用户权限后,就不会出错了!
例如:grant all on cactidb.* to cactiuser@ip;grant all on cactidb.* to root@ip;
注:以下几步,根据Cacti的版本不同,先后顺序会稍有不同,但大致内容都是一样的。
如果不出错误的话,应该就进入了Cacti InstallationGuide画面,点击Next>>,进入下一页; 这个画面可以选择是初次安装Cacti,还是升级安装Cacti,同时提醒核对数据库连接信息,点击Next>>,继续; 打开snmp、php、rrdtool等工具的路径设置画面,按照你的安装路径全部填上就行了。设置完成后,登录到cacti控制台画面,选择左侧菜单的settings->paths,可以修改设置。默认的配置中会出现许多“NotFound”,一定要全部填写正确!不然会影响画图。各个路径根据自己的安装路径填写,找不着的可以试着用whereis、find之类的命令检索一下。
RRDTool Binary Path: /usr/local/rrdtool/bin/rrdtool
PHP Binary Path:/usr/local/php/bin/php
snmpwalk Binary Path:/usr/bin/snmpwalk
snmpget Binary Path:/usr/bin/snmpget
snmpbulkwalk Binary Path:/usr/bin/snmpbulkwalk
snmpgetnext Binary Path:/usr/bin/snmpgetnext
CactiLogFilePath:/usr/local/apache22/htdocs/cacti/log/cacti.log
CactidPollerFilePath:/usr/local/apache22/htdocs/cacti/poller.php
RRDTool Default Font Path:/usr/local/rrdtool/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf
SNMP Utility Version选择NET-SNMP 5.x
点击Finish 结束配置,进入登录画面。
首次登陆默认账号:admin密码admin
登陆后系统会强制立即修改密码

生成统计图像:
手动运行一次poller.php,生成初始图像文件:
# /usr/local/php/bin/php /usr/local/apache22/htdocs/cacti/poller.php >/dev/null 2>&1
查看图像文件是否生成:
# ls /usr/local/apache22/htdocs/cacti/rra
这里我看网上很多朋友都遇到图像未生成或看不到图像的问题了,我第一次安装时也遇到了,查了好多资料,最后归根结底其实都是SNMP的配置问题!按照我上面的安装方法,安装完成之后,使用如下命令测试一下,如果没报错,说明SNMP就是没问题的!应该可以出现图像的:
# snmpwalk -v 1 127.0.0.1 -c public
正常会显示信息类似如下:
(略)HOST-RESOURCES-MIB::hrSWRunPerfCPU.2436= INTEGER: 8(略)
如果还是看不到图像的话,可以到cacti的控制台里,打开Data Sources->随便点一个例如Localhost – Processes,然后点击右上角的Turn on Data SourceDebug Mode,下面会有一些提示信息。或者看一下/usr/local/apache22/htdocs/cacti/log/cacti.log文件。一定会找到原因的。或者问我也可以!哈哈~~~~
添加自动执行:
# crontab –e
*/1 * * * * /usr/local/php/bin/php/usr/local/apache22/htdocs/cacti/poller.php > /dev/null 2>&1
这样,每过1分钟就会自动更新一次图像统计信息。
打开cacti控制台,在graphs中localhost里就可以看到本机的CPU、内存等的统计信息图了。
这里需要注意一下,cacti的版本不同,settings里的设定项也不太一样!我也是因为装了两次,用的不同版本才发现的!改动还满大的~哈哈,实在懒得去看版本更新日志,就直接进系统比较了~~~还有好多不一样的地方,大家一起去发现吧:)
小提示:注意整个安装过程中的权限相关的问题,主要涉及就如下几个:本次安装时我没用创建新用户单独给cacti使用,而是直接用的root。如果用别的用户,需要把/usr/local/apache22/htdocs/cacti的目录权限及自动执行poller.php的用户更改。还有就是mysql的用户问题,注意/usr/local/mysql/data文件夹及其子目录的权限问题,偶尔会出错。
好了,暂时就写到这吧~~如果有问题欢迎大家批评交流~~~呵呵:)

安装 spine
tar zxvfcacti-spine-0.8.7g.tar.gz
cd cacti-spine-0.87g
./configure--prefix=/usr/local/spine
Make && makeinstall
cd /usr/local/spine/etc/
cp spine.conf.distspine.conf
Vim spine.conf 修改
DB_Host localhost
DB_Database cacti 数据库的名字
DB_User root 数据苦用户
DB_Pass 123456 数据库密码
DB_Port 3306 端口号
DB_PreG 0

安装cacti插件,在官网上下载好对应cacti-0.87g的这个cacti-plugin-0.8.7g-PA-v2.8.tar.gz包,
tarzxvf cacti-plugin-0.8.7g-PA-v2.8.tar.gz
/usr/local/mysql/bin/mysql -u root cacti -p< cacti-plugin-arch/pa.sql
patch -p1 -N <cacti-plugin-arch/cacti-plugin-0.8.7g-PA-v2.8.diff
然后,vim /usr/local/apache22/htdocs/cacti/include/global.php 添加$config['url_path'] = '/cacti/';
下载monitor插件,cd /usr/local/apache22/htdocs/cacti/plugins
tar zxvfmonitor-0.8.2.tar.gz
/usr/local/mysql/bin/mysql-uroot cacti -p < monitor/monitor.sql
Vim/usr/local/apache22/htdocs/cacti/include/config.php
加上$plugins[] = 'monitor';
其他插件一样安装。

第六部分 后续问题
完成后报类似这样的错,经过google,查到是因为mysql默认连接数太小造成的。
SPINE: Poller[0] FATAL: Connection Failed, Error:'1040', Message:'Toomany connections' (Spine thread)

解决办法:/usr/local/mysql/bin/mysql -u root -p
set GLOBAL max_connections=200000;
/usr/local/mysql/bin/mysqladmin -uroot -p variables 查看是否改成功了=============================================================================
安装遇到问题总结

/usr/bin/ld: /usr/local/libpng2/lib/libpng12.a(libpng12_la-png.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/local/libpng2/lib/libpng12.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [libgd.la] 错误1
make[2]: Leaving directory `/data/soft/php/gd-2.0.35'
make[1]: *** [all-recursive] 错误1
make[1]: Leaving directory `/data/soft/php/gd-2.0.35'
make: *** [all] 错误2
-----------------------------
libpng的问题,我们改一改编译以及安装的方式。跟上边2个一样,要先把/usr/local/libpng2 都删干净,然后再重新编译安装。
编译安装 libpng
#tar zxvf libpng-1.2.34.tar.gz
#cd libpng-1.2.34
#cp scripts/makefile.gcmmx makefile
#./configure --prefix=/usr/local/libpng2/
# vi Makefile
找到 CFLAGS = -g -O2 后边加上 -fPIC
# make && make install

编译安装后php.ini 文件应该放在 /usr/lib64/php.ini 中 注意设定好时间
安装rrdtool之前确保安装了这些库zlib libpng freetype libart_lgpl
如如果./configure时出现下面这个错误

configure: error: Please fix the library issues listed above and try again.

就要安装libart_lgpl-devel这个包
make 进行编译
make install 将编译好的安装到/usr/local/rrdtool-1.2.6/
ls /usr/local/rrdtool-1.2.6/ 查看该目录
bin examples include lib man share shared 应该有这些目录才正至此rrdtool安装成功
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux mysql local