搭建ElasticSearch6.4.2
[root@test home]# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core)
创建用户
adduser elastic -m -U -p elastic
其中 -m 表示创建用户的主目录,在/home/username,-U 表示创建同名的组,-p表示密码
增加 sudoers 文件的写的权限,默认为只读
chmod -v u+w /etc/sudoers
赋予elastic和root一样的权限
vi /etc/sudoers
添加
elastic ALL=(ALL) ALL
修改 /etc/security/limits.conf
,在此配置中增加以下内容。
如果服务器已经配置好,可以不用重复配置。需要在 Root 下执行。
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
修改完成后同时使用命令修改配置:
$ ulimit -n 65536
$ ulimit -n
65536
这些配置主要为文件系统描述符及相关的配置,具体的配置可以根据自己的系统配置调大或调小。
修改 /etc/sysctl.conf
,增加如下内容:
如果服务器已经配置好,可以不用重复配置。需要在 Root 下执行。
vm.max_map_count=655360
修改完成后,执行 sysctl -p
命令,使配置生效。
下载EslaticSearch
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.2.tar.gz
解压
cd /opt/gkk/
tar -zxvf elasticsearch-6.4.2.tar.gz
在root用户登录的情况,把es目录赋予给elastic这个用户权限:
chown -R elastic:elastic /opt/gkk/elasticsearch-6.4.2
编辑配置:
$ vi config/elasticsearch.yml
修改配置项如下:
#实现内网可访问
network.host: 0.0.0.0
# 启动。通过 -d 参数,表示后台运行。
#切换用户
su elastic
$ bin/elasticsearch -d
可以通过日志,查看启动是否成功。访问http://10.0.19.148:9200
tail -f logs/elasticsearch.log
Kibana:
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.4.2-linux-x86_64.tar.gz
配置Kibana
vi ./kibana-6.4.2-linux-x86_64/config/kibana.yml
#设置elasticsearch的url地址
server.port: 5601
server.host: "0.0.0.0"
# The URL of the Elasticsearch instance to use for all your queries.
elasticsearch.url: "http://10.0.19.148:9200"
查看端口占用
netstat -tunlp|grep 5601
启动kibana
#后台运行
./bin/kibana &
# 使用exit退出shell终端
exit
访问 http://10.0.19.148:5601
我们试着通过kibana往里面加数据
PUT blog/mycsdn/1
{
"id":1,
"name":"Elasticsearch操作指南",
"author":"xiaocy66",
"content":"Elasticsearch是一个基于Lucene的搜索引擎"
}
我们可以安装 Chrome 插件 Elasticsearch Head ,可以查看 Elasticsearch 的集群概要、索引、数据。
Elasticsearch 6.X xpack安装使用详解(试用)
升级前ES的license
升级之前访问:http://10.0.19.148:9200/_xpack 其中security一项内容如下:
security
description “Security for the Elastic Stack”
available false
enabled true
在kibana中升级license
在 Kibana 中访问 Management -> Elasticsearch -> License Management,点击右侧的升级 License 按钮,可以免费试用 30 天的高级 License,升级完成之后kibana页面会显示如下:
修改ES配置文件
config/elasticsearch.yml 添加如下配置:
#开启监控
xpack.security.enabled: true
xpack.ml.enabled: true
#表示试用的意思
xpack.license.self_generated.type: trial
xpack.monitoring.collection.enabled: true
设置集群密码
./bin/elasticsearch-setup-passwords interactive
总共修改了4个用户的密码:elastic、kibana、logstash_system、beats_system。
修改kibana配置文件
config/kibana.yml,设置正确的ES访问用户名密码:
elasticsearch.username: "elastic"
elasticsearch.password: "123456"
xpack.monitoring.enabled: true
xpack.monitoring.kibana.collection.enabled: true
修改配置之后,记得重启ES!!! 以及,kibana!!!
再访问http://10.0.19.148:9200/_xpack 其中security一项内容如下:
访问kibana: http://10.0.19.148:5601 也需要用户名密码了:
PS:记住这个license只有30天试用期,时间到了之后要么购买,要么破解。
Logstash
下载 https://artifacts.elastic.co/downloads/logstash/logstash-6.4.2.tar.gz
指定配置文件启动
./bin/logstash -f config/kafka2es.conf &
kibana监控logstash
修改logstash.yml
xpack.monitoring.enabled: true
xpack.monitoring.elasticsearch.username: logstash_system
xpack.monitoring.elasticsearch.password: "123456"
xpack.monitoring.elasticsearch.url: ["http://10.0.19.148:9200"]
修改pipelines.yml 放开注释:
Kafka2ES
配置文件
vi kafka2es.conf
input{
kafka{
bootstrap_servers => "10.0.221.74:9092,10.0.221.69:9092,10.0.221.73:9092"
topics => ["AI-MP-API"]
codec => json
group_id=> "AI-MP"
}
}
output {
elasticsearch {
hosts => ["http://10.0.221.74:9200"]
index => "ai-mp-api-%{+YYYY.MM.dd}"
}
}
创建索引模板
PUT _template/ai-mp-api
{
"index_patterns": ["ai-mp-api*"],
"settings":{
"number_of_shards": 2,
"number_of_replicas": 1
},
"mappings":{
"doc":{
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "keyword"
},
"apiInfoId": {
"type": "long"
},
"apiName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"apiType": {
"type": "keyword"
},
"callDate": {
"type": "date"
},
"callStatus": {
"type": "keyword"
},
"createdAt": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || yyyy/MM/dd HH:mm:ss|| yyyy/MM/dd ||epoch_millis"
},
"dataSourceId": {
"type": "long"
},
"dataSourceName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"dataSourceTable": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"dataSourceType": {
"type": "keyword"
},
"duration": {
"type": "long"
},
"errorLog": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"method": {
"type": "keyword"
},
"success": {
"type": "long"
},
"userId": {
"type": "long"
}
}
}
}
}
KAFKA
启动
./kafka-server-start.sh -daemon ../config/server.properties