運維日誌管理系統

因公司數據安全和分析的需要,故調研了一下 

GlusterFS +  lagstash + elasticsearch + kibana 3  + redis 整合在一起的日誌管理應用:

安裝,配置過程,使用情況等續


一,glusterfs分佈式文件系統部署:

說明:

公司想做網站業務日誌及系統日誌統一收集和管理,經過對mfs, fastdfs 等分佈式文件系統的調研,最後選擇了 glusterfs,因爲Gluster具有高擴展性、高性能、高可用性、可橫向擴展的彈性特點,無元數據服務器設計使glusterfs沒有單點故障隱患,官網:www.gluster.org

1.      系統環境準備:

Centos 6.4

         服務端:

         192.168.10.101

         192.168.10.102

         192.168.10.188

         192.168.10.189

         客戶端:

         192.168.10.103

         EPEL源和GlusterFS

         增加EPEL源和GLusterFS源,EPEL源中包含GLusterFS,版本比較舊,相對穩定,本次測試採用最新的3.5.0版本。

 

         rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

         wget -P /etc/yum.repos.dhttp://download.gluster.org/pub/gluster/glusterfs/LATEST/CentOS/glusterfs-epel.repo

 

2.      部署過程

         服務端安裝:

 

         yum -y install glusterfs glusterfs-fuseglusterfs-server

         chkconfig glusterd on

         service glusterd start

         服務端配置:

         4個存儲節點組成一集羣,本文在第一個節點執行,只需要在任意節點執行就ok

 

         [root@db1 ~]# gluster peer probe192.168.10.102

         probe successful

         [root@db1 ~]# gluster peer probe192.168.10.188

         probe successful

         [root@db1 ~]# gluster peer probe 192.168.10.189

         probe successful

         查看集羣的節點信息:

 

         [root@db1 ~]# gluster peer status

         number of peers: 3

         hostname: 192.168.10.102

         uuid:b9437089-b2a1-4848-af2a-395f702adce8

         state: peer in cluster (connected)

         hostname: 192.168.10.188

         uuid: ce51e66f-7509-4995-9531-4c1a7dbc2893

         state: peer in cluster (connected)

         hostname: 192.168.10.189

         uuid:66d7fd67-e667-4f9b-a456-4f37bcecab29

         state: peer in cluster (connected)

         /data/gluster爲共享目錄,創建名爲test-volume的卷,副本數爲2

 

          sh cmd.sh "mkdir /data/gluster"

         [root@db1 ~]#  gluster volume create test-volume replica 2192.168.10.101:/data/gluster 192.168.10.102:/data/gluster192.168.10.188:/data/gluster 192.168.10.189:/data/gluster

         creation of volume test-volume has beensuccessful. please start the volume to access data.

         啓動卷:

 

         [root@db1 ~]# gluster volume starttest-volume

         starting volume test-volume has beensuccessful

         查看卷狀態:

 

         [root@db1 ~]# gluster volume info

         volume name: test-volume

         type: distributed-replicate

         status: started

         number of bricks: 2 x 2 = 4

         transport-type: tcp

         bricks:

         brick1: 192.168.10.101:/data/gluster

         brick2: 192.168.10.102:/data/gluster

         brick3: 192.168.10.188:/data/gluster

         brick4: 192.168.10.189:/data/gluster

3.      客戶端安裝配置:

         安裝:

 

         yum -y installglusterfs glusterfs-fuse

         掛載:

 

         mount -t glusterfs 192.168.10.102:/test-volume/mnt/ (掛載任意一個節點即可)推薦用這種方式。

 

         mount -t nfs -o mountproto=tcp,vers=3192.168.10.102:/test-volume /log/mnt/ (使用nfs掛載,注意遠端的rpcbind服務必須開啓)

         echo "192.168.10.102:/test-volume/mnt/ glusterfs defaults,_netdev 0 0" >> /etc/fstab (開機自動掛載)

