Tag: CentOS

CentOS+Cacti基本安装配置

Posted by – 2009-11-04

####################################
#Cacti Configuration
#Author:楚霏
#Date: 2009-11-04
#Env: Centos 5.4 x86_64
####################################


一、准备工作
####################################
环境:Centos 5.4 x86_64
所需软件:
http
Php
Php-mysql
Php-snmp
Mysql
Perl-DBD-MySQL
Php-pdo
rrdtool
Net-snmp
Net-snmp-libs
Net-snmp-utils
####################################


####################################
#下载相关软件
cd /usr/local/src/
wget http://www.cacti.net/downloads/cacti-0.8.7e.tar.gz

####################################

二、环境介绍
####################################
主监控机是Centos 5.4 x86_64
主监控机IP=10.0.0.52
####################################


三、安装配置
####################################
(1)在主监控机上安装apache+php+gd的web环境,推荐编译安装,不再赘述,本处方便起见用yum装了
yum install php php-mysql php-snmp mysql mysql-server net-snmp net-snmp-libs net-snmp-utils php-pdo perl-DBD-MySQL
####################################


####################################
(2)在主监控机上安装rrdtool,rrdtool依赖的包过多,所以选择增加源,然后用yum安装
#增加源
vi /etc/yum.repos.d/CentOS-Base.repo
#在文件末尾增加以下部分
#----------------------------引用文字-开始----------------------------
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
enabled=1
#----------------------------引用文字-结束----------------------------
yum install rrdtool
####################################


####################################
(3)配置snmp
vi /etc/snmp/snmp.conf
#----------------------------引用文字-结束----------------------------
#将下边这行中的default
com2secnotConfigUser default public
#改为127.0.0.1
com2secnotConfigUser 127.0.0.1 public

#将下边这行中的systemview
access notConfigGroup "" any noauth exact systemview none none
#改为all
access notConfigGroup "" any noauth exact all none none

#将下边这行的注释“#”号去掉
#view all included .1 80
#----------------------------引用文字-结束----------------------------

#重启snmpd服务
service snmpd restart
####################################


####################################
(4)安装cacti
#把解压后的包移动到你的相应的web目录
tar xvf cacti-0.8.7e.tar.gz
mv cacti-0.8.7e /var/www/html/cacti
####################################


####################################
(5)在数据库中建库、授权、导入数据库结构
#注意导入cacti.sql时该文件的路径
mysql -p
#----------------------------引用文字-结束----------------------------
mysql> create database cacti;
mysql> grant all privileges on cacti.* to cacti@localhost identified by 'cacti' with grant option;
mysql> grant all privileges on cacti.* to cacti@127.0.0.1 identified by 'cacti' with grant option;
mysql> use cacti;
mysql> source /var/www/html/cacti/cacti.sql;
#----------------------------引用文字-结束----------------------------
#配置cacti以连接数据库
vi /var/www/html/cacti/include/config.php
####################################


####################################
(6)浏览器下配置
#用浏览器打开 http://10.0.0.52/cacti ,会显示 cacti的安装指南,设置好就不会再出现了。
#点击 “Next”
#选择“New Install”,点击“Next”
#指定 rrdtool、 php、 snmp 工具的 Binary 文件路径,确保所有的路径都是显示“ FOUND”,没有 “NOT FOUND”的,点击 Finish 完成安装。
#Cacti 默认的用户名与密码是 admin,输入用户名与密码,点击 login
#为了安全的原因,第一次登录成功后,cacti 会强制要求你更改一个新的 password ,输入新密码并确认密码,点击 save ,进入 cacti 控制台界面:
#点击 graphs ,查看cacti 监控本机的图表:
####################################


####################################
(7)增加入一个计划任务,使得 cacti 每五分钟生成一个监控图表。
crontab -e
#加入如下内容。注意poller.php的路径
#----------------------------引用文字-结束----------------------------
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1
#----------------------------引用文字-结束----------------------------

#确保 /var/www/html/cacti/rra/目录存在
#如果暂时未看到图表,可以手工执行,生成图表
#php /var/www/html/cacti/poller.php > /dev/null 2>&1
####################################


####################################
(8)使用 Cacti 监控 Linux 主机
#在被监控的linux主机上安装net-snmp
yum install net-snmp
vi /etc/snmp/snmpd.conf
#更改以下部分
#----------------------------引用文字-结束----------------------------
#将下边这行中的default
com2secnotConfigUser default public
#改为10.0.0.52(cacti)服务器的地址)
com2secnotConfigUser 10.0.0.52 public

#将下边这行中的systemview
access notConfigGroup "" any noauth exact systemview none none
#改为all
access notConfigGroup "" any noauth exact all none none

#将下边这行的注释“#”号去掉
#view all included .1 80
#----------------------------引用文字-结束----------------------------
service snmpd restart
####################################


####################################
(9)如果出现问题请注意一下snmp协议的版本,都用version 1是一种解决方法
如果都用version 1,需要把所有监控机和被监控机的snmpd.conf改一下
#vi /etc/snmp/snmpd.conf
#----------------------------引用文字-结束----------------------------
#将下边这行
view systemview included .1.3.6.1.2.1.1
#改为
view systemview included .1.3.6.1.2.1
#----------------------------引用文字-结束----------------------------
####################################

Nagios搭建监控服务器

Posted by – 2009-08-11

####################################
#nagios_configuration
#Author:楚霏
#Date: 2009-3-19
#Update:2009-8-11
#Env: Centos 5.3 x86_64
#感谢Sery兄的帮助
####################################

一、准备工作
####################################
环境:Centos 5.3 x86_64
所需软件:
nagios-3.1.?.tar.gz
nagios-plugins-1.4.13.tar.gz
nrpe-2.12.tar.gz
httpd-2.2.??.tar.gz
gcc
glibc
glibc-common
gd
gd-devel
fetion20080910047-lin64.tar.gz
library64_linux.tar.gz
libstdc++-4.3.0-8.x86_64.rpm
####################################

####################################
#下载相关软件
cd /usr/local/src/
wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.1.2.tar.gz
wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz
wget http://jaist.dl.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
wget ftp://mirror.switch.ch/pool/2/mirror/fedora/linux/releases/9/Fedora/x86_64/os/Packages/libstdc++-4.3.0-8.x86_64.rpm
wget http://www.it-adv.net/fetion/downng/fetion20090406003-linux.tar.gz
wget http://www.it-adv.net/fetion/downng/library_linux.tar.gz
####################################

