cd /usr/local/elk
上传elasticsearch-6.2.1.tar.gz
tar -zxvf elasticsearch-6.2.1.tar.gz
cd /usr/local/elk/elasticsearch-6.2.1/config
vi elasticsearch.yml
network.host: 172.30.1.45
cd /usr/local/elk/elasticsearch-6.2.1/bin
./elasticsearch
查看进程: ps -ef | grep elasticsearch
后台运行: nohup ./elasticsearch &
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
原因:内存不足: 减少启动程序所需内存,或加大内存,如关闭一些程序。
由于elasticsearch5.0默认分配jvm空间大小为2g,修改jvm空间分配:
vi /usr/local/elk/elasticsearch-6.2.1/config/jvm.options
-Xms2g
-Xmx2g
修改为
-Xms512m
-Xmx512m
Exception in thread "main" SettingsException[Failed to load settings from [elasticsearch.yml]]; nested: ElasticsearchParseException[malformed, expected settings to start with 'object', instead was [VALUE_STRING]];
原因:
配置文件elasticsearch.yml中:network.host:172.30.1.45
冒号后面应该加空格:network.host: 172.30.1.45
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
这个错误,是因为使用root用户启动elasticsearch,elasticsearch是不允许使用root用户启动的,所以我们需要添加用户。
解决方案:新建用户elk-weifan
groupadd elktest
useradd -g elktest elk-weifan
passwd elk-weifan
密码: elk-weifan
再次输入密码: elk-weifan
chown -R elk-weifan:elktest /usr/local/elk/elasticsearch-6.2.1
chmod 755 /usr/local/elk/elasticsearch-6.2.1
su - elk-weifan
切换用户之后:
cd /usr/local/elk/elasticsearch-6.2.1/bin
./elasticsearch
启动成功
java.lang.UnsupportedOperationException: seccomp unavailable: CONFIG_SECCOMP not compiled into kernel, CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER are needed
原因:这个错误是因为centos6的内核不支持SecComp
解决:
查看centos版本
lsb_release -a
可以不必理会
补充问题:
ERROR: [1] bootstrap checks failed
[1]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
cd /usr/local/elk/elasticsearch-6.2.1/config
vi elasticsearch.yml
# 这个可以在配置文件中找到
bootstrap.memory_lock: false
# 这个找不到,复制粘贴就好,默认开启,由于内核问题,找不到,设置为false即可解决
bootstrap.system_call_filter: false
ERROR: bootstrap checks failed
max file descriptors [65535] for elasticsearch process likely too low, increase to at least [65536]
原因:无法创建本地文件问题,用户最大可创建文件数太小
解决:
切换到root用户,编辑limits.conf配置文件, 添加类似如下内容:
vi /etc/security/limits.conf
添加如下内容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 65535
ERROR: bootstrap checks failed
max number of threads [1024] for user [elk-weifan] likely too low, increase to at least [4096]
原因:无法创建本地线程问题,用户最大可创建线程数太小
解决:切换到root用户,进入limits.d目录下,修改90-nproc.conf 配置文件。
vi /etc/security/limits.d/90-nproc.conf
找到如下内容:
* soft nproc 1024
修改为
* soft nproc 4096
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
{
"name" : "_bPCCkF",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "3CBmAzhBSViAPTDmhxEd6g",
"version" : {
"number" : "6.2.1",
"build_hash" : "253032b",
"build_date" : "2016-10-26T04:37:51.531Z",
"build_snapshot" : false,
"lucene_version" : "6.2.1"
},
"tagline" : "You Know, for Search"
}
命令测试elasticsearch:
# 创建索引create_myindex
curl -XPUT '172.30.1.45:9200/create_myindex?pretty'
# 放入数据Fan Wei,,type:create_mytype,ID:1
curl -XPOST 'localhost:9200/create_myindex/create_mytype/1?pretty' -d' {"name": "Fan Wei" }'
# 查看索引信息
curl -XGET '172.30.1.45:9200/create_myindex/create_mytype/1?pretty'
# 获取索引内容
curl '172.30.1.45:9200/create_myindex/_search?q=*&pretty'
# 删除索引
curl -XDELETE '172.30.1.45:9200/create_myindex?pretty'
# 列出所有索引
curl 'http://172.30.1.45:9200/_cat/indices?v'
# 查看所有模板
curl -XGET 'http://172.30.1.45:9200/_template'
# 查看单个模板metricbeat-6.2.1
curl -XGET 'http://172.30.1.45:9200/_template/metricbeat-6.2.1'
# 删除单个模板metricbeat-6.2.1
curl -XDELETE 'http://172.30.1.45:9200/_template/metricbeat-6.2.1'
# 查看版本信息:
curl 172.30.1.45:9200
# 查看集群是否健康:
curl 'http://172.30.1.45:9200/_cat/health?v'
# 查看节点列表:
curl 'http://172.30.1.45:9200/_cat/nodes?v'
# 列出所有索引及存储大小:
curl 'http://172.30.1.45:9200/_cat/indices?v'
# 删除索引:
curl -XDELETE 'http://172.30.1.45:9200/test_system_log?pretty'
# 查看索引mapping
curl -XGET "http://172.30.1.45:9200/ecapi-2018.04.08/_mapping?pretty"
# 查看索引内容(其中 q=* 表示匹配索引中所有的数据。)
curl '172.30.1.45:9200/ecapi-2018.04.08/_search?q=*&pretty'
# 索引数据迁移:
POST _reindex
{
"source": {
"index": "twitter"
},
"dest": {
"index": "new_twitter"
}
}
参考博客:https://www.cnblogs.com/aaanthony/p/7380662.html