2012年5月26日 星期六

實用的 Cacti Monitoring Template


http://www.percona.com/downloads/percona-monitoring-plugins/

上述 URL 可以下載到許多實用的 Cacti Template , 安裝與使用的方式詳見

http://www.percona.com/doc/percona-monitoring-plugins/cacti/installing-templates.html
或 Percona_Monitoring_Plugins_100_Operations_Manual.pdf

以 WEB Server 來說它提供了
(1) cacti_host_template_percona_nginx_server_ht_0.8.6i-sver1.0.0.xml
(2) cacti_host_template_percona_apache_server_ht_0.8.6i-sver1.0.0.xml
這2個template

其它的還有:
 cacti_host_template_percona_gnu_linux_server_ht_0.8.6i-sver1.0.0.xml
 cacti_host_template_percona_jmx_server_ht_0.8.6i-sver1.0.0.xml
 cacti_host_template_percona_memcached_server_ht_0.8.6i-sver1.0.0.xml
 cacti_host_template_percona_mongodb_server_ht_0.8.6i-sver1.0.0.xml
 cacti_host_template_percona_mysql_server_ht_0.8.6i-sver1.0.0.xml
 cacti_host_template_percona_openvz_server_ht_0.8.6i-sver1.0.0.xml
 cacti_host_template_percona_redis_server_ht_0.8.6i-sver1.0.0.xml

所使用的scripts為:
(1)ss_get_mysql_stats.php
(2)ss_get_by_ssh.php

以 ss_get_by_ssh.php 必需使用 SSH key 的方式

vi ss_get_by_ssh.php

....
$ssh_user   = 'cactiuser';                          # SSH username
$ssh_port   = 22;                               # SSH port
$ssh_iden   = '-i /home/cactiuser/.ssh/id_rsa';  # SSH identity$ssh_tout   = 10;                               # SSH connect timeout
$nc_cmd     = 'nc -C -q1';                      # How to invoke netcat
$cache_dir  = '/tmp';  # If set, this uses caching to avoid multiple calls.
$poll_time  = 300; # Adjust to match your polling interval.
$timezone   = null;    # If not set, uses the system default.  Example: "UTC"
$use_ss     = FALSE; # Whether to use the script server or not
$use_ssh    = TRUE;  # Whether to connect via SSH or not (default yes).
$debug      = FALSE; # Define whether you want debugging behavior.
......

使用 SSH 自動 login 必需 vi /etc/ssh/sshd_config

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys

PasswordAuthentication yes
PermitEmptyPasswords yes

再 產生 ssh key

#ssh-keygen -t rsa -b 1024
#cat id_rsa.pub  > authorized_keys
#chmod 644 authorized_keys <非 root user>

[root@nginx ssh]# useradd xrcd2
[root@nginx ssh]# passwd xrcd2
Changing password for user xrcd2.
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@nginx ssh]# su - xrcd2
[xrcd2@nginx ~]$ ssh-keygen -t rsa -b 1024
Generating public/private rsa key pair.
Enter file in which to save the key (/home/xrcd2/.ssh/id_rsa):
Created directory '/home/xrcd2/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/xrcd2/.ssh/id_rsa.
Your public key has been saved in /home/xrcd2/.ssh/id_rsa.pub.
The key fingerprint is:
94:8b:ea:42:58:e0:09:e5:ed:37:07:6c:8b:86:55:f5 xrcd2@nginx
[xrcd2@nginx ~]$ cd .ssh
[xrcd2@nginx .ssh]$ pwd
/home/xrcd2/.ssh
[xrcd2@nginx .ssh]$ cat id_rsa.pub  > authorized_keys
[xrcd2@nginx .ssh]$ chmod 644 authorized_keys
[xrcd2@nginx .ssh]$ ssh 127.0.0.1
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
RSA key fingerprint is 54:0d:5b:cf:90:db:f5:98:c9:3a:52:3d:24:b1:ae:15.
Are you sure you want to continue connecting (yes/no)? yes
[xrcd2@nginx ~]$ ssh 127.0.0.1
Last login: Sat May 26 21:58:24 2012 from nginx
[xrcd2@nginx ~]$ w
 21:59:37 up  7:12,  3 users,  load average: 0.06, 0.12, 0.10
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1     -                14:39    7:18m  0.05s  0.05s -bash
root     pts/0    192.168.100.200  21:47    0.00s  0.16s  0.03s ssh 127.0.0.1
xrcd2    pts/3    nginx            21:58    0.00s  0.04s  0.01s w
[xrcd2@nginx ~]$

vi /etc/httpd/conf/httpd.conf

#
# ExtendedStatus controls whether Apache will generate "full" status
# information (ExtendedStatus On) or just basic information (ExtendedStatus
# Off) when the "server-status" handler is called. The default is Off.
#
ExtendedStatus On

#
# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Change the ".example.com" to match your domain to enable.
#
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1 192.168.100.1/24

</Location>


vi /usr/local/nginx/conf/nginx.conf


        location /server-status {
         stub_status on;
         access_log off;
         allow 127.0.0.1;
         allow 192.168.100.0/24;
         deny all;
        }

        location /nginx_status {
        stub_status on;
        access_log   off;
        allow 127.0.0.1;
        allow 192.168.100.0/24;
        deny all;
        }






沒有留言:

張貼留言