本文档都是通过网上的文档整理修改的!如有错误,请多提出!!

1.安装环境:Centos 4.8以上;

安装系统就不多做描述了;

 

2.安装MySQL

MySQL可在MySQL官网下载;

 

准备文件

mysql-standard-5.0.26-linux-i686.tar.gz

创建mysql组和用户,并设置密码:

 

groupadd mysql

useradd -g mysql mysql

passwd mysql

密码我这里设置为:111111;

解压mysql安装包

tar -xzvf mysql-standard-5.0.26-linux-i686.tar.gz

 

删除文件,创建连接

rm -f mysql-standard-5.0.26-linux-i686.tar.gz

ln -s mysql-standard-5.0.26-linux-i686 mysql

 

vi /etc/my.cnf

 

[mysql]

socket=/tmp/mysql.sock

 

[mysqld]

default-table-type=innodb

default-character-set=utf8

wait_timeout=315360000

 

innodb_buffer_pool_size=16M

innodb_additional_mem_pool_size=2M

 

innodb_log_file_size=5M

innodb_log_buffer_size=8M

innodb_flush_log_at_trx_commit=1

innodb_lock_wait_timeout=50

 

 

创建MySQL授权表

cd /usr/local/mysql

./scripts/mysql_install_db --user=mysql

 

修改目录的所有者

chown -R root .

chown -R mysql data

chgrp -R mysql .

 

设置mysql随操作系统启动

cp support-files/mysql.server /etc/init.d/mysql

chkconfig --add mysql

chkconfig --level 345 mysql on

启动mysql

./bin/mysqld_safe --user=mysql &

 

测试

./bin/mysqladmin version

修改root密码(本地使用不要修改)

./bin/mysqladmin -u root password '111111'

 

 

3、安装apache

 

装备安装文件:httpd-2.2.11.tar.gz

解压apache安装包

tar zxvf httpd-2.2.11.tar.gz

cd httpd-2.2.11

 

./configure --prefix=/usr/local/apache

make

make install

启动apache

/usr/local/apache/bin/apachectl –k start

 

4、安装PHP

先安装zlib,freetype,libpng,jpeg以便于让PHP支持GD库

库文件下载地址:http://oss.oetiker.ch/rrdtool/pub/libs/

1).安装zlib

  tar 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.16.tar.tar

  cd libpng-1.2.16

  cd scripts/

  mv makefile.linux ../makefile

  cd ..

  make

  make install

  注意,这里的makefile不是用./configure生成,而是直接从scripts/里拷一个

 

3).安装freetype

  tar zxvf freetype-2.3.4 .tar.gz

  cd freetype-2.3.4  

  ./configure --prefix=/usr/local/freetype

  make

  make install

 

4).安装Jpeg

   tar -zxf jpegsrc-1.v6b.tar.gz

   cd jpeg-6b/

   mkdir -p /usr/local/libjpeg/man/man1 一步创建多层目录

   ./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static

   make && make install

注意,这里configure一定要带--enable-shared参数,不然,不会生成共享库

 

5).安装Fontconfig

tar -zxvf fontconfig-2.4.2.tar.gz

cd fontconfig-2.4.2

./configure --with-freetype-config-dir=/usr/local/freetype

make

make install

 

6).安装GD

  tar -zxvf gd-2.0.34.tar.gz

  cd gd-2.0.34

  ./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.34:

 

   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命令,使用动态装入器装载找到共享库

 

8).安装libxml,RedHat AS 4默认安装libxml包,但版本太低,PHP5需要更高版本的libxml包。

tar –zxvf libxml2-2.6.25.tar.gz

cd libxml2-2.6.25

./configure

 make

make install

 

9).安装PHP

PHP下载地址:http://www.php.net/downloads.php#v5

tar -zxvf  php-5.2.3.tar.gz

cd php-5.2.3

./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

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 行,添加index.php

修改为DirectoryIndex index.php index.html index.html.var

 

vi /usr/local/apache/htdocs/test.php

添加以下行:

<?php       

 Phpinfo();

?>

wq保存退出。

/usr/local/apache/bin/apachectl -k stop

/usr/local/apache/bin/apachectl -k start

在浏览器中输入:http://www.yourdomain.com/test.php进行测试。

 

如果发现有加载不了php问题:

编辑/etc/selinux/config,找到这段:

# 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=enforcing 注释掉:#SELINUX=enforcing ,然后新加一行为:

SELINUX=disabled

保存,关闭。

......

 

编辑/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

保存,退出。

 

如果你碰到其他类似提示:

cannot restore segment prot after reloc: Permission denied

哪应该是SELinux的问题,可以考虑把它关闭。

-------------------------------------------------------------------------------------

