Winse Blog

走走停停都是风景, 熙熙攘攘都向最好, 忙忙碌碌都为明朝, 何畏之.

Nginx再折腾—统一访问入口

快照目录文件太多,准备安装一个方式分目录。但是又要能保证原来的访问方式不变化!使用rewrite和try_files成功实现。

目录结构:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
winse@Lenovo-PC /cygdrive/f/temp
$ ls -R
.:
1.jpg  snapshot  snapshot-1  snapshot-2  snapshot-3  snapshot-4

./snapshot:
0.html

./snapshot-1:
1.html

./snapshot-2:
2.html

./snapshot-3:
3.html

./snapshot-4:
4.html

Nginx配置尝试一:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
    location /snapshot {
        root   /home/hadoop/html-snapshot;
        add_header content-type "text/html";

        rewrite ^/snapshot/.*/(.*)$  /snapshot/$1 break ;
        
        try_files $uri /snapshot-1/$uri /snapshot-3/$uri;
    }

    location ~ /snapshot-\d+ {
        root   /home/hadoop/html-snapshot;

        rewrite ^/(.*)/.*/(.*)$ /$1/$2 break;
    }

这种方式是不行的,try_files要求除最后一个配置外其他都是文件!

It is possible to check directory’s existence by specifying a slash at the end of a name, e.g. “$uri/”. If none of the files were found, an internal redirect to the uri specified in the last parameter is made. [http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files]

也就是说,中间配置路径,nginx只把他们当做本地的去看待!文件存在就返回结果,否则直接重定向到最后一个路径!!

Nginx配置尝试二:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    location /snapshot {
        root   F:/temp;
        add_header content-type "text/html";

        rewrite ^/snapshot/.*/(.*)$  /snapshot/$1 break ;

        try_files $uri @backup;
    }

    location ~ /snapshot-\d+ {
        root   F:/temp;

      try_files $uri @backup;
    }
  
    location @backup {
      # 这里的顺序不能颠倒,[.*]会匹配所有的!
        rewrite ^/(.*)-3/(.*)$ /$1-4/$2 last;
        rewrite ^/(.*)-2/(.*)$ /$1-3/$2 last;
        rewrite ^/(.*)-1/(.*)$ /$1-2/$2 last;
        rewrite ^/(.*)/(.*)$ /$1-1/$2 last;
    }

这里使用循环的方式在backup的location中进行处理,一个个的循环查找。使用了正则表达式和一个统一rewrite的location。

Nginx配置尝试三:

上面发现,其实try_files都是去查找文件,其实目录结构和访问路径是匹配的,只是请求一开始就带snaphost,倒是每次都需要处理。如果请求过来的就没有带snaphost的话!

1
2
3
4
5
6
    location / {
        root   F:/temp;
        add_header content-type "text/html";

        try_files /snapshot/$uri /snapshot-1/$uri  /snapshot-2/$uri  /snapshot-3/$uri  /snapshot-4/$uri;
    }

一个location配置就行了!

Nginx配置完善版:

转变思路后,最开始就把请求的前置snapshot去掉rewrite去掉就行了!

1
2
3
4
5
6
7
8
    location /snapshot {
        root   F:/temp;
        add_header content-type "text/html";
      
      rewrite ^/snapshot/.*/(.*)$  /$1 break ;

        try_files /snapshot/$uri /snapshot-1/$uri  /snapshot-2/$uri  /snapshot-3/$uri  /snapshot-4/$uri;
    }

nginx添加模块

当我们启用 –with-debug 选项重新构建好调试版的 Nginx 之后,还需要同时在配置文件中通过标准的 error_log 配置指令为错误日志使用 debug 日志级别(这同时也是最低的日志级别):

1
error_log logs/error.log debug;

添加echo模块:

下载zlib、pcre、echo:

1
2
3
4
5
6
7
8
9
tar zxvf zlib-1.2.8.tar.gz 
mv zlib-1.2.8 src/zlib
tar zxvf pcre-8.36.tar.gz 
mv pcre-8.36 src/pcre

./configure --prefix=/home/hadoop/nginx --add-module=/home/hadoop/echo-nginx-module-0.58  --with-pcre=src/pcre --with-zlib=src/zlib --with-debug 
#[hadoop@cu2 nginx-1.7.10]$ ./configure --prefix=/home/hadoop/nginx --with-http_ssl_module --with-pcre=src/pcre/ --with-zlib=src/zlib/ --with-debug
make -j2
make install

编译成功后,就能在location里面直接echo,页面访问时就能看到echo内容了。

更新编译1.9

1
2
3
4
5
[root@cu1 ~]# yum install openssl openssl-devel -y
[root@cu1 ~]# yum install gcc gcc-c++ -y

[hadoop@cu1 nginx-1.9.12]$ ./configure --prefix=/home/hadoop/nginx --with-pcre=/home/hadoop/pcre-8.36  --with-http_ssl_module
[hadoop@cu1 nginx-1.9.12]$ make && make install

参考

–END

树莓派raspberrypi2简单使用 - Respberrypi

买的东西地址:

现在想来,其实可以多加100,买一整套的比较方便。内存卡还有外壳都在里面。

安装系统

  • 显示器: 恰好同时有HDMI的接口和显示器。如果没有,那就要考虑直接把系统写到SD卡了!!
  • 无线键盘、鼠标
  • 电源: 一般的手机充电器都可以,用充电宝也是OK的
  • NOOBS
    • NOOBS_v1_4_2.zip
    • SDFormatterv4.zip