4.      測試

         檢查文件正確性

 

         dd if=/dev/zero of=/mnt/1.img bs=1Mcount=1000 # 在掛載客戶端生成測試文件

         cp /data/navy /mnt/  # 文件拷貝到存儲上

 

         宕機測試。

         使用glusterfs-fuse掛載,即使目標服務器故障,也完全不影響使用。用NFS則要注意掛載選項,否則服務端故障容易導致文件系統halt住而影響服務!

 

         # 將其中一個節點停止存儲服務service glusterd stop

         service glusterfsd stop# 在掛載客戶端刪除測試文件

         rm -fv /mnt/navy# 此時在服務端查看,服務被停止的節點上navy並未被刪除。此時啓動服務:serviceglusterd start# 數秒後,navy就被自動刪除了。新增文件效果相同!

5.      運維常用命令:

 

         刪除卷

         gluster volume stop test-volume

         gluster volume delete test-volume

         將機器移出集羣

         gluster peer detach 192.168.10.102

         只允許172.28.0.0的網絡訪問glusterfs

         gluster volume set test-volumeauth.allow 192.168.10.*

         加入新的機器並添加到卷裏(由於副本數設置爲2,至少要添加2468..)臺機器)

         gluster peer probe 192.168.10.105

         gluster peer probe 192.168.10.106

         gluster volume add-brick test-volume192.168.10.105:/data/gluster 192.168.10.106:/data/gluster

         收縮卷

         # 收縮卷前gluster需要先移動數據到其他位置

         gluster volume remove-brick test-volume192.168.10.101:/data/gluster/test-volume192.168.10.102:/data/gluster/test-volume start

         # 查看遷移狀態

         gluster volume remove-brick test-volume192.168.10.101:/data/gluster/test-volume192.168.10.102:/data/gluster/test-volume status

         # 遷移完成後提交

         gluster volume remove-brick test-volume192.168.10.101:/data/gluster/test-volume192.168.10.102:/data/gluster/test-volume commit

         遷移卷

         # 192.168.10.101的數據遷移到,先將192.168.10.107加入集羣

         gluster peer probe 192.168.10.107

         gluster volume replace-bricktest-volume 192.168.10.101:/data/gluster/test-volume192.168.10.107:/data/gluster/test-volume start

         # 查看遷移狀態gluster volume replace-brick test-volume192.168.10.101:/data/gluster/test-volume192.168.10.107:/data/gluster/test-volume status

         # 數據遷移完畢後提交gluster volume replace-brick test-volume192.168.10.101:/data/gluster/test-volume192.168.10.107:/data/gluster/test-volume commit

         # 如果機器192.168.10.101出現故障已經不能運行,執行強制提交然後要求gluster馬上執行一次同步

         gluster volume replace-bricktest-volume 192.168.10.101:/data/gluster/test-volume192.168.10.102:/data/gluster/test-volume commit -force

         gluster volume heal test-volumes full

         24007

 

二.日誌收集系統部署

說明簡解:

系統各部分應用介紹

Logstash:做系統log收集,轉載的工具。同時集成各類日誌插件,對日誌查詢和分析的效率有很大的幫助.一般使用shipper作爲log收集、indexer作爲log轉載.

Logstash shipper收集log 並將log轉發給redis 存儲

Logstash indexerredis中讀取數據並轉發給elasticsearch

redis:是一個dblogstash shipperlog轉發到redis數據庫中存儲。Logstash indexerredis中讀取數據並轉發給elasticsearch

Elasticsearch:開源的搜索引擎框架,前期部署簡單,使用也簡單,但後期需要做必要的優化具體請參照博客http://chenlinux.com/categories.html#logstash-ref  logstash部分.可進行多數據集羣,提高效率。從redis中讀取數據,並轉發到kibana

Kibana 開源web展現。

 

虛擬服務器準備:

192.168.10.143    logstash shipper

192.168.10.144       logstash  indexer redis

192.168.10.145    elasticsearch  kibana3

1.三臺主機都要安裝jdk 1.7

推薦oracle jdk 1.7+版本

java -version

設置java的環境變量,比如

 

 vim~/.bashrc

 

>> 

JAVA_HOME=/usr/java/jdk1.7.0_55

PATH=$PATH:/$JAVA_HOME/bin

