삽질 1. timezone 부분

logstash, elasticsearch(plugis등), kibana 골치 아프니 UTC로 모두 바꾸니 편함...ㅡㅡ;


[logstash]

dd/MMM/yyyy:HH:mm:ss Z 했었는데 처리가 안되서.. 아래와 같이 했더니 해결...

         -> https://discuss.elastic.co/t/how-to-set-timestamp-timezone/28401/10

[kibana]

Settings -> Advanced -> dateFormat:tz -> UTC 선택




[logconf/apache.conf]

input {
  stdin { }
}

filter {
  grok {
    patterns_dir => ["./patterns"]
    # 본인 로그 패턴에 따라 설정
    match => { "message" => "%{COMMONAPACHELOG} %{NUMBER:responseTime} %{ALL_STR:qq1} %{ALL_STR:qq2} %{QS:referrer} %{QS:agent}" }
  }
  date {
    match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss +0900" ]
    timezone => "UTC"
  }
}

output {
  stdout { codec => json }
}


[logconf/apache.conf]

# 파일 단위 -> elasticsearch
input {
  file {
    path => "/usr/local/tomcat/logstash/dump_logs/ssl/*"
    start_position => "beginning"
  }
}

filter {
  grok {
    patterns_dir => ["./patterns"]
    # 본인 로그 패턴에 따라 설정
    match => { "message" => "%{COMMONAPACHELOG} %{ALL_STR:qq1} %{ALL_STR:qq2} %{QS:referrer} %{QS:agent}" }
  }
  date {
    match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss +0900" ]
    timezone => "UTC"
  }
}

output {
  elasticsearch { hosts => ["localhost:9200"]
                  index => "apache-access-log-%{+YYYY-MM-dd}"
                  document_type => "web01"
                }
  #stdout { codec => rubydebug }
}

[haproxy]

input {
  #stdin { }
  file {
    type => "searchWas"
    path => "/usr/local/tomcat/logstash/dump_logs/haproxy/haproxy-searchWas.log*"
    start_position => "beginning"
  }
  file {
    type => "aqmp"
    path => "/usr/local/tomcat/logstash/dump_logs/haproxy/haproxy-aqmp.log*"
    start_position => "beginning"
  }
}

  
filter {
  if [type] == "searchWas" {
    grok {
      patterns_dir => ["./patterns"]
    # 본인 로그 패턴에 따라 설정
      match => { "message" => "%{HAPROXYHTTP}" }
    }
    date {
      match => [ "accept_date", "dd/MMM/YYYY:HH:mm:ss.SSS" ]
      timezone => "UTC"
    }
  } else if [type] == "aqmp" {
    grok {
      patterns_dir => ["./patterns"]
      match => { "message" => "%{HAPROXYTCP}" }
    }
    date {
      match => [ "accept_date", "dd/MMM/YYYY:HH:mm:ss.SSS" ]
      timezone => "UTC"
    }
  }
}

output {
  #stdout { codec => json }
  
  if [type] == "searchWas" {
    elasticsearch {  
      hosts => ["localhost:9200"]
      index => "haproxy-access-log-%{+YYYY-MM-dd}"
      document_type => "searchWas"
    }
  } else if [type] == "aqmp" {
    elasticsearch {  
      hosts => ["localhost:9200"]
      index => "haproxy-access-log-%{+YYYY-MM-dd}"
      document_type => "aqmp"
    }
  }
}

[logconf/test-db.conf] db -> elasticsearch 케이스

input {
        jdbc {
                jdbc_driver_library => "/usr/local/tomcat/logstash/lib/mysql-connector-java-5.1.38.jar"
                jdbc_driver_class => "com.mysql.jdbc.Driver"
                jdbc_connection_string => "jdbc:mysql://mariadb-dev:3306/log"
                jdbc_user => "log"
                jdbc_password => "test"
                statement => "SELECT * FROM ez_apache_access_log_201602"
                #schedule => "* * * * *"
                jdbc_paging_enabled => "true"
                jdbc_page_size => "50000"

        }
}

[patterns/custom.conf]

ALL_STR .*

test exec

$ bin/logstash -f logconf/apache.conf 
192.168.1.100 - - [17/Jul/2016:21:08:51 +0900] "GET /test/list HTTP/1.1" 200 17194 5657 -/- (-%) "http://ddakker.test.com/test/add?test=1" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)"

mappings -> 수동 index/document mapping 생성 예제