二、环境介绍
####################################
两台机器全是Centos 5.3 x86_64
主监控机IP=10.0.0.52
被监控机IP=10.0.0.166
主监控机上运行nagios的用户名是nagios,这个用户隶属于nagios组和运行apache的用户组

主监控机需要安装nagios,nagios-plugins,nrpe,fetion
被监控机只需要安装nagios-plugins,nrpe

支持PHP和GD的WEB环境并不是nagios必需的,主要是为了在web上看到监控状态,而nagios所带的html需要php+gd的支持

所有增减主机增减服务器操作均在主监控机上配置
主监控机上的nagios.cfg是总的配置文件,配置各个部分的配置文件的位置等信息
####################################

三、安装配置
####################################
(1)在主监控机上安装apache+php+gd的web环境,推荐编译安装,不再赘述,本处方便起见用yum装了
yum -y install gcc glibc glibc-common gd gd-devel httpd php php-gd libpng
####################################

####################################
(2)在主监控机上安装Nagios
#创建相关的用户和组
useradd -m nagios
groupadd nagcmd && usermod -a -G nagcmd nagios

#下边这条命令是使nagios用户也隶属于运行web服务器的组
usermod -a -G nagcmd apache

cd /usr/local/src/
tar xvf nagios-3.1.?.tar.gz ; cd nagios-3.1.?

#可以先看一下编译帮助
./configure --help
./configure --prefix=/usr/local/nagios --with-command-group=nagcmd
make all

#第一步执行make install安装主要的程序、CGI及HTML文件
#第二步执行make install-init的步骤,它的作用是把nagios做成一个运行脚本,使nagios随系统开机启动
#第三步执行make install-commandmode 给外部命令访问nagios配置文件的权限
#第四步执行make install-config 把配置文件的例子复制到nagios的安装目录
make install
make install-init
make install-commandmode
make install-config

#验证程序是否被正确安装上文指定的安装路径(这里是/usr/local/nagios),看是否存在etc、bin、sbin、share、var这五个目录。
#bin 执行程序所在目录,这个目录只有一个文件nagios
#etc 配置文件位置,初始安装完后,只有几个*.cfg-sample文件
#sbin Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录
#share Nagios网页文件所在的目录
#var Nagios日志文件、spid 等文件所在的目录
ls /usr/local/nagios
####################################

####################################
(3)配置WEB接口
#相当于httpd.conf中加了

