Output到Google PubSub服務
Fluentd支援google cloud pubsub的Input(Subscriber)與Output(Topic),下面是介紹透過Fluentd把任何input的資料網pubsub送,讓pubsub作為大資料搜集的前端防線...
事先準備
Google專案
首先先要有Google的專案... 這邊先不多作說明如何申請...,然後再開啟pubsub的存取權限即可...
PubSub的建置
建立topic...
gcloud alpha pubsub topics create [topic_name]
建立該topic下面的subscriber...
gcloud alpha pubsub subscriptions create [subscriber_name] --topic [topic_name]
建置Docker Image
首先我們先針對docker image,未來可以透過這個docker來啟動fluentd...
FROM ruby:2.2.0
RUN apt-get update
RUN gem install fluentd
RUN mkdir /etc/fluent
RUN apt-get install -y libcurl4-gnutls-dev make
RUN /usr/local/bin/gem install fluent-plugin-kafka && \
/usr/local/bin/gem install fluent-plugin-secure-forward && \
/usr/local/bin/gem install fluent-plugin-gcloud-pubsub && \
/usr/local/bundle/bin/secure-forward-ca-generate /tmp/ notasecret
ADD fluent.conf /etc/fluent/
CMD ["/usr/local/bundle/bin/fluentd", "-c", "/etc/fluent/fluent.conf"]
fluentd設定檔
下面是fluentd的設定檔,透過http source來接收http request作為input,然後filter用stdout可以支援讓screen顯示log,最後match讓資料可以上到pubsub...
# fluentd.conf
<source>
type http
port 9880
</source>
<filter **>
@type stdout
</filter>
<match *.**>
type gcloud_pubsub
project [your-project-id]
topic projects/[yout-project-id]/topics/[yout-topic-name]
key key.json
flush_interval 10
autocreate_topic false
</match>
其中,設定檔需要填入project與topic的名稱
Build Docker Image
docker build -t test/myfluentd .
建置過程如果沒問題,應該就可以用docker images來查看建置好的image...
啟動
下面是docker-compose file,透過這個設定可以啟動這個fluentd服務,然後會expose 9880 port供連線使用...
#docker-compose.yml
log-gateway:
restart: always
image: test/myfluentd
container_name: log-gateway
ports:
- "9880:9880"
啟動:
docker-compose up -d