郁闷的是.我把SELinux关闭后还是不行.于是到google上search.发现这个很有用.

在你保证SElinux 被disable后.还执行下

chcon -t texrel_shlib_t 

如: chcon -t texrel_shlib_t /路径/路径/名字.so   (这个文件视具体执行文件.)

以上两步.已经解决了很多server的问题了.  

 

对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      //支持套接字

 

1.安装RRDTool

网上有安装RRDtool脚本,脚本如下,也可以yum install 安装;

http://61.156.20.41/autodownload/rrdtool-1.2.11.tar.gz

#!/bin/sh

BUILD_DIR='pwd'

INSTALL_DIR=/usr/local/rrdtool

cd $BUILD_DIR

tar zxf cgilib-0.5.tar.gz

cd cgilib-0.5

make CC=gcc CFLAGS="-O3 -fPIC -I."

mkdir -p $BUILD_DIR/lb/include

cp *.h $BUILD_DIR/lb/include

mkdir -p $BUILD_DIR/lb/lib

cp libcgi* $BUILD_DIR/lb/lib

cd $BUILD_DIR

tar  zxf zlib-1.2.3.tar.gz

cd zlib-1.2.3

env CFLAGS="-O3 -fPIC" ./configure --prefix=$BUILD_DIR/lb

make

make install

cd $BUILD_DIR

tar zxvf libpng-1.2.18.tar.gz

cd libpng-1.2.18

env CPPFLAGS="-I$BUILD_DIR/lb/include" LDFLAGS="-L$BUILD_DIR/lb/lib" CFLAGS="-O3 -fPIC" \

    ./configure --disable-shared --prefix=$BUILD_DIR/lb

make

make install

cd $BUILD_DIR

tar zxvf freetype-2.3.5.tar.gz

cd freetype-2.2.5

env CPPFLAGS="-I$BUILD_DIR/lb/include" LDFLAGS="-L$BUILD_DIR/lb/lib" CFLAGS="-O3 -fPIC" \

    ./configure --disable-shared --prefix=$BUILD_DIR/lb

make

make install

 

cd $BUILD_DIR

tar zxvf libart_lgpl-2.3.17.tar.gz

cd libart_lgpl-2.3.17

env CFLAGS="-O3 -fPIC" ./configure --disable-shared --prefix=$BUILD_DIR/lb

make

make install

 

IR=-I$BUILD_DIR/lb/include

CPPFLAGS="$IR $IR/libart-2.0 $IR/freetype2 $IR/libpng"

LDFLAGS="-L$BUILD_DIR/lb/lib"

CFLAGS=-O3

export CPPFLAGS LDFLAGS CFLAGS

 

cd $BUILD_DIR

tar zxf rrdtool-1.2.23.tar.gz

cd rrdtool-1.2.23

./configure --prefix=/usr/local/rrdtool --disable-python --disable-tcl && make && make install

 

装rrdtool之前确保安装了这些库zlib libpng freetype libart_lgpl

验证如下

[root@localhost rrdtool-1.2.6]# rpm -qa |grep zlib

zlib-1.2.3-3

zlib-devel-1.2.3-3

[root@localhost rrdtool-1.2.6]# rpm -qa |grep libpng

libpng-devel-1.2.10-7

libpng-1.2.10-7

[root@localhost rrdtool-1.2.6]# rpm -qa |grep freetype

freetype-2.2.1-16.el5

freetype-devel-2.2.1-16.el5

[root@localhost rrdtool-1.2.6]# rpm -qa |grep libart_lgpl

libart_lgpl-2.3.17-4

libart_lgpl-devel-2.3.17-4

/完成后建立符号连接 

