在CentOS 6.5上安装Collectd

在 CentOS 6.5 上安装 Collectd

#####准备工作

  • 更新源

    yum install wget
    
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
    
    yum makecache
    
    rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
    
    rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
    
    yum update
    
  • 修改主机名

    vi /etc/sysconfig/network
    HOSTNAME=monitor
    
  • 禁用selinux

    vi /etc/selinux/config
    SELINUX=disabled
    
  • 重启

    reboot
    
  • 安装依赖包

    yum -y install gcc gcc-c++ make pcre-devel openssl-devel libxml2-devel rrdtool rrdtool-devel rrdtool-prel libgcrypt-devel curl-devel libjpeg-devel libpng-devel freetype-devel gd git
    

#####安装Collectd

  • 下载解压

    wget https://collectd.org/files/collectd-5.4.1.tar.gz
    tar zxvf collectd-5.4.1.tar.gz
    cd collectd-5.4.1
    
  • 安装

    ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --libdir=/usr/lib --mandir=/usr/share/man --enable-all-plugins
    make
    make install	
    
  • 配置

    cd ~/collectd-5.4.1/contrib/redhat/
    cp init.d-collectd /etc/init.d/collectd
    
    chmod 755 /etc/init.d/collectd
    chown root:root /etc/init.d/collectd
    chkconfig --add collectd
    chkconfig collectd on
    
    vi /etc/collectd.conf
    
    Hostname "monitor"
    FQDNLookup true
    Interval 10
    Timeout 2
    ReadThreads 5
    LoadPlugin syslog
    <Plugin syslog>
    		LogLevel info
    </Plugin>
    LoadPlugin battery
    LoadPlugin cpu
    LoadPlugin df
    LoadPlugin disk
    LoadPlugin entropy
    LoadPlugin interface
    LoadPlugin irq
    LoadPlugin load
    LoadPlugin memory
    LoadPlugin network
    LoadPlugin processes
    LoadPlugin rrdtool
    LoadPlugin swap
    LoadPlugin users
    <Plugin network>
    	Listen "10.211.55.46" "25826"
    </Plugin>
    <Plugin rrdtool>
    	DataDir "/var/lib/collectd/rrd"
    </Plugin>
    
  • 启动

    /etc/init.d/collectd start
    
  • 重启

    /etc/init.d/collectd restart
    

