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。
软件包:
[[email protected] 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
[[email protected] httpdbao]#
二、安装httpd-2.4.12
1、在安装httpd之前需要先安装apr、apr-util以及pcre-devel等相关包。在编译安装httpd之前需要Development Tools开发工具集。具体步骤如下:
(1)安装apr:
[[email protected] httpdbao]# tar xf apr-1.5.2.tar.bz2
[[email protected] httpdbao]# cd apr-1.5.2
[[email protected] apr-1.5.2]# pwd
/root/httpdbao/apr-1.5.2
[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr
[[email protected] apr-1.5.2]# make
[[email protected] apr-1.5.2]# make install
(2)安装apr-util:
[[email protected] httpdbao]# tar xf apr-util-1.5.4.tar.bz2
[[email protected] httpdbao]# cd apr-util-1.5.4
[[email protected] apr-util-1.5.4]# pwd
/root/httpdbao/apr-util-1.5.4
[[email protected] apr-util-1.5.4]# ./configure--prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[[email protected] apr-util-1.5.4]# make
[[email protected] apr-util-1.5.4]# make install
(3)安装pcre-devel:
[[email protected] ~]# yum install pcre-devel -y
(4)安装httpd:
[[email protected] httpdbao]# tar xf httpd-2.4.12.tar.bz2
[[email protected] httpdbao]# cd httpd-2.4.12
[[email protected] httpd-2.4.12]# pwd
/root/httpdbao/httpd-2.4.12
[[email protected] 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
[[email protected] httpd-2.4.12]#
安装openssl-devel:
[[email protected] 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/.
[[email protected] httpd-2.4.12]#
解决:
[[email protected] httpdbao]# mv apr-1.5.2 apr
[[email protected] httpdbao]# mv apr-util-1.5.4 apr-util
[[email protected] httpdbao]# cp -r apr apr-util httpd-2.4.12/srclib/
编译安装:
[[email protected] 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
[[email protected] httpd-2.4.12]# make
[[email protected] httpd-2.4.12]# make install
2、启动服务进行简单测试
[[email protected] ~]# /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
[[email protected] ~]#
[[email protected] ~]# vim /etc/httpd/httpd.conf
192 ServerName www.example.com:80
"/etc/httpd/httpd.conf" 504L,18336C written
[[email protected] ~]#
[[email protected] ~]# /usr/local/apache/bin/apachectl start
httpd (pid 95896) already running
[[email protected] ~]#
3、为了更好的管理和使用httpd服务,可为其提供PATH环境变量和SysV风格的脚本。
(1) 提供PATH环境变量:
[[email protected] ~]# vim /etc/profile.d/httpd.sh
export PATH=$PATH:/usr/local/apache/bin
"/etc/profile.d/httpd.sh" [New]1L, 40C written
[[email protected] ~]# . /etc/profile.d/httpd.sh
[[email protected] ~]# 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
[[email protected] ~]#
(2) 提供SysV风格的脚本:
[[email protected] ~]# 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 [email protected]
RETVAL=$?
;;
*)
echo "Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
;;
esac
exit $RETVAL
[[email protected] ~]# chmod +x /etc/rc.d/init.d/httpd
[[email protected] ~]# service httpd status
httpd is stopped
[[email protected] ~]# service httpd start
Starting httpd: httpd (pid 95896) alreadyrunning
[ OK ]
[[email protected] ~]#
[[email protected] ~]# chkconfig --add httpd
[[email protected] ~]# chkconfig | grep httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[[email protected] ~]# chkconfig httpd on
[[email protected] ~]# chkconfig | grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[[email protected] ~]#
4、更换pid进程文件存放目录:
每个进程启动后都会有个pid文件,编译安装httpd的pid文件在logs目录里面:
[[email protected] logs]# pwd
/usr/local/apache/logs
[[email protected] 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
[[email protected] logs]#
系统进程一般pid文件都放在/var/run目录下,如果想更换pid进程文件存放目录,需要在主配置文件中加入PidFile "/var/run/httpd.pid"项,注意:编译安装默认没有该项,需要手工加入:
[[email protected] logs]# vim /etc/httpd/httpd.conf
34 Pidfile "/var/run/httpd.pid"
"/etc/httpd/httpd.conf" 505L,18365C written
[[email protected] logs]#
[[email protected] ~]# netstat -lntp | grep httpd
tcp 0 0 :::80 :::* LISTEN 95896/httpd
[[email protected] ~]# kill 95896
[[email protected] ~]# service httpd start
Starting httpd: [ OK ]
[[email protected] ~]# cd /var/run/
[[email protected] run]# ll -d httpd.pid
-rw-r--r--. 1 root root 6 May 22 15:06httpd.pid
[[email protected] run]#
5、为httpd添加man帮助及输出头文件:
(1) 为httpd添加man帮助:
[[email protected] ~]# vim /etc/man.config
48 MANPATH /usr/local/apache/man
[[email protected] ~]# man httpd
HTTPD(8) httpd HTTPD(8)
NAME
httpd - Apache Hypertext Transfer Protocol Server
……………
[[email protected] ~]#
(2) 输出头文件:
[[email protected] ~]#ln -sv /usr/local/apache/include/ /usr/include/httpd
`/usr/include/httpd‘ ->`/usr/local/apache/include/‘
[[email protected] ~]#
至此,httpd服务安装成功。
三、安装MySQL
1、创建mysql用户和mysql组
要想初始化mysql,需要有mysql用户和组。
[[email protected] ~]# groupadd -r -g 306 mysql
[[email protected] ~]# useradd -g 306 -r -u 306 mysql
[[email protected] ~]# id mysql
uid=306(mysql) gid=306(mysql)groups=306(mysql)
[[email protected] ~]#
2、创建mysql数据存放目录
[[email protected] ~]# mkdir /mydata/data -pv
mkdir: created directory `/mydata‘
mkdir: created directory `/mydata/data‘
[[email protected] ~]# 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/
[[email protected] ~]#
mysql数据目录,需要把属主属组更改为mysql,权限更改为0-rwx:
[[email protected] mysql]# cd /mydata/
[[email protected] mydata]# ll
total 4
drwxr-xr-x. 2 root root 4096 May 22 15:44data
[[email protected] mydata]# chown -R mysql:mysql data/
[[email protected] mydata]# chmod o-rwx data/
[[email protected] mydata]# ll
total 4
drwxr-x---. 2 mysql mysql 4096 May 22 15:44data
[[email protected] mydata]#
这里以目录代替,生产环境需要单独保存数据的磁盘。
3、解压并安装MySQL 5.6.24,使用的通用二进制格式的MySQL
(1).通用二进制包是编译好的,直接解压就可以用,注意:mysql要求解压的包需在/usr/local目录下,并且目录名字必须是mysql。
[[email protected] 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
[[email protected] httpdbao]# tar xfmysql-5.6.24-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
[[email protected] httpdbao]# cd /usr/local/
[[email protected] local]# ln -sv mysql-5.6.24-linux-glibc2.5-x86_64/mysql
`mysql‘ ->`mysql-5.6.24-linux-glibc2.5-x86_64/‘
[[email protected] local]# ll mysql
lrwxrwxrwx. 1 root root 35 May 22 15:48mysql -> mysql-5.6.24-linux-glibc2.5-x86_64/
[[email protected] local]#
(2). 更改mysql目录中的文件的属主、属组为mysql用户和mysql组:
[[email protected] 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
[[email protected] mysql]# chown -R mysql:mysql *
[[email protected] 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
[[email protected] mysql]#
4、初始化mysql数据库:
执行scripts目录下的脚本,该文件作用:mysql需要初始化,这个步骤就是完成初始化的,我们需要手动完成。
[[email protected] scripts]# pwd
/usr/local/mysql/scripts
[[email protected] scripts]# ll
total 36
-rwxr-xr-x. 1 mysql mysql 34558 Mar 2600:54 mysql_install_db
[[email protected] scripts]#
[[email protected] 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.
[[email protected] scripts]# cd ..
[[email protected] mysql]# scripts/mysql_install_db --user=mysql--datadir=/mydata/data/
为了安全,需要把mysql目录下文件属主更改回root用户:
[[email protected] mysql]# chown -R root /usr/local/mysql/*
5、修改及配置MySQL服务脚本及配置文件
(1) 拷贝MySQL服务脚本:
[[email protected] ~]# cp /usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld
[[email protected] ~]# chmod +x /etc/init.d/mysqld
[[email protected] ~]# chkconfig --add mysqld
[[email protected] ~]# chkconfig mysqld on
[[email protected] ~]# chkconfig | grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[[email protected] ~]#
(2)修改mysql配置文件datadir数据目录位置:
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
datadir=/mydata/data
"/etc/my.cnf" 10L, 249Cwritten
[[email protected] ~]#
(3)启动mysql服务:
[[email protected] ~]# service mysqld start
Starting MySQL. [ OK ]
[[email protected] ~]#
[[email protected] mysql]# netstat -lntp | grep mysqld
tcp 0 0 :::3306 :::* LISTEN 99386/mysqld
[[email protected] mysql]#
(4)mysql启动之后,会生成socket位置mysql.sock文件:
[[email protected] mysql]# pwd
/var/lib/mysql
[[email protected] mysql]# ll -d mysql.sock
srwxrwxrwx. 1 mysql mysql 0 May 22 16:14mysql.sock
[[email protected] mysql]#
修改其位置生成位置:
[root[email protected] mysql]# vim /etc/my.cnf
socket=/tmp/mysql.sock
[[email protected] mysql]#
6、为mysql添加PATH环境变量
[[email protected] mysql]# vi /etc/profile.d/mysqld.sh
export PATH=$PATH:/usr/local/mysql/bin
"/etc/profile.d/mysqld.sh" [New]1L, 39C written
[[email protected] mysql]# . /etc/profile.d/mysqld.sh
[[email protected] 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
[[email protected] mysql]#
7、为mysql添加man帮助及输出头文件和库文件
[[email protected] mysql]# vi /etc/man.config
49 MANPATH /usr/local/mysql/man
"/etc/man.config" 154L, 4999Cwritten
[[email protected] mysql]#
[[email protected] mysql]# ln -sv /usr/local/mysql/include//usr/include/mysql
`/usr/include/mysql‘ ->`/usr/local/mysql/include/‘
[[email protected] mysql]#
[[email protected] mysql]# vi /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
"/etc/ld.so.conf.d/mysql.conf"[New] 1L, 21C written
[[email protected] mysql]# ldconfig -v
8、为mysql添加密码:
[[email protected] ~]# mysqladmin -u root password ‘123456‘
Warning: Using a password on the commandline interface can be insecure.
[[email protected] ~]#
说明:
mysql-5.6会提示命令行使用密码不安全的。
至此,mysql安装完毕
四、安装PHP
1、解压并编译安装php-5.6.8:
[[email protected] php-5.6.8]# tar xf php-5.6.8.tar.bz2
[[email protected] php-5.6.8]# cd php-5.6.8
[[email protected] 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
[[email protected] php-5.6.8]#
安装:
[[email protected] php-5.6.8]# yum install bzip2-devel -y
[[email protected] php-5.6.8]#yum install libxml2-devel –y
在编译:
checking for mcrypt support... yes
configure: error: mcrypt.h not found.Please reinstall libmcrypt.
[[email protected]e php-5.6.8]#
安装:
[[email protected] 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
[[email protected] httpdbao]#
[[email protected] httpdbao]# tar xf libmcrypt-2.5.6.tar.gz
[[email protected] httpdbao]# cd libmcrypt-2.5.6
[[email protected] libmcrypt-2.5.6]# ./configure
[[email protected] libmcrypt-2.5.6]# make
[[email protected] libmcrypt-2.5.6]# make install
在编译:
[[email protected] 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
[[email protected] php-5.6.8]# make
错误:
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
[[email protected] php-5.6.8]#
解决:
[[email protected] php-5.6.8]#make clean
[[email protected] php-5.6.8]# make install
3、给php提供配置文件:
在php安装程序中,有两个文件叫php.ini-development和php.ini-production:
php.ini-development :开发用的配置文件。
php.ini-production :生产环境用的配置文件。
[[email protected] php-5.6.8]# pwd
/root/httpdbao/php-5.6.8
[[email protected] php-5.6.8]# cp php.ini-production /etc/php.ini
[[email protected] php-5.6.8]# ll -d /etc/php.ini
-rw-r--r--. 1 root root 72369 May 22 17:15/etc/php.ini
[[email protected] php-5.6.8]#
4、配置httpd,使其能够支持php
(1) 首先能够让apache能够处理php结尾的页面文件,添加php类型:
[[email protected] ~]# 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
[[email protected] ~]#
(2) 支持php网页:
[[email protected] ~]# vim /etc/httpd/httpd.conf
250 <IfModule dir_module>
251 DirectoryIndex index.php index.html
252 </IfModule>
"/etc/httpd/httpd.conf" 507L,18465C written
[[email protected] ~]#
5、重启httpd服务,测试PHP网页:
[[email protected] ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[[email protected] ~]#
[[email protected] htdocs]# pwd
/usr/local/apache/htdocs
[[email protected] htdocs]# vim index.html
<html><body><h1>Itworks!</h1></body></html>
<?php
phpinfo();
?>
[[email protected] htdocs]# mv index.html index.php
[[email protected] htdocs]# ll
total 4
-rw-r--r--. 1 root root 66 May 22 17:25index.php
[[email protected] htdocs]#
测试phpMyAdmin数据库:
[[email protected] httpdbao]# unzip phpMyAdmin-4.4.4-all-languages.zip
[[email protected] httpdbao]# mv phpMyAdmin-4.4.4-all-languages/usr/local/apache/htdocs/
[[email protected] httpdbao]# cd /usr/local/apache/htdocs/
[[email protected] 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
[[email protected] htdocs]# ln -sv phpMyAdmin-4.4.4-all-languages/ pam
`pam‘ -> `phpMyAdmin-4.4.4-all-languages/‘
[[email protected] htdocs]#
配置xcache进行加速
[[email protected] httpdbao]# ll
-rw-r--r--. 1 root root 173368 Sep 19 2014 xcache-3.2.0.tar.gz
[[email protected] httpdbao]#
[[email protected] httpdbao]# cd xcache-3.2.0
用phpize生成configure配置文件:
[[email protected] 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
[[email protected] xcache-3.2.0]#
[[email protected] xcache-3.2.0]#
./configure --enable-xcache--with-php-config=/usr/local/php/bin/php-config
[[email protected] xcache-3.2.0]# make
[[email protected] xcache-3.2.0]# make install
[[email protected] ~]# mkdir /etc/php.d
[[email protected] ~]# cp httpdbao/xcache-3.2.0/xcache.ini /etc/php.d
[[email protected] ~]#
[[email protected] ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[[email protected] ~]#
安装cacti
1.需要安装SNMP:
[[email protected] ~]# yum -y install net-snmp net-snmp-utils
2. 启动snmp服务:
[[email protected] ~]# service snmpd start
Starting snmpd: [ OK ]
[[email protected] ~]# chkconfig snmpd on
[[email protected] ~]#
3. 安装工具rrdtool
[[email protected] 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
[[email protected] rrd]# yum install -y ruby lua
[[email protected] rrd]# yum install -y libdbi-devel
[[email protected] rrd]# yum install perl-Time-HiRes
[[email protected] 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%]
[[email protected] rrd]#
4. cacti的安装
[[email protected] cactibao]# ll
total 2844
-rwxrw-rw-. 1 root root 2908451 May 2214:19 cacti-0.8.8c.tar.gz
[[email protected] cactibao]#
[[email protected] cactibao]# tar xf cacti-0.8.8c.tar.gz -C/usr/local/apache/htdocs/
[[email protected] htdocs]# pwd
/usr/local/apache/htdocs
[[email protected] htdocs]# ln -sv cacti-0.8.8c/ cacti
`cacti‘ -> `cacti-0.8.8c/‘
[[email protected] 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
[[email protected] htdocs]#
由于cacti需要用到mysql数据库的,因此需要一个专门的数据库保存他的表:
mysql> create database cactidb;
Query OK, 1 row affected (0.01 sec)
mysql> grant all on cactidb.* to [email protected] by ‘cacti‘;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all on cactidb.* to [email protected] 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数据库中:
[[email protected] cacti]# mysql -u root -p cactidb < cacti.sql
Enter password:
[[email protected] cacti]#
配置cacti配置文件,修改相应的账号数据库连接:
[[email protected] include]# pwd
/usr/local/apache/htdocs/cacti/include
[[email protected] 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
[[email protected] include]#
建立系统普通账户,该用户可以建立周期性的获取数据执行PHP脚本:
[[email protected] include]# useradd cacti
[[email protected] include]#
更改rra和 log目录属主属组改为cacti,其中rra目录是保存rrd文件的,log是日志目录:
[[email protected] cacti]# pwd
/usr/local/apache/htdocs/cacti
[[email protected] cacti]# chown -R cacti:cacti rra log
[[email protected] cacti]#
安装cacti,浏览器访问http://192.168.1.214/cacti:
[[email protected] cacti]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[[email protected] cacti]#
定义cacti默认的周期性计划,这个任务计划是靠一个脚本实现的:
[[email protected] ~]#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
[[email protected] ~]#
由于不会马上执行,手动执行测试一下:
[[email protected] ~]$ /usr/local/php/bin/php/usr/local/apache/htdocs/cacti/poller.php
更改php配置文件:
[[email protected] ~]$ su - root
Password:
[[email protected] ~]# vim /etc/php.ini
928 date.timezone = Asia/Shanghai
"/etc/php.ini" 1997L, 72399Cwritten
[[email protected] ~]#
[[email protected] ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[[email protected] ~]#
安装cacti-spine:
出于效率原因,在大量采集数据时使用自带的cmd.php轮询器会比较慢,1分钟1次的采集频率可能无法完成轮询所有机器。这里为了优化,采用官方推荐的spine来高效轮询。安装spine要和Cacti的版本相匹配
[[email protected] cactibao]# ll
total 3464
-rwxrw-rw-. 1 root root 632102 May 25 16:25 cacti-spine-0.8.8c.tar.gz
[[email protected] cactibao]#
[[email protected] cactibao]# tar xfcacti-spine-0.8.8c.tar.gz
[[email protected] cactibao]# cd cacti-spine-0.8.8c
[[email protected] 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
[[email protected] cacti-spine-0.8.8c]#
错误:找不到mysql,需要制定mysql安装位置:
[[email protected] local]# yum install -ynet-snmp-devel
[[email protected] cacti-spine-0.8.8c]# ./configure--prefix=/usr/local/cacti-spine --with-snmp=/usr --with-mysql=/usr/local/mysql/
[[email protected] cacti-spine-0.8.8c]# make
[[email protected] cacti-spine-0.8.8c]# makeinstall
修改访问数据库的用户名密码信息:
[[email protected] etc]# pwd
/usr/local/cacti-spine/etc
[[email protected] etc]# ll
total 4
-rw-r--r--. 1 root root 2791 May 25 17:08spine.conf.dist
[[email protected] etc]# cp spine.conf.distspine.conf
[[email protected] 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
[[email protected] etc]#
[[email protected] 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
[[email protected] etc]#
测试是否正常:
[[email protected] 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
[[email protected] 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.准备安装的软件:
[[email protected] nagios]# yum install -y glibcglibc-common gd gd-devel
[[email protected] 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
[[email protected] nagios]#
2. nagios运行所需要的用户nagios和组nagcmd,需要创建:
(1) 创建nagcmd组,创建用户nagios,并把它加入nagcmd组中:
[[email protected] nagios]# groupadd nagcmd
[[email protected] nagios]# useradd -G nagcmdnagios
[[email protected] nagios]# grep nagios /etc/passwd
nagios:x:501:502::/home/nagios:/bin/bash
[[email protected] nagios]#
(2) 把运行apache的用户加入到nagcmd组,以便于在通过网页操作nagios时能够具有足够的权限,如运行cgi程序等,yum安装为apache,如果是编译安装httpd,用户可能是daemon,需要注意:
[[email protected] nagios]# usermod -a -G nagcmddaemon
[[email protected] nagios]#
3.编译安装nagios:
[[email protected] nagios]# ll
total 2648
-rwxrw-rw-. 1 root root 48862 May 29 14:16 nagios-4.0.8.tar.gz
[[email protected] nagios]# tar xfnagios-4.0.8.tar.gz
[[email protected] nagios-4.0.8]# pwd
/root/nagios/nagios-4.0.8
[[email protected] nagios-4.0.8]# ./configure--sysconfdir=/etc/nagios --with-command-group=nagcmd --enable-event-broker
[[email protected] nagios-4.0.8]# make all
[[email protected] nagios-4.0.8]# make install
[[email protected] nagios-4.0.8]# make install-init
[[email protected] nagios-4.0.8]# makeinstall-commandmode
[[email protected] nagios-4.0.8]# makeinstall-config
4.在httpd的配置文件目录(conf.d)中创建Nagios的Web程序配置文件,就是创建web接口:
[[email protected] nagios-4.0.8]# pwd
/root/nagios/nagios-4.0.8
[[email protected] 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 ***
[[email protected] nagios-4.0.8]#
5.为了安全,创建一个登录nagios web程序的用户,这个用户帐号在以后通过web登录nagios认证时所用:
[[email protected] ~]# htpasswd -c/etc/nagios/htpasswd.users nagiosadmin
New password: (123456)
Re-type new password:
Adding password for user nagiosadmin
[[email protected] ~]#
[[email protected] ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[[email protected] ~]#
6.编译、安装nagios-plugins插件:
[[email protected] nagios]# tar xfnagios-plugins-2.0.3.tar.gz
[[email protected] nagios]# cd nagios-plugins-2.0.3
[[email protected] nagios-plugins-2.0.3]#
./configure --with-nagios-user=nagios--with-nagios-group=nagios
[[email protected] nagios-plugins-2.0.3]# make
[[email protected] nagios-plugins-2.0.3]# makeinstall
7.配置并启动Nagios:
[[email protected] ~]# chkconfig --add nagios
[[email protected] ~]# chkconfig nagios on
[[email protected] ~]# service nagios restart
Running configuration check...
Stopping nagios:No lock file found in/usr/local/nagios/var/nagios.lock
Starting nagios: done.
[[email protected] ~]# service nagios restart
Running configuration check...
Stopping nagios: done.
Starting nagios: done.
[[email protected] ~]#
8.检查其主配置文件的语法是否正确:
[[email protected] ~]# /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
[[email protected] ~]#
9.关闭selinux
[[email protected] ~]# setenforce 0
[[email protected] ~]#
10.浏览器访问:
不是yum安装的httpd,webconf生成的文件会放在/etc/httpd/conf.d/下,因为找不到这个目录,所以出错。
解决方法:
apache的主配置文件无法读取nagios的配置文件,在apache的配置文件httpd.conf 加入 Include/etc/httpd/conf.d/*。
[[email protected] ~]# vim /etc/httpd/httpd.conf
472 Include /etc/httpd/conf.d/*.conf
[[email protected] ~]# 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]
[[email protected] ~]#
[[email protected] ~]# cd /etc/httpd/conf.d/
[[email protected] conf.d]# ls
mod_dnssd.conf nagios.conf
[[email protected] conf.d]# mv mod_dnssd.confmod_dnssd.confbak
[[email protected] ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[[email protected] ~]#
开启cgi模块:
LoadModule cgid_module modules/mod_cgid.so
LoadModule cgi_module modules/mod_cgi.so