$ curl -XPUT http://localhost:9200/log_httpd -d '
{
  "mappings": {
    "web01": {
      "properties": {
        "req_query_string": {
          "type": "string",
          "fields": {
            "raw": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        "req_dt": {
          "type": "string"
        },
        "referrer_query_string": {
          "type": "string",
          "fields": {
            "raw": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        "referrer_domain": {
          "type": "string",
          "fields": {
            "raw": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        "req_ext": {
          "type": "string"
        },
        "referrer_ext": {
          "type": "string"
        },
        "res_status": {
          "type": "string"
        },
        "req_mall_type": {
          "type": "string"
        },
        "@version": {
          "type": "string"
        },
        "ip": {
          "type": "string"
        },
        "req_uri": {
          "type": "string",
          "fields": {
            "raw": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        "@timestamp": {
          "format": "strict_date_optional_time||epoch_millis",
          "type": "date"
        },
        "referrer_mall_type": {
          "type": "string",
          "fields": {
            "raw": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        "method": {
          "type": "string"
        },
        "referrer_uri": {
          "type": "string",
          "fields": {
            "raw": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        }
      }
    }
  }
}'


레드마인 사용 중 회사 보안지침 이슈 발생


※. 아래 트리거 사용 했다가 Rails 약간 공부 해서 "Login Audit 플러그인" 조금 수정 해서 해결(2016.06.27)

https://github.com/ddakker/redmine_login_audit


1. 비밀번호 주기적으로 변경

   - redmine 3.3.0 으로 업그레이드 하니 기본 기능으로 추가되어 있다.


2. 로그인 시도 중 비밀번호 5회 실패 시 계정 잠금

   - https://github.com/jbbarth/redmine_stronger 있었으나 Redmine 3.3.0 지원을 안 하는듯

   - ruby 같은 언어를 다뤄본적이 없어서 소스 수정 하려다 포기 (직접 수정하면 업그레이드 문제)

     plugin 개발은 현재로서 더 힘들고...


   - https://github.com/martin-denizet/redmine_login_audit 기능 활용

     로그인 성공/실패 로깅을 해주는 플러그인

     해당 플러그인과 db trigger 을 접목해서 해결..     



DELIMITER //

CREATE TRIGGER login_audits_tri
AFTER INSERT
   ON login_audits FOR EACH ROW

BEGIN
	DECLARE failCnt INT;
   
   SET failCnt = (
							select count(*) 
							from login_audits 
							where login = NEW.login 
							and success = 0 
							and created_on >= DATE_FORMAT(DATE_ADD(now(),INTERVAL -5 MINUTE),'%Y-%m-%d %H:%i:%s')
							and id > (
											select max(id) from login_audits
											where login = NEW.login 
											and success = 1
										)
						);


	IF NEW.success = 0 THEN
		IF failCnt > 5 THEN
		   update users set `status`=3 where login = NEW.login;
		END IF;
	END IF;
END; //


외부 mysql 활용

yum install epel-release

yum groupinstall "Development Tools"

yum install openssl-devel readline-devel zlib-devel curl-devel libyaml-devel

yum install httpd httpd-devel

yum install ImageMagick ImageMagick-devel

## ubuntu desktop 에서 할때
# sudo apt-get install apache2 curl bison libbison-dev zlib1g-dev libssl-dev sqlite3 libsqlite3-dev autoconf automake build-essential libtool libreadline6-dev libyaml-dev libxml2-dev libcurl4-openssl-dev libssl-dev libgpg-error-dev autotools-dev imagemagick libmagickcore-dev libmagickwand-dev

wget http://www.ruby-lang.org/ko/downloads/

tar zxvf ruby-2.3.1.tar.gz 
cd ruby-2.3.1
./configure
make
make install

gem install bundler --no-rdoc --no-ri

wget http://www.redmine.org/releases/redmine-3.3.0.tar.gz

tar xvzf redmine-3.3.0.tar.gz

mv redmine-3.0.3 /usr/local/.
ln -s redmine-3.0.3 redmine


cp config/database.yml.example 

vi config/database.yml

bundle install --without development test postgresql sqlite

rake generate_secret_token
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake redmine:load_default_data

#ruby bin/rails server webrick –e production –b 192.168.1.11
bundle exec rails server webrick -e production
bundle exec rails server webrick -e production --port=40000
bundle exec rails server webrick -e production --binding=192.168.1.11 --port=40000


# thin 서버로 띄우기

gem install thin

vi Gemfile
# 하위 추가
gem "thin"

bundle install --path vendor/bundle

thin start -e production -p 40000 -c /usr/local/redmine --prefix=/redmine
curl http://192.168.1.11:40000/


# context path 바꿔보기

cp config/additional_environment.rb additional_environment.rb.example
vi config/additional_environment.rb
# 하위 추가
config.relative_url_root = '/redmine'


thin start -e production -p 40000 -c /usr/local/redmine --prefix=/redmine
thin start -d -e production -p 40000 -c /usr/local/redmine --prefix=/redmine
curl http://192.168.1.11:40000/redmine

# 기존 웹서버 httpd 에 추가하기

ProxyPass /redmine http://192.168.1.11:40000/redmine

curl http://dev.ddakker.pe.kr/redmine

# 시작/중지/관리
startup.sh
stop.sh
rake_plugin.sh
 
 
# 플러그인 설치
wget https://github.com/peclik/clipboard_image_paste/archive/master.zip
unzip master.zip
mv clipboard_image_paste-master plugins/clipboard_image_paste
 
RAILS_ENV=production rake redmine:plugins    (rake_plugin.sh 만들어 놓음)
 
# 설치된 플러그인
1. 이미지 클립보드 붙여 넣기 - Clipboard image paste
2. 일감 진행현황 그래프 - Progressive Projects List plugin
3. 일감 상황 그래프 - Redmine Graphs plugin
4. 로그인 히스토리 - Redmine Login Audit plugin
5. 일감 작업자별 현황 - Redmine (Monitoring & Controlling | Monitoramento & Controle)
 
 
# 플러그인 삭제
rake redmine:plugins:migrate NAME=플러그임이름 VERSION=0 RAILS_ENV=production
rm -Rf plugins/플러그인이름


+ Recent posts