应团队ELK使用需要,特写了一篇Kibana介绍使用相关文章。
以下演示基于官方Kibana演示页面:http://demo.elastic.co/packetbeat/#/discover (更多…)
以下演示基于官方Kibana演示页面:http://demo.elastic.co/packetbeat/#/discover (更多…)
好奇Log4j格式化日志时,上述信息获取方式。 跟踪代码,发现了其利用异常实现的,下面是简单例子:
package com.billstudy.test;
import java.lang.reflect.Method;
/**
* Test exception stack infomation analysis
* @author LiBiao - Bill
* @since V1.0 2016年4月15日 - 下午5:48:35
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public class StackDemo {
private static Method getStackTraceMethod;
private static Method getClassNameMethod;
private static Method getMethodNameMethod;
private static Method getFileNameMethod;
private static Method getLineNumberMethod;
static {
Class[] noArgs = null;
try {
getStackTraceMethod = Throwable.class.getMethod("getStackTrace", noArgs);
Class stackTraceElementClass = Class.forName("java.lang.StackTraceElement");
getClassNameMethod = stackTraceElementClass.getMethod("getClassName", noArgs);
getMethodNameMethod = stackTraceElementClass.getMethod("getMethodName", noArgs);
getFileNameMethod = stackTraceElementClass.getMethod("getFileName", noArgs);
getLineNumberMethod = stackTraceElementClass.getMethod("getLineNumber", noArgs);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Obtain relevant information from the exception stack
* @author LiBiao - Bill
* @since V1.0 2016年4月15日 - 下午6:14:33
* @param e
* @param className
*/
private static void analysisException(Exception e, String className) {
Object[] noArgs = null;
try {
Object[] elements = (Object[]) getStackTraceMethod.invoke(e,noArgs);
for (int i = 0; i < elements.length; i++) {
Object element = elements[i];
String clazz = (String) getClassNameMethod.invoke(element, noArgs);
// find
if (className.equals(clazz)) {
String method = (String) getMethodNameMethod.invoke(element, noArgs);
int line = (Integer) getLineNumberMethod.invoke(element, noArgs);
String fileName = (String) getFileNameMethod.invoke(element, noArgs);
String result = String.format(
"class:%s \r\n "
+ "method:%s \r\n "
+ "line:%s \r\n "
+ "fileName:%s \r\n errorMsg:%s", clazz,method,line,fileName,e.getMessage());
System.out.println(result);
break;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
String findClassName = "com.billstudy.test.StackDemo$B";
try {
A a = new A();
a.test();
} catch (Exception e) {
//e.printStackTrace();
analysisException(e, findClassName);
}
// a.nullException();
}
public static class A {
private B b = new B();
public void test() {
b.test();
}
public void nullException() {
String target = null;
target.intern();
}
}
public static class B {
private C c = new C();
public void test() {
c.test();
}
}
public static class C {
public void test() {
throw new RuntimeException("别问我为啥,就是想抛个异常 ~");
}
}
}
1.解压zookeeper-3.4.6.tar.gz到重命名到/opt/bigdata/zookeeper下
#进入到Zookeeper安装目录执行
mkdir data
mkdir log
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/opt/bigdata/zookeeper/data
dataLogDir=/opt/bigdata/zookeeper/log
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=m1:2888:3888
server.2=m2:2888:3888
server.3=m3:2888:3888
#这个id 在别的机器上需要修改,根据zoo.cfg中声明的填写
echo 1 > /opt/bigdata/zookeeper/conf/myid
cd /opt/bigdata/
#下面这个是我写的批量scp脚本
#语法是:
#Usage: /usr/bin/scp_many filename targetname host[s]
#e.g: /usr/bin/scp_many love.txt /home/love.txt v2,v3,v4
scp_many ./zookeeper/ $PWD m2,m3
#!/bin/bash
# description: scp file to many hosts
filename=$1
targetname=$2
hosts=$3
if [ $# -lt 3 ];then
echo -e "Usage:\033[45;37m $0 filename targetname host[s] \033[0m"
echo -e "e.g:\033[45;37m $0 love.txt /home/love.txt v2,v3,v4\033[0m"
exit 1
fi
#for host in $(echo $3|awk -F,)
for host in ${hosts//,/ }
do
cmd="scp -r $filename $host:$targetname"
echo -e "$\033[46;37m$cmd\033[0m"
$cmd
done
数据迁移工具,可以和RDBMS相互迁移数据
hbase的设计思想来自于google的bigtable
1.删除了mysql数据库user表记录,会导致用户不能正常登录。
/*
Navicat MySQL Data Transfer
Source Server : localhost
Source Server Version : 50703
Source Host : localhost:3306
Source Database : mysql
Target Server Type : MYSQL
Target Server Version : 50703
File Encoding : 65001
Date: 2015-06-13 20:07:50
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `user`
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '',
`User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '',
`Password` char(41) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '',
`Select_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Insert_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Update_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Delete_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Drop_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Reload_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Shutdown_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Process_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`File_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Grant_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`References_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Index_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Alter_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Show_db_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Super_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_tmp_table_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Lock_tables_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Execute_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Repl_slave_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Repl_client_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Show_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Alter_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_user_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Event_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Trigger_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`Create_tablespace_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
`ssl_type` enum('','ANY','X509','SPECIFIED') CHARACTER SET utf8 NOT NULL DEFAULT '',
`ssl_cipher` blob NOT NULL,
`x509_issuer` blob NOT NULL,
`x509_subject` blob NOT NULL,
`max_questions` int(11) unsigned NOT NULL DEFAULT '0',
`max_updates` int(11) unsigned NOT NULL DEFAULT '0',
`max_connections` int(11) unsigned NOT NULL DEFAULT '0',
`max_user_connections` int(11) unsigned NOT NULL DEFAULT '0',
`plugin` char(64) COLLATE utf8_bin NOT NULL DEFAULT 'mysql_native_password',
`authentication_string` text COLLATE utf8_bin,
`password_expired` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
PRIMARY KEY (`Host`,`User`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Users and global privileges';
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('%', 'root', '*29A1BB43D3B9EB42028B4566E4836353285B9395', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', '0', '0', '0', '0', 'mysql_native_password', '', 'N');
INSERT INTO `user` VALUES ('127.0.0.1', 'root', '*29A1BB43D3B9EB42028B4566E4836353285B9395', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', '0', '0', '0', '0', 'mysql_native_password', '', 'N');
INSERT INTO `user` VALUES ('::1', 'root', '*29A1BB43D3B9EB42028B4566E4836353285B9395', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', '0', '0', '0', '0', 'mysql_native_password', '', 'N');
INSERT INTO `user` VALUES ('localhost', '', '', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', '', '', '', '', '0', '0', '0', '0', 'mysql_native_password', null, 'N');