CentOS 6.5下编译安装httpd+mysql+php+phpMyAdmin+cacti+nagios
一、安装环境
Linux系统:CentOS 6.5
Apache版本:http-2.4.12
MySQL版本:MySQL 5.6.24
PHP版本:PHP-5.6.8
基本的安装顺序为:先安装httpd,然后安装mysql,最后安装PHP。
软件包:
[root@make httpdbao]# ll
total 334908
-rwxrw-rw-. 1 root root 826885 May 22 13:09 apr-1.5.2.tar.bz2
-rwxrw-rw-. 1 root root 694427 May 22 13:09 apr-util-1.5.4.tar.bz2
-rwxrw-rw-. 1 root root 5054838 May 21 17:20 httpd-2.4.12.tar.bz2
-rwxrw-rw-. 1 root root 634589 May 22 13:09 libmcrypt-2.5.6.tar.gz
-rwxrw-rw-. 1 root root 312043744 May 2117:51 mysql-5.6.24-linux-glibc2.5-x86_64.tar.gz
-rwxrw-rw-. 1 root root 13724681 May 21 17:41 php-5.6.8.tar.bz2
[root@make httpdbao]#
二、安装httpd-2.4.12
1、在安装httpd之前需要先安装apr、apr-util以及pcre-devel等相关包。在编译安装httpd之前需要Development Tools开发工具集。具体步骤如下:
(1)安装apr:
[root@make httpdbao]# tar xf apr-1.5.2.tar.bz2
[root@make httpdbao]# cd apr-1.5.2
[root@make apr-1.5.2]# pwd
/root/httpdbao/apr-1.5.2
[root@make apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@make apr-1.5.2]# make
[root@make apr-1.5.2]# make install
(2)安装apr-util:
[root@make httpdbao]# tar xf apr-util-1.5.4.tar.bz2
[root@make httpdbao]# cd apr-util-1.5.4
[root@make apr-util-1.5.4]# pwd
/root/httpdbao/apr-util-1.5.4
[root@make apr-util-1.5.4]# ./configure--prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@make apr-util-1.5.4]# make
[root@make apr-util-1.5.4]# make install
(3)安装pcre-devel:
[root@make ~]# yum install pcre-devel -y
(4)安装httpd:
[root@make httpdbao]# tar xf httpd-2.4.12.tar.bz2
[root@make httpdbao]# cd httpd-2.4.12
[root@make httpd-2.4.12]# pwd
/root/httpdbao/httpd-2.4.12
[root@make httpd-2.4.12]# ./configure--prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl--enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util --enable-modules=most--enable-mpms-shared=all --with-mpm=event --with-included-apr
说明:
--prefix=/usr/local/apache :安装指定路径。
--sysconfdir=/etc/httpd :指定配置文件安装路径。
--enable-so :支持动态共享模块,如果没有此功能,php无法与apache一起工作,必须安。
--enable-ssl :启用ssl功能,不安装无法启用https。
--enable-rewrite :支持url重写。
--enable-cgi :支持cgi。
出现错误:
configure: WARNING: OpenSSL version is tooold
no
checking whether to enable mod_ssl...configure: error: mod_ssl has been requested but can not be built due toprerequisite failures
[root@make httpd-2.4.12]#
安装openssl-devel:
[root@make httpd-2.4.12]# yum installopenssl-devel -y
出现错误:
configure: error: Bundled APR requested butnot found at ./srclib/. Download and unpack the corresponding apr and apr-utilpackages to ./srclib/.
[root@make httpd-2.4.12]#
解决:
[root@make httpdbao]# mv apr-1.5.2 apr
[root@make httpdbao]# mv apr-util-1.5.4 apr-util
[root@make httpdbao]# cp -r apr apr-util httpd-2.4.12/srclib/
编译安装:
[root@make httpd-2.4.12]# ./configure--prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl--enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util --enable-modules=most--enable-mpms-shared=all --with-mpm=event --with-included-apr
[root@make httpd-2.4.12]# make
[root@make httpd-2.4.12]# make install
2、启动服务进行简单测试
[root@make ~]# /usr/local/apache/bin/apachectl start
AH00557: httpd: apr_sockaddr_info_get()failed for make
AH00558: httpd: Could not reliablydetermine the server‘s fully qualified domain name, using 127.0.0.1. Set the‘ServerName‘ directive globally to suppress this message
[root@make ~]#
[root@make ~]# vim /etc/httpd/httpd.conf
192 ServerName www.example.com:80
"/etc/httpd/httpd.conf" 504L,18336C written
[root@make ~]#
[root@make ~]# /usr/local/apache/bin/apachectl start
httpd (pid 95896) already running
[root@make ~]#
3、为了更好的管理和使用httpd服务,可为其提供PATH环境变量和SysV风格的脚本。
(1) 提供PATH环境变量:
[root@make ~]# vim /etc/profile.d/httpd.sh
export PATH=$PATH:/usr/local/apache/bin
"/etc/profile.d/httpd.sh" [New]1L, 40C written
[root@make ~]# . /etc/profile.d/httpd.sh
[root@make ~]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/apache/bin
[root@make ~]#
(2) 提供SysV风格的脚本:
[root@make ~]# vim /etc/init.d/httpd
#!/bin/bash
#
# chkconfig: - 85 15
# description: Apache is a World Wide Webserver. It is used to serve \
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
./etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowingup a pass-phrase prompt if
# mod_ssl needs a pass-phrase from theuser.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in/etc/sysconfig/httpd to use a server
# with the thread-based "worker"MPM; BE WARNED that some modules mays not
# work correctly with a thread-based MPM;notably PHP will refuse to start.
# Path to the apachectl script, server binary,and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if! LANG=$HTTPD_LANG $httpd $OPTIONS -t &> /dev/null; then
RETVAL=$?
echo $"not reloading due to configuration sysntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ]; then
stop
start
fi
;;
reload)
reload
;;
graceful|htlp|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo "Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
;;
esac
exit $RETVAL
[root@make ~]# chmod +x /etc/rc.d/init.d/httpd
[root@make ~]# service httpd status
httpd is stopped
[root@make ~]# service httpd start
Starting httpd: httpd (pid 95896) alreadyrunning
[ OK ]
[root@make ~]#
[root@make ~]# chkconfig --add httpd
[root@make ~]# chkconfig | grep httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@make ~]# chkconfig httpd on
[root@make ~]# chkconfig | grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@make ~]#
4、更换pid进程文件存放目录:
每个进程启动后都会有个pid文件,编译安装httpd的pid文件在logs目录里面:
[root@make logs]# pwd
/usr/local/apache/logs
[root@make logs]# ll
total 12
-rw-r--r--. 1 root root 951 May 22 14:57access_log
-rw-r--r--. 1 root root 289 May 22 14:46error_log
-rw-r--r--. 1 root root 6 May 22 14:46 httpd.pid
[root@make logs]#
系统进程一般pid文件都放在/var/run目录下,如果想更换pid进程文件存放目录,需要在主配置文件中加入PidFile "/var/run/httpd.pid"项,注意:编译安装默认没有该项,需要手工加入:
[root@make logs]# vim /etc/httpd/httpd.conf
34 Pidfile "/var/run/httpd.pid"
"/etc/httpd/httpd.conf" 505L,18365C written
[root@make logs]#
[root@make ~]# netstat -lntp | grep httpd
tcp 0 0 :::80 :::* LISTEN 95896/httpd
[root@make ~]# kill 95896
[root@make ~]# service httpd start
Starting httpd: [ OK ]
[root@make ~]# cd /var/run/
[root@make run]# ll -d httpd.pid
-rw-r--r--. 1 root root 6 May 22 15:06httpd.pid
[root@make run]#
5、为httpd添加man帮助及输出头文件:
(1) 为httpd添加man帮助:
[root@make ~]# vim /etc/man.config
48 MANPATH /usr/local/apache/man
[root@make ~]# man httpd
HTTPD(8) httpd HTTPD(8)
NAME
httpd - Apache Hypertext Transfer Protocol Server
……………
[root@make ~]#
(2) 输出头文件:
[root@make ~]#ln -sv /usr/local/apache/include/ /usr/include/httpd
`/usr/include/httpd‘ ->`/usr/local/apache/include/‘
[root@make ~]#
至此,httpd服务安装成功。
三、安装MySQL
1、创建mysql用户和mysql组
要想初始化mysql,需要有mysql用户和组。
[root@make ~]# groupadd -r -g 306 mysql
[root@make ~]# useradd -g 306 -r -u 306 mysql
[root@make ~]# id mysql
uid=306(mysql) gid=306(mysql)groups=306(mysql)
[root@make ~]#
2、创建mysql数据存放目录
[root@make ~]# mkdir /mydata/data -pv
mkdir: created directory `/mydata‘
mkdir: created directory `/mydata/data‘
[root@make ~]# ll -d /mydata/ /mydata/data/
drwxr-xr-x. 3 root root 4096 May 22 15:44/mydata/
drwxr-xr-x. 2 root root 4096 May 22 15:44/mydata/data/
[root@make ~]#
mysql数据目录,需要把属主属组更改为mysql,权限更改为0-rwx:
[root@make mysql]# cd /mydata/
[root@make mydata]# ll
total 4
drwxr-xr-x. 2 root root 4096 May 22 15:44data
[root@make mydata]# chown -R mysql:mysql data/
[root@make mydata]# chmod o-rwx data/
[root@make mydata]# ll
total 4
drwxr-x---. 2 mysql mysql 4096 May 22 15:44data
[root@make mydata]#
这里以目录代替,生产环境需要单独保存数据的磁盘。
3、解压并安装MySQL 5.6.24,使用的通用二进制格式的MySQL
(1).通用二进制包是编译好的,直接解压就可以用,注意:mysql要求解压的包需在/usr/local目录下,并且目录名字必须是mysql。
[root@make httpdbao]# ll mysql-5.6.24-linux-glibc2.5-x86_64.tar.gz
-rwxrw-rw-. 1 root root 312043744 May 2117:51 mysql-5.6.24-linux-glibc2.5-x86_64.tar.gz
[root@make httpdbao]# tar xfmysql-5.6.24-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
[root@make httpdbao]# cd /usr/local/
[root@make local]# ln -sv mysql-5.6.24-linux-glibc2.5-x86_64/mysql
`mysql‘ ->`mysql-5.6.24-linux-glibc2.5-x86_64/‘
[root@make local]# ll mysql
lrwxrwxrwx. 1 root root 35 May 22 15:48mysql -> mysql-5.6.24-linux-glibc2.5-x86_64/
[root@make local]#
(2). 更改mysql目录中的文件的属主、属组为mysql用户和mysql组:
[root@make mysql]# ll
total 172
drwxr-xr-x. 2 root root 4096 May 22 15:47bin
-rw-r--r--. 1 7161 wheel 17987 Mar 26 00:34COPYING
drwxr-xr-x. 3 root root 4096 May 22 15:48data
drwxr-xr-x. 2 root root 4096 May 22 15:48docs
drwxr-xr-x. 3 root root 4096 May 22 15:47include
-rw-r--r--. 1 7161 wheel 102986 Mar 26 00:35 INSTALL-BINARY
drwxr-xr-x. 3 root root 4096 May 22 15:48lib
drwxr-xr-x. 4 root root 4096 May 22 15:48man
drwxr-xr-x. 10 root root 4096 May 22 15:48 mysql-test
-rw-r--r--. 1 7161 wheel 2496 Mar 26 00:34README
drwxr-xr-x. 2 root root 4096 May 22 15:48scripts
drwxr-xr-x. 28 root root 4096 May 22 15:48 share
drwxr-xr-x. 4 root root 4096 May 22 15:48sql-bench
drwxr-xr-x. 2 root root 4096 May 22 15:48support-files
[root@make mysql]# chown -R mysql:mysql *
[root@make mysql]# ll
total 172
drwxr-xr-x. 2 mysql mysql 4096 May 22 15:47bin
-rw-r--r--. 1 mysql mysql 17987 Mar 26 00:34COPYING
drwxr-xr-x. 3 mysql mysql 4096 May 22 15:48data
drwxr-xr-x. 2 mysql mysql 4096 May 22 15:48docs
drwxr-xr-x. 3 mysql mysql 4096 May 22 15:47include
-rw-r--r--. 1 mysql mysql 102986 Mar 26 00:35 INSTALL-BINARY
drwxr-xr-x. 3 mysql mysql 4096 May 22 15:48lib
drwxr-xr-x. 4 mysql mysql 4096 May 22 15:48man
drwxr-xr-x. 10 mysql mysql 4096 May 22 15:48 mysql-test
-rw-r--r--. 1 mysql mysql 2496 Mar 26 00:34README
drwxr-xr-x. 2 mysql mysql 4096 May 22 15:48scripts
drwxr-xr-x. 28 mysql mysql 4096 May 22 15:48 share
drwxr-xr-x. 4 mysql mysql 4096 May 22 15:48sql-bench
drwxr-xr-x. 2 mysql mysql 4096 May 22 15:48support-files
[root@make mysql]#
4、初始化mysql数据库:
执行scripts目录下的脚本,该文件作用:mysql需要初始化,这个步骤就是完成初始化的,我们需要手动完成。
[root@make scripts]# pwd
/usr/local/mysql/scripts
[root@make scripts]# ll
total 36
-rwxr-xr-x. 1 mysql mysql 34558 Mar 2600:54 mysql_install_db
[root@make scripts]#
[root@make scripts]# ./mysql_install_db --user=mysql--datadir=/mydata/data/
FATAL ERROR: Could not find./bin/my_print_defaults
If you compiled from source, you need torun ‘make install‘ to
copy the software into the correct locationready for operation.
If you are using a binary release, you musteither be at the top
level of the extracted archive, or pass the--basedir option
pointing to that location.
[root@make scripts]# cd ..
[root@make mysql]# scripts/mysql_install_db --user=mysql--datadir=/mydata/data/
为了安全,需要把mysql目录下文件属主更改回root用户:
[root@make mysql]# chown -R root /usr/local/mysql/*
5、修改及配置MySQL服务脚本及配置文件
(1) 拷贝MySQL服务脚本:
[root@make ~]# cp /usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld
[root@make ~]# chmod +x /etc/init.d/mysqld
[root@make ~]# chkconfig --add mysqld
[root@make ~]# chkconfig mysqld on
[root@make ~]# chkconfig | grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@make ~]#
(2)修改mysql配置文件datadir数据目录位置:
[root@make ~]# vim /etc/my.cnf
[mysqld]
datadir=/mydata/data
"/etc/my.cnf" 10L, 249Cwritten
[root@make ~]#
(3)启动mysql服务:
[root@make ~]# service mysqld start
Starting MySQL. [ OK ]
[root@make ~]#
[root@make mysql]# netstat -lntp | grep mysqld
tcp 0 0 :::3306 :::* LISTEN 99386/mysqld
[root@make mysql]#
(4)mysql启动之后,会生成socket位置mysql.sock文件:
[root@make mysql]# pwd
/var/lib/mysql
[root@make mysql]# ll -d mysql.sock
srwxrwxrwx. 1 mysql mysql 0 May 22 16:14mysql.sock
[root@make mysql]#
修改其位置生成位置:
[root@make mysql]# vim /etc/my.cnf
socket=/tmp/mysql.sock
[root@make mysql]#
6、为mysql添加PATH环境变量
[root@make mysql]# vi /etc/profile.d/mysqld.sh
export PATH=$PATH:/usr/local/mysql/bin
"/etc/profile.d/mysqld.sh" [New]1L, 39C written
[root@make mysql]# . /etc/profile.d/mysqld.sh
[root@make mysql]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/apache/bin:/usr/local/mysql/bin
[root@make mysql]#
7、为mysql添加man帮助及输出头文件和库文件
[root@make mysql]# vi /etc/man.config
49 MANPATH /usr/local/mysql/man
"/etc/man.config" 154L, 4999Cwritten
[root@make mysql]#
[root@make mysql]# ln -sv /usr/local/mysql/include//usr/include/mysql
`/usr/include/mysql‘ ->`/usr/local/mysql/include/‘
[root@make mysql]#
[root@make mysql]# vi /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
"/etc/ld.so.conf.d/mysql.conf"[New] 1L, 21C written
[root@make mysql]# ldconfig -v
8、为mysql添加密码:
[root@make ~]# mysqladmin -u root password ‘123456‘
Warning: Using a password on the commandline interface can be insecure.
[root@make ~]#
说明:
mysql-5.6会提示命令行使用密码不安全的。
至此,mysql安装完毕
四、安装PHP
1、解压并编译安装php-5.6.8:
[root@make php-5.6.8]# tar xf php-5.6.8.tar.bz2
[root@make php-5.6.8]# cd php-5.6.8
[root@make php-5.6.8]# ./configure --prefix=/usr/local/php--with-mysql=/usr/local/mysql --with-openssl--with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs--with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d--with-bz2 --enable-maintainer-zts
安装选项说明:
--prefix=/usr/local/php (安装目录)
--with-mysql=/usr/local/mysql (指定mysql位置)
--with-openssl (支持openssl功能)
--with-mysqli=/usr/local/mysql/bin/mysql_config (一种mysql接口)
--enable-mbstring
--with-freetype-dir (支持freetype功能,字体库,引用特定字体)
--with-jpeg-dir (支持jpeg)
--with-png-dir (支持png)
--with-zlib (支持通用压缩库)
--with-libxml-dir=/usr (扩展标记语言,xml库路径位置)
--enable-xml (支持扩展标记语言)
--enable-sockets (套接字)
--with-apxs2=/usr/local/apache/bin/apxs (实现让php编译成apache模块)
--with-mcrypt (加密库)
--with-config-file-path=/etc (配置文件位置)
--with-config-file-scan-dir=/etc/php.d (文件php.d目录下也是配置文件一部分)
--with-bz2 (压缩)
--enable-maintainer-zts (apahce是prwork模式不需要用,其他需要用)
错误:
checking for BZip2 in default path... notfound
configure: error: Pleasereinstall the BZip2 distribution
[root@make php-5.6.8]#
安装:
[root@make php-5.6.8]# yum install bzip2-devel -y
[root@make php-5.6.8]#yum install libxml2-devel –y
在编译:
checking for mcrypt support... yes
configure: error: mcrypt.h not found.Please reinstall libmcrypt.
[root@make php-5.6.8]#
安装:
[root@make httpdbao]# ll
-rwxrw-rw-. 1 root root 634589 May 2213:09 libmcrypt-2.5.6.tar.gz
-rwxrw-rw-. 1 root root 9955372 May 2117:58 phpMyAdmin-4.4.4-all-languages.zip
[root@make httpdbao]#
[root@make httpdbao]# tar xf libmcrypt-2.5.6.tar.gz
[root@make httpdbao]# cd libmcrypt-2.5.6
[root@make libmcrypt-2.5.6]# ./configure
[root@make libmcrypt-2.5.6]# make
[root@make libmcrypt-2.5.6]# make install
在编译:
[root@make php-5.6.8]# ./configure --prefix=/usr/local/php--with-mysql=/usr/local/mysql --with-openssl--with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib--with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs--with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d--with-bz2 --enable-maintainer-zts
[root@make php-5.6.8]# make
错误:
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
[root@make php-5.6.8]#
解决:
[root@make php-5.6.8]#make clean
[root@make php-5.6.8]# make install
3、给php提供配置文件:
在php安装程序中,有两个文件叫php.ini-development和php.ini-production:
php.ini-development :开发用的配置文件。
php.ini-production :生产环境用的配置文件。
[root@make php-5.6.8]# pwd
/root/httpdbao/php-5.6.8
[root@make php-5.6.8]# cp php.ini-production /etc/php.ini
[root@make php-5.6.8]# ll -d /etc/php.ini
-rw-r--r--. 1 root root 72369 May 22 17:15/etc/php.ini
[root@make php-5.6.8]#
4、配置httpd,使其能够支持php
(1) 首先能够让apache能够处理php结尾的页面文件,添加php类型:
[root@make ~]# vim /etc/httpd/httpd.conf
380 AddType application/x-httpd-php .php
381 AddType application/x-httpd-php-source .phps
"/etc/httpd/httpd.conf" 507L,18455C written
[root@make ~]#
(2) 支持php网页:
[root@make ~]# vim /etc/httpd/httpd.conf
250 <IfModule dir_module>
251 DirectoryIndex index.php index.html
252 </IfModule>
"/etc/httpd/httpd.conf" 507L,18465C written
[root@make ~]#
5、重启httpd服务,测试PHP网页:
[root@make ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@make ~]#
[root@make htdocs]# pwd
/usr/local/apache/htdocs
[root@make htdocs]# vim index.html
<html><body><h1>Itworks!</h1></body></html>
<?php
phpinfo();
?>
[root@make htdocs]# mv index.html index.php
[root@make htdocs]# ll
total 4
-rw-r--r--. 1 root root 66 May 22 17:25index.php
[root@make htdocs]#
测试phpMyAdmin数据库:
[root@make httpdbao]# unzip phpMyAdmin-4.4.4-all-languages.zip
[root@make httpdbao]# mv phpMyAdmin-4.4.4-all-languages/usr/local/apache/htdocs/
[root@make httpdbao]# cd /usr/local/apache/htdocs/
[root@make htdocs]# ll
total 8
-rw-r--r--. 1 root root 65 May 22 17:32index.php
drwxr-xr-x. 10 root root 4096 Apr 26 06:45phpMyAdmin-4.4.4-all-languages
[root@make htdocs]# ln -sv phpMyAdmin-4.4.4-all-languages/ pam
`pam‘ -> `phpMyAdmin-4.4.4-all-languages/‘
[root@make htdocs]#
配置xcache进行加速
[root@make httpdbao]# ll
-rw-r--r--. 1 root root 173368 Sep 19 2014 xcache-3.2.0.tar.gz
[root@make httpdbao]#
[root@make httpdbao]# cd xcache-3.2.0
用phpize生成configure配置文件:
[root@make xcache-3.2.0]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[root@make xcache-3.2.0]#
[root@make xcache-3.2.0]#
./configure --enable-xcache--with-php-config=/usr/local/php/bin/php-config
[root@make xcache-3.2.0]# make
[root@make xcache-3.2.0]# make install
[root@make ~]# mkdir /etc/php.d
[root@make ~]# cp httpdbao/xcache-3.2.0/xcache.ini /etc/php.d
[root@make ~]#
[root@make ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@make ~]#
安装cacti
1.需要安装SNMP:
[root@make ~]# yum -y install net-snmp net-snmp-utils
2. 启动snmp服务:
[root@make ~]# service snmpd start
Starting snmpd: [ OK ]
[root@make ~]# chkconfig snmpd on
[root@make ~]#
3. 安装工具rrdtool
[root@make rrd]# ll
total 1084
-rwxrw-rw-. 1 root root 50612 May 25 15:55 perl-rrdtool-1.4.7-1.el6.rfx.x86_64.rpm
-rwxrw-rw-. 1 root root 840248 May 25 15:52rrdtool-1.4.7-1.el6.rfx.x86_64.rpm
-rwxrw-rw-. 1 root root 209504 May 25 15:54rrdtool-devel-1.4.7-1.el6.rfx.x86_64.rpm
[root@make rrd]# yum install -y ruby lua
[root@make rrd]# yum install -y libdbi-devel
[root@make rrd]# yum install perl-Time-HiRes
[root@make rrd]# rpm -ivh *
warning:perl-rrdtool-1.4.7-1.el6.rfx.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID6b8d79e6: NOKEY
Preparing... ###########################################[100%]
1:rrdtool ########################################### [ 33%]
2:perl-rrdtool ########################################### [ 67%]
3:rrdtool-devel ########################################### [100%]
[root@make rrd]#
4. cacti的安装
[root@make cactibao]# ll
total 2844
-rwxrw-rw-. 1 root root 2908451 May 2214:19 cacti-0.8.8c.tar.gz
[root@make cactibao]#
[root@make cactibao]# tar xf cacti-0.8.8c.tar.gz -C/usr/local/apache/htdocs/
[root@make htdocs]# pwd
/usr/local/apache/htdocs
[root@make htdocs]# ln -sv cacti-0.8.8c/ cacti
`cacti‘ -> `cacti-0.8.8c/‘
[root@make htdocs]# ll
total 12
lrwxrwxrwx. 1 root root 13 May 25 16:08cacti -> cacti-0.8.8c/
drwxr-xr-x. 13 1000 users 4096 Nov 24 04:18cacti-0.8.8c
-rw-r--r--. 1 root root 65 May 22 17:32index.php
lrwxrwxrwx. 1 root root 31 May 22 17:55 pam-> phpMyAdmin-4.4.4-all-languages/
drwxr-xr-x. 10 root root 4096 Apr 26 06:45phpMyAdmin-4.4.4-all-languages
[root@make htdocs]#
由于cacti需要用到mysql数据库的,因此需要一个专门的数据库保存他的表:
mysql> create database cactidb;
Query OK, 1 row affected (0.01 sec)
mysql> grant all on cactidb.* to cacti@localhostidentified by ‘cacti‘;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all on cactidb.* to cacti@127.0.0.1identified by ‘cacti‘;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
把安装包中文件cacti.sql文件导入创建的cactidb数据库中:
[root@make cacti]# mysql -u root -p cactidb < cacti.sql
Enter password:
[root@make cacti]#
配置cacti配置文件,修改相应的账号数据库连接:
[root@make include]# pwd
/usr/local/apache/htdocs/cacti/include
[root@make include]# vim config.php
26 $database_type = "mysql";
27$database_default = "cactidb";
28$database_hostname = "localhost";
29$database_username = "cacti";
30$database_password = "cacti";
31$database_port = "3306";
32$database_ssl = false;
"config.php" 44L, 2123Cwritten
[root@make include]#
建立系统普通账户,该用户可以建立周期性的获取数据执行PHP脚本:
[root@make include]# useradd cacti
[root@make include]#
更改rra和 log目录属主属组改为cacti,其中rra目录是保存rrd文件的,log是日志目录:
[root@make cacti]# pwd
/usr/local/apache/htdocs/cacti
[root@make cacti]# chown -R cacti:cacti rra log
[root@make cacti]#
安装cacti,浏览器访问http://192.168.1.214/cacti:
[root@make cacti]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@make cacti]#
定义cacti默认的周期性计划,这个任务计划是靠一个脚本实现的:
[root@make ~]#crontab -u cacti –e
*/5 * * * * /usr/local/php/bin/php/usr/local/apache/htdocs/cacti/poller.php &> /dev/null
"/tmp/crontab.iAZMZE" 1L, 90Cwritten
crontab: installing new crontab
[root@make ~]#
由于不会马上执行,手动执行测试一下:
[cacti@make ~]$ /usr/local/php/bin/php/usr/local/apache/htdocs/cacti/poller.php
更改php配置文件:
[cacti@make ~]$ su - root
Password:
[root@make ~]# vim /etc/php.ini
928 date.timezone = Asia/Shanghai
"/etc/php.ini" 1997L, 72399Cwritten
[root@make ~]#
[root@make ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@make ~]#
安装cacti-spine:
出于效率原因,在大量采集数据时使用自带的cmd.php轮询器会比较慢,1分钟1次的采集频率可能无法完成轮询所有机器。这里为了优化,采用官方推荐的spine来高效轮询。安装spine要和Cacti的版本相匹配
[root@make cactibao]# ll
total 3464
-rwxrw-rw-. 1 root root 632102 May 25 16:25 cacti-spine-0.8.8c.tar.gz
[root@make cactibao]#
[root@make cactibao]# tar xfcacti-spine-0.8.8c.tar.gz
[root@make cactibao]# cd cacti-spine-0.8.8c
[root@make cacti-spine-0.8.8c]# ./configure
………………checking whether we are using LinuxCapabilities... no
checking for mysql_init in-lmysqlclient_r... no
configure: error: MySQL libraries not found
[root@make cacti-spine-0.8.8c]#
错误:找不到mysql,需要制定mysql安装位置:
[root@make local]# yum install -ynet-snmp-devel
[root@make cacti-spine-0.8.8c]# ./configure--prefix=/usr/local/cacti-spine --with-snmp=/usr --with-mysql=/usr/local/mysql/
[root@make cacti-spine-0.8.8c]# make
[root@make cacti-spine-0.8.8c]# makeinstall
修改访问数据库的用户名密码信息:
[root@make etc]# pwd
/usr/local/cacti-spine/etc
[root@make etc]# ll
total 4
-rw-r--r--. 1 root root 2791 May 25 17:08spine.conf.dist
[root@make etc]# cp spine.conf.distspine.conf
[root@make etc]# ll
total 8
-rw-r--r--. 1 root root 2791 May 25 17:11spine.conf
-rw-r--r--. 1 root root 2791 May 25 17:08spine.conf.dist
[root@make etc]#
[root@make etc]# vim spine.conf
35 DB_Host localhost
36DB_Database cactidb
37DB_User cacti
38DB_Pass cacti
39DB_Port 3306
40DB_PreG 0
"spine.conf" 40L, 2785Cwritten
[root@make etc]#
测试是否正常:
[root@make bin]#/usr/local/cacti-spine/bin/spine
SPINE: Using spine config file[../etc/spine.conf]
SPINE: Version 0.8.8c starting
SPINE: Time: 0.3706 s, Threads: 5, Hosts: 2
[root@make bin]#
在cacti网页里设置spine路径:
Console -> Configuration -> Settings-> Paths -> Alternate Poller Path -> Spine Poller File Path
/usr/local/cacti-spine/bin/spine
修改Cacti使用的Poller Type:
Console -> CactiSettings->Poller->Poller Type
在下拉中选择spine
创建监控一台win 7客户端
一、Windows 7客户端配置
1、在windows 7客户端安装snmp服务
在“控制面板”—> ”程序和功能”—> “打开或关闭Windows功能”—> 勾选“简单网络管理协议(SNMP)”—>确定
2、配置Windows 7的SNMP服务
打开“计算机管理”—> 点击左下面的“服务”—> 在右则找到“SNMP Service”并双击—> 打开该服务的“属性”—>切换到“安全”选项卡。作如下修改。
二、cacti配置
1、添加受监控的主机
登陆cacti,点击“Devices”—> 点击“Add”。填写所添加主机的信息。信息填写完成后,点击“Create”。
为该主机进行画图,点击“Create Graphs for this Host”。
勾选信息后,并点击“Create”。进入为画图选择颜色界面。选好颜色,点击“Create”。完成。
2、将被监控的主机添加到图形树
点击左侧“Device”—> 选择主机—> 选择action“Place on a Tree(Windows Desktop)”—>点击“Go”。
点击“Continue”完成添加。
三、查看该主机监控信息
等一会,点击“graphs”选项卡—>“Windows Desktop”—>“Windows 7”,可以看到所监控的Windows 7主机情况。
安装nagios
1.准备安装的软件:
[root@make nagios]# yum install -y glibcglibc-common gd gd-devel
[root@make nagios]# ll
total 2648
-rwxrw-rw-. 1 root root 48862 May 29 14:16 nagios-4.0.8.tar.gz
-rwxrw-rw-. 1 root root 2659772 May 2914:11 nagios-plugins-2.0.3.tar.gz
-rwxrw-rw-. 1 root root 419695 May 29 14:41 nrpe-2.15.tar.gz
[root@make nagios]#
2. nagios运行所需要的用户nagios和组nagcmd,需要创建:
(1) 创建nagcmd组,创建用户nagios,并把它加入nagcmd组中:
[root@make nagios]# groupadd nagcmd
[root@make nagios]# useradd -G nagcmdnagios
[root@make nagios]# grep nagios /etc/passwd
nagios:x:501:502::/home/nagios:/bin/bash
[root@make nagios]#
(2) 把运行apache的用户加入到nagcmd组,以便于在通过网页操作nagios时能够具有足够的权限,如运行cgi程序等,yum安装为apache,如果是编译安装httpd,用户可能是daemon,需要注意:
[root@make nagios]# usermod -a -G nagcmddaemon
[root@make nagios]#
3.编译安装nagios:
[root@make nagios]# ll
total 2648
-rwxrw-rw-. 1 root root 48862 May 29 14:16 nagios-4.0.8.tar.gz
[root@make nagios]# tar xfnagios-4.0.8.tar.gz
[root@make nagios-4.0.8]# pwd
/root/nagios/nagios-4.0.8
[root@make nagios-4.0.8]# ./configure--sysconfdir=/etc/nagios --with-command-group=nagcmd --enable-event-broker
[root@make nagios-4.0.8]# make all
[root@make nagios-4.0.8]# make install
[root@make nagios-4.0.8]# make install-init
[root@make nagios-4.0.8]# makeinstall-commandmode
[root@make nagios-4.0.8]# makeinstall-config
4.在httpd的配置文件目录(conf.d)中创建Nagios的Web程序配置文件,就是创建web接口:
[root@make nagios-4.0.8]# pwd
/root/nagios/nagios-4.0.8
[root@make nagios-4.0.8]# makeinstall-webconf
/usr/bin/install -c -m 644sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
*** Nagios/Apache conf file installed ***
[root@make nagios-4.0.8]#
5.为了安全,创建一个登录nagios web程序的用户,这个用户帐号在以后通过web登录nagios认证时所用:
[root@make ~]# htpasswd -c/etc/nagios/htpasswd.users nagiosadmin
New password: (123456)
Re-type new password:
Adding password for user nagiosadmin
[root@make ~]#
[root@make ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@make ~]#
6.编译、安装nagios-plugins插件:
[root@make nagios]# tar xfnagios-plugins-2.0.3.tar.gz
[root@make nagios]# cd nagios-plugins-2.0.3
[root@make nagios-plugins-2.0.3]#
./configure --with-nagios-user=nagios--with-nagios-group=nagios
[root@make nagios-plugins-2.0.3]# make
[root@make nagios-plugins-2.0.3]# makeinstall
7.配置并启动Nagios:
[root@make ~]# chkconfig --add nagios
[root@make ~]# chkconfig nagios on
[root@make ~]# service nagios restart
Running configuration check...
Stopping nagios:No lock file found in/usr/local/nagios/var/nagios.lock
Starting nagios: done.
[root@make ~]# service nagios restart
Running configuration check...
Stopping nagios: done.
Starting nagios: done.
[root@make ~]#
8.检查其主配置文件的语法是否正确:
[root@make ~]# /usr/local/nagios/bin/nagios-v /etc/nagios/nagios.cfg
……………………..
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems weredetected during the pre-flight check
[root@make ~]#
9.关闭selinux
[root@make ~]# setenforce 0
[root@make ~]#
10.浏览器访问:
不是yum安装的httpd,webconf生成的文件会放在/etc/httpd/conf.d/下,因为找不到这个目录,所以出错。
解决方法:
apache的主配置文件无法读取nagios的配置文件,在apache的配置文件httpd.conf 加入 Include/etc/httpd/conf.d/*。
[root@make ~]# vim /etc/httpd/httpd.conf
472 Include /etc/httpd/conf.d/*.conf
[root@make ~]# service httpd restart
Stopping httpd: [FAILED]
Starting httpd: httpd: Syntax error on line472 of /etc/httpd/httpd.conf: Syntax error on line 1 of/etc/httpd/conf.d/mod_dnssd.conf: Cannot load modules/mod_dnssd.so into server:/usr/local/apache/modules/mod_dnssd.so: cannot open shared object file: No suchfile or directory
[FAILED]
[root@make ~]#
[root@make ~]# cd /etc/httpd/conf.d/
[root@make conf.d]# ls
mod_dnssd.conf nagios.conf
[root@make conf.d]# mv mod_dnssd.confmod_dnssd.confbak
[root@make ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@make ~]#
开启cgi模块:
LoadModule cgid_module modules/mod_cgid.so
LoadModule cgi_module modules/mod_cgi.so
CentOS 6.5下编译安装httpd+mysql+php+phpMyAdmin
原文地址:http://153744.blog.51cto.com/143744/1672030