#----------------------------引用文字-开始----------------------------
# Load config files from the config directory "/etc/httpd/conf.d".
Include conf.d/*.conf
#----------------------------引用文字-结束----------------------------

#然后在新建的/安装路径/httpd/conf.d/下新建了一个文件,内容是:

#----------------------------引用文字-开始----------------------------
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
# Last Modified: 11-26-2005
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file. Customize the paths, etc. as
# needed to fit your system.

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"


# SSLRequireSSL
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user

Alias /nagios "/usr/local/nagios/share"


# SSLRequireSSL
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user

#----------------------------引用文字-结束----------------------------

#yum安装的apache,可用下面命令来实现
make install-webconf
#生成验证用户,
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#在httpd.conf中的DirectoryIndex中加上index.php
#apache其它配置此处不再赘述
service httpd start
####################################

####################################
(4)安装Nagios Plugins
cd /usr/local/src/
tar xvf nagios-plugins-1.4.??.tar.gz && cd nagios-plugins-1.4.??
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
####################################

####################################
(5)把Nagios增加为服务器并试运行
chkconfig --add nagios
chkconfig --level 3 nagios on

#测试一下配置文件
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

#保证nagios用户有权限运行插件
chown -R nagios:nagios /usr/local/nagios/libexec/

#如果没有错误,启动
service nagios start
####################################

####################################
(6)Nagios配置文件简介
#主配置文件nagios.cfg

#日志文件
#格式:log_file=
#例如:
#log_file=/usr/local/nagios/var/nagios.log

#对象的配置文件
#格式:cfg_file=
#例如:
#cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
#cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg

#对象的配置目录
#格式:cfg_dir =
#例如:
#cfg_dir=/usr/local/nagios/etc/switches

#Nagios用户
#格式:nagios_user=
#例如:
#nagios_user = nagios

#配置文件cgi.cfg,它是控制相关cgi脚本的

#objects(对象)是所有可监控和通知的要素。
#下边包含的配置文件主要包括
#hosts.cfg定义被监控主机
#hostgroups.cfg定义被监控主机组
#services.cfg定义服务
#servicegroups.cfg定义服务组
#contacts.cfg定义联系人
#contactgroups.cfg定义联系人组
#timeperiods.cfg定义时间期限-如24x7全天候的监测
#commands.cfg定义命令
#servicedependency定义服务依赖
#serviceescalation定义服务扩展
#hostdependency定义主机依赖
#hostescalation定义主机扩展
####################################

####################################
(7)修改配置文件
cd /usr/local/nagios/etc/
cp nagios.cfg nagios.cfg.chushibak
vi nagios.cfg
#把下面部分

#----------------------------引用文字-开始----------------------------
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg

# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
#----------------------------引用文字-结束----------------------------

#修改为
#----------------------------引用文字-开始----------------------------
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg

cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/servicegroups.cfg

cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg

# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
#----------------------------引用文字-结束----------------------------

####################################

####################################
(8)创建和修改对象配置文件
cd /usr/local/nagios/etc/objects
mkdir bak
mv contacts.cfg ./bak/
mv localhost.cfg ./bak/

cat << EOF >> hosts.cfg
#----------------------------引用文字-开始----------------------------

define host{
host_name 10.0.0.52
alias 10.0.0.52
address 10.0.0.52
max_check_attempts 5
#check_interval 1
#retry_interval 1
check_period 24x7
contact_groups sa_groups
notification_interval 30
#first_notification_delay #
notification_period 24x7
notification_options d,u,r
}

define host{
host_name 10.0.0.166
alias 10.0.0.166
address 10.0.0.166
max_check_attempts 5
#check_interval 1
#retry_interval 1
check_period 24x7
contact_groups sa_groups
notification_interval 30
#first_notification_delay #
notification_period 24x7
notification_options d,u,r
}
EOF
#----------------------------引用文字-结束----------------------------

cat << EOF >> hostgroups.cfg
#----------------------------引用文字-开始----------------------------
define hostgroup{
hostgroup_name all_hosts
alias all_hosts
members 10.0.0.52,10.0.0.166
#notes note_string
#notes_url url
#action_url url
}
define hostgroup{
hostgroup_name http_hosts
alias http_hosts
members 10.0.0.166
#notes note_string
#notes_url url
#action_url url
}
EOF
#----------------------------引用文字-结束----------------------------

cat << EOF >> contacts.cfg
#----------------------------引用文字-开始----------------------------
define contact{
contact_name cheng
alias sa_cheng
host_notifications_enabled 1 [0/1]
service_notifications_enabled 1 [0/1]
host_notification_period 24x7
service_notification_period 24x7
host_notification_options d,u,r
service_notification_options w,u,c,r
host_notification_commands notify-service-by-email,notify-service-by-sms
service_notification_commands notify-host-by-email,notify-host-by-sms
email yxcx@yahoo.cn
pager 13712345678
can_submit_commands 1 [0/1]
#retain_status_information [0/1]
#retain_nonstatus_information [0/1]
}
EOF
#----------------------------引用文字-结束----------------------------

cat << EOF >> contactgroups.cfg
#----------------------------引用文字-开始----------------------------
define contactgroup{
contactgroup_name sa_groups
alias sa_groups
members cheng
#contactgroup_members contactgroups
}
EOF
#----------------------------引用文字-结束----------------------------

#下边检查调用的命令(check_command),在命令配置文件中定义或在nrpe配置文件中要有定义
#最大重试次数(max_check_attempts),一般设置为3-4次比较好,这样不会因为太敏感而发生误报,一丢包就发短信太崩溃了吧
#检查间隔(check_interval)和重试检查间隔(retry_interval)的单位是分钟,不同的检查项目酌情修改
#通知间隔(notification_interval)指探测到故障以后,每隔多少分钟发送一次报警信息。
#状态级别:
#d=send notifications on a DOWN state宕
#w=send notifications on a WARNING state警告状态
#c=send notifications on a CRITICAL state严重状态、临界状态
#u=send notifications on an UNREACHABLE or UNKNOWN state找不到、不可达
#r=send notifications on recoveries (OK state)OK状态
#f=send notifications when the host or service starts and stops flapping
#s=send notifications when scheduled downtime starts and ends

cat << EOF >> services.cfg
#----------------------------引用文字-开始----------------------------

#monitor hosts
define service{
host_name 10.0.0.166
service_description check_ftp
check_command check_ftp
max_check_attempts 3
check_interval 10
retry_interval 5
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c
#contacts contacts(*)
contact_groups sa_groups
}
EOF
#----------------------------引用文字-结束----------------------------

cat << EOF >> servicegroups.cfg
#----------------------------引用文字-开始----------------------------
#monitor all_hosts
define service{
hostgroup_name all_hosts
service_description check_host-alive
check_command check_ping
max_check_attempts 5
check_interval 3
retry_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c
#contacts contacts(*)
contact_groups sa_groups
}
define service{
hostgroup_name all_hosts
service_description check_df
check_command check_nrpe!check_df
max_check_attempts 4
check_interval 1440
retry_interval 5
check_period 24x7
notification_interval 1440
notification_period 24x7
notification_options w,u,c
#contacts contacts(*)
contact_groups sa_groups
}
define service{
hostgroup_name all_hosts
service_description check_load
check_command check_nrpe!check_load
max_check_attempts 5
check_interval 5
retry_interval 5
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c
#contacts contacts(*)
contact_groups sa_groups
}
define service{
hostgroup_name all_hosts
service_description check_zombie_procs
check_command check_nrpe!check_zombie_procs
max_check_attempts 5
check_interval 5
retry_interval 5
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c
#contacts contacts(*)
contact_groups sa_groups
}
define service{
hostgroup_name all_hosts
service_description check_total_procs
check_command check_nrpe!check_total_procs
max_check_attempts 5
check_interval 5
retry_interval 5
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c
#contacts contacts(*)
contact_groups sa_groups
}
define service{
hostgroup_name all_hosts
service_description check_ssh
check_command check_ssh
max_check_attempts 3
check_interval 60
retry_interval 5
check_period 24x7
notification_interval 60
notification_period 24x7
notification_options w,u,c
#contacts contacts(*)
contact_groups sa_groups
}

#monitor http_hosts
define service{
hostgroup_name http_hosts
service_description check_http
check_command check_http
max_check_attempts 4
check_interval 3
retry_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c
#contacts contacts(*)
contact_groups sa_groups
}
EOF
#----------------------------引用文字-结束----------------------------

####################################

####################################
(7)主监控机安装nrpe
cd /usr/local/src/
tar xvf nrpe-2.??.tar.gz && cd nrpe-2.??
./configure --prefix=/usr/local/nrpe

#编译结束后在屏幕打印出相关的一些系统信息
#----------------------------引用文字-开始----------------------------
General Options:
-------------------------
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios
#----------------------------引用文字-结束----------------------------
make
make install

#复制几个插件以便nrpe正常工作
cp /usr/local/nrpe/libexec/check_nrpe /usr/local/nagios/libexec/
cp /usr/local/nagios/libexec/check_disk /usr/local/nrpe/libexec/
cp /usr/local/nagios/libexec/check_load /usr/local/nrpe/libexec/
cp /usr/local/nagios/libexec/check_ping /usr/local/nrpe/libexec/
cp /usr/local/nagios/libexec/check_procs /usr/local/nrpe/libexec/
chown -R nagios:nagios /usr/local/nrpe/libexec/

#在/usr/local/nagios/etc/objects/commands.cfg中适当位置加入下面内容,我加在check_ssh和check_dhcp中间了
vi /usr/local/nagios/etc/objects/commands.cfg
#----------------------------引用文字-开始----------------------------
# 'check_nrpe' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
#----------------------------引用文字-结束----------------------------
####################################

####################################
(8)配置nrpe
mkdir /usr/local/nrpe/etc
cp sample-config/nrpe.cfg /usr/local/nrpe/etc/

#修改下边的几个选项
#server_address=按实际情况修改
#allowed_hosts=允许被哪些机器监控
#----------------------------引用文字-开始----------------------------
server_address=127.0.0.1
allowed_hosts=127.0.0.1
#----------------------------引用文字-结束----------------------------

#命令部分根据实际情况调整,比如硬盘,此处我注释了check_hda1命令,改为全部硬盘
#----------------------------引用文字-开始----------------------------
#command[check_hda1]=/usr/local/nrpe/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_df]=/usr/local/nrpe/libexec/check_disk -w 20% -c 10%
#----------------------------引用文字-结束----------------------------

#把nrpe增加为服务
cp init-script /etc/init.d/nrpe
chmod 755 /etc/init.d/nrpe
chkconfig --add nrpe
chkconfig --level 3 nrpe on
####################################

####################################
(9)安装飞信机器人
cd /usr/local/src/
rpm -Uvh libstdc++-4.3.0-8.x86_64.rpm
tar xvf fetion20090406003-linux.tar.gz
tar xvf library_linux.tar.gz
mv install ../sms
mv libACE* /usr/local/lib64/
mv libcrypto.so.0.9.8 /usr/local/lib64/
mv libssl.so.0.9.8 /usr/local/lib64/
echo "/usr/local/lib64/" >> /etc/ld.so.conf
ldconfig
chown -R nagios:nagios /usr/local/sms
chmod 755 /usr/local/sms/fetion

#最好能切换到nagios发短信测试一下
su nagios
#13744444444发短信所用的手机号
#jiubugaosuni为13744444444密码
#13712345678改为你自己的手机号
/usr/local/sms/fetion --mobile=13744444444 --pwd=jiubugaosuni --to=13712345678 --msg-utf8=test
#别忘了回到root用户
exit

#加入短信报警的命令,我加在email部分下边了
vi commands.cfg
#----------------------------引用文字-开始----------------------------
# 'notify-host-by-sms' command definition
define command{
command_name notify-host-by-sms
command_line /usr/local/sms/fetion --mobile=13744444444 --pwd=jiubugaosuni --to=$CONTACTPAGER$ --msg-utf8="$NOTIFICATIONTYPE$ $HOSTNAME$ $SERVICEDESC$ is $SERVICESTATE$ info: $SERVICEOUTPUT$"
}
# 'notify-service-by-sms' command definition
define command{
command_name notify-service-by-sms
command_line /usr/local/sms/fetion --mobile=13744444444 --pwd=jiubugaosuni --to=$CONTACTPAGER$ --msg-utf8="$NOTIFICATIONTYPE$: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$"
}
#----------------------------引用文字-结束----------------------------

#修改contacts.cfg和contactgroups.cfg相关信息,主要是手机号
####################################

####################################
(10)重启nagios服务,验证对主监控机本身的监控情况
#测试一下配置文件,看是否有错误输出
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios restart
#用浏览器打开http://ip/nagios/看一下情况
####################################

####################################
(11)在被监控机上安装nagios-plugins和nrpe
useradd -m nagios
cd /usr/local/src/
tar xvf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
cd ../
tar xvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make
make install
mkdir /usr/local/nagios/etc/
cp sample-config/nrpe.cfg /usr/local/nagios/etc/

#修改/usr/local/nagios/etc/nrpe.cfg下边的几个选项
#server_address=按实际情况修改
#allowed_hosts=允许被哪些机器监控
#----------------------------引用文字-开始----------------------------
server_address=10.0.0.166
allowed_hosts=127.0.0.1,10.0.0.52,10.0.0.166
#----------------------------引用文字-结束----------------------------
#命令部分根据实际情况调整,比如硬盘,此处我注释了check_hda1命令,改为全部硬盘
#----------------------------引用文字-开始----------------------------
#command[check_hda1]=/usr/local/nrpe/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_df]=/usr/local/nrpe/libexec/check_disk -w 20% -c 10%
#----------------------------引用文字-结束----------------------------
cp init-script /etc/init.d/nrpe
chmod 755 /etc/init.d/nrpe
chkconfig --add nrpe
chkconfig --level 3 nrpe on
####################################

####################################
(12)如何添加一台被监控机
#步骤:
#a.保证被监控机已经正确安装nagios-plugins和nrpe
#b.在hosts.cfg定义这台被监控机。把主机定义这部分复制粘贴后稍做修改即可
#c.在hostgroups.cfg定义这台机器应该属于哪些组
#d.需要监控的服务未在servicegroups被定义时在services.cfg中定义
####################################

####################################
(13)监控一台mysql服务器需注意
#编译nagios-plugins时需要加上--with-mysql=/usr/local/mysql(你的mysql安装路径)
#./configure --with-mysql=/usr/local/mysql --with-nagios-user=nagios --with-nagios-group=nagios
#在被监控机上做相关操作
#实际是以一个只有查询权限的用户nrpe来查询一个空数据库nrpe。功能等于mysqladmin -u 用户 --password='密码' status -i 2
mysql -p
#----------------------------引用文字-开始----------------------------
mysql> create database nrpe;
mysql> grant select on nrpe.* to nrpe@localhost identified by 'password' with grant option;
mysql> grant select on nrpe.* to nrpe@主监控机ip identified by 'password' with grant option;
#----------------------------引用文字-结束----------------------------
#试运行,会输出mysql运行情况
/usr/local/nagios/libexec/check_mysql -u nrpe -d nrpe
#在监控机所在的服务器上试运行(需要mysql_client)
/usr/local/nagios/libexec/check_mysql -H 10.0.0.166 -u nrpe -d nrpe
####################################

####################################
(14)监控一台web服务器时,可以采用nrpe来监控
#在主监控机的services.cfg中如需调用check_http命令的改为调用check_nrpe!check_http
#在被监控机中的nrpe.cfg中加下条
#----------------------------引用文字-开始----------------------------
command[check_http]=/usr/local/nagios/libexec/check_http -H www.chengyongxu.com -u /index.php
#----------------------------引用文字-结束----------------------------
#也就是说访问这台web服务器上的一个页面,这个页面正常说明web服务正常

CentOS+memcached

Posted by – 2009-05-15


####################################
#CentOS+memcached #
#Author:楚霏 #
#Date: 2009-5-15 #
#Env: Centos 5.3 x86_64 #
####################################
一、准备工作
环境:Centos 5.3 x86_64
所需软件:
libevent
memcached服务端与客户端
libmemcached
####################################
下载相关软件
cd /usr/local/src
wget http://monkey.org/~provos/libevent-1.4.10-stable.tar.gz
wget http://danga.com/memcached/dist/memcached-1.3.0.tar.gz
wget http://pecl.php.net/get/memcached-0.1.5.tgz
wget http://download.tangent.org/libmemcached-0.28.tar.gz
####################################
二、安装
(1)安装memcached的服务端支持库
cd /usr/local/src
tar xvf libevent-1.4.10-stable.tar.gz
cd libevent-1.4.10-stable
./configure --help
./configure
make
make install
(2)安装memcached服务器端
cd /usr/local/src
tar xvf memcached-1.3.0.tar.gz
./configure
make
make install
ln -s /usr/local/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2
(3)安装libmemcached
cd /usr/local/src
tar xvf libmemcached-0.28.tar.gz
cd libmemcached-0.28
./configure
make
make install
(4)让php支持memcached
cd /usr/local/src
tar xvf memcached-0.1.5.tgz
cd memcached-0.1.5
/usr/local/php-fcgi/bin/phpize
./configure --help
./configure --enable-memcache --with-php-config=/usr/local/php-fcgi/bin/php-config
make
make test
make install
cp /usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-200*/memcached.so /usr/local/php-fcgi/ext/
echo "extension=memcached.so" >> /usr/local/php-fcgi/etc/php.ini
#测试一下是否已加载上
/usr/local/php-fcgi/bin/php-cgi -m |grep mem
(5)启动
#启动memcached
#看一下启动参数
memcached --help
memcached -d -u root -m 1000 -l 127.0.0.1 -p 11211 -P /tmp/memcached.pid
#重启一下web服务器
service nginx restart