插上SD卡,安装系统就行了。

无线网卡

网站上没说有linux的驱动,但是直接插上后是能检测到设备的!

1
2
3
4
5
pi@raspberrypi:~$ lsusb
Bus 001 Device 004: ID 0bda:8179 Realtek Semiconductor Corp. 
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

ifconfig也能查看到wlan0的无线网卡。接下来修改配置,添加用户密码即可。

配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
pi@raspberrypi:~$ cat /etc/network/interfaces
# Please note that this file is written to be used with dhcpcd.
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'.

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
#iface eth0 inet manual
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
#iface wlan0 inet manual
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

pi@raspberrypi:~$ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1


network={
ssid="winse.liu"
psk="MIMA"
}

network={
ssid="1108"
psk="MIMA"
}

USB转串口使用COM控制raspberry

在淘宝上面买的,我系统是win10,抱着尝试下的心态也很便宜就买了一个。买来后,安装了win7的驱动PL-2303 Vista&Win7 Driver Installer.exe, 能用。

配置见图:

连接后按enter才会出现登录提示! pi默认密码raspberry

最终效果:

用到的一些命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
sudo raspi-config
修改配置,默认使用图形界面登录,可以使用`Boot Options`修改为文本console模式

sudo iwlist wlan0 scan | grep ESSID
查看可用的无线

systemctl list-units

sudo apt-get install screen

sudo apt-get -y install vim
sudo apt-get install nginx
systemctl status nginx.service
sudo cp /etc/skel/.* /home/robot/

手机放一个热点出来,然后手机安装一个ssh的工具(JuiceSSH v2.0.2)就可以控制树莓派了。

网上有用手机当屏幕,然后键盘连树莓派usb,结合来控制树莓派。一开始挺新奇的,后来感觉挺扯淡的!不过学习到了screen的程序,自动登录啥的没弄成,直接输入用户密码登录也行了。在boot选项看到有自动登录,不知道有没有用。现在有无线网卡和com来控制,感觉已经够用了。

参考

–END

Cacti批量添加配置

所有机器SNMP配置同步

1
2
3
for h in `cat /etc/hosts| grep hadoop|awk '{print $2}'` ; do scp -r /etc/snmp/snmpd.conf $h:/etc/snmp/ ; done

for h in `cat /etc/hosts| grep hadoop|awk '{print $2}'` ; do ssh $h "service snmpd start" ; done

Cacti批量添加配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
批量添加device。ip也可以为hostname;template为机器模板;version为SNMP的版本
[root@cu-omc1 cacti]# for h in `cat /etc/hosts | grep hadoop | awk '{print $2}'` ; do php cli/add_device.php --description="$h" --ip="$h" --template=9 --version=2 ; done

了解参数
[root@cu-omc1 cacti]# php cli/add_graphs.php --list-hosts

[root@cu-omc1 cacti]# php cli/add_graphs.php --list-graph-templates --host-template-id=9
Known Graph Templates:(id, name)
29      Host MIB - Processes
35      ucd/net - Users Logged On
36      ucd/net - TCP Current Established
37      ucd/net - Uptime
38      ucd/net - TCP Counters
39      ucd/net - Memory Usage (enhanced)
40      ucd/net - Load Average (enhanced)
41      ucd/net - CPU Usage (enhanced)

[root@cu-omc1 cacti]# php cli/add_graphs.php --list-snmp-queries
Known SNMP Queries:(id, name)
1       SNMP - Interface Statistics
2       ucd/net -  Get Monitored Partitions
3       Karlnet - Wireless Bridge Statistics
4       Netware - Get Available Volumes
6       Unix - Get Mounted Partitions
7       Netware - Get Processor Information
8       SNMP - Get Mounted Partitions
9       SNMP - Get Processor Information

[root@cu-omc1 cacti]# php cli/add_graphs.php --list-snmp-fields --host-id=2 --snmp-query-id=1
Known SNMP Fields for host-id 2: (name)
ifAlias
ifDescr
ifHighSpeed
ifHwAddr
ifIndex
ifIP
ifName
ifOperStatus
ifSpeed
ifType

[root@cu-omc1 cacti]# php cli/add_graphs.php --list-snmp-values --host-id=2 --snmp-query-id=1 --snmp-field=ifIP
Known values for ifIP for host 2: (name)
127.0.0.1
192.168.20.11

