已經過去快半年了,在草稿箱中記錄了一下當時的學習筆記:(當時悲催的記錄)
1、在啓動fluentd 的時候,進入到fluent.conf 目錄下,執行fluentd -c fluent.conf 如果啓動失敗,出現error
大概問題有:
(1)
unexpected error error="Address already in use - bind(2)" 說明你fluentd 可能已經啓動起來了。很多時候都是因爲你已經啓動了fluent 在不知道的情況下你又去啓動。這個時候導致,再次啓動失敗:
執行: ps -ef | grep fluentd 查看當前已經啓動的目錄。kill -9 8998 8839 把對應起來的fluent的ID號 殺掉,然後重啓。
(這一步很重要,很多的時候,就是因爲你是後臺在 fluentd -c fluent.conf & 爲後臺運行,你也不知道是否已經啓動fluent,這樣導致報錯)
4月10日
在安裝mongodb的遇到的問題:
1.下載:wget 對應的網址
2.解壓:tar xzf mongodb-linux-x86_64-2.4.1.tgz
bash-3.2# ./mongod --dbpath=/home/zhangzhen/software/mongodb-linux-x86_64-2.4.1/mongodb-date/mongodb-db --logpath=/home/zhangzhen/software/mongodb-linux-x86_64-2.4.1/mongodb-date/mongodb-logs/mongodb.log --logappend&
[1] 9396
bash-3.2# all output going to: /home/zhangzhen/software/mongodb-linux-x86_64-2.4.1/mongodb-date/mongodb-logs/mongodb.log
bash-3.2# netstat -lanp | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 9396/./mongod
unix 2 [ ACC ] STREAM LISTENING 8495321 9396/./mongod /tmp/mongodb-27017.sock
安裝mongod
第一:下載,解壓mongodb文件。把解壓的文件放在/opt/下面(存放目錄安裝自己習慣存放)
# wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.4.tgz
# tar -zxvfmongodb-linux-x86_64-2.0.4.tgz
# mv mongodb-linux-x86_64-2.0.4.tgz mongodb2.0.4 (爲了方便,把它從命名的更加簡潔些)
第二:創建mongodb存放的數據文件、日子文件(mongodb_db、mongodb_logs)
# cd /
#mkdir mongodb_data
#cd mongodb_data
#mkdir mongodb_db
#mkdir mongodb_logs
第三:進入剛纔解壓的mongodb2.0.4/bin 目錄,啓動mongodb,指定輸出路徑
#cd /opt/mongodb2.0.4/bin
# ./mongod --dbpath=/mongodbdata/mongodb_db --logpath=/mongodbdata/mongodb_logs/mongodb.log --logappend&
執行完會出現“ all output going to: /mongodbdata/mongodb_logs/mongodb.log”
./mongod --dbpath=//home/zhangzhen/software/mongodb-linux-x86_64-2.4.1/mongodb-date/mongodb-db --logpath=//home/zhangzhen/software/mongodb-linux-x86_64-2.4.1/mongodb-date/mongodb-logs/mongodb.log --logappend&
第四:檢查端口是否啓動,端口爲:27017
# netstat -lanp | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 560/mongod
unix 2 [ ACC ] STREAM LISTENING 128435 560/mongod /tmp/mongodb-27017.sock
啓動成功。
第5:可以用mongodb客戶端,連接數據庫了。進入到bin目錄,執行mongo
# ./mongo
MongoDB shell version: 2.0.4
connecting to: test
>use mongo_test 創建庫
>db.createCollection("test") 創建表
show dbs 顯示當前所有的庫 你要想建一個庫,如:use apache 然後是執行你在apache中建立的表 “表名如:access”
#
在52的機器上:mongo的啓動路徑是在/home/zhangzhen/software/mongodb-linux-x86_64-2.4.1/bin
執行的命令:不是mongo 而是,執行: ./mongo 就是運行當前目錄的 mongo這個可執行文件。這個要能很清楚。而至253上執行的mongo 這個有個路徑的問題: mongod 執行的時候,出現 --dbpath 的問題。 mongod --dbpath 指定的路徑是: /home/liujian/local/mongodb-linux-x86_64-2.4.1/database 。
在52的機器上說明的路徑是在:
在52上執行mongo的命令:在 mongo安裝後的bin的目錄下執行的:: ./mongod --dbpath=/home/zhangzhen/software/mongodb-linux-x86_64-2.4.1/mongodb-date/mongodb-db/
然後是: ./mongo
這樣每次執行這麼長句話很麻煩:自己寫一個shell 腳本。改成可執行文件就OK。然後 sh 文件名 OK。
#!/bin/sh
./mongod --dbpath=/home/zhangzhen/software/mongodb-linux-x86_64-2.4.1/mongodb-date/mongodb-db --logpath=/home/zhangzhen/software/mongodb-linux-x86_64-2.4.1/mongodb-date/mongodb-logs/mongodb.log --logappend&
這個格式。然後保存。chmod +x 文件名 。把其改成可執行文件
在執行的過程中要注意的地方是:有的時候要用root的權限來執行。有的時候執行不成功的原因有:已經起來了mongo,su 到root 的權限,kill -9 然後再去執行這個文件,sh ex_mongo 。注意一定是在這個路徑中去執行 ./mongo。
2、在安裝fluentd—plagin-mongodb 插件的過程:
(1)fluent-gem install fluent-plugin-mongo
3;遇到的問題:(很關鍵的事情)http://docs.fluentd.org/articles/apache-to-mongodb
提到了apache 的日誌收集,而你做的是cf 的收集。就是爲什麼,官網 tag mongo.apache.access//
關於tag cf.router 這個是什麼意思;
4月11日
今天的任務,還是自己去配置mongodb ,把每一個細節都要呂清。然後自己再去嘗試這就去配置。這個必須要熟練。這也是你工作的第一可以啃下的內容。去嘗試。
1.遇到的問題是爲什麼,你能單獨的起mongodb 和fluentd ,但是在寫的時候,還是不清楚,之間就是沒有交互。問題在哪兒?
這篇文章爲我們展示如何在redhat中安裝td-agent這個
At first, please create /etc/yum.repos.d/td.repo with the following contents. 如果你沒有td.repo 這個你自己建一個,然後把下面的寫入。
[treasuredata]
name=TreasureData
baseurl=http://packages.treasure-data.com/redhat/$basearch
gpgcheck=0
Then, you can install via yum command.
$ yum update 這個似乎沒有必要,執行後會下載四百多兆的東西,沒意思。直接執行下句。
$ yum install td-agent 安裝td-agent 這個似乎有必要
$ /etc/init.d/td-agent start
/etc/init.d/td-agent script is also provided to start, stop, or restart the agent.
$ /etc/init.d/td-agent start
$ /etc/init.d/td-agent stop
$ /etc/init.d/td-agent restart
配置
如果你是使用上面的deb/rpm包安裝的Fluentd,那麼配置文件位置在:/etc/td-agent/td-agent.conf,否則其位置應該在:/etc/fluentd/fluentd.conf
首先我們編輯配置文件中的source來設置日誌來源
官網上的說明:
The in_tail
Input plugin allows Fluentd to read events from the tail of text files. Its behavior is similar to thetail -F
command.
Example Configuration
in_tail
is included in Fluentd’s core. No additional installation process is required.
<source>
type tail
path /var/log/httpd-access.log
pos_file /var/log/td-agent/httpd-access.log.pos
tag apache.access
format apache2
</source>
1.什麼事 td-agent -----------Installing td-agent for Redhat and CentOS
安裝td-agent 就是在上面寫的東西。
網站上的說明:
<source>
type tail
format apache
path /var/log/apache2/access_log
tag mongo.apache
</source>
其中:
- type tail: tail方式是 Fluentd 內置的輸入方式,其原理是不停地從源文件中獲取新的日誌。
- format apache: 指定使用 Fluentd 內置的 Apache 日誌解析器。
- path /var/log/apache2/access_log: 指定日誌文件位置。
- tag mongo.apache: 指定tag,tag被用來對不同的日誌進行分類
下面再來編輯輸出配置,配置日誌收集後存儲到MongoDB中
<match mongo.**>
# plugin type
type mongo
# mongodb db + collection
database apache
collection access
# mongodb host + port
host localhost
port 27017
# interval
flush_interval 10s
</match>
match標籤後面可以跟正則表達式以匹配我們指定的tag,只有匹配成功的tag對應的日誌纔會運用裏面的配置。配置中的其它項都比較好理解,看註釋就可以了,其中flush_interval是用來控制多長時間將日誌寫入MongoDB一次。
fluentd的開始的配置:
source 指令決定了input source
match 指令決定論 output 的目的地
include指令包含其他的文件。
在52的機器上》
fluentd的目錄是在這個中 ::::::/etc/fluent
source指令:指的具體的內容:
<source>
type forward port
24224
</source>
# http://this.host:9880/myapp.access?json={"event":"data"}
<source> type http port 9880</source>
source 把事件提交到fluentd路由引擎。一個事件包含三個實體:tag 、 time、record
The tag is a string separated by ‘.’s (e.g. myapp.access), and is used as the directions for Fluentd’s internal routing engine.
The time is the UNIX time when the event occurs.
The record is a JSON object.
match 指令:fluent 的標準輸出插件,包含file 和forward
每一個match 都包含:match pattern(用於過濾事件) 和一個type 類型(用於爲指定輸出插件使用):
For example, the user can send all matches to the pattern myapp.accesslog.**
tofile
in a specified directory.
用戶可以編寫自己的插件擴大Fluentd的輸出默認選項以外的來源。欲瞭解更多信息關於Fluentd的輸出目的地,請參閱輸出插件概述文章。
關於match模式說明:
* 指匹配一個單獨的tag元素:a.* 匹配a.b 但不匹配a 和 a.b.c 這種形式
** 匹配 0 或者是更多的tag 元素。a.* =a=a.b=a.b.c
{X,Y,Z}匹配X,Y,or Z .例如:{a,b}匹配a和b ,但不匹配c
可以利用組合來顯示::::: ------------*
or**
patterns. Examples includea.{b,c}.*
anda.{b,c.**}
fluentd 是爲日誌傳遞的主要設計的。在這樣的系統中,一些運輸保證是可能的
4月12號
出現的問題是:在開始書寫數據的時候,導致在253上[warn]: no patterns matched tag="cf.router"
。。。就說明match cf 是沒有啓動的:這個沒有辦法:也不知道怎麼改
遇到一個比較扯淡的事,match cf * 這個的時候,你要注意的是: 只能緊挨着你上面的匹配,對應下面的,dubug.agent什麼的,只能是在下面。
做工程和寫作業不一樣,你要仔細,仔細到每一點,這個不能含糊。