iRedMail解决方案

Posted by – 2009-05-09

#########################
#iRedMail解决方案       #
#Author: 楚霏            #
#Date: 2009-4-14        #
#Env: Centos 5.2 x86_64    #
#########################
一、准备工作:
环境:Centos 5.2 x86_64
所需软件:
iRedMail-0.4.0.tar.bz2
####################################
下载相关软件
wget http://iredmail.googlecode.com/files/iRedMail-0.4.0.tar.bz2
####################################
二、安装配置
(1)配置系统主机名
hostname mail.chengyongxu.com
#修改与主机名有关的两个文件
vi /etc/sysconfig/network
#----------------------------引用文字-开始----------------------------
HOSTNAME=mail.chengyongxu.com
#----------------------------引用文字-结束----------------------------
vi /etc/hosts
#----------------------------引用文字-开始----------------------------
127.0.0.1       localhost.localdomain localhost mail.chengyongxu.com mail
::1             localhost6.localdomain6 localhost6
################################################
127.0.0.1       mail.chengyongxu.com
127.0.0.1       pop3.chengyongxu.com
127.0.0.1       smtp.chengyongxu.com
#----------------------------引用文字-结束----------------------------
(2)解压安装
cd /usr/local/src
tar xvf iRedMail-0.4.0.tar.bz2
cd iRedMail-0.4.0/pkgs/
#建议先看一下下载相关软件包的这个脚本
less get_all.sh
#运行,下载相关软件并且会生成/etc/yum.repos.d/iRedMail.repo
sh get_all.sh
#其实下载的都是基于postfix+dovecot+clamav的相关包。漫长的等待,直到下载完毕。进行安装
cd ..
sh iRedMail.sh
#此时会出现安装进程的欢迎页面
#选择用于存储所有邮件的目录
#选择使用哪种程序来存储虚拟域和虚拟用户
#设置 MySQL 数据库的 root 用户的密码
#设置用于管理所有虚拟域的数据库管理员 vmailadmin 的密码
#设置邮件服务器的第一个虚拟域。例如:chengyongxu.com,chengyongxu.cn
#设置上面定义的虚拟域的管理员名称,默认的是 postmaster。
#设置虚拟域管理员的密码
#设置第一个普通的虚拟用户,如:user1
#设置上面定义的普通虚拟用户的密码
#选择是否使用managesieve服务,该服务用于提供给您的邮件用户自定义邮件过滤规则,以及假期自动回复等功能。建议使用
#选择是否为您的邮件服务提供 POP3, POP3S, IMAP,IMAPS 服务。建议选择该服务
#选择额外的软件。
#PostfixAdmin:作为虚拟域、虚拟用户的管理工具;
#Awstats:作为 Apache 和邮件的日志分析工具;
#Mailgraph:作为查看邮件收发情况简单工具。
#如果您选择了 PostfixAdmin,需要设置邮件虚拟域的全局管理员,该管理员可以管理所有虚拟域与虚拟用户。
#如果您选择了 Awstats 作为 web 和邮件日志分析工具,需要配置用于访问该程序的用户名和密码
#设置操作系统的root用户的邮件别名,必须是邮件地址。
#开始自动安装软件包,并对安装好的软件包进行自动配置
#安装完成后建议查看/usr/local/src/iRedMail目录下的iRedMail.tips文件,这里保存了密码和相关软件的配置信息。
#安装完毕后,对apache进行适宜的配置,如主机名、DocumentRoot和虚拟主机等,不再赘述。
#对DocumentRoot下的相关目录建议重命名,postfixadmin、awstats、pma能有验证机制更好
ls /var/www/
awstats  error  icons                              postfixadmin-2.2.1.1
cgi-bin  html   phpMyAdmin-2.11.9.4-all-languages  roundcubemail-0.2-stable
#登录http://mail.chengyongxu.com,就可进行收发邮件等操作。
#Thunderbird和Foxmail等邮件客户端工具的接收服务器填pop3.chengyongxu.com,发送服务器填smtp.chengyongxu.com
#完