[root@cu-omc1 cacti]# php cli/add_graphs.php  --list-graph-templates 
Known Graph Templates:(id, name)
2       Interface - Traffic (bits/sec)
3       ucd/net - Available Disk Space
4       ucd/net - CPU Usage
5       Karlnet - Wireless Levels
6       Karlnet - Wireless Transmissions
7       Unix - Ping Latency
8       Unix - Processes
9       Unix - Load Average
10      Unix - Logged in Users
11      ucd/net - Load Average
12      Linux - Memory Usage
13      ucd/net - Memory Usage
14      Netware - File System Cache
15      Netware - CPU Utilization
16      Netware - File System Activity
17      Netware - Logged In Users
18      Cisco - CPU Usage
19      Netware - Volume Information
20      Netware - Directory Information
21      Unix - Available Disk Space
22      Interface - Errors/Discards
23      Interface - Unicast Packets
24      Interface - Non-Unicast Packets
25      Interface - Traffic (bytes/sec)
26      Host MIB - Available Disk Space
27      Host MIB - CPU Utilization
28      Host MIB - Logged in Users
29      Host MIB - Processes
30      Netware - Open Files
31      Interface - Traffic (bits/sec, 95th Percentile)
32      Interface - Traffic (bits/sec, Total Bandwidth)
33      Interface - Traffic (bytes/sec, Total Bandwidth)
34      SNMP - Generic OID Template
35      ucd/net - Users Logged On
36      ucd/net - TCP Current Established
37      ucd/net - Uptime
38      ucd/net - TCP Counters
39      ucd/net - Memory Usage (enhanced)
40      ucd/net - Load Average (enhanced)
41      ucd/net - CPU Usage (enhanced)

[root@cu-omc1 cacti]# php cli/add_graphs.php  --list-query-types  --snmp-query-id=1
Known SNMP Query Types: (id, name)
2       In/Out Errors/Discarded Packets
3       In/Out Non-Unicast Packets
4       In/Out Unicast Packets
9       In/Out Bytes (64-bit Counters)
13      In/Out Bits
14      In/Out Bits (64-bit Counters)
16      In/Out Bytes
20      In/Out Bits with 95th Percentile
21      In/Out Bits with Total Bandwidth
22      In/Out Bytes with Total Bandwidth

先测试单机添加,对应到Device页面点击`Create Graphs for this Host`添加图像的操作
[root@cu-omc1 cacti]# php cli/add_graphs.php --host-id=2 --graph-type=cg --graph-template-id=40
Graph Added - graph-id: (5) - data-source-ids: (8, 9, 10)
[root@cu-omc1 cacti]# php cli/add_graphs.php --host-id=2 --graph-type=cg --graph-template-id=41
Graph Added - graph-id: (6) - data-source-ids: (11, 12, 13, 14)
[root@cu-omc1 cacti]# php cli/add_graphs.php --host-id=2 --graph-type=cg --graph-template-id=39
Graph Added - graph-id: (7) - data-source-ids: (15, 16, 17, 18, 19)
[root@cu-omc1 cacti]# php cli/add_graphs.php --host-id=2 --graph-type=cg --graph-template-id=38

[root@cu-omc1 cacti]# php cli/add_graphs.php --host-id="2" --graph-type=ds  --graph-template-id=2 --snmp-query-id=1 --snmp-query-type-id=16 --snmp-field=ifIP --snmp-value="192.168.20.11"
Graph Added - graph-id: (9) - data-source-ids: (24, 24)

批量操作
添加Graph Templates
[root@cu-omc1 cacti]# php cli/add_graphs.php --list-hosts | awk '{print $1}' | while read line ; do 
>  php cli/add_graphs.php --host-id=$line --graph-type=cg --graph-template-id=41
>  php cli/add_graphs.php --host-id=$line --graph-type=cg --graph-template-id=40
>  php cli/add_graphs.php --host-id=$line --graph-type=cg --graph-template-id=39
>  php cli/add_graphs.php --host-id=$line --graph-type=cg --graph-template-id=38
> done

添加Data Query。比较复杂点,需要查询匹配
php cli/add_graphs.php --list-hosts | awk '{print $1}' | while read line ; do 
  php cli/add_graphs.php --host-id=$line --graph-type=ds  --graph-template-id=2 --snmp-query-id=1 --snmp-query-type-id=16 --snmp-field=ifIP --snmp-value=$(grep "`php cli/add_graphs.php --list-hosts | grep "^$line\s" | awk '{print $2}'`\s" /etc/hosts | awk '{print $1}')
done

其他命令

1
2
3
4
5
6
7
8
9
10
11

dmesg |grep eth0

iftop –i eth0 –B

sar -n DEV 1 100 

ethtool eth0

[omc@cu-omc1 ~]$ sort -k 2 /tmp/cacti.list > /tmp/cacti.sort.list
[omc@cu-omc1 ~]$ grep hadoop /etc/hosts | sort -k 2 | join -j 2 - /tmp/cacti.sort.list 

参考

–END

Nagios监控主机

更新

  • 2016-1-20
  • 2016-4-20 nrpe编译好后,在编译目录有 init-script 服务脚本。

正文

和Cacti查看时间序列图形不同,Nagios更多的是状态的预警。

  • 下载应用

sourceforge下面最新版的应用。

1
2
3
4
5
6
[root@cu2 nagios]# cat /etc/redhat-release 
CentOS release 6.6 (Final)
[root@cu2 nagios]# ll
-rw-r--r--  1 root root 11206656 Sep 23 12:47 nagios-4.1.1.tar.gz
-rw-r--r--  1 root root  2677352 Sep 23 12:47 nagios-plugins-2.1.1.tar.gz
-rw-r--r--  1 root root   419695 Sep 23 15:18 nrpe-2.15.tar.gz
  • 新增nagios用户
1
2
3
4
5
[root@cu2 nagios]# useradd nagios
[root@cu2 nagios]# groupadd nagcmd
[root@cu2 nagios]# usermod -G nagcmd nagios
[root@cu2 nagios]# usermod -G nagcmd apache 
# 如果已经安装了httpd,查看下是哪个用户进程,把该用户加入到nagcmd组。修改后需要重启httpd
  • 编译Nagios服务端

