终于搞定了
CACTI
,特写手记一篇,也向网上无数被我抄袭的朋友们问好
:)
1. 安装环境: RedHat AS 5 UP1( 其实 4.0 我也能搞定,但是 spine 就一直搞不定,还是用 AS5 吧,至少还是新版本呵 )
分区什么的可以用默认设置,特别要说明的是安装时切记要安装 development tools ,否则下面安装时会问题百出呵。
为方便大家安装,我特将所有的源程序打了个包放在网上供大家下载,地址为:
http://218.4.155.86/cacti.rar
2. 安装 Apache 、 MySQL 、 PHP
( 1 ) . 安装 MySQL
下载地址: http://dev.mysql.com/downloads/mysql/5.0.html
// 查看系统中是否已经安装了 MySQL ,如果是卸载所有以 mysql 开头的包。
# rpm -qa | grep mysql
# rpm -e mysql-*
// 查找 /etc/my.cnf ( MySQL 的选项配置文件),如果有请删除它,以免影响新安装版本的启动。
# rm -f /etc/my.cnf
# tar zxvf mysql-5.0.51a-linux-i686-icc-glibc23.tar.tar
# cp -rf mysql-5.0.51a-linux-i686-icc-glibc23 /usr/local/
// 建立符号链接,如果以后有新版本的 MySQL 的话,你可以仅仅将源码解压到新的路径,然后重新做一个符号链接就可以了。这样非常方便,数据也更加安全。
# ln -s mysql-5.0.51a-linux-i686-icc-glibc23 /usr/local/mysql
// 添加用于启动 MySQL 的用户及用户组(如果以前安装过 MySQl ,用户及用户组可能已存在)。
# useradd mysql
# groupadd mysql
// 初始化授权表
# cd /usr/local/mysql
# scripts/mysql_install_db
// 修改 MySQl 目录的所有权
# cd /usr/local
# chgrp -R mysql mysql-5.0.51a-linux-i686-icc-glibc23
# chgrp -R mysql mysql
# chown -R mysql mysql-5.0.51a-linux-i686-icc-glibc23/data
# chown -R mysql mysql/data
# ln -s /usr/local/mysql/bin/* /usr/local/bin/
// 启动 Mysql
# bin/safe_mysqld --user=mysql &
// 配置系统启动时自动启动 MySQl
# cd /usr/local/mysql
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
// 修改 MySQL 的最大连接数
# vi /etc/my.cnf
// 添加以下行
[mysqld]
set-variable=max_connections=1000
set-variable=max_user_connections=500
set-variable=wait_timeout=200
//max_connections 设置最大连接数为 1000
//max_user_connections 设置每用户最大连接数为 500
//wait_timeout 表示 200 秒后将关闭空闲( IDLE )的连接,但是对正在工作的连接不影响。
// 保存退出,并重新启动 MySQL
# service mysqld restart
// 重新启动 MySQL 后使用下面的命令查看修改是否成功
# mysqladmin -uroot -p variables
Password:
// 可以看到以下项说明修改成功
| max_connections | 1000
| max_user_connections | 500
| wait_timeout | 200
( 2 ) . 安装 Apache
下载地址: http://httpd.apache.org/
# tar jxvf httpd-2.2.8.tar.bz2
# cd httpd-2.2.8
# ./configure --prefix=/usr/local/apache --enable-so
// 编译时加上加载模块参数 --enable-so
# make
# make install
#vi /usr/local/apache/conf/httpd.conf
// 修改 Apache 配置文件,添加 ServerName www.yourdomain.com (或 ServerName 本机 ip )
# vi /etc/rc.d/rc.local
// 在 rc.local 上加入一行 /usr/local/apache/bin/apachectl -k start, 系统启动时启动 Apache 服务。
( 3 ) . 安装 PHP
先安装 zlib,freetype,libpng,jpeg 以便于让 PHP 支持 GD 库( Cacti 的 WeatherMap 插件必须要较新 GD 库的支持)
库文件下载地址: http://oss.oetiker.ch/rrdtool/pub/libs/
1 ) . 安装 zlib
# tar zxvf zlib-1.2.3.tar.gz
# cd zlib-1.2.3
# ./configure --prefix=/usr/local/zlib
# make
# make install
2 ) . 安装 libpng
# tar zxvf libpng-1.2.18.tar.tar
# cd libpng-1.2.18
# cd scripts
# mv makefile.linux ../makefile
# cd ..
# make
# make install
// 注意,这里的 makefile 不是用 ./configure 生成,而是直接从 scripts/ 里拷一个
3 ) . 安装 freetype
# tar zxvf freetype-2.3.5.tar.gz
# cd freetype-2.3.5
# ./configure --prefix=/usr/local/freetype
# make
# make install
# cp /usr/local/freetype/lib/pkgconfig/freetype2.pc /usr/lib/pkgconfig/
// 这句话等下装 rrdtool 会用到,就在这里操作掉完事呵 :)
4 ) . 安装 Jpeg
# tar zxvf jpegsrc.v6b.tar.tar
# cd jpeg-6b/
# mkdir /usr/local/libjpeg
# mkdir /usr/local/libjpeg/include
# mkdir /usr/local/libjpeg/bin
# mkdir /usr/local/libjpeg/lib
# mkdir /usr/local/libjpeg/man
# mkdir /usr/local/libjpeg/man/man1
// 可以用 mkdir -p /usr/local/libjpeg/man/man1 一步创建多层目录
# ./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static
# make && make install
// 注意,这里 configure 一定要带 --enable-shared 参数,不然,不会生成共享库
5 ) . 安装 Fontconfig( 这里搞了我很久呵,主要是 configure 后面的参数要全呵)
# tar zxvf fontconfig-2.4.2.tar.gz
# cd fontconfig-2.4.2
# ./configure --with-freetype-config=/usr/local/freetype/bin/freetype-config
# make
# make install
6 ) . 安装 GD (这里有可能第一次 make 不会成功, make 程序会自动修正,所以请多试一次)
# tar zxvf gd-2.0.35.tar.gz
# cd gd-2.0.35
# ./configure --prefix=/usr/local/libgd --with-png --with-freetype=/usr/local/freetype --with-jpeg=/usr/local/libjpeg
# make
# make install
编译时显示以下信息:
** Configuration summary for gd 2.0.35:
Support for PNG library: yes
Support for JPEG library: yes
Support for Freetype 2.x library: yes
Support for Fontconfig library: yes
Support for Xpm library: no
Support for pthreads: yes
7 ) . 编辑 /etc/ld.so.conf ,添加以下几行到此文件中。
/usr/local/zlib/lib
/usr/local/freetype/lib
/usr/local/libjpeg/lib
/usr/local/libgd/lib
// 执行 ldconfig 命令,使用动态装入器装载找到共享库
# ldconfig
8 ) . 安装 libxml , RedHat AS 4 默认安装 libxml 包,但版本太低, PHP5 需要更高版本的 libxml 包。
# tar zxvf libxml2-sources-2.6.31.tar.gz
# cd libxml2-2.6.31/
# ./configure
# make
# make install
9 ) . 安装 PHP
PHP 下载地址: http://www.php.net/downloads.php#v5
# tar jxvf php-5.2.6.tar.bz2
# cd php-5.2.6
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-gd=/usr/local/libgd --enable-gd-native-ttf --with-ttf --enable-gd-jis-conv --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/libjpeg --with-png-dir=/usr --with-zlib-dir=/usr/local/zlib --enable-xml --enable-mbstring --enable-sockets
# make
# make install
在 RHEL5 上安装 PHP 时有可能会出现
error while loading shared libraries: /usr/local/gd/lib/libgd.so.2: cannot restore segment prot after reloc: Permission denied
原来这是 SELinux 搞的鬼,解决办法有如下两个
1. 使用 chcon 命令
chcon -t texrel_shlib_t / 路径 / 路径 / 名字 .so ( 这个文件视具体执行文件 .)
2. 禁止掉 SELinux
编辑 /etc/sysconfig/selinux ,找到 :
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=enforcing
如果 SELINUX 已经是 SELINUX=disabled ,那么就不用改了,否则就把 SELINUX=enforcing 注释掉,新加一行:
SELINUX=disabled
保存,退出,重新启动即可 make install 了。
# cp php.ini-recommended /usr/local/php/lib/php.ini
# ln -s /usr/local/php/bin/* /usr/local/bin/
# vi /usr/local/apache/conf/httpd.conf
// 查找到
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在其下加入
AddType application/x-tar .tgz
AddType application/x-httpd-php .php
AddType p_w_picpath/x-icon .ico
修改 DirectoryIndex 行,找到
DirectoryIndex index.html
修改为
DirectoryIndex index.php index.html index.html.var
# vi /usr/local/apache/htdocs/test.php
// 建立一个测试页面,看看 php 是否能正常运行,在内容中添加以下行:
<?php
Phpinfo();
?>
wq! 保存退出,下面我们来重启下 apache
# /usr/local/apache/bin/apachectl -k stop
# /usr/local/apache/bin/apachectl -k start
在浏览器中输入: http://www.yourdomain.com/test.php 进行测试,如果不能显示,请注意下检查 linux 的防火墙是否把 www 服务阻挡了。
下面是对刚刚 php 编译选项的解释:
--prefix=/usr/local/php // 指定 PHP 的安装目录
--with-apxs2=/usr/local/apache2/bin/apxs // 支持 Apache 模块
--with-mysql=/usr/local/mysql // 支持 MySQl
--with-gd=/usr/local/libgd // 支持 GD 库
--enable-gd-native-ttf // 激活对本地 TrueType 字符串函数的支持
--with-ttf // 激活对 FreeType 1.x 的支持
--with-freetype-dir=/usr/local/freetype // 激活对 FreeType 2.x 的支持
--with-jpeg-dir=/usr/local/libjpeg // 激活对 jpeg-6b 的支持
--with-png-dir=/usr // 激活对 png 的支持
--with-zlib-dir=/usr/local/zlib // 激活对 zlib 的支持
--enable-mbstring // 激活 mbstring 模块
--enable-gd-jis-conv // 使 JIS-mapped 可用,支持日文字体
--with-mail // 支持 Mail 函数
--enable-xml // 支持 XML
--enable-sockets // 支持套接字
好了,环境基本都搭好了,下面我们来装 rrdtool ,这也是个公认比较难装的东东,不过我在网上找到了一个兄弟打好的包,把啥啥东东都配好了,一次性运行就成,大家可以在附件中下载 rrdtool-1.2.23.tar.gz 就是啦。
1. 安装 RRDTool
# tar zxvf rrdtool-1.2.23.tar.gz
# cd rrdtool-1.2.23.tar.gz
# ./rrdinstall.sh
// 完成后建立符号连接
# ln -s /usr/local/rrdtool/bin/* /usr/local/bin/
// 执行 rrdtool 看是否安装正确
# rrdtool
2. 安装 net-snmp
RedHat 默认安装了 SNMP 服务,但好象没有 snmpwalk,snmpget 这两个命令,所以需要编译安装 NET-SNMP 。
NET-SNMP 官方网站: http://www.net-snmp.org/
# tar zxvf net-snmp-5.4.1.tar.gz
# cd net-snmp-5.4.1
# ./configure --prefix=/usr/local/net-snmp --enable-developer
# make
# make install
如果出错找不到 libbeecrypt.la ,在 make 时可能出现如下 error
libtool: link: cannot find the library `/usr/lib/libbeecrypt.la' (librpmio.la: /usr/lib/libbeecrypt.la)
make[1]: *** [snmpd] Error 1
make[1]: Leaving directory `/home/xxx/net-snmp-5.3.2/agent'
make: *** [subdirs] Error 1
解决办法:
到 http://sourceforge.net/projects/beecrypt 下载 beecrypt-4.1.2.tar.gz
然后运行如下命令:
# tar -zxvf beecrypt-4.1.2.tar.gz
# ./configure -prefix=/usr (默认是安装在 /usr/local, 我们需要安装在 /usr 目录下)
# make
# make install
如果出错 /usr/bin/ld: cannot find -lelf ,在 make 时可能出现如下 error
/usr/bin/ld: cannot find -lelf
collect2: ld returned 1 exit status
make[1]: *** [snmpd] Error 1
make[1]: Leaving directory `/home/xxx/net-snmp-5.3.2/agent'
make: *** [subdirs] Error 1
解决办法:
# ln -s libelf.so.1 /usr/lib/libelf.so
好,我们完成 make install 后
# ln -s /usr/local/net-snmp/bin/* /usr/local/bin/
# cp EXAMPLE.conf /usr/local/net-snmp/share/snmp/snmpd.conf
// 修改 snmpd.conf (修改 COMMUNITY 、允许抓取 snmp 数据的主机、抓取数据范围等)。
# /usr/local/net-snmp/sbin/snmpd // 启动 SNMP 服务
# vi /etc/rc.d/rc.local
// 在 rc.local 上加入一行 /usr/local/net-snmp/sbin/snmpd, 系统启动时启动 SNMP 服务。
3. 安装 Cacti
Cacti 官方网站: www.cacti.net/
# tar zxvf cacti-0.8.7b.tar.gz
# cd cacti-0.8.7b
# cp -rf * /usr/local/apache/htdocs/
# cd /usr/local/apache/htdocs
# vi /usr/local/apache/htdocs/include/config.php
// 修改配置文件,设置好数据库信息
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
// 这个密码就随便你设啦,但是请记住在下面配置数据库时要一致呵
// 添加 cacti 用户
# useradd cacti
// 将 rra 目录的所有权给 cacti 用户
# chown -R cacti /usr/local/apache/htdocs/rra
// 修改 cacti 所在目录所属组
# chgrp -R cacti /usr/local/apache/htdocs
// 为 cacti 用户添加 cron 任务
# su - cacti
# crontab -e
// 在其中加入
*/5 * * * * /usr/local/bin/php /usr/local/apache/htdocs/poller.php > /dev/null 2
>&1
//wq 保存退出, exit 退回 root 用户。
// 注意:首次执行 poller.php 时请使用 cacti 用户,否则生成的 rrd 文件 cacti 将没有写入权限。
4. 安装 Spine (这个只在 RHAS 5 up1 上测试成功过呵,在 RHAS 4 上装还要安装 libtool ,俺就不烦啦)
Spine 的安装需要以下支持:
o net-snmp-devel (需要编译安装 net-snmp 时添加 --enable-developer 选项)
o mysql
o mysql-devel ( mysql 源文件编译安装后默认支持)
o openssl-devel ( Redhat 默认安装)
# tar -zxvf cacti-spine-0.8.7a.tar.gz
# cd cacti-spine-0.8.7a
# ./configure --with-mysql=/usr/local/mysql --with-snmp=/usr/local/net-snmp
# make
// 这时你将在此目录下看到多出了 spine 、 spine.conf 两个文件
# mkdir /usr/local/spine
# cp spine spine.conf /usr/local/spine
# vi /usr/local/spine/spine.conf // 修改 spine 配置文件
DB_Host 127.0.0.1
DB_Database cacti
DB_User cacti
DB_Pass cacti
//DB_Host 注意要改成 127.0.0.1 。
# ln -s /usr/local/mysql/lib/libmysqlclient_r.so.15 /usr/lib/libmysqlclient_r.so.15
// 这个是 spine 运行需要的东东,可惜它自己编译的时候没有搞好,只好我们手工加啦。
5. 数据库配置
#mysql -uroot -p
Password:
mysql> create database cacti;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on cacti.* to cacti@localhost identified by "cacti";
Query OK, 1 row affected (0.00 sec)
mysql>exit
# cd /usr/local/apache/htdocs
# mysql -uroot -p cacti < cacti.sql
Password:
// 好了,数据基本配完了 :)
6. 完成 cacti 的安装
1 ) . 在浏览器中输入: http://www.yourdomain.com/ // 这个要看你刚刚配的网址啦 :)
默认用户名: admin 密码: admin
2 ) . 更改密码
3 ) . 设置 cacti 用到的命令路径
snmpwalk Binary Path /usr/local/bin/snmpwalk
snmpget Binary Path /usr/local/bin/snmpget
RRDTool Binary Path /usr/local/bin/rrdtool
PHP Binary Path /usr/local/bin/php
Cacti Log File Path /usr/local/apache/htdocs/cacti/log/cacti.log
Cactid Poller File Path /usr/local/spine/spine
大功告成,下面就是进系统配置啦,我就不详述啦:)
1. 安装环境: RedHat AS 5 UP1( 其实 4.0 我也能搞定,但是 spine 就一直搞不定,还是用 AS5 吧,至少还是新版本呵 )
分区什么的可以用默认设置,特别要说明的是安装时切记要安装 development tools ,否则下面安装时会问题百出呵。
为方便大家安装,我特将所有的源程序打了个包放在网上供大家下载,地址为:
http://218.4.155.86/cacti.rar
2. 安装 Apache 、 MySQL 、 PHP
( 1 ) . 安装 MySQL
下载地址: http://dev.mysql.com/downloads/mysql/5.0.html
// 查看系统中是否已经安装了 MySQL ,如果是卸载所有以 mysql 开头的包。
# rpm -qa | grep mysql
# rpm -e mysql-*
// 查找 /etc/my.cnf ( MySQL 的选项配置文件),如果有请删除它,以免影响新安装版本的启动。
# rm -f /etc/my.cnf
# tar zxvf mysql-5.0.51a-linux-i686-icc-glibc23.tar.tar
# cp -rf mysql-5.0.51a-linux-i686-icc-glibc23 /usr/local/
// 建立符号链接,如果以后有新版本的 MySQL 的话,你可以仅仅将源码解压到新的路径,然后重新做一个符号链接就可以了。这样非常方便,数据也更加安全。
# ln -s mysql-5.0.51a-linux-i686-icc-glibc23 /usr/local/mysql
// 添加用于启动 MySQL 的用户及用户组(如果以前安装过 MySQl ,用户及用户组可能已存在)。
# useradd mysql
# groupadd mysql
// 初始化授权表
# cd /usr/local/mysql
# scripts/mysql_install_db
// 修改 MySQl 目录的所有权
# cd /usr/local
# chgrp -R mysql mysql-5.0.51a-linux-i686-icc-glibc23
# chgrp -R mysql mysql
# chown -R mysql mysql-5.0.51a-linux-i686-icc-glibc23/data
# chown -R mysql mysql/data
# ln -s /usr/local/mysql/bin/* /usr/local/bin/
// 启动 Mysql
# bin/safe_mysqld --user=mysql &
// 配置系统启动时自动启动 MySQl
# cd /usr/local/mysql
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
// 修改 MySQL 的最大连接数
# vi /etc/my.cnf
// 添加以下行
[mysqld]
set-variable=max_connections=1000
set-variable=max_user_connections=500
set-variable=wait_timeout=200
//max_connections 设置最大连接数为 1000
//max_user_connections 设置每用户最大连接数为 500
//wait_timeout 表示 200 秒后将关闭空闲( IDLE )的连接,但是对正在工作的连接不影响。
// 保存退出,并重新启动 MySQL
# service mysqld restart
// 重新启动 MySQL 后使用下面的命令查看修改是否成功
# mysqladmin -uroot -p variables
Password:
// 可以看到以下项说明修改成功
| max_connections | 1000
| max_user_connections | 500
| wait_timeout | 200
( 2 ) . 安装 Apache
下载地址: http://httpd.apache.org/
# tar jxvf httpd-2.2.8.tar.bz2
# cd httpd-2.2.8
# ./configure --prefix=/usr/local/apache --enable-so
// 编译时加上加载模块参数 --enable-so
# make
# make install
#vi /usr/local/apache/conf/httpd.conf
// 修改 Apache 配置文件,添加 ServerName www.yourdomain.com (或 ServerName 本机 ip )
# vi /etc/rc.d/rc.local
// 在 rc.local 上加入一行 /usr/local/apache/bin/apachectl -k start, 系统启动时启动 Apache 服务。
( 3 ) . 安装 PHP
先安装 zlib,freetype,libpng,jpeg 以便于让 PHP 支持 GD 库( Cacti 的 WeatherMap 插件必须要较新 GD 库的支持)
库文件下载地址: http://oss.oetiker.ch/rrdtool/pub/libs/
1 ) . 安装 zlib
# tar zxvf zlib-1.2.3.tar.gz
# cd zlib-1.2.3
# ./configure --prefix=/usr/local/zlib
# make
# make install
2 ) . 安装 libpng
# tar zxvf libpng-1.2.18.tar.tar
# cd libpng-1.2.18
# cd scripts
# mv makefile.linux ../makefile
# cd ..
# make
# make install
// 注意,这里的 makefile 不是用 ./configure 生成,而是直接从 scripts/ 里拷一个
3 ) . 安装 freetype
# tar zxvf freetype-2.3.5.tar.gz
# cd freetype-2.3.5
# ./configure --prefix=/usr/local/freetype
# make
# make install
# cp /usr/local/freetype/lib/pkgconfig/freetype2.pc /usr/lib/pkgconfig/
// 这句话等下装 rrdtool 会用到,就在这里操作掉完事呵 :)
4 ) . 安装 Jpeg
# tar zxvf jpegsrc.v6b.tar.tar
# cd jpeg-6b/
# mkdir /usr/local/libjpeg
# mkdir /usr/local/libjpeg/include
# mkdir /usr/local/libjpeg/bin
# mkdir /usr/local/libjpeg/lib
# mkdir /usr/local/libjpeg/man
# mkdir /usr/local/libjpeg/man/man1
// 可以用 mkdir -p /usr/local/libjpeg/man/man1 一步创建多层目录
# ./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static
# make && make install
// 注意,这里 configure 一定要带 --enable-shared 参数,不然,不会生成共享库
5 ) . 安装 Fontconfig( 这里搞了我很久呵,主要是 configure 后面的参数要全呵)
# tar zxvf fontconfig-2.4.2.tar.gz
# cd fontconfig-2.4.2
# ./configure --with-freetype-config=/usr/local/freetype/bin/freetype-config
# make
# make install
6 ) . 安装 GD (这里有可能第一次 make 不会成功, make 程序会自动修正,所以请多试一次)
# tar zxvf gd-2.0.35.tar.gz
# cd gd-2.0.35
# ./configure --prefix=/usr/local/libgd --with-png --with-freetype=/usr/local/freetype --with-jpeg=/usr/local/libjpeg
# make
# make install
编译时显示以下信息:
** Configuration summary for gd 2.0.35:
Support for PNG library: yes
Support for JPEG library: yes
Support for Freetype 2.x library: yes
Support for Fontconfig library: yes
Support for Xpm library: no
Support for pthreads: yes
7 ) . 编辑 /etc/ld.so.conf ,添加以下几行到此文件中。
/usr/local/zlib/lib
/usr/local/freetype/lib
/usr/local/libjpeg/lib
/usr/local/libgd/lib
// 执行 ldconfig 命令,使用动态装入器装载找到共享库
# ldconfig
8 ) . 安装 libxml , RedHat AS 4 默认安装 libxml 包,但版本太低, PHP5 需要更高版本的 libxml 包。
# tar zxvf libxml2-sources-2.6.31.tar.gz
# cd libxml2-2.6.31/
# ./configure
# make
# make install
9 ) . 安装 PHP
PHP 下载地址: http://www.php.net/downloads.php#v5
# tar jxvf php-5.2.6.tar.bz2
# cd php-5.2.6
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-gd=/usr/local/libgd --enable-gd-native-ttf --with-ttf --enable-gd-jis-conv --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/libjpeg --with-png-dir=/usr --with-zlib-dir=/usr/local/zlib --enable-xml --enable-mbstring --enable-sockets
# make
# make install
在 RHEL5 上安装 PHP 时有可能会出现
error while loading shared libraries: /usr/local/gd/lib/libgd.so.2: cannot restore segment prot after reloc: Permission denied
原来这是 SELinux 搞的鬼,解决办法有如下两个
1. 使用 chcon 命令
chcon -t texrel_shlib_t / 路径 / 路径 / 名字 .so ( 这个文件视具体执行文件 .)
2. 禁止掉 SELinux
编辑 /etc/sysconfig/selinux ,找到 :
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=enforcing
如果 SELINUX 已经是 SELINUX=disabled ,那么就不用改了,否则就把 SELINUX=enforcing 注释掉,新加一行:
SELINUX=disabled
保存,退出,重新启动即可 make install 了。
# cp php.ini-recommended /usr/local/php/lib/php.ini
# ln -s /usr/local/php/bin/* /usr/local/bin/
# vi /usr/local/apache/conf/httpd.conf
// 查找到
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在其下加入
AddType application/x-tar .tgz
AddType application/x-httpd-php .php
AddType p_w_picpath/x-icon .ico
修改 DirectoryIndex 行,找到
DirectoryIndex index.html
修改为
DirectoryIndex index.php index.html index.html.var
# vi /usr/local/apache/htdocs/test.php
// 建立一个测试页面,看看 php 是否能正常运行,在内容中添加以下行:
<?php
Phpinfo();
?>
wq! 保存退出,下面我们来重启下 apache
# /usr/local/apache/bin/apachectl -k stop
# /usr/local/apache/bin/apachectl -k start
在浏览器中输入: http://www.yourdomain.com/test.php 进行测试,如果不能显示,请注意下检查 linux 的防火墙是否把 www 服务阻挡了。
下面是对刚刚 php 编译选项的解释:
--prefix=/usr/local/php // 指定 PHP 的安装目录
--with-apxs2=/usr/local/apache2/bin/apxs // 支持 Apache 模块
--with-mysql=/usr/local/mysql // 支持 MySQl
--with-gd=/usr/local/libgd // 支持 GD 库
--enable-gd-native-ttf // 激活对本地 TrueType 字符串函数的支持
--with-ttf // 激活对 FreeType 1.x 的支持
--with-freetype-dir=/usr/local/freetype // 激活对 FreeType 2.x 的支持
--with-jpeg-dir=/usr/local/libjpeg // 激活对 jpeg-6b 的支持
--with-png-dir=/usr // 激活对 png 的支持
--with-zlib-dir=/usr/local/zlib // 激活对 zlib 的支持
--enable-mbstring // 激活 mbstring 模块
--enable-gd-jis-conv // 使 JIS-mapped 可用,支持日文字体
--with-mail // 支持 Mail 函数
--enable-xml // 支持 XML
--enable-sockets // 支持套接字
好了,环境基本都搭好了,下面我们来装 rrdtool ,这也是个公认比较难装的东东,不过我在网上找到了一个兄弟打好的包,把啥啥东东都配好了,一次性运行就成,大家可以在附件中下载 rrdtool-1.2.23.tar.gz 就是啦。
1. 安装 RRDTool
# tar zxvf rrdtool-1.2.23.tar.gz
# cd rrdtool-1.2.23.tar.gz
# ./rrdinstall.sh
// 完成后建立符号连接
# ln -s /usr/local/rrdtool/bin/* /usr/local/bin/
// 执行 rrdtool 看是否安装正确
# rrdtool
2. 安装 net-snmp
RedHat 默认安装了 SNMP 服务,但好象没有 snmpwalk,snmpget 这两个命令,所以需要编译安装 NET-SNMP 。
NET-SNMP 官方网站: http://www.net-snmp.org/
# tar zxvf net-snmp-5.4.1.tar.gz
# cd net-snmp-5.4.1
# ./configure --prefix=/usr/local/net-snmp --enable-developer
# make
# make install
如果出错找不到 libbeecrypt.la ,在 make 时可能出现如下 error
libtool: link: cannot find the library `/usr/lib/libbeecrypt.la' (librpmio.la: /usr/lib/libbeecrypt.la)
make[1]: *** [snmpd] Error 1
make[1]: Leaving directory `/home/xxx/net-snmp-5.3.2/agent'
make: *** [subdirs] Error 1
解决办法:
到 http://sourceforge.net/projects/beecrypt 下载 beecrypt-4.1.2.tar.gz
然后运行如下命令:
# tar -zxvf beecrypt-4.1.2.tar.gz
# ./configure -prefix=/usr (默认是安装在 /usr/local, 我们需要安装在 /usr 目录下)
# make
# make install
如果出错 /usr/bin/ld: cannot find -lelf ,在 make 时可能出现如下 error
/usr/bin/ld: cannot find -lelf
collect2: ld returned 1 exit status
make[1]: *** [snmpd] Error 1
make[1]: Leaving directory `/home/xxx/net-snmp-5.3.2/agent'
make: *** [subdirs] Error 1
解决办法:
# ln -s libelf.so.1 /usr/lib/libelf.so
好,我们完成 make install 后
# ln -s /usr/local/net-snmp/bin/* /usr/local/bin/
# cp EXAMPLE.conf /usr/local/net-snmp/share/snmp/snmpd.conf
// 修改 snmpd.conf (修改 COMMUNITY 、允许抓取 snmp 数据的主机、抓取数据范围等)。
# /usr/local/net-snmp/sbin/snmpd // 启动 SNMP 服务
# vi /etc/rc.d/rc.local
// 在 rc.local 上加入一行 /usr/local/net-snmp/sbin/snmpd, 系统启动时启动 SNMP 服务。
3. 安装 Cacti
Cacti 官方网站: www.cacti.net/
# tar zxvf cacti-0.8.7b.tar.gz
# cd cacti-0.8.7b
# cp -rf * /usr/local/apache/htdocs/
# cd /usr/local/apache/htdocs
# vi /usr/local/apache/htdocs/include/config.php
// 修改配置文件,设置好数据库信息
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
// 这个密码就随便你设啦,但是请记住在下面配置数据库时要一致呵
// 添加 cacti 用户
# useradd cacti
// 将 rra 目录的所有权给 cacti 用户
# chown -R cacti /usr/local/apache/htdocs/rra
// 修改 cacti 所在目录所属组
# chgrp -R cacti /usr/local/apache/htdocs
// 为 cacti 用户添加 cron 任务
# su - cacti
# crontab -e
// 在其中加入
*/5 * * * * /usr/local/bin/php /usr/local/apache/htdocs/poller.php > /dev/null 2
>&1
//wq 保存退出, exit 退回 root 用户。
// 注意:首次执行 poller.php 时请使用 cacti 用户,否则生成的 rrd 文件 cacti 将没有写入权限。
4. 安装 Spine (这个只在 RHAS 5 up1 上测试成功过呵,在 RHAS 4 上装还要安装 libtool ,俺就不烦啦)
Spine 的安装需要以下支持:
o net-snmp-devel (需要编译安装 net-snmp 时添加 --enable-developer 选项)
o mysql
o mysql-devel ( mysql 源文件编译安装后默认支持)
o openssl-devel ( Redhat 默认安装)
# tar -zxvf cacti-spine-0.8.7a.tar.gz
# cd cacti-spine-0.8.7a
# ./configure --with-mysql=/usr/local/mysql --with-snmp=/usr/local/net-snmp
# make
// 这时你将在此目录下看到多出了 spine 、 spine.conf 两个文件
# mkdir /usr/local/spine
# cp spine spine.conf /usr/local/spine
# vi /usr/local/spine/spine.conf // 修改 spine 配置文件
DB_Host 127.0.0.1
DB_Database cacti
DB_User cacti
DB_Pass cacti
//DB_Host 注意要改成 127.0.0.1 。
# ln -s /usr/local/mysql/lib/libmysqlclient_r.so.15 /usr/lib/libmysqlclient_r.so.15
// 这个是 spine 运行需要的东东,可惜它自己编译的时候没有搞好,只好我们手工加啦。
5. 数据库配置
#mysql -uroot -p
Password:
mysql> create database cacti;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on cacti.* to cacti@localhost identified by "cacti";
Query OK, 1 row affected (0.00 sec)
mysql>exit
# cd /usr/local/apache/htdocs
# mysql -uroot -p cacti < cacti.sql
Password:
// 好了,数据基本配完了 :)
6. 完成 cacti 的安装
1 ) . 在浏览器中输入: http://www.yourdomain.com/ // 这个要看你刚刚配的网址啦 :)
默认用户名: admin 密码: admin
2 ) . 更改密码
3 ) . 设置 cacti 用到的命令路径
snmpwalk Binary Path /usr/local/bin/snmpwalk
snmpget Binary Path /usr/local/bin/snmpget
RRDTool Binary Path /usr/local/bin/rrdtool
PHP Binary Path /usr/local/bin/php
Cacti Log File Path /usr/local/apache/htdocs/cacti/log/cacti.log
Cactid Poller File Path /usr/local/spine/spine
大功告成,下面就是进系统配置啦,我就不详述啦:)
转载于:https://blog.51cto.com/zwb1119/301434