计算机技术

CentOS下安装Munin监控服务器运行情况

1、切换到epel源

各版本对应命令如下:

CentOS 5.x 32bit

1
2
3
rpm -ivh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5
yum -y install yum-priorities

CentOS 5.x 64bit

1
2
3
rpm -ivh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5
yum -y install yum-priorities

CentOS 6.x 32bit

1
2
3
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
yum -y install yum-priorities

CentOS 6.x 64bit

1
2
3
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
yum -y install yum-priorities

2、安装Munin服务端、客户端

因为我只监控本机,不监控其他VPS,所以直接执行:

1
yum -y install munin munin-node

blob.png

安装完成

3、配置虚拟主机

因为Munin生成的全是静态文件,LANMP架构下我用的是Nginx,打开nginx/conf/vhost建立虚拟主机文件,这点根据自己实际的运行环境写,我的是这样:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
server {
        listen       80;
        server_name vps.94cb.com;
        root /www/web/vps/public_html;
        index  index.html index.php index.htm;
        error_page  400 /errpage/400.html;
        location ~ .php$ {
                proxy_pass http://127.0.0.1:88;
                include naproxy.conf;
        }
        location / {
                try_files $uri @apache;
        }
        location @apache {
                 proxy_pass http://127.0.0.1:88;
                 include naproxy.conf;
        }
}

因为Munin要往这里写入文件,一般这个目录是www用户才有写权限的,因此要给munin写权限,为了方便我直接执行:

1
chmod -R 777 /www/web/vps/public_html

4、修改Munin配置

执行指令编辑Munin配置文件

1
vi /etc/munin/munin.conf

可以看到配置文件开头一部分是这样的。我们去掉目录配置前面的注释符,并且修改htmldir为实际的虚拟主机路径,我Nginx中指定的路径是/www/web/vps/public_html

1
2
3
4
5
6
7
8
9
# The next three variables specifies where the location of the RRD
# databases, the HTML output, logs and the lock/pid files.  They all
# must be writable by the user running munin-cron.  They are all
# defaulted to the values you see here.
#
#dbdir  /var/lib/munin
#htmldir /var/www/html/munin
#logdir /var/log/munin
#rundir  /var/run/munin

修改后是这样的:

1
2
3
4
5
6
7
8
9
# The next three variables specifies where the location of the RRD
# databases, the HTML output, logs and the lock/pid files.  They all
# must be writable by the user running munin-cron.  They are all
# defaulted to the values you see here.
#
dbdir  /var/lib/munin
htmldir /www/web/vps/public_html
logdir /var/log/munin
rundir  /var/run/munin

5、启动Munin并设置开机自启

执行以下语句启动:

1
/etc/init.d/munin-node start

blob.png

执行以下语句添加服务并开机自启:

1
2
chkconfig --add munin-node
chkconfig munin-node on

5分钟后打开你在Web服务器中设置的虚拟主机(例如http://vps.94cb.com),可以看到效果。

想马上看到的话可以直接执行(munin-cron是munin的定时任务,5分钟调用一次,手动调用的话可以直接生成统计结果的静态网站,只能以munin用户启动),不急的就别管了。

1
su - munin --shell=/usr/bin/munin-cron

下面是Munin运行之后生成的统计图。

QQ图片20141210095657.jpg

QQ图片20141210095733.jpg

vda-day.pngif_eth0-day.png

Munin还有很多插件,安装教程可以看这里:

http://gallery.munin-monitoring.org/

我也会在下面继续演示一些我需要用到的插件的安装。

https://www.94cb.com/t/2301

Related Articles

发表回复

Check Also
Close
Back to top button