반응형

http://stackoverflow.com/questions/26595620/how-to-install-ruby-2-1-4-on-ubuntu-14-04 => 우분투 ruby 설치

http://qiita.com/y_matsuwitter/items/901065962edb7ea8c6ec => GEM path 설정

 

출처: http://neverstoplearning.tistory.com/entry/%EB%A1%9C%EA%B7%B8%EC%88%98%EC%A7%91%EA%B8%B0-fluentd-on-redhat-enterprise-linux-6

 

 

mysql 로 출력을 설정하기 위한 플러그인을 설치합니다.

 

# td-agent-gem install fluent-plugin-mysql

# td-agent-gem list --local | grep fluent-plugin-mysql

fluent-plugin-mysql (0.0.7)

 

 

 

데이터 베이스와 테이블을 생성합니다. 테스트니 그냥 컬럼 하나만 만듭니다.

 

# mysql -uroot

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database application_log;

mysql> use application_log;

mysql> CREATE TABLE `access_log` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `text` char(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
);

 

 

이제 td-agent 설정 파일을 생성합니다.

 

 

# emacs /etc/td-agent/td-agent.conf 

 

 

아파치 로그에서 agent 값을 생성된 컬럼에 넣도록 합니다. 한 라인 전체를 넣을 수도 있습니다. (document 페이지에 가면 입력, 처리, 출력 관련 내용이 있습니다.) 

 

## read apache logs continuously and tags td.apache.access
<source>
  type tail                    # tail 명령어로 소스에서 로그를 가져옴
  format apache2         # 로그 포맷은 apache2
  path /var/log/httpd/access_log  # 로그 파일 위치
  pos_file /var/log/td-agent/apache.pos
  tag apache.access    # 태그 지정
</source>

## File output
## match tag=local.** and write to file
<match apache.access>
  type mysql                  # 출력은 mysql
  host localhost             # 호스트는 로컬
  #port 3306                   # 디폴트 3306
  database application_log      # DB명
  username root             # 유저
  #password ""              
  key_names agent         # 로그 추출 필드
  sql INSERT INTO access_log (text) VALUES (?)    # 실행 SQL
  flush_interval 1s          # 실행 간격
</match> 

 

 

이제 기본적인 설정이 모두 끝났습니다. 웹 서버와 fluentd 데몬을 구동합니다.

 

 

# /etc/init.d/httpd start

# /etc/init.d/td-agent start

 

 

td-agent 구동시 에러가 발생된다면 conf 파일에 잘못 쓴 부분이 있는지 확인합니다.

 

웹서버에 접근하면 아래와 같이 DB에 로그가 적재되게 됩니다.

 

 

이상. fluentd 시작하기 였습니다. ^^

 

 

반응형

+ Recent posts