Varnish2搭建缓存服务器

Posted by – 2009-05-07


####################################
#Varnish_configuration             #
#Author:楚霏                       #
#Date: 2009-3-27                   #
#Env: Centos 5.2 x86_64            #
####################################
一、准备工作
环境:Centos 5.2 x86_64
所需软件:
gcc            #4.2.0以上版本
varnish-2.0.?.tar.gz
####################################
下载相关软件
http://sourceforge.net/project/showfiles.php?group_id=155816
####################################
二、安装过程
(1)创建运行Varnish的用户和组,以及Varnish缓存文件存放目录(/vcache):
groupadd www -g 48 && useradd -u 48 -g www www
mkdir -p /vcache && chmod +w /vcache
chown -R www:www /vcache
(2)创建Varnish日志目录(/var/logs/):
mkdir -p /var/logs
chmod +w /var/logs
chown -R www:www /var/logs
(3)安装
cd /usr/local/src
tar xvf varnish-2.0.?.tar.gz
./configure --prefix=/usr/local/varnish
make && make install
三、配置
vi /usr/local/varnish/etc/varnish/vcl.conf
#----------------------------引用文字-开始----------------------------
#backend vhost
backend  bbs {
.host = "yourserverip";
.port = "80";
}

backend  www {
.host = "yourserverip";
.port = "80";
}

