ELK集群的搭建和Elasticsearchd api的简单使用
為什么80%的碼農都做不了架構師?>>> ??
Elasticsearchd的安裝,具體的安裝步驟很簡單不過有些配置還是需要注意的,下面簡單介紹下安裝步驟
第一步:從官網下載最新的版本:elasticsearch-5.4.1_1,安裝前先安裝jdk8,elasticsearch是java開發的,解壓到你想放的位置:修改配置文件,配置文件的位置:/usr/local/elasticsearch-5.4.1_1/config/elasticsearch.yml,因為為了安全elasticsearch不能用root用戶啟動,需要從新建立新的用戶,并且給文件夾賦值權限給新用戶,例如用戶名叫elasticsearch,在root用戶下chown -R?elasticsearch:elasticsearch?/usr/local/elasticsearch-5.4.1_1然后修改一下系統的參數:
a.添加 /etc/security/limits.conf
* ???????????????soft ???nofile ?????????65536
* ???????????????hard ???nofile ?????????131072
* ???????????????soft ???nproc ??????????2048
* ???????????????hard ???nproc ??????????4096
b./etc/security/limits.d/90-nproc.conf
?把soft nproc 1024這行的1024改大就行了。
c.vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=262144
d.并執行命令:
sysctl -p
E.修改elasticsearch.yml
cluster.name: es_test_1bootstrap.memory_lock: false bootstrap.system_call_filter: false node.name: esc_test_node_1 http.enabled: true node.master: true node.data: true // 文件的位置 path.logs: /path/to/logs // 日志的位置 path.logs: /home/data/elasticsearch/log///這個要設置下不然外網無法訪問 network.host: 193.168.6.87 http.port: 9201 transport.tcp.port: 9301http.cors.enabled: true http.cors.allow-origin: /.*/ http.cors.allow-credentials: true// 這個是集群的配置單機不需要配置 discovery.zen.ping.unicast.hosts: ["x.x.x.x"] // 2個節點 node.max_local_storage_nodes: 2bin目錄啟動服務:./elasticsearch -d,看日志/home/data/elasticsearch/log/,如果日志正常就說明啟動成功
常見錯誤
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.4.1.jar:5.4.1] Caused by: java.lang.RuntimeException: can not run elasticsearch as rootat org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.4.1.jar:5.4.1]at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.4.1.jar:5.4.1]at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:350) ~[elasticsearch-5.4.1.jar:5.4.1]at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.4.1.jar:5.4.正常啟動日志:
[2017-08-20T15:56:07,031][INFO ][o.e.n.Node ] [esc_test_node_1] JVM arguments [-Xms512m, -Xmx512m, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+DisableExplicitGC, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/usr/local/elasticsearch-5.4.1_1] [2017-08-20T15:56:07,889][INFO ][o.e.p.PluginsService ] [esc_test_node_1] loaded module [aggs-matrix-stats] [2017-08-20T15:56:07,889][INFO ][o.e.p.PluginsService ] [esc_test_node_1] loaded module [ingest-common] [2017-08-20T15:56:07,889][INFO ][o.e.p.PluginsService ] [esc_test_node_1] loaded module [lang-expression] [2017-08-20T15:56:07,890][INFO ][o.e.p.PluginsService ] [esc_test_node_1] loaded module [lang-groovy] [2017-08-20T15:56:07,890][INFO ][o.e.p.PluginsService ] [esc_test_node_1] loaded module [lang-mustache] [2017-08-20T15:56:07,890][INFO ][o.e.p.PluginsService ] [esc_test_node_1] loaded module [lang-painless] [2017-08-20T15:56:07,890][INFO ][o.e.p.PluginsService ] [esc_test_node_1] loaded module [percolator] [2017-08-20T15:56:07,890][INFO ][o.e.p.PluginsService ] [esc_test_node_1] loaded module [reindex] [2017-08-20T15:56:07,890][INFO ][o.e.p.PluginsService ] [esc_test_node_1] loaded module [transport-netty3] [2017-08-20T15:56:07,890][INFO ][o.e.p.PluginsService ] [esc_test_node_1] loaded module [transport-netty4] [2017-08-20T15:56:07,891][INFO ][o.e.p.PluginsService ] [esc_test_node_1] no plugins loaded [2017-08-20T15:56:09,451][INFO ][o.e.d.DiscoveryModule ] [esc_test_node_1] using discovery type [zen] [2017-08-20T15:56:10,205][INFO ][o.e.n.Node ] [esc_test_node_1] initialized [2017-08-20T15:56:10,205][INFO ][o.e.n.Node ] [esc_test_node_1] starting ... [2017-08-20T15:56:10,387][INFO ][o.e.t.TransportService ] [esc_test_node_1] publish_address {192.168.6.87:9300}, bound_addresses {192.168.6.87:9300} [2017-08-20T15:56:10,394][INFO ][o.e.b.BootstrapChecks ] [esc_test_node_1] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks [2017-08-20T15:56:13,446][INFO ][o.e.c.s.ClusterService ] [esc_test_node_1] new_master {esc_test_node_1}{xSFrf7feRD25YuwgtBeSLw}{G4byr3dMRc6T1QN_PRxxDQ}{192.168.6.87}{192.168.6.87:9300}, reason: zen-disco-elected-as-master ([0] nodes joined) [2017-08-20T15:56:13,465][INFO ][o.e.h.n.Netty4HttpServerTransport] [esc_test_node_1] publish_address {192.168.6.87:9200}, bound_addresses {192.168.6.87:9200} [2017-08-20T15:56:13,468][INFO ][o.e.n.Node ] [esc_test_node_1] started [2017-08-20T15:56:14,573][INFO ][o.e.g.GatewayService ] [esc_test_node_1] recovered [11] indices into cluster_state第二步:安裝logstash,這個安裝很簡單,從官網下載最新的版本解壓
創建一個輸入輸出文件sample.conf
input {stdin {} } output {elasticsearch {hosts => ["192.168.6.87:9201"] }stdout {codec => rubydebug } }啟動服務:
第三步安裝kibana-5.1.1-linux-x86_64,修改配置文件/usr/local/kibana-5.1.1-linux-x86_64/config/kibana.yml,修改一下server.host: "192.168.x",不然無法訪問的通過外網,啟動服務?
[root@localhost bin]# ./kibanalog [08:09:06.517] [info][status][plugin:kibana@5.1.1] Status changed from uninitialized to green - Readylog [08:09:06.593] [info][status][plugin:elasticsearch@5.1.1] Status changed from uninitialized to yellow - Waiting for Elasticsearchlog [08:09:06.625] [info][status][plugin:console@5.1.1] Status changed from uninitialized to green - Readylog [08:09:06.648] [warning] You're running Kibana 5.1.1 with some different versions of Elasticsearch. Update Kibana or Elasticsearch to the same version to prevent compatibility issues: v5.4.1 @ 192.168.6.87:9200 (192.168.6.87)log [08:09:06.657] [error][status][plugin:elasticsearch@5.1.1] Status changed from yellow to red - Elasticsearch is still initializing the kibana index.log [08:09:06.865] [info][status][plugin:timelion@5.1.1] Status changed from uninitialized to green - Readylog [08:09:06.871] [info][listening] Server running at http://192.168.6.87:5601log [08:09:06.872] [error][status][ui settings] Status changed from uninitialized to red - Elasticsearch plugin is red瀏覽器里打開kibana,然后輸入“星兒”
Elasticsearchd的使用實際很簡單的,一切都是resful,用postman簡單的做個例子,插入一條消息到elsearch中
可以獲取的到
下次博客會比較詳細的介紹下elsearch的用法
轉載于:https://my.oschina.net/zaxb/blog/1517641
總結
以上是生活随笔為你收集整理的ELK集群的搭建和Elasticsearchd api的简单使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (个人)Zookeeper集群环境部署
- 下一篇: SOA与微服务基本原则及对比