yum groupinstall "Development tools"
yum install vim
yum install gcc openssh openssh-devel pcre-devel zlib-devel
yum install libevent
tar xf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure
make && make install
ldconfig -v |grep libevent
cd
tar xf nginx-1.4.3
cd nginx-1.4.3
groupadd -r nginx
useradd -r -g nginx -s /bin/false -M nginx
./configure \
--prefix=/usr/local/webserver/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--with-pcre
make && make install
为nginx 配置启动脚本
在/etc/rc.d/init.d/目录下新建文件nginx,添加如下内容
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=([^ ]*).*/1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
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
}
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|configtest)
$1
;;
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|configtest}"
exit 2
esac
然后在赋予该脚本执行权限 chmod +x /etc/rc.d/init.d/nginx
chkconfig –add nginx
chkconfig nginx on
service nginx start 就可以启动nginx了
安装mysql
yum install mysql mysql-server mysql-devel
service mysqld start
chkconfig mysqld on
mysqladmin -u root password "qaz,./"
service mysqld start
yum install php lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy php-common php-devel php-fpm
service php-fpm start
chkconfig php-fpm on
建立网站目录
mkdir -p /data0/www
//修改nginx配置文件,优化nginx,添加fastcgi(PHP)支持
[root@CentOS ~]# vi /etc/nginx/nginx.conf
//优化段
#user  nobody;
user nginx nginx;
worker_processes  2;
worker_cpu_affinity 01 10;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
worker_rlimit_nofile 10240;
events {
use epoll;
worker_connections  10240;
}
http {
include       mime.types;
default_type  application/octet-stream;
#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  main;
sendfile        on;
tcp_nopush     on;
#keepalive_timeout  0;
keepalive_timeout  30;
tcp_nodelay on;
fastcgi_buffers 2 256k;
fastcgi_buffer_size 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
proxy_connect_timeout 100;
proxy_read_timeout 30;
proxy_buffer_size 8k;
proxy_buffers 8 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
gzip  on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain text/javascript application/x-javascript text/css application/xml;
gzip_vary on;
//加入index.php,并将默认根目录设置成/data0/www
server {
listen       80;
server_name  localhost;
#charset koi8-r;
#access_log  logs/host.access.log  main;
location / {
root   /data0/www;
index  index.php index.html index.htm;
}
#error_page  404              /404.html;
# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /data0/www;
}
//将以下代码注释去掉,并修改成nginx根路径
location ~ \.php$ {
root           html;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /data0/www$fastcgi_script_name;  //注意$符前路径为nginx的网站路径
include        fastcgi_params;
}
配置php
//编辑文件php.ini,找到并去掉注释cgi.fix_pathinfo = 1
重启nginx php-fpm
service nginx restart
service php-fpm restart
在/data0/www/ 下建立phpinfo.php文件,访问测试。
vi phpinfo.php
<?php
phpinfo();
?>
安装配置cacti
yum install net-snmp net-snmp-utils net-snmp-devel rrdtool rrdtool-perl rrdtool-devel
cacti官网下载并解压
tar zxvf cacti-0.8.8b.tar.gz
将文件放到网站目录
mv cacti-0.8.8b /data0/www/cacti
增加cacti用户,用以在该用户下建立执行poller的cron
useradd cacti
将cacti目录下的rra和log目录赋给cacti用户
cd /data0/www/cacti/
chown -R cacti:cacti rra/ log
建立cron
crontab -u cacti -e
cron内容
MAILTO=""
*/5 * * * * /usr/bin/php /data0/www/cacti/poller.php &>/dev/null
登陆http://ip/cacti/进行安装
被监控的linux服务器需要安装net-snmp包(yum即可),安装后更改snmpd.conf文件
vi /etc/snmp/snmpd.conf
更改段:
#       sec.name  source          community
com2sec notConfigUser  58.30.241.221     public
# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#       name           incl/excl     subtree         mask(optional)
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
disk / 10000
更改后重启snmpd服务
service snmpd restart
chkconfig snmpd on
被监控的windows服务器需要设置snmp service服务,在安全里建立public社区,设置cacti服务器的ip地址。
如果使用Cacti_SNMP_INFORMANT_STD_W32_Metrics.zip模板,需要在windows服务器上安装informant-std-16.zip(http://www.wtcs.org/informant/download.htm)
模板Cacti_SNMP_INFORMANT_STD_W32_Metrics.zip
解压后10个文件
cacti_data_query_w32_-_cpu_statistics.xml
cacti_data_query_w32_-_network_statistics.xml
cacti_data_query_w32_-_disk_statistics.xml
cacti_data_query_w32_-_object_statistics.xml
cacti_data_query_w32_-_memory_statistics.xml
以上文件在cactit管理界面,Import Templates导入。
snmp_informant_disk.xml
snmp_informant_objects.xml
snmp_informant_memory.xml
snmp_informant_cpu.xml
snmp_informant_network.xml
以上文件copy到服务器cacti安装目录的resource/snmp_queries
登陆cacti地址进行配置。
添加Devices时,SNMP Version最好使用version 2,SNMP Community使用自己定义好的社区(默认和snmpd.conf中的一样是public)
安装spine,安装spine可以提升cacti性能和执行速度,在安装spine之前必须已经安装好了net-snmp net-snmp-devel(之前已经安装过);使用cmd.php来完成数据采集,发现cmd.php采集存在很大的延迟,执行效率太低。比较了一下,从添加device好到设备up,spine只需要不到一分钟,而cmd等的时间较长。
下载cacti-spine-0.8.8b.tar(与cacti版本对应)
tar xf cacti-spine-0.8.8b.tar
cd cacti-spine-0.8.8b.tar
./configure
make && make install
cd /usr/local/spine/
mv spine.conf.dist spine.conf
配置数据库
vi spine.conf
spine需要将配置文件放在/etc下才能运行,所以建立一个软连接
ln -s /usr/local/spine/etc/spine.conf /etc/spine.conf
测试,运行spine的运行文件
/usr/local/spine/bin/spine
配置cacti使用spine
在setting里配置Spine Poller File Path,spine执行二进制文件默认安装的位置是/usr/local/spine/bin/spine
在poller的Poller Type里将cmd.php更改为spine即可。