#acl
acl purge {
"localhost";
"127.0.0.1";
"10.0.0.1"/24;
}

sub vcl_recv {
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
lookup;
}

if (req.http.host ~ "^bbs.chengyongxu.com") {
set req.backend = bbs;}
elseif (req.http.host ~ "^(www)|(bbs).chengyongxu.com") {
set req.backend = www;}
else {
error 404 "Not found!";
}

if (req.request != "GET" && req.request != "HEAD") {
pipe;
}
elseif (req.url ~ "\.(php|cgi)($|\?)")
{
pass;
}
lookup;
}

sub vcl_hit {
if (req.request == "PURGE") {
set obj.ttl = 0s;
error 200 "Purged.";
}
}

sub vcl_miss {
if (req.request == "PURGE") {
error 404 "Not in cache.";
}
}

sub vcl_fetch {
if (req.request == "GET" && req.url ~ "\.(txt|js|css)[ DISCUZ_CODE_1 ]quot;") {
set obj.ttl = 10s;
}
else {
set obj.ttl = 1d;
}
}
#----------------------------引用文字-结束----------------------------
四、启动
/usr/local/varnish/sbin/varnishd -n /vcache -f /usr/local/varnish/etc/varnish/vcl.conf -a 0.0.0.0:80 -s file,/vcache/varnish_cache.data,1G -g www -u www -T 127.0.0.1:3500 -p thread_pool_max=2048 -p thread_pools=4 -p client_http11=on
五、常见操作
#先看一下帮助
/usr/local/varnish/bin/varnishadm -T 127.0.0.1:3500 help
#----------------------------引用文字-开始----------------------------
help [command]
ping [timestamp]
status
start
stop
stats
vcl.load <configname> <filename>
vcl.inline <configname> <quoted_VCLstring>
vcl.use <configname>
vcl.discard <configname>
vcl.list
vcl.show <configname>
param.show [-l] [<param>]
param.set <param> <value>
quit
purge.url <regexp>
purge.hash <regexp>
purge <field> <operator> <arg> [&& <field> <oper> <arg>]...
purge.list
#----------------------------引用文字-结束----------------------------
#查看连接数与命中率
/usr/local/varnish/bin/varnishadm -T 127.0.0.1:3500 stats | less

nginx+mysql+php配置

Posted by – 2009-01-19

#########################
# Nginx Configuration #########
# Author: hao32#############
# Update: 楚霏##############
# Date: 2009-1-19###########
# Env: Centos 5.2 x86_64#####
######################
一. 分区完毕后, 关闭selinux等不必要的服务等等, 重启下系统:
相关文件
/etc/selinux/config    selinux配置文件
chkconfig    管理服务
dmesg    查看系统是否有报错等信息
###########################################################

二. 配置加速yum
cd /etc/yum.repos.d
cp CentOS-Base.repo--  CentOS-Base.repo.bak
vi CentOS-Base.repo
加入内容如下:
#----------------------------引用文字-开始----------------------------
[base]
name=CentOS-5 - Base
baseurl=http://centos.ustc.edu.cn/centos/5/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#released updates
[update]
name=CentOS-5 - Updates
baseurl=http://centos.ustc.edu.cn/centos/5/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#packages used/produced in the build but not released
[addons]
name=CentOS-5 - Addons
baseurl=http://centos.ustc.edu.cn/centos/5/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras]
name=CentOS-5 - Extras
baseurl=http://centos.ustc.edu.cn/centos/5/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-5 - Plus
baseurl=http://centos.ustc.edu.cn/centos/5/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS-5 - Contrib
baseurl=http://centos.ustc.edu.cn/centos/5/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#packages in testing
[testing]
name=CentOS-5 - Testing
baseurl=http://centos.ustc.edu.cn/centos/5/testing/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#----------------------------引用文字-结束----------------------------
###########################################################

三. 准备工作:
yum -y update
安装如下软件包:
yum install -y wget at ntp sysstat vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel curl curl-devel patch make libtool gettext-devel mlocate zlib zlib-devel compat-libstdc* libxml2 libxml2-devel openssl-devel e2fsprogs-devel krb5-devel libidn-devel *g77
###########################################################

四. 准备如下软件包(尽量都去官方站点去下载最新的release):
gd-2.0.35.tar.gz
pcre-7.8.tar.gz
libmcrypt-2.5.8.tar.bz2
libxml2-2.7.2.tar.gz
php-5.2.8-fpm-0.5.10.diff.gz
php-5.2.8.tar.bz2
mysql-5.1.30-linux-x86_64-icc-glibc23.tar.gz
nginx-0.6.34.tar.gz
eaccelerator-0.9.5.3.tar.bz2
ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz
###########################################################

cd /usr/local/src
wget http://www.libgd.org/releases/gd-2.0.35.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz
wget ftp://xmlsoft.org/libxml2/libxml2-2.7.2.tar.gz
wget http://php-fpm.anight.org/downloads/head/php-5.2.8-fpm-0.5.10.diff.gz
wget http://sysoev.ru/nginx/nginx-0.6.34.tar.gz
wget http://downloads.phpchina.com/zend/optimizer/3.3.3/ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz
wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
下面几个软件下载后上传至服务器
#http://www.php.net/get/php-5.2.8.tar.bz2/from/a/mirror
php-5.2.8.tar.bz2

#http://nchc.dl.sourceforge.net/sourceforge/mcrypt/
#http://sourceforge.net/project/showfiles.php?group_id=87941&package_id=91774&release_id=487459
libmcrypt-2.5.8.tar.bz2

#http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.30-linux-x86_64-icc-glibc23.tar.gz/from/pick#mirrors
mysql-5.1.30-linux-x86_64-icc-glibc23.tar.gz
###########################################################

