Linux 版本
Centos 6.5
ElasticSearch + Kibana + X-Pack 版本
Elasticsearch 5.1.1 提供數據的搜索 存儲
Head-plugin 5.1.1.1 方便查看es索引 數據 es基本狀態
Kibana 5.1.1.1 提供ES數據提供圖形化界面分析
X-Pack 5.1.1.1 提供ES集群狀態監控 Kibana用戶權限管理,安全,報告
Java 版本
ELK 對JDK 最低版本要求 1.8 安裝Java 1.8版本
下載地址 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
下載解壓 配置環境變量
tar xzvf jdk-8u112-linux-x64.tar.gz
export JAVA_HOME=/data1/JDK 1.8
export PATH=$JAVA_HOME/bin:$PATH
source /etc/profile
Elasticsearch
安裝
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.1.tar.gz
tar xzvf elasticsearch-5.1.1.tar.gz
配置
1.ES有執行腳本的能力,因安全因素,不能在root用戶下運行,強行運行會報如下錯誤:
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
解決:配置es用戶和es組
groupadd es #增加es組
useradd es -g es -p pwd #增加es用戶并附加到es組 password為pwd
chown -R es:es elasticsearch-5.1.1 #給目錄權限
su es #使用es用戶
2.ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
max number of threads [1024] for user [lishang] likely too low, increase to at least [2048]
解決:切換到root用戶,編輯limits.conf 添加類似如下內容
vi /etc/security/limits.conf
添加如下內容:
* soft nofile 655350
* hard nofile 655350
* soft nproc 2048
* hard nproc 4096
3.max number of threads [1024] for user [lish] likely too low, increase to at least [2048]
解決:切換到root用戶,進入limits.d目錄下修改配置文件。
vi /etc/security/limits.d/90-nproc.conf
修改如下內容:
* soft nproc 1024
修改為
* soft nproc 2048
4.max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解決:切換到root用戶修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并執行命令:
sysctl -p
5.配置es配置文件
vim elasticsearch/config/elasticsearch.yml
cluster.name: es_cluster #集群名字
node.name: node0 #節點名字
path.data: /data1/es/data #數據存放路徑
path.logs: /data1/es/logs #日志存放路勁
network.host: 10.10.10.10 #綁定主機地址
http.port: 9200 #地址端口號
discovery.zen.ping.unicast.hosts: #配置多節點,發現方式為unicast,指定master節點,方便快速定位主節點
- 10.10.10.11
- 10.10.10.12
http.cors.enabled: true #允許跨域訪問 這樣head插件可以訪問es
http.cors.allow-origin: "*"
action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history* #自動建立x-pack索引
啟動
bin/elasticsearch &
寫入數據
1.pom文件按添加依賴
<dependencies>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
</dependencies>
2.配置log4j2.properties文件 放在src目錄下
appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
rootLogger.level = info
rootLogger.appenderRef.console.ref = consol
3.創建ESClinet
java api 參考https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
public class CreateEsClient {
public static TransportClient Client() {
// 設置集群名稱
Settings settings = Settings.builder()
.put("cluster.name", "es_cluster").build();
// 創建client
TransportClient client = null;
try {
client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(
InetAddress.getByName("10.10.10.10"), 9300));
} catch (UnknownHostException e) {
e.printStackTrace();
}
//返回client
return client;
}
public static void main(String[] args) {
}
}
4.寫入數據
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.transport.TransportClient;
import static org.elasticsearch.common.xcontent.XContentFactory.*;
public class AddEsIndex {
// 文檔索引
private static final String Index = "test";
public static void main(String[] args) {
// 創建客戶端
TransportClient client = CreateEsClient.Client();
SimpleDateFormat Formate = new SimpleDateFormat("yyyyMMdd");
String IndexType = Formate.format(new Date(System.currentTimeMillis()));
for (int i = 0; i < 1000; i++) {
IndexResponse response;
// 寫入一條數據
try {
response = client.prepareIndex(Index, IndexType)
// 創建索引和類型 id自動生成
.setSource(
jsonBuilder()
.startObject()
// 寫入字段和值
.field("domain", "www.baidu.com")
.field("timestamp",
String.valueOf(System
.currentTimeMillis() / 1000))
.field("flow_size",
String.valueOf((int) (Math
.random() * 10000)))
.endObject()).get();
} catch (IOException e) {
e.printStackTrace();
break;
}
}
// 關閉客戶端
client.close();
}
}
安裝elasticsearch-head插件
1.安裝git
yum -y install git
2.下載源碼
git clone git://github.com/mobz/elasticsearch-head.git
3.安裝node
由于head插件本質上還是一個nodejs的工程,因此需要安裝node,使用npm來安裝依賴的包,npm可以理解為maven
wget https://nodejs.org/dist/v4.2.2/node-v4.2.2-linux-x64.tar.gz
4.解壓node
tar xf node-v4.2.2-linux-x64.tar.gz
5.配置node環境變量
export NODE_HOME=/data1/node
export PATH=$NODE_HOME/bin:$PATH
source /etc/profile
6.測試node是否生效
node -v
npm -v
7.安裝grunt
grunt是一個很方便的構建工具,可以進行打包壓縮、測試、執行等等的工作,5.1.1里的head插件就是通過grunt啟動的。因此需要安裝一下
npm install grunt-cli
8.檢查安裝是否成功
grunt -version
9.修改服務器監聽地址
vim elasticsearch-head/Gruntfile.js
connect: {
server: {
options: {
port: 9100,
hostname: '*',
base: '.',
keepalive: true
}
}
}
增加hostname屬性設置為*
10.修改head的連接地址:
vim elasticsearch-head/_site/app.js
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
把localhost修改成你es的服務器地址,如:
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://10.10.10.10:9200";
11.運行head, 在head目錄中,執行npm install
npm install
12.啟動nodejs
grunt server
13.訪問target:9100
http://10.10.10.10:9100
Kibana安裝
安裝
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.1.tar.gz
tar xzvf kibana-5.1.1-linux-x86_64.tar.gz
配置
vim kibana/config/kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://10.10.10.10:9200"
啟動
./bin/kibana &
訪問地址http://10.10.10.10:5601
配置Index
查看Discover 發現數據
可視化數據Visualize
保存圖形數據 Dashboard
安裝X-PACK
Elasticsearch下載X-Pack
1.在Es的根目錄(每個節點),運行
bin/elasticsearch-plugin
2.如果你在Elasticsearch已禁用自動索引的創建,在elasticsearch.yml配置action.auto_create_index允許X-pack創造以下指標:
action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*
3.運行Elasticsearch
bin/elastucsearch
Kibana下載X-Pack
1.在Kibana根目錄運行 bin/kibana-plugin 進行安裝,安裝過程會比較久,耐心等待
bin/kibana-plugin install x-pack
2.運行Kibana
bin/kibana
驗證X-Pack
在瀏覽器上輸入如下, 可以打開Kibana,此時需要輸入用戶名和密碼登錄,默認分別是 elastic 和 changeme
http://10.10.10.10:5601/