本实验在CentOS release 5.7上完成的,所有的软件均是目前(2013.04.15)最新的!
所需要的软件包在这里:http://down.51cto.com/data/764169
本文来自http://better.blog.51cto.com/
1、安装Nginx
源码包存放目录
[root@radius ~]# cd /usr/local/src/
上传源码包
[root@radius src]# rz
安装编译工具及依赖库
[root@radius src]# yum install gcc gcc-c++ automake autoconf libtool make
安装PCRE库
[root@radius src]# tar -zxvf pcre-8.32.tar.gz
[root@radius src]# cd pcre-8.32
[root@radius pcre-8.32]# ./configure && make && make install
安装zlib库
[root@radius src]# tar -zxvf zlib-1.2.7.tar.gz
[root@radius src]# cd zlib-1.2.7
[root@radius zlib-1.2.7]# ./configure && make && make install
解压缩openssl源码包,不用安装仅仅用于安装nginx时指定关联文件
[root@radius src]# tar -zxvf openssl-1.0.1c.tar.gz
安装nginx
[root@radius src]# tar -zxvf nginx-1.2.8.tar.gz
[root@radius src]# cd nginx-1.2.8
[root@radius nginx-1.2.8]# ./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.32 --with-zlib=/usr/local/src/zlib-1.2.7 --with-openssl=/usr/local/src/openssl-1.0.1c
[root@radius nginx-1.2.8]# make && make install
加入开机启动脚本
[root@radius nginx-1.2.8]# vim /etc/init.d/nginx
#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: 345 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse # proxy and IMAP/POP3 proxy server # processname: nginx # config: /usr/local/nginx/nginx.conf # pidfile: /usr/local/nginx/nginx.pid # Source function library. . /etc/init.d/functions # Source networking configuration. . /etc/sysconfig/network if [ -f /etc/sysconfig/nginx ];then . /etc/sysconfig/nginx fi # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx #-c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval killall -9 nginx } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t #-c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart) $1 ;; test) configtest ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|test}" exit 2 esac |
修改执行权限
[root@radius nginx-1.2.8]# chmod 755 /etc/init.d/nginx
启动服务
[root@radius nginx-1.2.8]# service nginx start
打开网页查看是否成功
到此nginx配置完成
参考链接:http://www.nginx.cn/install
2、安装PHP集成在nginx
源码包存放目录
[root@radius ~]# cd /usr/local/src/
上传源码包
[root@radius src]# rz
由于光盘里面有几个依赖库没有所以还要用到互联网上的epel源
[root@radius src]# wget http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
[root@radius src]# rpm -ivh epel-release-5-4.noarch.rpm
安装编译工具及依赖库
[root@radius src]# yum install gcc automake autoconf libtool make gcc-c++ glibc libxml2 libxml2-devel curlpp curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel mhash-devel libxslt-devel bzip2 bzip2-devel
[root@radius src]# tar -zxvf php-5.4.14.tar.gz
[root@radius src]# cd php-5.4.14
[root@radius php-5.4.14]# ./configure --prefix=/usr/local/php --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --disable-pdo --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-gd
[root@radius php-5.4.14]# make && make install
[root@radius php-5.4.14]# cp php.ini-production /usr/local/php/lib/php.ini
[root@radius php-5.4.14]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@radius php-5.4.14]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@radius php-5.4.14]# vim /etc/init.d/php-fpm
增加如下
# chkconfig: 345 84 16
[root@radius php-5.4.14]# chmod 755 /etc/rc.d/init.d/php-fpm
修改nginx配置文件使其支持fastcgi
[root@radius php-5.4.14]# vim /usr/local/nginx/nginx.conf
location / { root html; index index.php index.html index.htm; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } |
设置时区
[root@radius php-5.4.14]# vim /usr/local/php/lib/php.ini
找到date.timezone去掉注释并修改如下
date.timezone = "Asia/Chongqing"
新建一个测试页面
[root@radius php-5.4.14]# vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
启动服务
[root@radius php-5.4.14]# service php-fpm start
[root@radius php-5.4.14]# service nginx restart
访问测试
http://php-fpm.org/wiki/Features
参考链接:
3、安装MYSQL
源码包存放目录
[root@radius ~]# cd /usr/local/src/
上传源码包
[root@radius src]# rz
安装编译工具及依赖库
[root@radius src]# yum install ncurses libaio gcc gcc-c++ perl ncurses-devel bison
安装cmake编译工具
[root@radius src]# tar -zxvf cmake-2.8.10.2.tar.gz
[root@radius src]# cd cmake-2.8.10.2
[root@radius src]# ./configure && make && make install
安装mysql
[root@radius cmake-2.8.10.2]# groupadd mysql
[root@radius cmake-2.8.10.2]# useradd -g mysql -s /sbin/nologin mysql
[root@radius cmake-2.8.10.2]# mkdir -p /data/mysql
[root@radius cmake-2.8.10.2]# chown -R mysql:mysql /data/mysql
[root@radius src]# tar -zxvf mysql-5.6.11.tar.gz
[root@radius src]# cd mysql-5.6.11
[root@radius mysql-5.6.11]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc
[root@radius mysql-5.6.11]# make && make install
[root@radius mysql-5.6.11]# cp ./support-files/my-default.cnf /etc/my.cnf
[root@radius mysql-5.6.11]# vim /etc/my.cnf
修改下面内容
basedir = /usr/local/mysql
datadir = /data/mysql
[root@radius mysql-5.6.11]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@radius mysql-5.6.11]# chmod 755 /etc/rc.d/init.d/mysqld
[root@radius mysql-5.6.11]# vim /etc/rc.d/init.d/mysqld
修改下面内容
basedir=/usr/local/mysql
datadir=/data/mysql
[root@radius mysql-5.6.11]# chkconfig mysqld on
[root@radius mysql-5.6.11]# chown mysql:mysql . -R
[root@radius mysql-5.6.11]# chmod 755 ./scripts/mysql_install_db
[root@radius mysql-5.6.11]# ./scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql
[root@radius mysql-5.6.11]# service mysqld start
[root@radius mysql-5.6.11]# /usr/local/mysql/bin/mysql -uroot –p
mysql> show databases;
4、安装rrdtool
源码包存放目录
[root@radius ~]# cd /usr/local/src/
上传源码包
[root@radius src]# rz
安装依赖库
[root@radius ~]# yum install cairo-devel libxml2-devel pango-devel pango libpng-devel freetype freetype-devel libart_lgpl-devel
编译安装rrdtool
[root@radius src]# tar -zxvf rrdtool-1.4.7.tar.gz
[root@radius src]# cd rrdtool-1.4.7
[root@radius rrdtool-1.4.7]# ./configure --prefix=/usr/local/rrdtool && make && make install
5、安装snmp
[root@radius ~]# yum install net-snmp-utils php-snmp net-snmp-libs
[root@radius ~]# vim /etc/snmp/snmpd.conf
[root@radius ~]# chkconfig snmpd on
注释掉下面2行
#view systemview included .1.3.6.1.2.1.1
#view systemview included .1.3.6.1.2.1.25.1.1
增加如下一行
view systemview included .1
完整配置文件如下
com2sec notConfigUser default public group notConfigGroup v1 notConfigUser group notConfigGroup v2c notConfigUser view systemview included .1 access notConfigGroup "" any noauth exact systemview none none syslocation Unknown (edit /etc/snmp/snmpd.conf) syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf) pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat |
6、安装cacti
源码包存放目录
[root@radius ~]# cd /usr/local/src/
上传源码包
[root@radius src]# rz
开始安装
[root@radius src]# useradd -g users -s /sbin/nologin cactiuser
[root@radius src]# tar -zxvf cacti-0.8.8a.tar.gz
[root@radius src]# cp cacti-0.8.8a /usr/local/nginx/html/cacti –rf
创建cacti数据库
[root@radius src]# cd /usr/local/mysql/bin/
[root@radius bin]# ./mysqladmin --user=root create cacti
[root@radius bin]# ./mysql cacti < /usr/local/nginx/html/cacti/cacti.sql
[root@radius bin]# ./mysql --user=root mysql
mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY '123456';
mysql> flush privileges;
mysql> \q
编辑配置文件
[root@radius bin]# vim /usr/local/nginx/html/cacti/include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "123456";
$database_port = "3306";
$database_ssl = false;
[root@radius bin]# cd /usr/local/nginx/html/cacti/
[root@radius cacti]# chown -R cactiuser rra/ log/
[root@radius cacti]# cd scripts/
[root@radius scripts]# chown cactiuser:users *
[root@radius scripts]# crontab -u cactiuser –e
*/1 * * * * /usr/local/php/bin/php /usr/local/nginx/html/cacti/poller.php > /dev/null 2>&1
打开浏览器进行初始化安装(第一次登录默认密码帐号admin密码admin)
以下内容可忽略,将会在下一次笔记时详细解释
排错
[root@radius rra]# /usr/local/rrdtool/bin/rrdtool fetch localhost_load_1min_5.rrd AVERAGE
[root@radius ~]# snmpwalk -v2c -c public 192.168.137.20
重置管理员密码
shell> mysql -u root -p cacti
mysql> update user_auth set password=md5('admin') where username='admin';
Cacti清除日志
cat /dev/null > cacti.log
修改轮询时间及绘图时间
安装cacti-spine支持快速轮询
http://skyou.blog.51cto.com/2915693/544914
[root@radius src]# yum install net-snmp-devel
[root@radius src]# tar -zxvf cacti-spine-0.8.8a.tar.gz
[root@radius src]# cd cacti-spine-0.8.8a
[root@radius cacti-spine-0.8.8a]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
[root@radius cacti-spine-0.8.8a]# ./configure --prefix=/usr/local/cacti-spine --with-snmp=/usr
[root@radius cacti-spine-0.8.8a]# make && make install
[root@radius cacti-spine-0.8.8a]# cp spine.conf.dist /etc/spine.conf
[root@radius cacti-spine-0.8.8a]# vim /etc/spine.conf
[root@radius cacti-spine-0.8.8a]# /usr/local/cacti-spine/bin/spine
SPINE: Using spine config file [/etc/spine.conf]
SPINE: Version 0.8.8a starting
SPINE: Time: 0.1390 s, Threads: 4, Hosts: 3
进入http://192.168.137.20/
设置cacti,选择spine轮询机制运行
Paths
Poller
Cron
[root@radius cacti-spine-0.8.8a]# crontab -u cactiuser -e
*/1 * * * * /usr/local/php/bin/php /usr/local/nginx/html/cacti/poller.php > /dev/null 2>&1
选中Data Templates → Unix - Logged in Users →
重建轮询缓存
[root@radius ~]# /usr/local/php/bin/php -q /usr/local/nginx/html/cacti/cli/rebuild_poller_cache.php -d
参考链接
Cacti安装配置的详细步骤
http://www.mysqlops.com/2011/06/08/cacti-install-setting.html
RedHat / CentOS Install and Configure Cacti Network Graphing Tool
http://www.cyberciti.biz/faq/fedora-rhel-install-cacti-monitoring-rrd-software/
Install and Configure Cacti
http://www.cacti.net/downloads/docs/html/unix_configure_cacti.html
Install RRDTool on Red Hat Enterprise Linux
http://www.cyberciti.biz/faq/howto-install-rrdtool-on-rhel-linux/
Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建)
http://www.osyunwei.com/archives/3209.html
Chapter 1. Installing MySQL from Source
http://dev.mysql.com/doc/mysql-sourcebuild-excerpt/5.6/en/source-installation.html
Download, Configure, Compile, And Install MySQL 5.6
Error Header
http://php-fpm.org/wiki/Features
实战Nginx与PHP(FastCGI)的安装、配置与优化
http://ixdba.blog.51cto.com/2895551/806622
Nginx安装
nginx php-fpm安装配置
CentOS 6.3下MySQL 5.6源码安装
http://database.51cto.com/art/201304/388452.htm
Chapter 2. Installing MySQL from a Standard Source Distribution
http://dev.mysql.com/doc/mysql-sourcebuild-excerpt/5.6/en/installing-source-distribution.html
Chapter 4. MySQL Source-Configuration Options
http://dev.mysql.com/doc/mysql-sourcebuild-excerpt/5.6/en/source-configuration-options.html
Installing RRDTool
转载于:https://blog.51cto.com/better/1199143