CentOS7.4下ELK6.2.4從0開始部署安裝

公司原本已經做了日誌收集,不過是收集於單臺雲服務器,還需要研發以及運維去登陸查看日誌。以前用的都是低版本的ELK(2.X),這次準備體驗試用下最新版本的。理論以及架構這些不再說明,網上很多請自行查看! 環境說明:CentOS7.4、jdk1.8等 下面是安裝過程 首先是確認環境rpm -qa|grep java 如果有其他版本的請刪除 rpm–e --nodeps java-* 檢查是否刪除 java –version # 開始安裝jdk1.8自行從oracle官網下載 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 解壓改名設置環境變量 vim /etc/profile在末行加入 export JAVA_HOME=/usr/local/jdk1.8 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib/dt.JAVA_HOME/lib/tools.jar:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:${PATH} 配置設置source /etc/profile 測試java -version # 設置內核參數 vim /etc/sysctl.conf 增加以下參數 vm.max_map_count=655360 執行以下命令,確保生效配置生效: sysctl -p 設置資源參數 vim /etc/security/limits.conf #修改 * soft nofile 65536 * hard nofile 131072 * soft nproc 65536 * hard nproc 131072 #設置elk用戶參數 vim /etc/security/limits.d/20-nproc.conf elk soft nproc 65536 elk用戶默認已經創建 ELK官網下載地址 https://www.elastic.co/cn/downloads 所有組件都在根據自己喜歡下 # elasticsearch-6.2.4(3臺) 解壓到/usr/local改名elasticsearch chown -R elk.elk elasticsearch/ 到解壓目錄下 vim config/elasticsearch.yml 同樣是末行加入 #這裏指定的是集羣名稱,需要修改爲對應的,開啓了自發現功能後,ES會按照此集羣名稱進行集羣發現 cluster.name: elk123 #數據目錄 path.data: data/elk/data #log目錄 path.logs: data/elk/logs #節點名稱(3臺1-3) node.name: node-1 #修改一下ES的監聽地址,這樣別的機器也可以訪問 network.host: 0.0.0.0 #默認的端口號以及訪問 http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" ##集羣以及節點數 discovery.zen.ping.unicast.hosts: ["192.168.1.112", "192.168.1.113","192.168.1.114"] discovery.zen.minimum_master_nodes: 3 注意配置冒號後有空格,新建日誌和數據目錄給 mkdir -p /data/elk/log mkdir -p /data/elk/data chown -R elk.elk /data/ 啓動elasticsearch su elk -c "/usr/local/elasticsearch/bin/elasticsearch -d " 測試訪問ip:9200 es集羣可視化(5.0以後ES不再提供內置) # elasticsearch-head安裝 依賴安裝 yum install git nodejs npm 檢測 git clone git://github.com/mobz/elasticsearch-head.git node -v npm -v 到目錄下 npm install -g cnpm --registry=https://registry.npm.taobao.org vim /usr/local/elasticsearch/config/elasticsearch.yml 末行加入 http.cors.enabled: true http.cors.allow-origin: "*" cd elasticsearch-head/ vim Gruntfile.js 在connect屬性中,增加hostname: ‘0.0.0.0’ connect: { server: { options: { hostname: '0.0.0.0', port: 9100, base: '.', keepalive: true vi _site/app.js #編輯配置文件,填寫elasticsearch server的地址 init: function(parent) { this._super(); this.prefs = services.Preferences.instance(); this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://es_ip:9200"; if( this.base_uri.charAt( this.base_uri.length - 1 ) !== "/" ) { // XHR request fails if the URL is not ending with a "/" this.base_uri += "/"; } #啓動程序 cnpm install -g grunt 重啓es 啓動elasticsearch-head nohup grunt server & #訪問web http://xxx:9100 ![](https://s1.51cto.com/images/blog/201805/02/fb0078a6d200c842ae351f66b1e8165b.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) # kibana-6.2.4(單臺即可) 解壓安裝改名 cd kibana/ vim config/kibana.yml #開啓默認端口5601如果5601被佔用可用5602或其他 server.port: 5601 server.host: “hostname” 這裏填你的主機名 #指向elasticsearch服務的ip地址 elasticsearch.url: http://localhost:9200 kibana.index: “.kibana” 啓動 /usr/local/kibana/bin/kibana & 測試ip:5601 # logstash-6.2.4 這個要安裝在你日誌所在服務器上 解壓安裝改名到目錄下 vim config/*-logst.conf新建一個配置文件名字自定 input{ file { path => "/usr/loca/*.log" #你的日誌路徑 start_position => beginning ignore_older => 0 sincedb_path =>"/dev/null" }} filter{ grok { match => { "message" =>"%{IPORHOST:clientip} - %{USER:auth} \"(?:%{WORD:verb}%{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})\"%{NUMBER:response} (?:%{NUMBER:bytes}|-)"} }date { match => [ "timestamp" ,"dd/MMM/YYYY:HH:mm:ss +0800" ] } } output{ elasticsearch { hosts => ["ip:9200" ] index => "logs-%{+YYYY.MM.dd}" } stdout {} } 該配置只是匹配單個項目如果多個請參考以下 input { file { path => "/var/log/messages" type => "system" start_position => "beginning" } file { path => "/var/log/elasticsearch/chuck-clueser.log" type => "es-error" start_position => "beginning" codec => multiline { pattern => "^\[" negate => true what => "previous" } } } output { if [type] == "system" { elasticsearch { hosts => ["192.168.56.11:9200"] index => "system-%{+YYYY.MM.dd}" } } if [type] == "es-error" { elasticsearch { hosts => ["192.168.56.11:9200"] index => "es-error-%{+YYYY.MM.dd}" } } } 然後啓動 /usr/local/logstash/bin/logstash -f /usr/local/logstash/config/*-logst.conf 然後去kibana看下是否有數據!要先創建索引! 此安裝模式ELK的head和kibana基本等於無任何安全措施,建議基於nginx反向代理IP限制或者內網使用。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章