五. 开始安装过程:
tar jxvf php-5.2.8.tar.bz2
gzip -cd php-5.2.8-fpm-0.5.10.diff.gz | patch -d php-5.2.8 -p1
#编译 php 增加此参数 --enable-fpm
(1)安装GD库和PHP支持相关的库
tar xvf gd-2.0.3?.tar.gz; cd gd-2.0.3?/
./configure --prefix=/usr/local/gd2
make
make install
(2) LibXML2
cd /usr/local/src
tar zxvf libxml2-2.7.2.tar.gz; cd libxml2-2.7.2
./configure --prefix=/usr/local/libxml2
make
make install
(3) LibMcrypt
cd /usr/local/src
tar xjvf libmcrypt-2.5.8.tar.bz2; cd libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt
make
make install
(4) MySQL服务的安装
cd /usr/local/src
tar zxvf mysql-5.1.30-linux-x86_64-icc-glibc23.tar.gz
mv mysql-5.1.30-linux-x86_64-icc-glibc23 /usr/local/
ln -s /usr/local/mysql-5.1.30-linux-x86_64-icc-glibc23 /usr/local/mysql
useradd mysql -M
chown -R mysql:root /usr/local/mysql/
cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
vi /etc/my.cnf
----------------- my.cnf说明 -------------------
务必指定datadir的位置, 一般是/var/lib/mysql
------------------------------------------------
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 3 mysqld on
chown -R mysql:mysql /var/lib/mysql
cd /usr/local/mysql/bin
for i in *; do ln -s /usr/local/mysql/bin/$i /usr/bin/$i; done
(5) 编译PHP(fastcgi模式)
cd /usr/local/src/php-5.2.8
./configure --prefix=/usr/local/php-fcgi --enable-fastcgi --enable-fpm --enable-discard-path --enable-force-cgi-redirect --with-config-file-path=/usr/local/php-fcgi/etc --enable-zend-multibyte --with-mysql=/usr/local/mysql --with-libxml-dir=/usr/local/libxml2 --with-gd=/usr/local/gd2 --with-jpeg-dir --with-png-dir --with-bz2 --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-curl --with-mcrypt=/usr/local/libmcrypt --enable-sysvsem --enable-inline-optimization --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-debug --disable-ipv6
make
make install
cp php.ini-dist /usr/local/php-fcgi/etc/php.ini
(6) 安装ZendOptimizer
cd /usr/local/src; tar zxvf ZendOptimizer-3.3.?-linux-glibc23-x86_64.tar.gz
cd ZendOptimizer-3.3.?-linux-glibc23-x86_64; ./install
----------------- 安装ZendOptimizer说明 ------------------
基本上是一直回车, 值得注意一点的是:
当您看到要选择php的路径时就写:
/usr/local/php-fcgi/etc
看到Are you using Apache Web server?
选NO
-----------------------------------------------------------
(7) 安装eaccelerator
cd ../ ;tar jxvf eaccelerator-0.9.?.?.tar.bz2
cd eaccelerator-0.9.?.?
/usr/local/php-fcgi/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php-fcgi/bin/php-config
make
make install
mkdir /tmp/eaccelerator && chmod 777 /tmp/eaccelerator && touch /var/log/eaccelerator_log && mkdir /usr/local/php-fcgi/ext
mv /usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so /usr/local/php-fcgi/ext/

(8) 编辑php.ini
mv /usr/local/php-fcgi/etc/php.ini /usr/local/php-fcgi/etc/php.ini.chushibak
#把extension_dir = "./" 修改成: extension_dir = "/usr/local/php-fcgi/ext/"
sed 's/extension_dir = "./"/extension_dir = "/usr/local/php-fcgi/ext/"/g' /usr/local/php-fcgi/etc/php.ini.chushibak >>/usr/local/php-fcgi/etc/php.ini
cat <<EOF>>/usr/local/php-fcgi/etc/php.ini
#----------------------------引用文字-开始----------------------------
extension=eaccelerator.so
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.log_file = "/var/log/eaccelerator_log"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
EOF
#----------------------------引用文字-结束----------------------------
(7) 创建nginx运行用户和虚拟主机目录
groupadd www -g 78 ; useradd -u 78 -g www www -M
mkdir -p /www/wwwroot/test.com
chown  www:www /www/wwwroot
(8) nginx的安装与配置
安装Nginx所需的pcre库:
tar xvf pcre-7.8.tar.gz ; cd pcre-7.8/
./configure
make && make install
安装Nginx:
cd /usr/local/src ; tar xvf nginx-0.6.3?.tar.gz ; cd nginx-0.6.3?
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log  --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/var/nginx.pid --lock-path=/usr/local/nginx/var/nginx.lock --without-select_module --without-poll_module --with-http_realip_module --with-http_sub_module   --with-http_gzip_static_module --with-http_stub_status_module --without-http_ssi_module --without-http_userid_module --without-http_geo_module --without-http_memcached_module --without-http_map_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module
make && make install
cd /usr/local/nginx/conf/ ; cp nginx.conf nginx.conf.bak
vi nginx.conf
加入以下内容(事例):
#----------------------------引用文字-开始----------------------------
daemon on;
user www www;
worker_rlimit_nofile 8192;
worker_processes 4;
error_log logs/error.log error;
#pid var/nginx.pid;
lock_file var/nginx.lock;
events {
worker_connections  4096;
use epoll;
multi_accept on;
}
http {
include       mime.types;
default_type  application/octet-stream;
server_names_hash_max_size 512;
server_names_hash_bucket_size 128;
sendfile       off;
tcp_nopush     off;
tcp_nodelay    on;
keepalive_timeout  3;
client_max_body_size  2m;
client_header_timeout 30;
client_body_timeout   30;
send_timeout          30;
fastcgi_connect_timeout 300;
fastcgi_send_timeout    300;
fastcgi_read_timeout    300;
client_header_buffer_size    1k;
large_client_header_buffers  4 4k;
gzip_static on;
gzip_min_length  1024;
gzip_buffers     4 8k;
gzip_http_version 1.1;
gzip_comp_level 1;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log combined;
# include virtual host config
include vhosts/test.com;
}
#----------------------------引用文字-结束----------------------------
mkdir vhost
vi test.com
添加如下内容(事例):
#----------------------------引用文字-开始----------------------------
server {
listen       80;
server_name test.com www.test.com;
access_log  logs/test.com-access.log combined buffer=32k;
error_log   logs/test.com-error.log crit;
location / {
index           index.html index.htm index.php;
root            /www/wwwroot/test.com;
}
location ~ .php$ {
include fastcgi_params;
fastcgi_pass  unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/wwwroot/test.com$fastcgi_script_name;
}

}
#----------------------------引用文字-结束----------------------------