由于前面安装Cacti已经把依赖都安装了,如gcc、gd、httpd、php php-devel php-mysql php-pear php-common php-gd php-mbstring php-cli。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
[root@cu2 nagios]# cd nagios-4.1.1/
[root@cu2 nagios-4.1.1]# ./configure --with-command-group=nagcmd
...
Creating sample config files in sample-config/ ...


*** Configuration summary for nagios 4.1.1 08-19-2015 ***:

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagcmd
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
    Install ${includedir}:  /usr/local/nagios/include/nagios
                Lock file:  ${prefix}/var/nagios.lock
   Check result directory:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/rc.d/init.d
  Apache conf.d directory:  /etc/httpd/conf.d
             Mail program:  /bin/mail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.


# 编译
[root@cu2 nagios-4.1.1]# make all
...

*** Compile finished ***

If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

  make install
     - This installs the main program, CGIs, and HTML files

  make install-init
     - This installs the init script in /etc/rc.d/init.d

  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

  make install-config
     - This installs *SAMPLE* config files in /usr/local/nagios/etc
       You'll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!

  make install-webconf
     - This installs the Apache config file for the Nagios
       web interface

  make install-exfoliation
     - This installs the Exfoliation theme for the Nagios
       web interface

  make install-classicui
     - This installs the classic theme for the Nagios
       web interface


*** Support Notes *******************************************

If you have questions about configuring or running Nagios,
please make sure that you:

     - Look at the sample config files
     - Read the documentation on the Nagios Library at:
           https://library.nagios.com

before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you.  This might include:

     - What version of Nagios you are using
     - What version of the plugins you are using
     - Relevant snippets from your config files
     - Relevant error messages from the Nagios log file

For more information on obtaining support for Nagios, visit:

       https://support.nagios.com

*************************************************************

Enjoy.


# 安装
[root@cu2 nagios-4.1.1]# make install
...

*** Main program, CGIs and HTML files installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

  make install-init
     - This installs the init script in /etc/rc.d/init.d

  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

  make install-config
     - This installs sample config files in /usr/local/nagios/etc