ln -s /usr/local/rrdtool/bin/* /usr/local/bin/

安装rrdtool报错:configure: error: Please fix the library issues listed above and try again.

解决方法:

 第一:

安装 cgilib-0.5.tar.gz

从这里下载:

 weget http://download.chinaunix.net/down.php?id=2531&ResourceID=1333&site=1

tar zxvf cgilib-0.5.tar.gz

cd cgilib-0.5

make

cp libcgi.a /usr/local/lib

cp cgi.h /usr/include

如果还不行,请看

第二:

安装libart_lgpl-devel这个包

yum –y install libart_lgpl-devel

 如果还报错configure: error: Please fix the library issues listed above and try again. 请看

第三:

把这两个包装上pango-devel cairo-devel

 yum –y install pango-devel* cairo-devel*

然后在

 cd cd rrdtool-X.X.X

./configure --prefix=/usr/local/rrdtool

    这样肯定能行,一般在第二部就能解决了。

//执行rrdtool看是否安装正确

 

安装net-snmp

RedHat默认安装了SNMP服务,但好象没有snmpwalk,snmpget这两个命令,所以需要编译安装NET-SNMP。

NET-SNMP官方网站:http://www.net-snmp.org/

tar zxvf net-snmp-5.2.4.tar.gz

 

cd net-snmp-5.2.4

./configure --prefix=/usr/local/net-snmp  --enable-developer

make

make install

也许在执行第四不步make后,过了一会儿程序退出,并提示一下错误:

Grep /usr/lib/libbeecrypt.la: No such file or directory

/bin/sed: can't read /usr/lib/libbeecrypt.la: No such file or directory

libtool: link: `/usr/lib/libbeecrypt.la' is not a valid libtool archive

make[1]: *** [libnetsnmpmibs.la] Error 1

make[1]:Leavingdirectory /email/share/ceno_soft/net-snmp-5.4.1/agent'

make: *** [subdirs] Error 1

解决方法

说明缺少libbeecrypt.la ,libbeecrypt.so等共享库

如果确认系统中有libbeecrypt.la,也许他安装在/usr/local下面,可尝试:

ln -s /usr/local/lib/libbeecrypt.la /usr/lib/libbeecrypt.la

如果/usr/local下面没有,那么你必须安装beecrypt

下载路径

http://nchc.dl.sourceforge.net/sourceforge/beecrypt/beecrypt-4.1.2.tar.gz

解压并安装到/usr目录下:

tar -zxvf beecrypt-4.1.2.tar.gz

./configure -prefix=/usr

#默认是安装在/usr/local,我们需要安装在/usr目录下。如果没有加这个参数需要做连接

ln -s /usr/local/lib/libbeecrypt.la /usr/lib/libbeecrypt.la

编译并安装beecrypt库,先执行make编译源码包文件编译成功后执行安装命令make install,其命令如下:

make

make install

好,beecrypt安装完成后,我们继续NET-SNMP的编译,执行一下make 命令。

当我们继续make的时候,第一个错消逝了,但不幸的是出现了一个新的错误,错误提示如下:rpath -Wl,/usr/local/lib

/usr/bin/ld: cannot find –lelf

collect2: ld returned 1 exit status

make[1]: *** [snmpd] Error 1 make[1]: Leaving directory `/local/akazam/cacti/bak/net-snmp-5.4.2/agent'

make: *** [subdirs] Error 1

ke[1]: Leaving directory `/local/akazam/cacti/bak/net-snmp-5.4.2/agent

make: *** [subdirs] Error 1

解决方法

执行命令: ln -s /usr/lib/libelf.so.1  /usr/lib/libelf.so

现在估计该装的软件包都已经装上了,链接库也差不多了吧,我们现在可以大胆的回到net-snmp-5.4.2.1目录下,继续从第4步往下执行,这样就一路畅通了。

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

 

4.安装Cacti

Cacti官方网站:www.cacti.net/

tar -zxvf cacti-0.8.6j.tar.gz

mv -r cacti-0.8.6j /usr/local/apache/htdocs/cacti

vi /usr/local/apache/htdocs/cacti/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/cacti/rra

 

//修改cacti目录所属组

chgrp -R cacti /usr/local/apache/htdocs/cacti

 

//为cacti用户添加cron任务

su – cacti

crontab –e

*/5 * * * * /usr/local/bin/php /usr/local/apache/htdocs/cacti/poller.php > /dev/null 2>&1

 

注意:首次执行poller.php时请使用cacti用户,否则生成的rrd文件cacti将没有写入权限。

 

    

 

5.安装Cactid

CACTID 的安装需要以下支持:

o    net-snmp-devel (需要编译安装net-snmp时添加--enable-developer选项)

o    mysql               

o    mysql-devel     (mysql源文件编译安装后默认支持)

o    openssl-devel  (Redhat默认安装)

 

tar -zxvf cacti-cactid-0.8.6i.tar.gz

cd cacti-cactid-0.8.6i

./configure --with-mysql=/usr/local/mysql --with-snmp=/usr/local/net-snmp

make

 

//这时你将在此目录下看到多出了cactid、cactid.conf两个文件

mkdir /usr/local/cactid

cp cactid cactid.conf /usr/local/cactid

vi /usr/local/cactid/cactid.conf       //修改cactid配置文件

DB_Host         127.0.0.1

DB_Database     cacti

DB_User         cacti

DB_Pass         cacti

  

 

6.数据库配置

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/cacti

mysql -uroot -p cacti < cacti.sql

Password:

 

7.完成cacti的安装

1).在浏览器中输入:http://www.yourdomain.com/cacti/

默认用户名: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/cactid/cactid

 

OK !cacit就安装陈功了,这个是英文版本的,我的有做过汉化,也是在网上找的资源,后面在慢慢不上来