設定 SPF record 的工具網站
http://www.microsoft.com/mscorp/safety/content/technologies/senderid/wizard/
依據網站指示即可產出 DNS 的 SPF record
如
v=spf1 a mx:mail.xxxx.com.tw mx:mail2.xxxx.com.tw mx:xxxx.com.tw ~all
or
v=spf1 ip4:xxx.xxx.xxx.xxx mx:mail.xxxx.com.tw mx:mail2.xxxx.com.tw ~all
接下來是在 DNS Server 上宣告使用以 PowerDNS 為例:
Poweradmin
SPF Type 的說明
http://doc.powerdns.com/html/types.html
2013年11月26日 星期二
2013年6月24日 星期一
CentOS 6.4 64 bit w3af_gui 無法執行 ( w3af )
w3af 請參考
http://xrcd2.blogspot.tw/2012/07/w3af-waf-for-apache.html
root@w3af w3af]# ./w3af_gui
On Debian systems please install the following operating system packages before running the pip installer:
sudo apt-get install build-essential python-setuptools git python-pip graphviz python2.7-dev libsqlite3-dev libxslt1-dev python-gtksourceview2 python-gtk2 libxml2-dev
Your python installation needs the following modules to run w3af:
clamd github git.util esmre phply chardet pdfminer concurrent.futures guess_language cluster msgpack ntlm xdot
After installing any missing operating system packages, use pip to install the remaining modules:
sudo pip install clamd PyGithub GitPython esmre chardet pdfminer futures guess-language cluster msgpack-python python-ntlm xdot
sudo pip install -e git+git://github.com/ramen/phply.git#egg=phply
A script with these commands has been created for you at /tmp/w3af_dependency_install.sh
=======================
python-setuptools
Easy Install 是一個 Python的模組化工具 (easy_install),是包含在 setuptools rpm 中,提供Python自動化程式下載、編譯、安裝和管理的模組。
使用方法 #easy_install [套件名稱]
如 easy_install pip
或使用 #pip [套件名稱] 也行
更詳細的介紹請自行參閱
http://www.openfoundry.org/tw/tech-column/8536-introduction-of-python-extension-management-tools
2013年6月13日 星期四
簡單的 linux H.A 架構 keepalived (linux vrrp) Part III
延續 簡單的 linux H.A 架構 這個主題,
Part I
http://xrcd2.blogspot.tw/2013/04/linux-ha-keepalived-linux-vrrp.html
Part II
http://xrcd2.blogspot.tw/2013/05/linux-ha-keepalived-linux-vrrp-part-ii.html
加入 notify shell
notify_master "/etc/keepalived/notify_master.sh" #變成 master 時執行的 shell
notify_backup "/etc/keepalived/notify_backup.sh" #變成 backup 時執行的 shell
notify_fault "/etc/keepalived/notify_fault.sh" #故障時執行的 shell
notify "/etc/keepalived/notify.sh" # 狀態轉換時執行的 shell
加入的位置如下:
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 1
priority 100
advert_int 3
smtp_alert
authentication {
auth_type PASS
auth_pass 1234
}
virtual_ipaddress {
192.168.1.1
}
notify_master "/etc/keepalived/notify_master.sh"
notify_backup "/etc/keepalived/notify_backup.sh"
track_script {
check_shell
chk_httpd
chk_http_port
chk_https_port
chk_8080_port
}
track_interface{
eth0
}
}
Part I
http://xrcd2.blogspot.tw/2013/04/linux-ha-keepalived-linux-vrrp.html
Part II
http://xrcd2.blogspot.tw/2013/05/linux-ha-keepalived-linux-vrrp-part-ii.html
加入 notify shell
notify_master "/etc/keepalived/notify_master.sh" #變成 master 時執行的 shell
notify_backup "/etc/keepalived/notify_backup.sh" #變成 backup 時執行的 shell
notify_fault "/etc/keepalived/notify_fault.sh" #故障時執行的 shell
notify "/etc/keepalived/notify.sh" # 狀態轉換時執行的 shell
加入的位置如下:
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 1
priority 100
advert_int 3
smtp_alert
authentication {
auth_type PASS
auth_pass 1234
}
virtual_ipaddress {
192.168.1.1
}
notify_master "/etc/keepalived/notify_master.sh"
notify_backup "/etc/keepalived/notify_backup.sh"
track_script {
check_shell
chk_httpd
chk_http_port
chk_https_port
chk_8080_port
}
track_interface{
eth0
}
}
2013年5月10日 星期五
perl , ssh2 , vyatta , vbash and remote executio
perl , ssh2 , vyatta , vbash and remote executio
如何使用 perl 寫一支 shell 連入 vyatta OS 內,並下指令 show ????,
並將 結果 自動以 E-Mail 方式寄回給網管人員!
About vyatta
www.vyatta.com or www.vyatta.org
or 我以前發表過的文章如下:
http://www.pczone.com.tw/vbb3/thread/16/147986/
程式範列如下,可依需要自行修改之:
[xrcd2@centos shell]# cat ssh2-vyatta-show.pl
#!/usr/bin/perl
use Net::SSH2;
$ssh=Net::SSH2->new() or die "couldn't make SSH object\n";
#$ssh->debug(1);
$ssh->blocking(1);
print "\n made SSH object\n";
$ssh->connect('xxx.xxx.xxx.xxx') or die "couldn't connect to host\n";
print "\n connected to vyatta-host\n";
$ssh->auth_password('vyatta-id','vyatta-pwd') or die "couldn't authenticate \n";
print "\n \n authenticated vyatta-id \n \n";
print " \n ================== send command ====================== \n ";
$command1 = $ssh->channel();
$command1->exec('vbash -i -c "show version "');
$buflen = 10000;
$show = '0' x $buflen;
$command1->read($show, $buflen);
chomp($show);
print "\n $show";
print " \n \n ================= end ============================== \n \n ";
$ssh->disconnect or die "couldn't disconnect\n";
get_mail();
sub get_mail{
use Encode qw(decode encode_utf8);
use Encode qw(encode);
use MIME::Base64;
use MIME::Lite;
$foot0=' 自動使用SSH2 到 Vyatta OS 的 Shell ( ssh2 vyatta vbash ) ';
use Encode qw/from_to/;
from_to($foot0, "utf8", "big5");
$line='=====================================================';
$msg = MIME::Lite->new(
From =>'vyatta@xrcd2.com.tw',
To =>'xrcd2@xrcd2.com.tw',
Subject => "show vyatta version ",
Encoding => 'base64',
Data =>"$foot0 \n\n $line \n\n $show \n\n $line\n\n"
);
$msg->get_length;
$msg->attr("content-type.charset" => "UTF8");
$msg->send('smtp','x.x.x.x');
print $Mail::SendMail::Error eq "" ? "\n\n send ok! \n\n" : $Mail::SendMail::Error;
}
[root@centos63 shell]# perl blog-ssh.pl
made SSH object
connected to vyatta-host
authenticated vyatta-id
================== send command ======================
Version: VC6.5R1
Description: Vyatta Core 6.5 R1
Copyright: 2006-2012 Vyatta, Inc.
Built by: autobuild@vyatta.com
Built on: Fri Nov 16 16:39:16 UTC 2012
Build ID: 1211161646-334fb58
System type: Intel 32bit
Boot via: disk
Hypervisor: VMware
HW model: VMware Virtual Platform
HW S/N: VMware-56 4d 5b da 3e 1c d1 93-43 38 03 40 4a 5c e9 29
HW UUID: 564D5BDA-3E1C-D193-4338-03404A5CE929
Uptime: 16:58:35 up 2:11, 1 user, load average: 0.00, 0.01, 0.05
================= end ==============================
send ok!
[xrcd2@centos shell]#
2013年5月6日 星期一
簡單的 linux H.A 架構 keepalived (linux vrrp) Part II
透過 keepalived 達成簡單的 linux H.A 架構. (linux vrrp)
http://www.keepalived.org/
延續這個主題.
http://xrcd2.blogspot.tw/2013/04/linux-ha-keepalived-linux-vrrp.html
加入切換條件, 如 track_script
Master config 如下
! Configuration File for keepalived
vrrp_script check_sh {
script "/etc/keepalived/chk_ftp.sh"
interval 2 # check every 2 seconds
weight -30 # default prio: -30
fall 2 # require 2 failures
rise 2 # require 2 successes
}
vrrp_script chk_httpd {
script "killall -0 httpd"
interval 2
weight -30
fall 2
rise 2
}
vrrp_script chk_8080_port {
script "</dev/tcp/127.0.0.1/8080"
interval 1
weight -30
fall 2
rise 2
}
global_defs {
notification_email {
xrcd2@xrcd2.com.tw
}
notification_email_from keepalived@xrcd2.com.tw
smtp_server 192.168.1.100
smtp_connect_timeout 30
router_id NodeA
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 1
priority 100
advert_int 1
smtp_alert
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.3
}
track_script {
check_sh
chk_httpd
chk_8080_port
}
track_interface{
eth0
}
}
DIY 檢查的 shell
======================
cat /etc/keepalived/chk_ftp.sh
#!/bin/bash
chktcp21=`nmap 127.0.0.1 | grep '21/tcp' | wc -l`
if [ $chktcp21 = 1 ]
then
#echo "============="
#echo " FTPD Is Up "
#echo "============="
exit 0
else
#echo "============="
#echo " FTPD Is Down "
#echo "============="
exit 1
fi
=====================
Backup config 如下
! Configuration File for keepalived
vrrp_script check_sh {
script "/etc/keepalived/chk_ftp.sh"
interval 2 # check every 2 seconds
weight -30 # default prio: -30
fall 2 # require 2 failures
rise 2 # require 2 successes
}
vrrp_script chk_httpd {
script "killall -0 httpd"
interval 2
weight -30
fall 2
rise 2
}
vrrp_script chk_8080_port {
script "</dev/tcp/127.0.0.1/8080"
interval 1
weight -30
fall 2
rise 2
}
global_defs {
notification_email {
xrcd2@xrcd2.com.tw
}
notification_email_from keepalived@xrcd2.com.tw
smtp_server 192.168.1.100
smtp_connect_timeout 30
router_id NodeB
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 1
priority 90
advert_int 1
smtp_alert
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.3
}
track_script {
check_sh
chk_httpd
chk_8080_port
}
track_interface{
eth0
}
}
運作通知!
切換通知!
http://www.keepalived.org/
延續這個主題.
http://xrcd2.blogspot.tw/2013/04/linux-ha-keepalived-linux-vrrp.html
加入切換條件, 如 track_script
Master config 如下
! Configuration File for keepalived
vrrp_script check_sh {
script "/etc/keepalived/chk_ftp.sh"
interval 2 # check every 2 seconds
weight -30 # default prio: -30
fall 2 # require 2 failures
rise 2 # require 2 successes
}
vrrp_script chk_httpd {
script "killall -0 httpd"
interval 2
weight -30
fall 2
rise 2
}
vrrp_script chk_8080_port {
script "</dev/tcp/127.0.0.1/8080"
interval 1
weight -30
fall 2
rise 2
}
global_defs {
notification_email {
xrcd2@xrcd2.com.tw
}
notification_email_from keepalived@xrcd2.com.tw
smtp_server 192.168.1.100
smtp_connect_timeout 30
router_id NodeA
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 1
priority 100
advert_int 1
smtp_alert
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.3
}
track_script {
check_sh
chk_httpd
chk_8080_port
}
track_interface{
eth0
}
}
DIY 檢查的 shell
======================
cat /etc/keepalived/chk_ftp.sh
#!/bin/bash
chktcp21=`nmap 127.0.0.1 | grep '21/tcp' | wc -l`
if [ $chktcp21 = 1 ]
then
#echo "============="
#echo " FTPD Is Up "
#echo "============="
exit 0
else
#echo "============="
#echo " FTPD Is Down "
#echo "============="
exit 1
fi
=====================
Backup config 如下
! Configuration File for keepalived
vrrp_script check_sh {
script "/etc/keepalived/chk_ftp.sh"
interval 2 # check every 2 seconds
weight -30 # default prio: -30
fall 2 # require 2 failures
rise 2 # require 2 successes
}
vrrp_script chk_httpd {
script "killall -0 httpd"
interval 2
weight -30
fall 2
rise 2
}
vrrp_script chk_8080_port {
script "</dev/tcp/127.0.0.1/8080"
interval 1
weight -30
fall 2
rise 2
}
global_defs {
notification_email {
xrcd2@xrcd2.com.tw
}
notification_email_from keepalived@xrcd2.com.tw
smtp_server 192.168.1.100
smtp_connect_timeout 30
router_id NodeB
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 1
priority 90
advert_int 1
smtp_alert
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.3
}
track_script {
check_sh
chk_httpd
chk_8080_port
}
track_interface{
eth0
}
}
運作通知!
切換通知!
2013年4月24日 星期三
簡單的 linux H.A 架構 keepalived (linux vrrp)
透過 keepalived 達成簡單的 linux H.A 架構. (linux vrrp)
http://www.keepalived.org/
[root@Test-Tomcat1 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
xrcd2@xrcd2.com.tw
}
notification_email_from keepalived@xrcd2.com.tw
smtp_server 192.168.1.100
smtp_connect_timeout 30
router_id NodeA
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 1
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
virtual_ipaddress {
192.168.1.3
}
}
[root@Test-Tomcat2 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
xrcd2@xrcd2.com.tw
}
notification_email_from keepalived@xrcd2.com.tw
smtp_server 192.168.1.100
smtp_connect_timeout 30
router_id NodeB
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 1
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
virtual_ipaddress {
192.168.1.3
}
}
http://www.keepalived.org/
[root@Test-Tomcat1 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
xrcd2@xrcd2.com.tw
}
notification_email_from keepalived@xrcd2.com.tw
smtp_server 192.168.1.100
smtp_connect_timeout 30
router_id NodeA
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 1
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
virtual_ipaddress {
192.168.1.3
}
}
[root@Test-Tomcat2 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
xrcd2@xrcd2.com.tw
}
notification_email_from keepalived@xrcd2.com.tw
smtp_server 192.168.1.100
smtp_connect_timeout 30
router_id NodeB
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 1
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
virtual_ipaddress {
192.168.1.3
}
}
2013年3月26日 星期二
JDK 1.6.0_43 64 Bit 無法使用 jvm snmp
JDK 1.6.0_43 64 Bit 無法使用 jvm snmp ,一定要使用檔案的方式宣告方可使用.
之前使用直寫的方式,在 java 32 Bit 的版本是沒問題的.
另外一個問題是 /etc/hosts 一定要將主機名稱寫入,要不然 jmx 是無法使用
-Djava.rmi.server.hostname=192.168.x.x 這個參數!
java snmp 以檔案方式宣告如下:
tomcat startup.sh
export JAVA_OPTS="-Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m -Dcom.sun.management.config.file=/usr/local/tomcat/bin/snmp.properties -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.x.x. -Dcom.sun.management.jmxremote.port=9012 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
[root@Test-Tomcat bin]# cat snmp.acl
acl = {
{
communities = public
access = read-only
managers = localhost
}
}
[root@Test-Tomcat bin]# cat snmp.properties
com.sun.management.snmp.interface=0.0.0.0
com.sun.management.snmp.port=1610
com.sun.management.snmp.acl=/usr/local/tomcat/bin/snmp.acl
直寫方式如下:
export JAVA_OPTS="="-Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.xx.xx -Dcom.sun.management.jmxremote
.port=9012 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.managemen
t.snmp.port=1610 -Dcom.sun.management.snmp.acl.file=/tmp/snmp.acl -Dcom.sun.management.snmp.interface=0.0.0.0"
之前使用直寫的方式,在 java 32 Bit 的版本是沒問題的.
另外一個問題是 /etc/hosts 一定要將主機名稱寫入,要不然 jmx 是無法使用
-Djava.rmi.server.hostname=192.168.x.x 這個參數!
java snmp 以檔案方式宣告如下:
tomcat startup.sh
export JAVA_OPTS="-Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m -Dcom.sun.management.config.file=/usr/local/tomcat/bin/snmp.properties -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.x.x. -Dcom.sun.management.jmxremote.port=9012 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
[root@Test-Tomcat bin]# cat snmp.acl
acl = {
{
communities = public
access = read-only
managers = localhost
}
}
[root@Test-Tomcat bin]# cat snmp.properties
com.sun.management.snmp.interface=0.0.0.0
com.sun.management.snmp.port=1610
com.sun.management.snmp.acl=/usr/local/tomcat/bin/snmp.acl
直寫方式如下:
export JAVA_OPTS="="-Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.xx.xx -Dcom.sun.management.jmxremote
.port=9012 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.managemen
t.snmp.port=1610 -Dcom.sun.management.snmp.acl.file=/tmp/snmp.acl -Dcom.sun.management.snmp.interface=0.0.0.0"
2013年3月15日 星期五
apache 整合 tomcat 的二種方式
tomcat-connectors
http://tomcat.apache.org/connectors-doc/
#wget http://www.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.37-src.tar.gz
#tar -zvxf tomcat-connectors-1.2.37-src.tar.gz
#cd tomcat-connectors-1.2.37-src/native
#./buildconf.sh
#./configure --with-apxs=/usr/sbin/apxs
#make
#make install
#vi workers.properties
#vi jk_mode.conf
#vi ssl.conf
#service httpd restart
jk_module
workers.properties
worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.connection_pool_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=60
jk_mod.conf
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile /tmp/mod_jk.log
JkMount /test1/*.jsp worker1
JkMount /manager/* worker1
ssl.conf
.......
JkMount /test1/*.jsp worker1
JkMount /manager/* worker1
</VirtualHost>
Proxy_ajp
proxy_ajp.conf
LoadModule proxy_ajp_module
modules/mod_proxy_ajp.so
#
# When loaded, the mod_proxy_ajp module
adds support for
# proxying to an AJP/1.3 backend server
(such as Tomcat).
# To proxy to an AJP backend, use the
"ajp://" URI scheme;
# Tomcat is configured to listen on port
8009 for AJP requests
# by default.
# Uncomment the following lines to serve
the ROOT webapp
# under the /tomcat/ location, and the
jsp-examples webapp
# under the /examples/ location.
#
#ProxyPass /tomcat/ ajp://localhost:8009/
#ProxyPass /examples/
ajp://localhost:8009/jsp-examples/
ProxyPass /test1/ ajp://localhost:8009/test1/
ProxyPass /manager/
ajp://localhost:8009/manager/
2013年3月8日 星期五
使用 perl 做 scp 的二種方式
使用 perl 做 scp 的二種方式
#yum install libssh2-devel
#yum install libssh2
#yum install perl-Net-SSH2
#yum install perl-Net-SFTP
========================================================
#!/usr/bin/perl
use Net::SFTP;
$sftp = Net::SFTP->new('xxx.xxx.xxx.xxx',user=>'userID',password=>'userPWD');
$sftp->get("/xxx/xxx", "/xxx/xxx");
========================================================
#!/usr/bin/perl
@ip=qw
(
192.168.1.1
192.168.1.2
);
@host=qw
(
server1
server2
);
@list=qw
(
server1.txt
server1.txt
);
for ($x=0;$x<=$#ip;$x++) {
print " \n $x SCP IP : $ip[$x] HostName : $host[$x] DFCHK_File : $df[$x] \n";
sshget();
}
sub sshget {
use Net::SSH2;
use Net::SSH2::Dir;
$ssh=Net::SSH2->new() or die "couldn't make SSH object\n";
#$ssh->debug(1);
$ssh->blocking(1);
print "made SSH object\n";
$ssh->connect("$ip[$x]") or die "couldn't connect to host\n";
print "connected to $host[$x] $ip[$x] \n";
$ssh->auth_password('userID','userPWD') or die "couldn't authenticate user \n";
print "authenticated UserID\n";
$ssh->scp_get("/xxx/$list[$x]","/xxx/$list[$x]") or warn "couldn't get file in $list[$x] \n ";
print "\n Download Successfully \n";
$ssh->disconnect or die "couldn't disconnect\n";
}
========================================================
#yum install libssh2-devel
#yum install libssh2
#yum install perl-Net-SSH2
#yum install perl-Net-SFTP
========================================================
#!/usr/bin/perl
use Net::SFTP;
$sftp = Net::SFTP->new('xxx.xxx.xxx.xxx',user=>'userID',password=>'userPWD');
$sftp->get("/xxx/xxx", "/xxx/xxx");
========================================================
#!/usr/bin/perl
@ip=qw
(
192.168.1.1
192.168.1.2
);
@host=qw
(
server1
server2
);
@list=qw
(
server1.txt
server1.txt
);
for ($x=0;$x<=$#ip;$x++) {
print " \n $x SCP IP : $ip[$x] HostName : $host[$x] DFCHK_File : $df[$x] \n";
sshget();
}
sub sshget {
use Net::SSH2;
use Net::SSH2::Dir;
$ssh=Net::SSH2->new() or die "couldn't make SSH object\n";
#$ssh->debug(1);
$ssh->blocking(1);
print "made SSH object\n";
$ssh->connect("$ip[$x]") or die "couldn't connect to host\n";
print "connected to $host[$x] $ip[$x] \n";
$ssh->auth_password('userID','userPWD') or die "couldn't authenticate user \n";
print "authenticated UserID\n";
$ssh->scp_get("/xxx/$list[$x]","/xxx/$list[$x]") or warn "couldn't get file in $list[$x] \n ";
print "\n Download Successfully \n";
$ssh->disconnect or die "couldn't disconnect\n";
}
========================================================
2013年2月25日 星期一
md5deep reporting to E-mail ( 使用 perl )
程式需求說明,對某一個目錄做 MD5 檢核!並將檢核結果以 E-Mail 方式自動通知!
md5deep
http://md5deep.sourceforge.net/
md5deep.exe -h
md5deep.exe version 4.3 by Jesse Kornblum and Simson Garfinkel.
C:\> md5deep.exe [OPTION]... [FILES]...
See the man page or README.txt file or use -hh for the full list of options
-p <size> - piecewise mode. Files are broken into blocks for hashing
-r - recursive mode. All subdirectories are traversed
-e - show estimated time remaining for each file
-s - silent mode. Suppress all error messages
-z - display file size before hash
-m <file> - enables matching mode. See README/man page
-x <file> - enables negative matching mode. See README/man page
-M and -X are the same as -m and -x but also print hashes of each file
-w - displays which known file generated a match
-n - displays known hashes that did not match any input files
-a and -A add a single hash to the positive or negative matching set
-b - prints only the bare name of files; all path information is omitted
-l - print relative paths for filenames
-t - print GMT timestamp (ctime)
-i/I <size> - only process files smaller/larger than SIZE
-v - display version number and exit
-d - output in DFXML; -u - Escape Unicode; -W FILE - write to FILE.
-j <num> - use num threads (default 2)
-Z - triage mode; -h - help; -hh - full help
#!/usr/bin/perl
#md5filenameok 這個陣列是用來是用來檢核並列出MD5正常的檔案
@md5filenameok=`c:\\perl-shell\\md5deep.exe -r -m c:\\perl-shell\\md5\\syslog.md5 d:\\backup\\*.*`;
#md5filenameoknumber 這個陣列是用來是用來檢核並列出MD5正常的檔案的檔案數量
$md5filenameoknumber=`c:\\perl-shell\\md5deep.exe -r -m c:\\perl-shell\\md5\\syslog.md5 d:\\backup\\*.* | find /c "d:\"`;
#下面這個方式是在 windows command mode 對目錄做出 MD5的檢核檔
#system(`c:\perl-shell\md5deep -l -r d:\backup > c:\perl-shell\md5\syslog.md5`);
#這個陣列是用來是用來檢核並列出MD5異常的檔案
@md5filename=`c:\\perl-shell\\md5deep.exe -r -x c:\\perl-shell\\md5\\syslog.md5 d:\\backup\\*.*`;
#這個陣列是用來是用來檢核並列出MD5異常的檔案的檔案數量
$md5number=`c:\\perl-shell\\md5deep.exe -r -x c:\\perl-shell\\md5\\syslog.md5 d:\\backup\\*.* | find /c "d:\" `;
chomp($md5filenameoknumber);
chomp($md5number);
print '=============== 正常 ===============';
print "\n\n";
print "\n MD5比對正確的檔案清單如下: \n\n @md5filenameok \n";
print "比對正確的檔案數量合計共有 $md5filenameoknumber 個 \n\n";
print '=============== 異常 ===============';
print "\n\n";
print "MD5比對異常的檔案清單如下: \n\n @md5filename \n";
print "比對異常的檔案數量合計共有 $md5number 個 \n ";
@message1="\n MD5比對正確的檔案清單如下: \n\n @md5filenameok \n 比對正確的檔案數量合計共有: $md5filenameoknumber \n\n";
@message2="\n MD5比對異常的檔案清單如下: \n\n @md5filename \n 比對異常的檔案數量合計共有: $md5number \n\n";
#可自行選擇在何種條件才寄出郵件通知!
if ($md5number==0){
print "\n ----> MD5 比對異常的檔案數量為 0 不寄出郵件通知! \n";
$status='[ Normal ]';
get_mail();
}
else {
print " \n ----> MD5 比對異常出郵件通知 \n ";
$status='[ --->Error ]';
get_mail();
}
sub get_mail{
use Encode qw(decode encode_utf8);
use Encode qw(encode);
use MIME::Base64;
use MIME::Lite;
($sec,$min,$hour,$day,$mon,$year,$mday)=localtime(time);
$mon++;
if (length ($mon) == 1) {$mon = '0'.$mon;}
if (length ($day) == 1) {$day = '0'.$day;}
if (length ($hour) == 1) {$hour = '0'.$hour;}
if (length ($min) == 1) {$min = '0'.$min;}
if (length ($sec) == 1) {$sec = '0'.$sec;}
$year+=1900;
$clock=" $status Syslog-Server md5 CheckMail $year/$mon/$day/$hour:$min/";
@foot0=' Syslog-Server D:\BACKUP MD5自動檢查通知程式!';
use Encode qw/from_to/;
from_to(@foot0, "utf8", "big5");
from_to(@message1, "utf8", "big5");
from_to(@message2, "utf8", "big5");
from_to($clock, "utf8", "big5");
$line='=====================================================';
$msg = MIME::Lite->new(
From =>'Syslog-MD5@xrcd2.com.tw',
To =>'xrcd2@xrcd2.com.tw',
Subject => "$clock",
Encoding => 'base64',
Data =>"@foot0 \n\n $line \n\n @message1 \n\n $line\n\n @message2 \n\n $line \n\n"
);
$msg->get_length;
$msg->attr("content-type.charset" => "UTF8");
$msg->send('smtp','smpt.server.ip.address');
print $Mail::SendMail::Error eq "" ? "\n send ok!\n" : $Mail::SendMail::Error;
}
md5deep
http://md5deep.sourceforge.net/
md5deep.exe -h
md5deep.exe version 4.3 by Jesse Kornblum and Simson Garfinkel.
C:\> md5deep.exe [OPTION]... [FILES]...
See the man page or README.txt file or use -hh for the full list of options
-p <size> - piecewise mode. Files are broken into blocks for hashing
-r - recursive mode. All subdirectories are traversed
-e - show estimated time remaining for each file
-s - silent mode. Suppress all error messages
-z - display file size before hash
-m <file> - enables matching mode. See README/man page
-x <file> - enables negative matching mode. See README/man page
-M and -X are the same as -m and -x but also print hashes of each file
-w - displays which known file generated a match
-n - displays known hashes that did not match any input files
-a and -A add a single hash to the positive or negative matching set
-b - prints only the bare name of files; all path information is omitted
-l - print relative paths for filenames
-t - print GMT timestamp (ctime)
-i/I <size> - only process files smaller/larger than SIZE
-v - display version number and exit
-d - output in DFXML; -u - Escape Unicode; -W FILE - write to FILE.
-j <num> - use num threads (default 2)
-Z - triage mode; -h - help; -hh - full help
#!/usr/bin/perl
#md5filenameok 這個陣列是用來是用來檢核並列出MD5正常的檔案
@md5filenameok=`c:\\perl-shell\\md5deep.exe -r -m c:\\perl-shell\\md5\\syslog.md5 d:\\backup\\*.*`;
#md5filenameoknumber 這個陣列是用來是用來檢核並列出MD5正常的檔案的檔案數量
$md5filenameoknumber=`c:\\perl-shell\\md5deep.exe -r -m c:\\perl-shell\\md5\\syslog.md5 d:\\backup\\*.* | find /c "d:\"`;
#下面這個方式是在 windows command mode 對目錄做出 MD5的檢核檔
#system(`c:\perl-shell\md5deep -l -r d:\backup > c:\perl-shell\md5\syslog.md5`);
#這個陣列是用來是用來檢核並列出MD5異常的檔案
@md5filename=`c:\\perl-shell\\md5deep.exe -r -x c:\\perl-shell\\md5\\syslog.md5 d:\\backup\\*.*`;
#這個陣列是用來是用來檢核並列出MD5異常的檔案的檔案數量
$md5number=`c:\\perl-shell\\md5deep.exe -r -x c:\\perl-shell\\md5\\syslog.md5 d:\\backup\\*.* | find /c "d:\" `;
chomp($md5filenameoknumber);
chomp($md5number);
print '=============== 正常 ===============';
print "\n\n";
print "\n MD5比對正確的檔案清單如下: \n\n @md5filenameok \n";
print "比對正確的檔案數量合計共有 $md5filenameoknumber 個 \n\n";
print '=============== 異常 ===============';
print "\n\n";
print "MD5比對異常的檔案清單如下: \n\n @md5filename \n";
print "比對異常的檔案數量合計共有 $md5number 個 \n ";
@message1="\n MD5比對正確的檔案清單如下: \n\n @md5filenameok \n 比對正確的檔案數量合計共有: $md5filenameoknumber \n\n";
@message2="\n MD5比對異常的檔案清單如下: \n\n @md5filename \n 比對異常的檔案數量合計共有: $md5number \n\n";
#可自行選擇在何種條件才寄出郵件通知!
if ($md5number==0){
print "\n ----> MD5 比對異常的檔案數量為 0 不寄出郵件通知! \n";
$status='[ Normal ]';
get_mail();
}
else {
print " \n ----> MD5 比對異常出郵件通知 \n ";
$status='[ --->Error ]';
get_mail();
}
sub get_mail{
use Encode qw(decode encode_utf8);
use Encode qw(encode);
use MIME::Base64;
use MIME::Lite;
($sec,$min,$hour,$day,$mon,$year,$mday)=localtime(time);
$mon++;
if (length ($mon) == 1) {$mon = '0'.$mon;}
if (length ($day) == 1) {$day = '0'.$day;}
if (length ($hour) == 1) {$hour = '0'.$hour;}
if (length ($min) == 1) {$min = '0'.$min;}
if (length ($sec) == 1) {$sec = '0'.$sec;}
$year+=1900;
$clock=" $status Syslog-Server md5 CheckMail $year/$mon/$day/$hour:$min/";
@foot0=' Syslog-Server D:\BACKUP MD5自動檢查通知程式!';
use Encode qw/from_to/;
from_to(@foot0, "utf8", "big5");
from_to(@message1, "utf8", "big5");
from_to(@message2, "utf8", "big5");
from_to($clock, "utf8", "big5");
$line='=====================================================';
$msg = MIME::Lite->new(
From =>'Syslog-MD5@xrcd2.com.tw',
To =>'xrcd2@xrcd2.com.tw',
Subject => "$clock",
Encoding => 'base64',
Data =>"@foot0 \n\n $line \n\n @message1 \n\n $line\n\n @message2 \n\n $line \n\n"
);
$msg->get_length;
$msg->attr("content-type.charset" => "UTF8");
$msg->send('smtp','smpt.server.ip.address');
print $Mail::SendMail::Error eq "" ? "\n send ok!\n" : $Mail::SendMail::Error;
}
2013年2月23日 星期六
linux Perl 開發環境初使化工作
http://www.ncftp.com/download/
download & install ncftp-client
初使化 cpan ( Perl Module 安裝工具)
#cpan
#cpan -h (說明)
cpan的使用方式
#cpan Module::Name
如
#cpan DBI
或 安裝 cpanm ( Perl Module 安裝工具)
#curl -LO http://bit.ly/cpanm
#chmod +x cpanm
#cp cpanm /bin
#cpanm --help (說明)
#cpanm DBI
[root@centos63 tmp]# cpanm DBIDBI is up to date. (1.623)
[root@centos63 tmp]# cpan DBI CPAN: Storable loaded ok (v2.20)
Going to read '/root/.cpan/Metadata'
Database was generated on Sat, 23 Feb 2013 14:29:04 GMT
DBI is up to date (1.623).
或 cpanp (perl Module 安裝工具 perl 5.10.xx 以後才支援)
#cpanp -i SVK
cpan> install CPANPLUS
[root@centos63 tmp]# cpanp
CPANPLUS::Shell::Default -- CPAN exploration and module installation (v0.9134)
*** Please report bugs to <bug-cpanplus@rt.cpan.org>.
*** Using CPANPLUS::Backend v0.9134.
*** ReadLine support available (try 'i Term::ReadLine::Perl').
*** Type 'p' now to show start up log
Did you know...
You can type 'h' for help and 'q' to exit
CPAN Terminal> h
[General]
h | ? # display help
q # exit
e # exit and reload
v # version information
[Search]
a AUTHOR ... # search by author(s)
m MODULE ... # search by module(s)
f MODULE ... # list all releases of a module
o [ MODULE ... ] # list installed module(s) that aren't up to date
w # display the result of your last search again
[Operations]
i MODULE | NUMBER ... # install module(s), by name or by search number
i URI | ... # install module(s), by URI (ie http://foo.com/X.tgz)
i DIR | ... # install module(s), by path (ie ./Module-1.0)
t MODULE | NUMBER ... # test module(s), by name or by search number
u MODULE | NUMBER ... # uninstall module(s), by name or by search number
d MODULE | NUMBER ... # download module(s)
l MODULE | NUMBER ... # display detailed information about module(s)
r MODULE | NUMBER ... # display README files of module(s)
c MODULE | NUMBER ... # check for module report(s) from cpan-testers
z MODULE | NUMBER ... # extract module(s) and open command prompt in it
[Local Administration]
b # write a bundle file for your configuration
s program [OPT VALUE] # set program locations for this session
s conf [OPT VALUE] # set config options for this session
s mirrors # show currently selected mirrors
s reconfigure # reconfigure settings
s selfupdate # update your CPANPLUS install
s save [user|system] # save settings for this user or systemwide
s edit [user|system] # open configuration file in editor and reload
! EXPR # evaluate a perl statement
p [FILE] # print the error stack (optionally to a file)
x # reload CPAN indices (purges cache)
x --update_source # reload CPAN indices, get fresh source files
[Common Options]
i ... --skiptest # skip tests
i ... --force # force all operations
i ... --verbose # run in verbose mode
[Plugins]
/plugins # list available plugins
/? [PLUGIN NAME] # show usage for (a particular) plugin(s)
CPAN Terminal>
reconfig cpan 的方法
cpan> o conf init
以前會使用 perlcc 去 compile 但那是在 perl 5.8.xx (CentOS Linux 5.xx) 的時代,
在 perl 5.10.xx (CentOS Linux 6.xx )以後,已由 pp 取代了原 perlcc 的功能!
使用方式
#pp -o test test.pl
[root@centos63 tmp]# perl -v
This is perl, v5.10.1 (*) built for i386-linux-thread-multi
Copyright 1987-2009, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
[root@centos63 tmp]# pp -version
PAR Packager, version 1.014 (PAR version 1.007)
Copyright 2002-2009 by Audrey Tang <cpan@audreyt.org>
Neither this program nor the associated "parl" program impose any
licensing restrictions on files generated by their execution, in
accordance with the 8th article of the Artistic License:
"Aggregation of this Package with a commercial distribution is
always permitted provided that the use of this Package is embedded;
that is, when no overt attempt is made to make this Package's
interfaces visible to the end user of the commercial distribution.
Such use shall not be construed as a distribution of this Package."
Therefore, you are absolutely free to place any license on the resulting
executable, as long as the packed 3rd-party libraries are also available
under the Artistic License.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself. There is NO warranty; not even for
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@centos63 tmp]# cpanm --help
Usage: cpanm [options] Module [...]
Options:
-v,--verbose Turns on chatty output
-q,--quiet Turns off the most output
--interactive Turns on interactive configure (required for Task:: modules)
-f,--force force install
-n,--notest Do not run unit tests
--test-only Run tests only, do not install
-S,--sudo sudo to run install commands
--installdeps Only install dependencies
--showdeps Only display direct dependencies
--reinstall Reinstall the distribution even if you already have the latest version installed
--mirror Specify the base URL for the mirror (e.g. http://cpan.cpantesters.org/)
--mirror-only Use the mirror's index file instead of the CPAN Meta DB
--prompt Prompt when configure/build/test fails
-l,--local-lib Specify the install base to install modules
-L,--local-lib-contained Specify the install base to install all non-core modules
--auto-cleanup Number of days that cpanm's work directories expire in. Defaults to 7
Commands:
--self-upgrade upgrades itself
--info Displays distribution info on CPAN
--look Opens the distribution with your SHELL
-V,--version Displays software version
Examples:
cpanm Test::More # install Test::More
cpanm MIYAGAWA/Plack-0.99_05.tar.gz # full distribution path
cpanm http://example.org/LDS/CGI.pm-3.20.tar.gz # install from URL
cpanm ~/dists/MyCompany-Enterprise-1.00.tar.gz # install from a local file
cpanm --interactive Task::Kensho # Configure interactively
cpanm . # install from local directory
cpanm --installdeps . # install all the deps for the current directory
cpanm -L extlib Plack # install Plack and all non-core deps into extlib
cpanm --mirror http://cpan.cpantesters.org/ DBI # use the fast-syncing mirror
You can also specify the default options in PERL_CPANM_OPT environment variable in the shell rc:
export PERL_CPANM_OPT="--prompt --reinstall -l ~/perl --mirror http://cpan.cpantesters.org"
Type `man cpanm` or `perldoc cpanm` for the more detailed explanation of the options.
個人必裝的是
cpanm Net::Telnet::Cisco
cpanm Mail::Sendmail
cpanm Mail::Sender
cpanm MIME::Lite
cpanm Mail::Builder::Simple
cpanm pp
自動備份 cisco 設備 show run 的 config ( 使用 perl )
使用環境 perl + cisco (ios) + telnet + smtp + 排程
程式碼如下,請視實務需求自行修改!
#!/usr/bin/perl
($sec,$min,$hour,$day,$mon,$year)=localtime(time);
$mon++;
if (length ($mon) == 1) {$mon = '0'.$mon;}
if (length ($day) == 1) {$day = '0'.$day;}
if (length ($hour) == 1) {$hour = '0'.$hour;}
if (length ($min) == 1) {$min = '0'.$min;}
if (length ($sec) == 1) {$sec = '0'.$sec;}
$year+=1900;
$clock="$year$mon$day$hour$min$sec";
$subname='.txt';
$dir='/root/shell/cisco/';
#設備 IP 請務必正確輸入於下面
@cisco=qw
(
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.5
192.168.1.6
192.168.1.7
192.168.1.8
192.168.1.9
);
#設備名稱請輸入於下面以方便做為存檔或郵件示別使用
@hostname=qw
(
Switch-1
Switch-2
Switch-3
Switch-4
Router-1
Router-2
Router-3
Router-4
Router-5
);
for ($x=0;$x<=$#cisco;$x++){
print " \n telnet IP $cisco[$x] HostName $hostname[$x] \n";
print " \n Write File Name is $hostname[$x].$clock$subname \n\n ";
$savefile="$dir$hostname[$x].$clock$subname";
print "\n save $savefile \n\n ";
print " \n No. $x IP $cisco[$x] $hostname[$x] Start Sending command .... \n";
# 使用下面這種方式連入 Cisco 設備
get_cisco();
# show run 的存檔作業
open(write_file,">$savefile") or "open file error";
print write_file "@showrun";
close(write_file);
#使用下面這種方式寄信 show run 的資訊會在郵件本文中,
#如不使用~下面 get_mail()前方請加上 #
get_mail();
sleep 5;
#使用下面這種方式寄信 show run 的資訊會變成以附件的方式傳送,
#如不使~用下面 send_config_file() 前方請加上 #
send_config_file();
sleep 5;
}
sub get_cisco{
use Net::Telnet::Cisco;
$session = Net::Telnet::Cisco->new(Host => "$cisco[$x]",Timeout=>'120');
#使用 ID + PWD login 請使用下一行 , 如不使用~下一行前方請加上 #
#$session->login('login', 'password');
#只使有 pwd login 請使用下一行, 如不使用~下一行前方請加上 #
$session->cmd('xxxxxxxxx');
$session->enable('xxxxxxxxx');
@showrun = $session->cmd('show run ');
$session->close;
}
sub get_mail{
use Encode qw(decode encode_utf8);
use Encode qw(encode);
use MIME::Base64;
use MIME::Lite;
$foot0=' Cisco Devices configuration auto backup ';
use Encode qw/from_to/;
from_to($foot0, "utf8", "big5");
from_to(@showrun, "utf8", "big5");
from_to($clock, "utf8", "big5");
$line='=====================================================';
$msg = MIME::Lite->new(
From =>'cisco-show-run@xrcd2.com.tw',
To =>'xrcd2@xrcd2.com.tw',
Subject => "$hostname[$x].$clock.txt",
Encoding => 'base64',
Data =>"$foot0 \n\n $line \n\n @showrun \n\n $line\n\n"
);
$msg->get_length;
$msg->attr("content-type.charset" => "UTF8");
$msg->send('smtp','smtp.server.ip.address');
print $Mail::SendMail::Error eq "" ? "\n send ok!\n" : $Mail::SendMail::Error;
}
sub send_config_file{
use Mail::Sender;
$sender = new Mail::Sender
{smtp => 'smtp.server.ip.address', from => 'showrun@xrcd2.com.tw'};
$sender->MailFile({to => 'xrcd2@xrcd2.com.tw',
subject => "$hostname[$x].$clock$subname",
msg => "$hostname[$x].$clock$subname",
file => "$dir$hostname[$x].$clock$subname"});
}
下圖為以附加檔案方式將 show run 的資訊寄出!
下圖為將 show run 的資訊顯示在郵件本文中!
程式碼如下,請視實務需求自行修改!
#!/usr/bin/perl
($sec,$min,$hour,$day,$mon,$year)=localtime(time);
$mon++;
if (length ($mon) == 1) {$mon = '0'.$mon;}
if (length ($day) == 1) {$day = '0'.$day;}
if (length ($hour) == 1) {$hour = '0'.$hour;}
if (length ($min) == 1) {$min = '0'.$min;}
if (length ($sec) == 1) {$sec = '0'.$sec;}
$year+=1900;
$clock="$year$mon$day$hour$min$sec";
$subname='.txt';
$dir='/root/shell/cisco/';
#設備 IP 請務必正確輸入於下面
@cisco=qw
(
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.5
192.168.1.6
192.168.1.7
192.168.1.8
192.168.1.9
);
#設備名稱請輸入於下面以方便做為存檔或郵件示別使用
@hostname=qw
(
Switch-1
Switch-2
Switch-3
Switch-4
Router-1
Router-2
Router-3
Router-4
Router-5
);
for ($x=0;$x<=$#cisco;$x++){
print " \n telnet IP $cisco[$x] HostName $hostname[$x] \n";
print " \n Write File Name is $hostname[$x].$clock$subname \n\n ";
$savefile="$dir$hostname[$x].$clock$subname";
print "\n save $savefile \n\n ";
print " \n No. $x IP $cisco[$x] $hostname[$x] Start Sending command .... \n";
# 使用下面這種方式連入 Cisco 設備
get_cisco();
# show run 的存檔作業
open(write_file,">$savefile") or "open file error";
print write_file "@showrun";
close(write_file);
#使用下面這種方式寄信 show run 的資訊會在郵件本文中,
#如不使用~下面 get_mail()前方請加上 #
get_mail();
sleep 5;
#使用下面這種方式寄信 show run 的資訊會變成以附件的方式傳送,
#如不使~用下面 send_config_file() 前方請加上 #
send_config_file();
sleep 5;
}
sub get_cisco{
use Net::Telnet::Cisco;
$session = Net::Telnet::Cisco->new(Host => "$cisco[$x]",Timeout=>'120');
#使用 ID + PWD login 請使用下一行 , 如不使用~下一行前方請加上 #
#$session->login('login', 'password');
#只使有 pwd login 請使用下一行, 如不使用~下一行前方請加上 #
$session->cmd('xxxxxxxxx');
$session->enable('xxxxxxxxx');
@showrun = $session->cmd('show run ');
$session->close;
}
sub get_mail{
use Encode qw(decode encode_utf8);
use Encode qw(encode);
use MIME::Base64;
use MIME::Lite;
$foot0=' Cisco Devices configuration auto backup ';
use Encode qw/from_to/;
from_to($foot0, "utf8", "big5");
from_to(@showrun, "utf8", "big5");
from_to($clock, "utf8", "big5");
$line='=====================================================';
$msg = MIME::Lite->new(
From =>'cisco-show-run@xrcd2.com.tw',
To =>'xrcd2@xrcd2.com.tw',
Subject => "$hostname[$x].$clock.txt",
Encoding => 'base64',
Data =>"$foot0 \n\n $line \n\n @showrun \n\n $line\n\n"
);
$msg->get_length;
$msg->attr("content-type.charset" => "UTF8");
$msg->send('smtp','smtp.server.ip.address');
print $Mail::SendMail::Error eq "" ? "\n send ok!\n" : $Mail::SendMail::Error;
}
sub send_config_file{
use Mail::Sender;
$sender = new Mail::Sender
{smtp => 'smtp.server.ip.address', from => 'showrun@xrcd2.com.tw'};
$sender->MailFile({to => 'xrcd2@xrcd2.com.tw',
subject => "$hostname[$x].$clock$subname",
msg => "$hostname[$x].$clock$subname",
file => "$dir$hostname[$x].$clock$subname"});
}
下圖為以附加檔案方式將 show run 的資訊寄出!
下圖為將 show run 的資訊顯示在郵件本文中!
2013年2月19日 星期二
cacti linux memory usage template
第一次發現 cacti 的怪現象,使用 cacti 預設的 ucd/net - Memory Usage 的方式,
去 Monitor memory usage 會產生異常,某些主機跑出來的圖示就是怪怪的,
後來在網路上找出其它的 template !
http://forums.cacti.net/viewtopic.php?f=12&t=24501
http://freeccnp-cacti.blogspot.tw/2012/07/memory-usage-linux-graph-template-work.html
但直接匯入 linux memory usage template 並無法使用.
異常的訊息為:
ERROR: invalid rpn expression in: g,e,-,c,-,a,-,1024,*
後來將 CDEFs 改為 cdef=d,b,-,c,-,a,-,1024,* 方可使用.希望不會再出現其它的怪問題了.
正常的圖示如下:
異常的圖示如下:
上圖為 linux memory usage template (ucd/net - Memory Usage (Linux) )
CDEF 修改方式
去 Monitor memory usage 會產生異常,某些主機跑出來的圖示就是怪怪的,
後來在網路上找出其它的 template !
http://forums.cacti.net/viewtopic.php?f=12&t=24501
http://freeccnp-cacti.blogspot.tw/2012/07/memory-usage-linux-graph-template-work.html
但直接匯入 linux memory usage template 並無法使用.
異常的訊息為:
ERROR: invalid rpn expression in: g,e,-,c,-,a,-,1024,*
後來將 CDEFs 改為 cdef=d,b,-,c,-,a,-,1024,* 方可使用.希望不會再出現其它的怪問題了.
正常的圖示如下:
異常的圖示如下:
上圖為 linux memory usage template (ucd/net - Memory Usage (Linux) )
CDEF 修改方式
2013年1月5日 星期六
tomcat Error: Failed to start SNMP adaptor with address
之前在測試 JVM SNMP + JMX 時,皆是以 Tomcat 做為 LAB 的測試標的.
但在使用 /usr/local/tomcat/shutdown.sh 將 tomcat 的服務停止時,
總會產生 tomcat Error: Failed to start SNMP adaptor with address 這樣的訊息.
最後總是直接使用 killall -9 去停止該項服務.最後 google 到 解法.
資料參考 http://www.tikalk.com/java/forums/when-use-tomcat-catalina-opts-instead-java-opts
將 JMX & SNMP 的 JAVA_OPTS 從 /etc/profile.d/java.sh
移到 /usr/local/tomcat/startup.sh
在上方處放上原先設定:
export JAVA_OPTS="-Dcom.sun.management.snmp.port=1610 -Dcom.sun.management.snmp.acl.file=/usr/java/jre/lib/management/snmp.acl -Dcom.sun.management.snmp.interface=0.0.0.0 -Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.100.101 -Dcom.sun.management.jmxremote.port=9012 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
相關文章如下:
Cacti JVM Monitoring template ( Part I )
http://xrcd2.blogspot.tw/2012/12/cacti-jvm-monitoring-template.html
Cacti JVM Monitoring template ( Part II )
http://xrcd2.blogspot.tw/2013/01/cacti-jvm-monitoring-template-part-ii.html
jmx4perl ( JMX access for Perl )
http://xrcd2.blogspot.tw/2013/01/jmx4perl-jmx-access-for-perl.html
JVM Monitor tools
http://visualvm.java.net/
但在使用 /usr/local/tomcat/shutdown.sh 將 tomcat 的服務停止時,
總會產生 tomcat Error: Failed to start SNMP adaptor with address 這樣的訊息.
最後總是直接使用 killall -9 去停止該項服務.最後 google 到 解法.
資料參考 http://www.tikalk.com/java/forums/when-use-tomcat-catalina-opts-instead-java-opts
將 JMX & SNMP 的 JAVA_OPTS 從 /etc/profile.d/java.sh
移到 /usr/local/tomcat/startup.sh
在上方處放上原先設定:
export JAVA_OPTS="-Dcom.sun.management.snmp.port=1610 -Dcom.sun.management.snmp.acl.file=/usr/java/jre/lib/management/snmp.acl -Dcom.sun.management.snmp.interface=0.0.0.0 -Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.100.101 -Dcom.sun.management.jmxremote.port=9012 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
相關文章如下:
Cacti JVM Monitoring template ( Part I )
http://xrcd2.blogspot.tw/2012/12/cacti-jvm-monitoring-template.html
Cacti JVM Monitoring template ( Part II )
http://xrcd2.blogspot.tw/2013/01/cacti-jvm-monitoring-template-part-ii.html
jmx4perl ( JMX access for Perl )
http://xrcd2.blogspot.tw/2013/01/jmx4perl-jmx-access-for-perl.html
JVM Monitor tools
http://visualvm.java.net/
2013年1月3日 星期四
jmx4perl ( JMX access for Perl )
延續 Cacti JVM Monitoring 這個主題.
JMX 是一個標準.可使用 ant 或 jconsole 去取得 JVM 的效能相關數據資料,
以下再介紹使用 webapps agent + perl 的用法,同樣的以 tomcat 為 LAB!
tomcat-connectors
http://tomcat.apache.org/connectors-doc/
#wget http://www.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.37-src.tar.gz
#tar -zvxf tomcat-connectors-1.2.37-src.tar.gz
#cd tomcat-connectors-1.2.37-src/native
#./buildconf.sh
#./configure --with-apxs=/usr/sbin/apxs
#make
#make install
#vi /etc/httpd/conf/httpd.conf
LoadModule jk_module modules/mod_jk.so
#service httpd restart
jolokia (Jolokia is remote JMX with JSON over HTTP)
http://www.jolokia.org/
Jolokia Quickstart
http://www.jolokia.org/tutorial.html
#wget http://www.jolokia.org/dist/1.0.6/jolokia-1.0.6-bin.tar.gz
#tar -zvxf olokia-1.0.6-bin.tar.gz
#cp ./jolokia-1.0.6/agents/jolokia.war /usr/local/tomcat/webapps
#cp ./jolokia-1.0.6/agents/*.jar /usr/local/tomcat/lib
#/usr/local/tomcat/shutdown.sh
#/usr/local/tomcat/startup.sh
test jolokia url
http://jmx.tomcat.server.ip:8080/jolokia/
Perl
install JMX::Jmx4Perl JMX::Jmx4Perl::Alia
#cpan install JMX::Jmx4Perl JMX::Jmx4Perl::Alias
About Jmx4Perl.pm Alias.pm
JMX access for Perl (jmx4perl)
http://search.cpan.org/~roland/jmx4perl/lib/JMX/Jmx4Perl.pm
JMX alias names for jmx4perl
http://search.cpan.org/~roland/jmx4perl-0.71/lib/JMX/Jmx4Perl/Alias.pm
[root@centos63 tmp]# cat jmx.pl
#!/usr/bin/perl
use JMX::Jmx4Perl;
use JMX::Jmx4Perl::Alias;
$jmx1 = JMX::Jmx4Perl->new(url => "http://localhost:8080/jolokia")->get_attribute(MEMORY_HEAP_USED);
$jmx2 = JMX::Jmx4Perl->new(url => "http://localhost:8080/jolokia")->get_attribute(THREAD_COUNT);
print "\n JMX MEMORY_HEAP_USED= $jmx1 \n\n";
print "\n ThreadCount= $jmx2 \n\n";
[root@centos63 tmp]# perl jmx.pl
JMX MEMORY_HEAP_USED= 31746000
ThreadCount= 22
對照 jmx4perl 與 cacti 看到的資料是否一致!
相關文章如下:
Cacti JVM Monitoring template ( Part I )
http://xrcd2.blogspot.tw/2012/12/cacti-jvm-monitoring-template.html
Cacti JVM Monitoring template ( Part II )
http://xrcd2.blogspot.tw/2013/01/cacti-jvm-monitoring-template-part-ii.html
JMX 是一個標準.可使用 ant 或 jconsole 去取得 JVM 的效能相關數據資料,
以下再介紹使用 webapps agent + perl 的用法,同樣的以 tomcat 為 LAB!
tomcat-connectors
http://tomcat.apache.org/connectors-doc/
#wget http://www.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.37-src.tar.gz
#tar -zvxf tomcat-connectors-1.2.37-src.tar.gz
#cd tomcat-connectors-1.2.37-src/native
#./buildconf.sh
#./configure --with-apxs=/usr/sbin/apxs
#make
#make install
#vi /etc/httpd/conf/httpd.conf
LoadModule jk_module modules/mod_jk.so
#service httpd restart
jolokia (Jolokia is remote JMX with JSON over HTTP)
http://www.jolokia.org/
Jolokia Quickstart
http://www.jolokia.org/tutorial.html
#wget http://www.jolokia.org/dist/1.0.6/jolokia-1.0.6-bin.tar.gz
#tar -zvxf olokia-1.0.6-bin.tar.gz
#cp ./jolokia-1.0.6/agents/jolokia.war /usr/local/tomcat/webapps
#cp ./jolokia-1.0.6/agents/*.jar /usr/local/tomcat/lib
#/usr/local/tomcat/shutdown.sh
#/usr/local/tomcat/startup.sh
test jolokia url
http://jmx.tomcat.server.ip:8080/jolokia/
Perl
install JMX::Jmx4Perl JMX::Jmx4Perl::Alia
#cpan install JMX::Jmx4Perl JMX::Jmx4Perl::Alias
About Jmx4Perl.pm Alias.pm
JMX access for Perl (jmx4perl)
http://search.cpan.org/~roland/jmx4perl/lib/JMX/Jmx4Perl.pm
JMX alias names for jmx4perl
http://search.cpan.org/~roland/jmx4perl-0.71/lib/JMX/Jmx4Perl/Alias.pm
[root@centos63 tmp]# cat jmx.pl
#!/usr/bin/perl
use JMX::Jmx4Perl;
use JMX::Jmx4Perl::Alias;
$jmx1 = JMX::Jmx4Perl->new(url => "http://localhost:8080/jolokia")->get_attribute(MEMORY_HEAP_USED);
$jmx2 = JMX::Jmx4Perl->new(url => "http://localhost:8080/jolokia")->get_attribute(THREAD_COUNT);
print "\n JMX MEMORY_HEAP_USED= $jmx1 \n\n";
print "\n ThreadCount= $jmx2 \n\n";
[root@centos63 tmp]# perl jmx.pl
JMX MEMORY_HEAP_USED= 31746000
ThreadCount= 22
對照 jmx4perl 與 cacti 看到的資料是否一致!
相關文章如下:
Cacti JVM Monitoring template ( Part I )
http://xrcd2.blogspot.tw/2012/12/cacti-jvm-monitoring-template.html
Cacti JVM Monitoring template ( Part II )
http://xrcd2.blogspot.tw/2013/01/cacti-jvm-monitoring-template-part-ii.html
Cacti JVM Monitoring template ( Part II )
延續 Cacti JVM Monitoring template 這個主題,
上次已提過 JVM Monitor 的二種型態!
分別為: (1) java snmp (2) jmx
其中的 java snmp 的使用方式請參考 Cacti JVM Monitoring template ( Part I ) URL 如下:
http://xrcd2.blogspot.tw/2012/12/cacti-jvm-monitoring-template.html
接下來要介紹的是,透過 jmx 的方式與 cacti 的運用.
本 LAB 的假設情境為 使用 tomcat 做為 jmx 的 監控目標.
利用 Percona JMX Monitoring Template for Cacti 的方式,進行 jmx monitor
安裝與測試方式參考如下:
http://www.percona.com/doc/percona-monitoring-plugins/cacti/jmx-templates.html
其中的重點是要設定 ant 及 jmx 的使用環境.
請自行參考 Cacti JVM Monitoring template 的 /etc/profile.d/java.sh 的設定.
ant 可於 http://ant.apache.org/ download
#wget http://apache.cdpa.nsysu.edu.tw//ant/binaries/apache-ant-1.8.4-bin.tar.gz
#tar -zvxf apache-ant-1.8.4-bin.tar.gz
#mv apache-ant-1.8.4 /usr/local/ant (配合 /etc/profile.d/java.sh 的設定 )
可透過 ant -version 去測試 ant 是否可以正常使用.
[root@centos bin]# pwd
/usr/local/ant/bin
[root@centos bin]# ./ant -version
Apache Ant(TM) version 1.8.4 compiled on May 22 2012
接下來是 cp /usr/local/tomcat/lib/catalina.jar /home/cactiuser/.ant/lib
download percona-monitoring-plugins-1.0.1.tar.gz 下來使用,URL 如下:
http://www.percona.com/downloads/percona-monitoring-plugins/
解開 percona-monitoring-plugins-1.0.1.tar.gz
在 cacti web 中 使用 Import Templates 將
templates/cacti_host_template_percona_jmx_server_ht_0.8.6i-sver1.0.1.xml 匯入
cp misc/jmx-monitor.xml /home/cacti 供 ss_get_by_ssh.php 使用
cp scripts/ss_get_by_ssh.php /var/www/html/cacti/scripts/ 供 cacti Data Input Methods 使用
而 ss_get_by_ssh.php 則是必須建立 ssh key 方可使用
可參考 [實用的 Cacti Monitoring Template] 一文中的介紹
http://xrcd2.blogspot.tw/2012/05/cacti-monitoring-template.html
上述的檔案中,必須修改的是 ss_get_by_ssh.php & jmx-monitor.xml
請參考下圖:
設定 jmx 不使用 id & pwd 方式即可連入 jmx server
設定 ssh key 的 使用 id & key file
在全數前置作業完成後可透過指令 ant -Djmx.server.port=9012 -e -q -f jmx-monitor.xml
去驗證設定是否正確及運作正常
[root@centos cactiuser]# su - cactiuser
[cactiuser@centos ~]$ ant -Djmx.server.port=9012 -e -q -f jmx-monitor.xml
BUILD FAILED
/home/cactiuser/jmx-monitor.xml:53: javax.management.InstanceNotFoundException: Catalina:type=ThreadPool,name=${jmx.catalina.threadpool.name}
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1094)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:662)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
at javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
at sun.reflect.GeneratedMethodAccessor50.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl_Stub.getAttribute(Unknown Source)
at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.getAttribute(RMIConnector.java:878)
at org.apache.catalina.ant.jmx.JMXAccessorGetTask.jmxGet(JMXAccessorGetTask.java:136)
at org.apache.catalina.ant.jmx.JMXAccessorGetTask.jmxExecute(JMXAccessorGetTask.java:121)
at org.apache.catalina.ant.jmx.JMXAccessorTask.execute(JMXAccessorTask.java:347)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe cutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 1 second
及
[cactiuser@centos ~]$php /var/www/html/cacti/scripts/ss_get_by_ssh.php --type jmx --host 127.0.0.1 --items j4,j5,j6,j7,j8,j9,ja,jb
j4:131728176 j5:1037959168 j6:1037959168 j7:25814184 j8:159055872 j9:325058560 ja:52 jb:4096
分別去驗證 jmx-monitor.xml & ss_get_by_ssh.php 的設定
接下來就是在 cacti web 中將 Host Templates \ Percona JMX Server HT 直接拿來使用
實作畫面如下:
上次已提過 JVM Monitor 的二種型態!
分別為: (1) java snmp (2) jmx
其中的 java snmp 的使用方式請參考 Cacti JVM Monitoring template ( Part I ) URL 如下:
http://xrcd2.blogspot.tw/2012/12/cacti-jvm-monitoring-template.html
接下來要介紹的是,透過 jmx 的方式與 cacti 的運用.
本 LAB 的假設情境為 使用 tomcat 做為 jmx 的 監控目標.
利用 Percona JMX Monitoring Template for Cacti 的方式,進行 jmx monitor
安裝與測試方式參考如下:
http://www.percona.com/doc/percona-monitoring-plugins/cacti/jmx-templates.html
其中的重點是要設定 ant 及 jmx 的使用環境.
請自行參考 Cacti JVM Monitoring template 的 /etc/profile.d/java.sh 的設定.
ant 可於 http://ant.apache.org/ download
#wget http://apache.cdpa.nsysu.edu.tw//ant/binaries/apache-ant-1.8.4-bin.tar.gz
#tar -zvxf apache-ant-1.8.4-bin.tar.gz
#mv apache-ant-1.8.4 /usr/local/ant (配合 /etc/profile.d/java.sh 的設定 )
可透過 ant -version 去測試 ant 是否可以正常使用.
[root@centos bin]# pwd
/usr/local/ant/bin
[root@centos bin]# ./ant -version
Apache Ant(TM) version 1.8.4 compiled on May 22 2012
接下來是 cp /usr/local/tomcat/lib/catalina.jar /home/cactiuser/.ant/lib
download percona-monitoring-plugins-1.0.1.tar.gz 下來使用,URL 如下:
http://www.percona.com/downloads/percona-monitoring-plugins/
解開 percona-monitoring-plugins-1.0.1.tar.gz
在 cacti web 中 使用 Import Templates 將
templates/cacti_host_template_percona_jmx_server_ht_0.8.6i-sver1.0.1.xml 匯入
cp misc/jmx-monitor.xml /home/cacti 供 ss_get_by_ssh.php 使用
cp scripts/ss_get_by_ssh.php /var/www/html/cacti/scripts/ 供 cacti Data Input Methods 使用
而 ss_get_by_ssh.php 則是必須建立 ssh key 方可使用
可參考 [實用的 Cacti Monitoring Template] 一文中的介紹
http://xrcd2.blogspot.tw/2012/05/cacti-monitoring-template.html
上述的檔案中,必須修改的是 ss_get_by_ssh.php & jmx-monitor.xml
請參考下圖:
設定 jmx 不使用 id & pwd 方式即可連入 jmx server
設定 ssh key 的 使用 id & key file
在全數前置作業完成後可透過指令 ant -Djmx.server.port=9012 -e -q -f jmx-monitor.xml
去驗證設定是否正確及運作正常
[root@centos cactiuser]# su - cactiuser
[cactiuser@centos ~]$ ant -Djmx.server.port=9012 -e -q -f jmx-monitor.xml
BUILD FAILED
/home/cactiuser/jmx-monitor.xml:53: javax.management.InstanceNotFoundException: Catalina:type=ThreadPool,name=${jmx.catalina.threadpool.name}
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1094)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:662)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
at javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
at sun.reflect.GeneratedMethodAccessor50.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl_Stub.getAttribute(Unknown Source)
at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.getAttribute(RMIConnector.java:878)
at org.apache.catalina.ant.jmx.JMXAccessorGetTask.jmxGet(JMXAccessorGetTask.java:136)
at org.apache.catalina.ant.jmx.JMXAccessorGetTask.jmxExecute(JMXAccessorGetTask.java:121)
at org.apache.catalina.ant.jmx.JMXAccessorTask.execute(JMXAccessorTask.java:347)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:392)
at org.apache.tools.ant.Target.performTasks(Target.java:413)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe cutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:811)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Total time: 1 second
及
[cactiuser@centos ~]$php /var/www/html/cacti/scripts/ss_get_by_ssh.php --type jmx --host 127.0.0.1 --items j4,j5,j6,j7,j8,j9,ja,jb
j4:131728176 j5:1037959168 j6:1037959168 j7:25814184 j8:159055872 j9:325058560 ja:52 jb:4096
分別去驗證 jmx-monitor.xml & ss_get_by_ssh.php 的設定
接下來就是在 cacti web 中將 Host Templates \ Percona JMX Server HT 直接拿來使用
實作畫面如下:
訂閱:
文章 (Atom)