make[1]: Leaving directory `/data/nagios/nagios-4.1.1'


# 初始化
[root@cu2 nagios-4.1.1]# make install-init
/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios

*** Init script installed ***


# 安装/初始化配置
[root@cu2 nagios-4.1.1]# make install-config
...

*** Config files installed ***

Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.


# 修改权限
[root@cu2 nagios-4.1.1]# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw

*** External command directory configured ***


# 配置
[root@cu2 nagios-4.1.1]# vi /usr/local/nagios/etc/objects/contacts.cfg 
...修改define contact定义中的mail为你邮件。
define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user

        email                           1234@XXX.cn      ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }


# httpd配置
[root@cu2 nagios-4.1.1]# make install-webconf
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf

*** Nagios/Apache conf file installed ***


# 权限/密码
[root@cu2 nagios-4.1.1]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: 
Re-type new password: 
Adding password for user nagiosadmin
[root@cu-omc1 nagios-4.1.1]# chmod 644 /usr/local/nagios/etc/htpasswd.users 


# 重启HTTPD(应该可以不用重启)
[root@cu2 nagios-4.1.1]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.0.214 for ServerName
                                                           [  OK  ]
                                             
  • 编译nagios-plugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
如果configure没有mysql和ssl,先安装依赖
yum -y install mysql-devel openssl

[root@cu2 nagios]# cd nagios-plugins-2.1.1/
[root@cu2 nagios-plugins-2.1.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
...
            --with-apt-get-command: 
              --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
               --with-ping-command: /bin/ping -n -U -w %d -c %d %s
                       --with-ipv6: yes
                      --with-mysql: /usr/bin/mysql_config
                    --with-openssl: yes
                     --with-gnutls: no
               --enable-extra-opts: yes
                       --with-perl: /usr/bin/perl
             --enable-perl-modules: no
                     --with-cgiurl: /nagios/cgi-bin
               --with-trusted-path: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
                   --enable-libtap: no
[root@cu2 nagios-plugins-2.1.1]# make 
[root@cu2 nagios-plugins-2.1.1]# make install

打开浏览器,使用nagiosadmin和刚刚用htpasswd设置的密码登录就可以localhost的状态了。

手动制造一点异常,如登录用户超过50个。然后看刚刚设置的提醒邮箱是否收到告警。

1
2
3
4
5
6
7
8
9
10
11
[root@cu2 nagios]# service nagios status
nagios (pid 53764) is running...
[root@cu2 nagios]# lsof -p 53764
nagios  53764 nagios    4u   REG                8,3    12715   280762 /usr/local/nagios/var/nagios.log


# 日志目录,看看是否有错误,然后做相应的处理
[root@cu2 nagios]# less /usr/local/nagios/var/nagios.log

# 如,机器可能没有安装mail等
[root@cu2 nagios]# yum install mail -y
  • 被监控机器安装nrpe

程序编译都在cu2上面操作,编译完后,把编译安装的程序直接scp到其他机器就可以了。被监控机器需要nagios-plugin和nrpe。

编译之前可以先看看nrpe-2.15/docs/NRPE.pdf,讲的很详细和清楚。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
[root@cu2 nagios-plugins-2.1.1]# cd ../nrpe-2.15
[root@cu2 nrpe-2.15]# ./configure 
...

*** Configuration summary for nrpe 2.15 09-06-2013 ***:

 General Options:
 -------------------------
 NRPE port:    5666
 NRPE user:    nagios
 NRPE group:   nagios
 Nagios user:  nagios
 Nagios group: nagios


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the NRPE daemon and client.

[root@cu2 nrpe-2.15]# make all
cd ./src/; make ; cd ..
make[1]: Entering directory `/data/nagios/nrpe-2.15/src'
gcc -g -O2 -I/usr/include/openssl -I/usr/include -DHAVE_CONFIG_H -I ../include -I ./../include -o nrpe ./nrpe.c ./utils.c ./acl.c -L/usr/lib64  -lssl -lcrypto -lnsl -lwrap  
gcc -g -O2 -I/usr/include/openssl -I/usr/include -DHAVE_CONFIG_H -I ../include -I ./../include -o check_nrpe ./check_nrpe.c ./utils.c -L/usr/lib64  -lssl -lcrypto -lnsl 
make[1]: Leaving directory `/data/nagios/nrpe-2.15/src'

*** Compile finished ***

If the NRPE daemon and client compiled without any errors, you
can continue with the installation or upgrade process.

Read the PDF documentation (NRPE.pdf) for information on the next
steps you should take to complete the installation or upgrade.

[root@cu2 nrpe-2.15]# make install-plugin
cd ./src/ && make install-plugin
make[1]: Entering directory `/data/nagios/nrpe-2.15/src'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios check_nrpe /usr/local/nagios/libexec
make[1]: Leaving directory `/data/nagios/nrpe-2.15/src'

[root@cu2 nrpe-2.15]# make install-daemon
cd ./src/ && make install-daemon
make[1]: Entering directory `/data/nagios/nrpe-2.15/src'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin
/usr/bin/install -c -m 775 -o nagios -g nagios nrpe /usr/local/nagios/bin
make[1]: Leaving directory `/data/nagios/nrpe-2.15/src'

[root@cu2 nrpe-2.15]# make install-daemon-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 644 -o nagios -g nagios sample-config/nrpe.cfg /usr/local/nagios/etc

# 启动nrpe服务
[root@cu2 nrpe-2.15]#  /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

[root@cu2 nrpe-2.15]# /usr/local/nagios/libexec/check_nrpe -H localhost
CHECK_NRPE: Error - Could not complete SSL handshake.
[root@cu2 nrpe-2.15]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.15

注意: 如果需要启用传递参数功能需要添加参数--enable-command-args,同时修改配置dont_blame_nrpe=1http://www.cppblog.com/fwxjj/archive/2011/10/28/159262.aspx

~~更新201604:(2016-4-20 13:10:02)

编译好nrpe后,在编译目录下面有 init-script 脚本,直接把脚本拷贝到 /etc/init.d 目录就可以把 nrpe 作为服务来管理了。

1
2
3
4
5
6
[root@cu2 nrpe-2.15]# cp init-script /etc/init.d/nrpe
[root@cu2 nrpe-2.15]# chmod +x /etc/init.d/nrpe 
[root@cu2 nrpe-2.15]# service nrpe start
Starting nrpe:                                             [  OK  ]
[root@cu2 nrpe-2.15]# service nrpe status
nrpe (pid  30791) is running...

其实管理nrpe的启动。同步到其他机器,就可以用 service nrpe start 来代替启动命令了。

~~更新201604END

拷贝程序到其他机器:

1
2
3
4
5
6
7
[root@cu2 local]# scp -r nagios cu3:/usr/local/

[root@cu3 ~]# cd /usr/local/nagios/
[root@cu3 nagios]# bin/nrpe -c etc/nrpe.cfg -d
[root@cu3 nagios]# 
[root@cu3 nagios]# libexec/check_nrpe -H 127.0.0.1
NRPE v2.15

修改配置,添加可以访问nrpe的白名单:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@cu3 nagios]# vi etc/nrpe.cfg 
...修改
allowed_hosts=127.0.0.1,192.168.0.0/24
...查看
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 

nrpe.cfg最下面是nrpe的command,nagios配置中会用到

[root@cu3 nagios]# pkill nrpe
[root@cu3 nagios]# bin/nrpe -c etc/nrpe.cfg -d

注意:如果你用xinetd的话: only_from = 127.0.0.1 192.168.0.0/16

再回到cu2,把cu3加入nagios管理列表中:

首先,nagios的配置入口为etc/nagios.cfg。其他配置文件都是通过cfg_file去定位的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
[root@cu2 nagios]# vi etc/nagios.cfg 
...添加
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=/usr/local/nagios/etc/objects/cu3.cfg


[root@cu2 nagios]# vi etc/objects/commands.cfg 
...添加
# 'check_nrpe' command definition
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

[root@cu2 nagios]# vi etc/objects/cu3.cfg 
...新增

define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               cu3
        alias                   cu3
        address                 192.168.0.148
        }

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       cu3
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       cu3
        service_description             Root Partition
        check_command                   check_nrpe!check_hda1
        }

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       cu3
        service_description             Current Users
        check_command                   check_nrpe!check_users
        }

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       cu3
        service_description             Total Processes
        check_command                   check_nrpe!check_total_procs
        }


define service{
        use                             generic-service         ; Name of service template to use
        host_name                       cu3
        service_description             Current Load
        check_command                   check_nrpe!check_load
        }

[root@cu2 nagios]# vi etc/objects/hosts.cfg 
... 新增
define hostgroup{
        hostgroup_name  linux-servers ; The name of the hostgroup
        alias           Linux Servers ; Long name of the group
        members         localhost,cu3,cu4,cu5,cu1     ; Comma separated list of hosts that belong to this group
        }

配置完后,校验配置,然后重启nagios。然后就可以打开浏览器查看cu3状态。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[root@cu2 nagios]# bin/nagios -v etc/nagios.cfg 

Nagios Core 4.1.1
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-19-2015
License: GPL

Website: https://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
        Checked 23 services.
        Checked 4 hosts.
        Checked 1 host groups.
        Checked 0 service groups.
        Checked 1 contacts.
        Checked 1 contact groups.
        Checked 25 commands.
        Checked 5 time periods.
        Checked 0 host escalations.
        Checked 0 service escalations.
Checking for circular paths...
        Checked 4 hosts
        Checked 0 service dependencies
        Checked 0 host dependencies
        Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check
[root@cu2 nagios]# service nagios restart
Running configuration check...
Stopping nagios: done.
Starting nagios: done.

后记

技巧:配置服务的时刻,制定host_name可以使用正则表达式,一个服务通吃。对于功能类似的机器,可以减少很多工作量:

1
2
3
4
5
6
7
8
9
10
11
12
13
vi etc/nagios.cfg 
... 修改
use_regexp_matching=1
use_true_regexp_matching=1

vi cu.cfg
... 
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       cu.*
        service_description             Current Load
        check_command                   check_nrpe!check_load
        }

基本功能就算配置好了,如果出现异常就能得到邮件提醒。

后后后记(2015-12-7 21:42:03)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
tar zxvf nagios-plugins-2.1.1.tar.gz 
tar zxvf nrpe-2.15.tar.gz 

ps axu|grep httpd
useradd nagios
groupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd apache 


yum -y install mysql-devel openssl
cd nagios-plugins-2.1.1/
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make && make install

cd ../nrpe-2.15
./configure 
make all
make install-plugin
make install-daemon
make install-daemon-config

cd /usr/local/
for h in `cat /etc/hosts | grep hadoop | awk '{print $2}'` ; do rsync -vaz nagios root@$h:/usr/local/  ; done 

rsync --dry-run -vaz nagios nagios-client > nagios-client.list
rsync --dry-run --include-from=nagios-client.list --exclude=* -vaz nagios nagios-clint

for h in `cat /etc/hosts | grep "-" | grep -v omc1 | awk '{print $2}'` ; do 
  rsync  --include-from=nagios-client.list --exclude=* -vaz nagios $h:/usr/local/  ;
  ssh $h "pkill nrpe; cd /usr/local/nagios ; bin/nrpe -c etc/nrpe.cfg -d"  ; 
  echo $h; ssh $h "if ! ps aux|grep nrpe | grep -v grep  | grep nrpe ; then cd /usr/local/nagios ; bin/nrpe -c etc/nrpe.cfg -d ; fi"   ;
done

# nrpe下面有init-script,拷贝到/etc/init.d/下面就可以用service来进行启动了。
cp init-script /etc/init.d/nrpe
chmod +x /etc/init.d/nrpe
service nrpe start
chkconfig --add nrpe

--

umask 0022
cd 
tar zxvf nagios-4.1.1.tar.gz 
cd nagios-4.1.1
./configure --with-command-group=nagcmd
make all
make install
 make install-init
make install-config
make install-commandmode
make install-webconf
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
chmod 644 /usr/local/nagios/etc/htpasswd.users 
service httpd restart
service nagios start

##======================================================================

修改 vi nagios.cfg

  cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
  cfg_file=/usr/local/nagios/etc/objects/cu.cfg

  use_regexp_matching=1

添加 for h in `cat /etc/hosts | grep "-" | grep -v omc1 | awk '{print $2}'` ; do echo "
> define host {
> use linux-server
> host_name HN-${h#*-}
> alias HN-${h#*-}
> address $h
> }
> " ; done >hosts.cfg

define hostgroup{
        hostgroup_name  cu servers
        alias           cu servers
        members         HN-omc*, HN-uc*, HN-ud*, HN-db*
        }

define hostgroup{
        hostgroup_name  hadoop slavers
        alias           hadoop slavers
        members         HN-slaver*, HN-master*
        }
      
添加 vi commands.cfg    

# 'check_nrpe' command definition
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}


编辑 vi /etc/mail.rc 

set from=esw_notify@189.cn
set smtp=smtp.189.cn
set smtp-auth-user=XXX
set smtp-auth-password=XXX
set smtp-auth=login

echo test  | /bin/mail -s "** Service Alert **" XXX@189.cn

##-----------------------------------
[root@dr01 ~]# umount /root/.gvfs

command_line  /usr/lib/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$  -u GB -A -i .gvfs
   

参考

–END

Cacti监控主机

其实通过yum好依赖的php、rrdtool、snmp后,安装配置Cacti其实很简单。

环境说明

五台机器:cu1~cu5(centos6.6), 其中仅cu2作为cacti服务器,所有服务器都安装snmp服务。

1
2
3
4
5
cu1     192.168.0.37 
cu2     192.168.0.214 
cu3     192.168.0.148 
cu4     192.168.0.30 
cu5     192.168.0.174 

软件安装

版本信息在贴的内容中体现。PHP不会,仅仅作为一个工具来使用。

Cacti服务器机器安装

mysql数据库5.1

1
2
[root@cu2 ~]# rpm -q mysql 
mysql-5.1.73-5.el6_6.x86_64

首先用yum安装依赖软件php,httpd,snmp和rrdtool

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
[root@cu2 ~]# yum install epel-release

[root@cu2 ~]# yum install httpd php php-devel php-mysql php-pear php-common php-gd php-mbstring php-cli php-snmp net-snmp net-snmp-utils net-snmp-libs rrdtool 
...

Installed:
  net-snmp-libs.x86_64 1:5.5-54.el6_7.1 net-snmp-utils.x86_64 1:5.5-54.el6_7.1 php.x86_64 0:5.3.3-46.el6_6          php-cli.x86_64 0:5.3.3-46.el6_6   php-common.x86_64 0:5.3.3-46.el6_6
  php-devel.x86_64 0:5.3.3-46.el6_6     php-gd.x86_64 0:5.3.3-46.el6_6         php-mbstring.x86_64 0:5.3.3-46.el6_6 php-mysql.x86_64 0:5.3.3-46.el6_6 php-pear.noarch 1:1.9.4-4.el6     
  php-snmp.x86_64 0:5.3.3-46.el6_6      rrdtool.x86_64 0:1.3.8-7.el6          

Dependency Installed:
  autoconf.noarch 0:2.63-5.1.el6               automake.noarch 0:1.11.1-4.el6                  dejavu-fonts-common.noarch 0:2.33-1.el6   dejavu-lgc-sans-mono-fonts.noarch 0:2.33-1.el6  
  dejavu-sans-mono-fonts.noarch 0:2.33-1.el6   fontpackages-filesystem.noarch 0:1.41-1.1.el6   lm_sensors-libs.x86_64 0:3.1.1-17.el6     net-snmp.x86_64 1:5.5-54.el6_7.1                
  php-pdo.x86_64 0:5.3.3-46.el6_6             

Updated:
  httpd.x86_64 0:2.2.15-47.el6.centos                                                                                                                                                       

Dependency Updated:
  httpd-tools.x86_64 0:2.2.15-47.el6.centos                                                                                                                                                 

Complete!

[root@cu2 ~]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.0.214 for ServerName
                                                           [  OK  ]
[root@cu2 ~]# service snmpd start
Starting snmpd:                                            [  OK  ]

[root@cu2 ~]# vi /etc/snmp/snmpd.conf 
     41 #com2sec notConfigUser  default       public
     42 com2sec notConfigUser  192.168.0.214       public
   ...
     63 #access  notConfigGroup ""      any       noauth    exact  systemview none none
     64 access  notConfigGroup ""      any       noauth    exact  all none none
   ...
     86 ##           incl/excl subtree                          mask
     87 view all    included  .1                               80  

[root@cu2 ~]# service snmpd restart

# 使用snmpwalk可以得到数据
[root@cu2 ~]# snmpwalk -Os -c public -v 1 cu2 system
[root@cu2 ~]# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

然后,把Cacti应用解压到httpd默认目录下/var/www/html。同时配置cacti连接到数据库。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@cu2 ~]# cd /var/www/html/
[root@cu2 html]# tar zxvf cacti-0.8.8f.tar.gz 

[root@cu2 html]# ln -s cacti-0.8.8f cacti

[root@cu2 html]$ mysql -u root -p -h 127.0.0.1
Enter password: 
mysql> 
mysql> create database cacti character set UTF8;
mysql> grant all on cacti.* to cacti@'%' identified by 'cacti';
mysql> flush privileges;
mysql> source /var/www/html/cacti/cacti.sql;

[root@cu2 html]# vi cacti/include/config.php 
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "127.0.0.1";
$database_username = "cacti";
$database_password = "cacti";
$database_port = "3306";

[root@cu2 html]$ vi /etc/php.ini 
date.timezone = "Asia/Shanghai"

# 重启httpd服务

[root@cu2 cacti]# php poller.php 

[root@cu2 cacti]# crontab -e
* * * * * php /var/www/html/cacti/poller.php > /var/www/html/cacti/log/cron.log 2>&1

打开浏览器访问:http://cu2/cacti/ 首先会进入到install步骤,按照提示一步下一步,最后输入admin/admin登录。点击右上角的Preview View就可以看到图了。

如果启动错误,查看日志文件看日志:

1
2
[root@cu2 cacti]# less /var/log/httpd/error_log 
[root@cu2 cacti]# less log/cacti.log 

添加插件

(网上很多文章都要打补丁,我这里的版本是最新的,同时plugin的补丁没有对应的版本,这里直接安装插件)

http://docs.cacti.net/plugins下载monitor。把下载文件解压到plugins目录下:

1
2
3
4
5
[root@cu2 plugins]# pwd
/var/www/html/cacti/plugins
[root@cu2 plugins]# ll
-rw-r--r-- 1 1000 users   44 Jul 20 21:42 index.php
drwxr-xr-x 4 root root  4096 Oct  6  2011 monitor

然后进入Plugin Management页面http://cu2/cacti/plugins.php,就能看到Monitor插件。点击表格Actions列的安装和启用图标(按钮),启用后,最上面页签会增加新的页签项monitor。

点击monitor页签,可以查看机器存活的状态。

同时Settings页面多了Misc选项卡,可以配置修改monitor属性。

注意:网上版本资料都有配置config.php添加plugins变量。我这里没进行这个操作也是ok的,安装-启用成功后会把monitor下面的sql更新到数据库,不需要手动执行。

安装spine

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
注意:设置下umask避免不需要的麻烦: umask 0022
[root@cu2 ~] tar zxvf cacti-spine-0.8.8f.tar.gz

[root@cu2 cacti-spine-0.8.8f]# yum install -y mysql-devel net-snmp-devel

[root@cu2 cacti-spine-0.8.8f]# ./configure --prefix=/usr/local/cacti-spine
[root@cu2 cacti-spine-0.8.8f]# make && make install
# 如果make缺少报了错,需要重新configuration一遍

[root@cu2 cacti-spine-0.8.8f]# cd /usr/local/cacti-spine/etc
[root@cu2 etc]# mv spine.conf.dist spine.conf
[root@cu2 etc]# vi spine.conf 
DB_Host         127.0.0.1
DB_Database     cacti
DB_User         cacti
DB_Pass         cacti
DB_Port         3306
  • 然后修改Cacti使用spine来获取信息。

在[Settings]-[Paths]添加Spine Poller File Path为/usr/local/cacti-spine/bin/spine。在[Poller]选项卡,[Poller Type]修改为spine,[Poller Interval]和[Cron Interval]修改为一分钟即Every Minute。

  • 添加“每分钟”流量视图:

点击Console -> Data Templates -> [Interface -> Traffic ] 添加“每分钟”流量视图,将轮询时间设置为60秒,Heartbeat时间设置为120秒(traffic_in/traffic_out里面的Heartbeat时间也设置为120秒)

被监控机器配置

被监控的机器,仅仅需要安装snmp即可。然后配置snpmd.conf即可。

1
2
3
4
5
6
7
8
9
10
11
12
[root@cu5 ~]# yum install  net-snmp net-snmp-utils net-snmp-libs -y
[root@cu5 ~]# vi /etc/snmp/snmpd.conf 
     41 #com2sec notConfigUser  default       public
     42 com2sec notConfigUser  192.168.0.214       public
   ...
     63 #access  notConfigGroup ""      any       noauth    exact  systemview none none
     64 access  notConfigGroup ""      any       noauth    exact  all none none
   ...
     86 ##           incl/excl subtree                          mask
     87 view all    included  .1                               80  

[root@cu2 ~]# service snmpd restart

然后在Cacti的web页面添加Device(主机):

  • 点击Console->Devices,打开设备管理页面。
  • 点击右上角的add,添加一个新的机器
  • 当主机的信息填好之后,点击Create
    • Host Template就是一个模板,会事先建立一些Associated Graph Templates和Associated Data Queries的数据,如Load Average,Memory Uages等。如果不确定直接选None即可。
    • SNMP Version选Version 2,SNMP Community与snmpd.conf中对应,如果安装上面操作,默认即可。
  • 此时你的页面左上角应该显示:Save Successful,并且已经显示出了主机信息和SNMP信息,如果SNMP信息显示 SNMP error,请查看最后的问题综述。
  • 这时我们就可以添加相应的监控项了,在页面最下方的Associated Graph Templates中添加图形模板,在Associated Data Queries中添加数据模板。
  • 保存,点击右上角的Create Graphs for this Host,来为刚才通过模板所获得到的数据进行画图。
  • 选择好需要画图的项目后,点击右下角的Create,左上角会出现被创建出来的画图项。

总结就是添加设备,然后生成图形,最后等待生成画图查看。

在Graphs界面左边显示树新添加主机。

  • 在Cacti界面Graph Trees中,选择进入节点(或者系统默认的Default Tree)。
  • 添加一个新的显示项,在Tree Item Type中选择Host,然后在下面的Host中选择我们刚才创建的主机。点击Create。

http://docs.cacti.net/templates

进阶

http://skypegnu1.blog.51cto.com/8991766/1537374

cacti是如何获取数据呢?
其实cacti获取数据的方式是多样化的,通过周期性的执行某个脚本,或者使用snmp,更或者是ssh,这些都是根据实际需要以及方便性来抉择。cacti需要周期性的驱动这些获取数据的脚本执行,并把取得的数据保存至相应的rrd数据库中。 cacti是如何保存数据(创建rrd,并更新数据)呢? 这就是数据模板的功能。 cacti是如何展示数据(绘图)呢? 这就是图形模板的功能。

http://skypegnu1.blog.51cto.com/8991766/1537615 http://skypegnu1.blog.51cto.com/8991766/1538459 http://skypegnu1.blog.51cto.com/8991766/1547029

资料

入门的文档不错,可以到微盘下载。

1
2
3
4
5
6
7
8
9
Cacti.0.8_Beginner.Guide.pdf

Cacti实战指南--备份还原.pdf
Cacti实战指南-完美部署.pdf
Cacti实战指南-巧设轮询.pdf
Cacti实战指南-插件安装.pdf
Cacti实战指南-用户权限.pdf
Cacti实战指南-邮件预警.pdf
Cacti实战指南-阀值预警.pdf

参考

–END