CLASSPATH=.:$JAVA_HOME/lib

JRE_HOME=$JAVA_HOME/jre

export JAVA_HOME PATH CLASSPATH JRE_HOME

>> 

source ~/.bashrc

2.安裝redis192.168.10.144

wgethttp://download.redis.io/releases/redis-2.6.16.tar.gz

tar -zxf redis-2.6.16.tar.gz

cd redis-2.6.16

make &&  make install

./src/redis-server ../redis.conf

 

 

啓動redis客戶端來驗證安裝

./src/redis-cli

> keys *    #列出所有的key

 

 

3.安裝Elasticsearch192.168.10.145

wgethttp://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.13.zip

 unzipelasticsearch-0.90.13.zip

elasticsearch解壓即可使用非常方便,接下來我們看一下效果,首先啓動ES服務,切換到elasticsearch目錄,運行bin下的elasticsearch

cd  elasticsearch-0.90.13

bin/elasticsearch -f

訪問默認的9200端口

 

curl -X GET http://localhost:9200

          

4.安裝logstash 192.168.10.143 192.168.10.144

wgethttp://download.elasticsearch.org/logstash/logstash/logstash-1.2.1-flatjar.jar

logstash下載即可使用,命令行參數可以參考logstash flags,主要有

agent  #運行Agent模式

-f CONFIGFILE #指定配置文件

web    #自動Web服務

-p PORT #指定端口,默認9292

 

 

5. 安裝kibana192.168.10.145

logstash的最新版已經內置kibana,你也可以單獨部署kibanakibana3是純粹JavaScript+html的客戶端,所以可以部署到任意http服務器上。

wgethttp://download.elasticsearch.org/kibana/kibana/kibana-latest.zip

 unzip kibana-latest.zip

 cp-r  kibana-latest /var/www/html

可以修改config.js來配置elasticsearch的地址和索引。

 修改以下行。

 elasticsearch:"http://192.168.10.145:9200",

 

 

 

 

 

 

 

6.      整合配置:

192.168.10.143 logstash shipper  配置收集日誌

Vim /etc/logstash_shipper.conf

    input{

    

           file  {

          type => "linux-syslog"

           path => [ "/var/log/lastlog", "/var/log/syslog","/var/log/lastlog" ]

         }

 

}

    

output {

        redis {

        host => "192.168.10.144"

                    port => “6379”

        data_type =>"list"

        key => "syslog"

       }

}

      啓動logstash shipper

       Nohup java –jar logstash-1.2.1-flatjar.jar agent –f /etc/ logstash_shipper.conf &

              過十秒後,輸出如下信息:

Using milestone 2input plugin 'file'. This plugin should be stable, but if you see strangebehavior, please let us know! For more information on plugin milestones, seehttp://logstash.net/docs/1.2.2/plugin-milestones {:level=>:warn}

Using milestone 2 output plugin 'redis'.This plugin should be stable, but if you see strange behavior, please let usknow! For more information on plugin milestones, see http://logstash.net/docs/1.2.2/plugin-milestones{:level=>:warn}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

192.168.10.144  logstash indexer 配置如下:

Vim /etc/logstash_indexer.conf

 input{

   redis

   {

   host => "192.168.10.144"

   data_type =>"list"

   port => "6379"

   key => "syslog"

   type => "redis-input"

   }

 

}

 

output

   {

   elasticsearch {

   host => "192.168.10.145"

   port => "9300"

   }

}

 

啓動logstash  indexer 

Nohup java –jar logstash-1.2.1-flatjar.jar agent –f /etc/ logstash_indexer.conf &

 

輸出同上。

 

7.      登錄 http://192.168.10.145/kibana  訪問如下

                             

 wKiom1Ph7HmiripNAAMEXMUr9gQ661.jpg

 

 

三,整合分佈式文件存儲和日誌收集系統

邏輯圖如下:

 wKioL1Ph7UfScu8OAAST_tSjG_4895.jpg

glusterfs 掛載到web服務器端,具體需要編寫日誌結構化程序配合日誌寫到glusterfs存儲上。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章