gork 准备工作

1、调试工具的准备

安装ruby

yum install ruby
[root@localhost ~]# yum install ruby
[root@localhost ~]# ruby -v
ruby 2.0.0p598 (2014-11-13) [x86_64-linux]

安装gem包

[root@localhost ~]# gem install jls-grok awesome_print
Fetching: cabin-0.8.1.gem (100%)
Successfully installed cabin-0.8.1
Fetching: jls-grok-0.11.3.gem (100%)
Successfully installed jls-grok-0.11.3
Parsing documentation for cabin-0.8.1
Installing ri documentation for cabin-0.8.1
Parsing documentation for jls-grok-0.11.3
Installing ri documentation for jls-grok-0.11.3
Fetching: awesome_print-1.7.0.gem (100%)
Successfully installed awesome_print-1.7.0
Parsing documentation for awesome_print-1.7.0
Installing ri documentation for awesome_print-1.7.0
3 gems installed

开发调试工具

vim grokdebug.rb

注意:第三行中的jls-grok的版本要和之前安装的版本一致

#!/usr/bin/env ruby
require 'rubygems'
gem 'jls-grok', '=0.11.3'
require 'grok-pure'
require 'optparse'
require 'ap'

options = {}
ARGV.push('-h') if ARGV.size === 0
OptionParser.new do |opts|
  opts.banner = 'Run grokdebug at your terminal.'
  options[:dirs] = %w(patterns)
  options[:named] = false
  opts.on('-d DIR1,DIR2', '--dirs DIR1,DIR2', Array, 'Set grok patterns directories. Default: "./patterns"') do |value|
    options[:dirs] = value
  end
  opts.on('-m MESSAGE', '--msg MESSAGE', 'Your raw message to be matched') do |value|
    options[:message] = value
  end
  opts.on('-p PATTERN', '--pattern PATTERN', 'Your grok pattern to be compiled') do |value|
    options[:pattern] = value
  end
  opts.on('-n', '--named', 'Named captures only') do
    options[:named] = true
  end
end.parse!

grok = Grok.new
options[:dirs].each do |dir|
  if File.directory?(dir)
    dir = File.join(dir, "*")
  end
  Dir.glob(dir).each do |file|
    grok.add_patterns_from_file(file)
  end
end
grok.compile(options[:pattern], options[:named])
ap grok.match(options[:message]).captures()

2、grokdebug的使用

例如:

./grokdebug.rb 
                 -d /root/logstash-patterns-core/patterns 
                 -m "5.3.244.1 GET /index.html 15824 0.043" 
                 -p "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}"

其中:

  • -d :用于指定已有正则表达式文件的路径。这里可以指向logstash-patterns-core项目的文件夹;也可以指向logstash程序的/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-2.0.5
  • -m :待解析的目标字符串
  • -p :用于解析目标字符串的正则表达式
{
       "client" => [
        [0] "5.3.244.1"
    ],
         "IPV6" => [
        [0] nil
    ],
         "IPV4" => [
        [0] "5.3.244.1"
    ],
       "method" => [
        [0] "GET"
    ],
      "request" => [
        [0] "/index.html"
    ],
      "URIPATH" => [
        [0] "/index.html"
    ],
     "URIPARAM" => [
        [0] nil
    ],
        "bytes" => [
        [0] "15824"
    ],
    "BASE10NUM" => [
        [0] "15824",
        [1] "0.043"
    ],
     "duration" => [
        [0] "0.043"
    ]
}

3、部署Rails

3.1、安装rvm

  • rvm 全称Ruby Version Manager,是一个非常好ruby版本管理和安装工具。
curl -sSL https://get.rvm.io | bash -s stable
  • 出错后,执行以下代码解决错误
    curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
    
  • 安装rails
gem install rails

安装rails框架

[root@localhost ~]# gem install rails

rails 部署安装: http://guides.ruby-china.org/getting_started.html

Rails中Bootstrap的安装和使用 http://blog.csdn.net/lissdy/article/details/9195651

http://my.oschina.net/u/913344/blog/365433 Rails中使用Bootstrap
http://blog.163.com/fuhaocn@126/blog/static/366650802013414262295/

results matching ""

    No results matching ""