编辑fpm配置文件:
vi /usr/local/php-fcgi/etc/php-fpm.conf
加入如下内容:
#----------------------------引用文字-开始----------------------------
<?xml version="1.0" ?>
<configuration>
<section name="global_options">
<value name="pid_file">/usr/local/php-fcgi/logs/php-fpm.pid</value>
<value name="error_log">/usr/local/php-fcgi/logs/php-fpm.log</value>
<value name="log_level">notice</value>
<value name="emergency_restart_threshold">10</value>
<value name="emergency_restart_interval">1m</value>
<value name="process_control_timeout">5s</value>
<value name="daemonize">yes</value>
</section>
<workers>
<section name="pool">
<value name="name">default</value>
<value name="listen_address">/tmp/php-fcgi.sock</value>
<value name="listen_options">
<value name="backlog">-1</value>
<value name="owner">www</value>
<value name="group">www</value>
<value name="mode">0666</value>
</value>.
<value name="php_defines">
<!--            <value name="sendmail_path">/usr/sbin/sendmail -t -i</value>            -->
<!--            <value name="display_errors">0</value>                                                          -->
</value>
<value name="user">www</value>
<value name="group">www</value>
<value name="pm">
<value name="style">static</value>
<value name="max_children">100</value>
<value name="apache_like">
<value name="StartServers">20</value>
<value name="MinSpareServers">5</value>
<value name="MaxSpareServers">35</value>
</value>
</value>
<value name="request_terminate_timeout">31s</value>
<value name="request_slowlog_timeout">0s</value>
<value name="slowlog">logs/slow.log</value>
<value name="rlimit_files">4096</value>
<value name="rlimit_core">0</value>
<value name="chroot"></value>
<value name="chdir"></value>
<value name="catch_workers_output">yes</value>
<value name="max_requests">500</value>
<value name="allowed_clients">127.0.0.1</value>
<value name="environment">
<value name="HOSTNAME">$HOSTNAME</value>
<value name="PATH">/usr/local/bin:/usr/bin:/bin</value>
<value name="TMP">/tmp</value>
<value name="TMPDIR">/tmp</value>
<value name="TEMP">/tmp</value>
<value name="OSTYPE">$OSTYPE</value>
<value name="MACHTYPE">$MACHTYPE</value>
<value name="MALLOC_CHECK_">2</value>
</value>
</section>
</workers>
</configuration>
#----------------------------引用文字-结束----------------------------
创建nginx的启动脚本:
vi /etc/init.d/nginx
#----------------------------引用文字-开始----------------------------
#! /bin/bash
#
# nginx          Start/Stop the nginx daemon.
#
# chkconfig: 2345 90 60
# description: nginx
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid

# Source function library.
. /etc/init.d/functions

# Nginx Settings
NGX_PID_FILE='/usr/local/nginx/var/nginx.pid'
NGX_PROC='/usr/local/nginx/sbin/nginx'
NGX_LOCK_FILE='/var/lock/subsys/nginx'
PHP_FPM='/usr/local/php-fcgi/sbin/php-fpm'

# Progran name
prog="nginx"

start() {
ulimit -HSn 65536
echo -n $"Starting $prog: "
if [ -e $NGX_LOCK_FILE ]; then
if [ -e $NGX_PID_FILE ] && [ -e /proc/`cat $NGX_PID_FILE` ]; then
echo -n $"cannot start $prog: nginx is already running."
failure $"cannot start $prog: nginx is already running."
echo
return 1
fi
fi
$NGX_PROC
RETVAL=$?
[ $RETVAL -eq 0 ] && success $"$prog start" || failure $"$prog start"
[ $RETVAL -eq 0 ] && touch $NGX_LOCK_FILE
echo

#php-fpm
$PHP_FPM start
return $RETVAL
}

stop() {
echo -n $"Stopping $prog: "
if [ ! -e $NGX_LOCK_FILE ] || [ ! -e $NGX_PID_FILE ]; then
echo -n $"cannot stop $prog: nginx is not running."
failure $"cannot stop $prog: nginx is not running."
echo
return 1
fi
PID=`cat $NGX_PID_FILE`
if checkpid $PID 2>&1; then
# TERM first, then KILL if not dead
kill -TERM $PID >/dev/null 2>&1
usleep 100000
if checkpid $PID && sleep 1 && checkpid $PID && sleep 3 && checkpid $PID; then
kill -KILL $PID >/dev/null 2>&1
usleep 100000
fi
fi
checkpid $PID
RETVAL=$((! $?))
[ $RETVAL -eq 0 ] && success $"$prog shutdown" || failure $"$prog shutdown"
[ $RETVAL -eq 0 ] && rm -f $NGX_LOCK_FILE;
echo

#php-fpm
$PHP_FPM stop
return $RETVAL
}

status() {
status $prog
}

restart() {
stop
start
}

reload() {
echo -n $"Reloading $prog: "
if [ ! -e $NGX_LOCK_FILE ] || [ ! -e $NGX_PID_FILE ]; then
echo -n $"cannot reload $prog: nginx is not running."
failure $"cannot reload $prog: nginx is not running."
echo
return 1
fi
kill -HUP `cat $NGX_PID_FILE` >/dev/null 2>&1
RETVAL=$?
[ $RETVAL -eq 0 ] && success $"$prog reload" || failure $"$prog reload"
echo
return $RETVAL
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
status)
status
;;
condrestart)
[ -f $NGX_LOCK_FILE ] && restart || :
;;
configtest)
$NGX_PROC -t
;;
*)
echo $"Usage: $0 {start|stop|status|reload|restart|condrestart|configtest}"
exit 1
esac
#----------------------------引用文字-结束----------------------------
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level 3 nginx on
启动nginx:
service nginx start
启动mysql:
service mysqld restart

设定mysql的root密码
mysql> update mysql.user set password=PASSWORD('新密码') where User='root';
mysql> flush privileges;
mysql> quit