#####安装 Nginx

  • 下载

    wget http://nginx.org/download/nginx-1.7.2.tar.gz
    tar zxvf nginx-1.7.2.tar.gz
    cd nginx-1.7.2
    
  • 编译安装

    ./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module
    make
    make install
    
    useradd -M -r --shell /bin/sh --home-dir /opt/nginx nginx
    
  • 设置启动脚本

    vi /etc/init.d/nginx
    
    
    #!/bin/sh
    #
    # nginx – this script starts and stops the nginx daemongg
    #
    # chkconfig: - 85 15
    # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
    # proxy and IMAP/POP3 proxy server
    # processname: nginx
    # config: /opt/nginx/conf/nginx.conf
    # pidfile: /opt/nginx/logs/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="/opt/nginx/sbin/nginx"
    prog=$(basename $nginx)
    
    NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"
    
    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
    }
    
    restart() {
    	configtest || return $?
    	stop
    	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 755 /etc/init.d/nginx
    service nginx start
    
  • 配置

    mkdir -p /data0/www
    mkdir -p /data0/logs
    
    vi /opt/nginx/conf/nginx.conf
    
    
    user  nginx nginx;
    worker_processes  8;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    pid        /opt/nginx/logs/nginx.pid;
    
    events {
    	use epoll;
    	worker_connections  1024;
    }
    
    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;
    	server_names_hash_bucket_size 128;
    	client_header_buffer_size 32k;
    	large_client_header_buffers 4 32k;
    	client_max_body_size 1024m;
    
    	sendfile        on;
    	tcp_nopush     on;
    
    	#keepalive_timeout  0;
    	keepalive_timeout  65;
    
    		tcp_nodelay on;
    		fastcgi_connect_timeout 300;
    		fastcgi_send_timeout 300;
    		fastcgi_read_timeout 300;
    		fastcgi_buffer_size 64k;
    		fastcgi_buffers 4 64k;
    		fastcgi_busy_buffers_size 128k;
    		fastcgi_temp_file_write_size 128k;
    
    		fastcgi_intercept_errors on;
    
    		gzip_min_length  1k;
    		gzip_buffers     4 16k;
    		gzip_http_version 1.0;
    		gzip_comp_level 2;
    		#       gzip_types       text/plain application/x-javascript text/css application/xml;
    		gzip_types       application/x-javascript text/css application/xml;
    		gzip_vary on;
    
    		gzip  on;
    
    
    include /opt/nginx/conf/sites-enabled/*;
    }
    
    mkdir -p /opt/nginx/conf/sites-enabled
    
    vi /opt/nginx/conf/sites-enabled/collectd.conf
    
    server {
    	server_name _;
    	access_log /data0/logs/access.log ;
    	error_log /data0/logs/error.log ;
    	root /data0/www;
    
    	error_page 404 /404.html;
    
    	location / {
    		index index.html index.htm index.php;
    	}
    
    	location ~ \.php$ {
    		include /opt/nginx/conf/fastcgi_params;
    		fastcgi_pass  127.0.0.1:9000;
    		fastcgi_index index.php;
    		fastcgi_param SCRIPT_FILENAME /data0/www$fastcgi_script_name;
    	}
    }
    

#####安装PHP

  • 下载

    wget -O ./php.tar.gz http://cn2.php.net/get/php-5.4.29.tar.gz/from/this/mirror
    tar zxvf php.tar.gz 
    
  • 编译安装

    cd php-5.4.2
    
    ./configure \
    --prefix=/opt/php \
    --with-gd \
    --with-jpeg-dir \
    --with-png-dir \
    --with-freetype-dir \
    --with-iconv \
    --with-zlib \
    --enable-xml \
    --enable-bcmath \
    --enable-shmop \
    --enable-sysvsem \
    --enable-inline-optimization \
    --with-curlwrappers \
    --enable-mbregex \
    --enable-fpm \
    --enable-mbstring \
    --enable-ftp \
    --enable-gd-native-ttf \
    --with-openssl \
    --enable-pcntl \
    --enable-sockets \
    --with-xmlrpc \
    --enable-zip \
    --enable-soap \
    --without-pear \
    --with-gettext \
    --enable-session \
    --with-curl \
    
    make 
    make install
    
  • 配置

    mv /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
    vi /opt/php/etc/php-fpm.conf
    
    pid = run/php-fpm.pid
    error_log = log/php-fpm.log
    process.max = 128
    daemonize = yesth-curl \
    
    mak= 50
    pm.start_servers = 4
    pm.min_spare_servers = 2
    pm.max_spare_servers = 10
    
  • 启动

    /opt/php/sbin/php-fpm 
    
安装 collectd 前端
  • 下载代码

    git clone  http://git.nethuis.nl/pub/cgp.git
    
安装 collectd 客户端
  • 安装

    yum install collectd
    
  • 配置

    vi /etc/collectd.conf 
    
    
    Hostname "clent1"
    FQDNLookup true
    LoadPlugin syslog
    <Plugin syslog>
    	LogLevel info
    </Plugin>
    LoadPlugin cpu
    LoadPlugin df
    LoadPlugin disk
    LoadPlugin entropy
    LoadPlugin interface
    LoadPlugin irq
    LoadPlugin load
    LoadPlugin memory
    LoadPlugin network
    LoadPlugin processes
    LoadPlugin swap
    LoadPlugin users
    <Plugin network>
    	Server "10.211.55.46" "25826"
    </Plugin>
    
  • 启动

    service collectd start
    
0%