ElasticSearch
安装java环境
- sudo apt-get update
- java -version
- sudo apt-get install default-jre
- sudo apt-get install default-jdk
- (或者: yum -y install java-1.7.0-openjdk* )
设置JAVA_HOME
- sudo update-alternatives --config java(返回YOUR_PATH)
- sudo nano /etc/environment
- JAVA_HOME="YOUR_PATH"
- source /etc/environment
- echo $JAVA_HOME
安装ElasticSearch(以1.7.2为例)
- wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.2.deb(yum 下载rpm包)
- sudo dpkg -i elasticsearch-1.7.2.deb (sudo rpm -ivh *.rpm)
- sudo update-rc.d elasticsearch defaults (chkconfig –-add elasticsearch ; chkconfig elasticsearch on )
启动ElasticSearch
- sudo service elasticsearch start
- elasticsearch 结构目录位置: /var/lib/elasticsearch
配置ElasticSearch
- 配置文件地址:/etc/elasticsearch/elasticsearch.yml
- 配置文件详解:http://www.cnblogs.com/sunxucool/p/3799190.html
配置防火墙
- sudo ufw disable
- sudo ufw allow from 192.168.1.141
- sudo ufw enable
或者防火墙
#/usr/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
#/usr/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
#/usr/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
#/usr/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
/usr/sbin/iptables -I INPUT -p tcp --dport 9200 -j DROP
/usr/sbin/iptables -I INPUT -s 10.44.136.154 -p tcp --dport 9200 -j ACCEPT
/usr/sbin/iptables -I INPUT -s 某个ip -p tcp --dport 9200 -j ACCEPT
/usr/sbin/iptables -I INPUT -s 某个ip -p tcp --dport 9200 -j ACCEPT
/usr/sbin/service iptables save
创建快照
- elasticsearch.yml添加: path.repo: ["/mount/backups", "/mount/longterm_backups"]
- 创建目录: /mount/backups/my_backup, /mount/longterm_backups
- 添加权限: sudo chmod -R 777 /mount
- 重启elasticsearch服务: sudo service elasticsearch restart
- 创建仓库,并指定仓库类型:
curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '
{
"type": "fs",
"settings": {
"location": "/mount/backups/my_backup",
"compress": true
}
}'
- 创建第一个快照:curl -XPUT http://localhost:9200/_snapshot/my_backup/snapshot_1?wait_for_completion=true
- 查看所有快照: curl -XGET http://localhost:9200/_snapshot/my_backup/_all
- 删除一个快照: curl -XDELETE http://localhost:9200/_snapshot/my_backup/snapshot_1
- 使用快照:
curl -XPOST http://localhost:9200/_snapshot/my_backup/snapshot_1/_restore -d '
{
"indices": "index_1,index_2",
"ignore_unavailable": "true",
"include_global_state": false,
"rename_pattern": "index_(.+)",
"rename_replacement": "restored_index_$1"
}'
配置ik分词
- 版本参考
master | 2.1.0 -> master |
1.6.0 | 2.1.0 |
1.5.0 | 2.0.0 |
1.4.1 | 1.7.2 |
1.4.0 | 1.6.0 |
1.3.0 | 1.5.0 |
1.2.9 | 1.4.0 |
1.2.8 | 1.3.2 |
1.2.7 | 1.2.1 |
1.2.6 | 1.0.0 |
1.2.5 | 0.90.2 |
1.2.3 | 0.90.2 |
1.2.0 | 0.90.0 |
1.1.3 | 0.20.2 |
1.1.2 | 0.19.x |
1.0.0 | 0.16.2 -> 0.19.0 |
- checkout对应tag: git checkout tags/v1.4.1 -b v1.4.1
- 安装maven: (略)
- 编译jar包: sudo mvn package
- copy ik文件夹到/etc/elasticsearch/: sudo cp config/ik /etc/elasticsearch/
- copy jar到/usr/share/elasticsearch/lib/: sudo cp target/*.jar /usr/share/elasticsearch/lib
- 配置elasticsearch.yml
index:
analysis:
analyzer:
ik:
alias: [ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
ik_max_word:
type: ik
use_smart: false
ik_smart:
type: ik
use_smart: true
index.analysis.analyzer.default.type : "ik"
- 创建index:
curl -XPUT http://localhost:9200/index
- 创建mapping
curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'
{
"fulltext": {
"_all": {
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"term_vector": "no",
"store": "false"
},
"properties": {
"content": {
"type": "string",
"store": "no",
"term_vector": "with_positions_offsets",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"include_in_all": "true",
"boost": 8
}
}
}
}'
mapping:
curl -XPUT localhost:9200/feiliwu -d '{
"mappings":{
"product":{
"_timestamp":{
"enables": true
}
}
}
}'
- 录入数据
curl -XPOST http://localhost:9200/index/fulltext/1 -d'
{"content":"美国留给伊拉克的是个烂摊子吗"}
'
curl -XPOST http://localhost:9200/index/fulltext/2 -d'
{"content":"公安部:各地校车将享最高路权"}
'
curl -XPOST http://localhost:9200/index/fulltext/3 -d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
'
curl -XPOST http://localhost:9200/index/fulltext/4 -d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
'
- 查询
curl -XPOST http://localhost:9200/index/fulltext/_search -d'
{
"query" : { "term" : { "content" : "中国" }},
"highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"],
"fields" : {
"content" : {}
}
}
}
'
安装Marvel
- run sudo ./bin/plugin -i elasticsearch/marvel/latest
- 浏览器访问:http://localhost:9200/_plugin/marvel/
参考资料
- How To Install Java on Ubuntu with Apt-Get
- How To Install and Configure Elasticsearch on Ubuntu 14.04
- Setting up a Secure Single Node Elasticsearch server behind Nginx:
- Elasticsearch 权威指南(中文版)
- UFW防火墙简单设置
- Ufw使用指南
- Snapshot And Restore
- elasticsearch-analysis-ik
- Linux下安装maven
- ElasticSearch入门笔记
- ElasticSearch中文社区
Logstash
下载安装
- wget https://download.elastic.co/logstash/logstash/packages/debian/logstash_1.5.4-1_all.deb
- sudo dpkg -i logstash_1.5.4-1_all.deb
- sudo update-rc.d logstash defaults
配置jdk
- sudo nano /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar
export PATH=$PATH:$JAVA_HOME/bin
export LOGSTASH_HOME=/opt/logstash
export LOGSTASH=$LOGSTASH_HOME/bin
export PATH=$LOGSTASH:$PATH
- source /etc/profile
配置logstash
- sudo nano /etc/logstash/conf.d/logstash-simple.conf
input {
tcp {
port => 5000
type => syslog
}
udp {
port => 5000
type => syslog
}
}
filter {
if [type] == "syslog" {
grok {
match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}" }
add_field => [ "received_at", "%{@timestamp}" ]
add_field => [ "received_from", "%{host}" ]
}
syslog_pri { }
date {
match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ]
}
}
}
output {
elasticsearch {
protocol => "http"
host => "localhost:9200"
}
stdout { }
}
启动logstash
- sudo service logstash status
- sudo service logstash start
查看log
- tail -f /var/log/logstash/logstash.log
参考资料
Kibana
建立使用kibana的分组
- sudo groupadd -g 999 kibana
- sudo useradd -u 999 -g 999 kibana
-
If those commands fail because the
999
GID or UID already exist, replace the number with IDs that are free
下载安装
- cd ~
- wget https://download.elastic.co/kibana/kibana/kibana-4.1.2-linux-x64.tar.gz
- tar xvf kibana-*.tar.gz
配置
- sudo nano ~/kibana-4*/config/kibana.yml(server.host: "localhost")
- sudo mkdir -p /opt/kibana
- sudo cp -R ~/kibana-4*/* /opt/kibana/
- sudo chown -R kibana: /opt/kibana
run as a service
- cd /etc/init.d && sudo curl -o kibana https://gist.githubusercontent.com/thisismitch/8b15ac909aed214ad04a/raw/fc5025c3fc499ad8262aff34ba7fde8c87ead7c0/kibana-4.x-init
- cd /etc/default && sudo curl -o kibana https://gist.githubusercontent.com/thisismitch/8b15ac909aed214ad04a/raw/fc5025c3fc499ad8262aff34ba7fde8c87ead7c0/kibana-4.x-default
- sudo chmod +x /etc/init.d/kibana
- sudo update-rc.d kibana defaults 96 9
- sudo service kibana start
- visit localhost:5601
Install Nginx
- sudo apt-get install nginx apache2-utils(sudo yum install nginx httpd)
- sudo htpasswd -c /etc/nginx/htpasswd.users kibanaadmin
- sudo vi /etc/nginx/sites-available/default
server {
listen 80;
server_name localhost;
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/htpasswd.users;
location / {
proxy_pass http://localhost:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
- sudo service nginx restart
Configure An Index Pattern
- Go to Settings → Advanced.
- Edit the metaFields and add "_timestamp". Hit save.
- Now go back to Settings → Indices
- create
参考资料
相关推荐
### ElasticSearch2.0安装与1.7.2升级知识点详解 #### 一、ElasticSearch2.0安装 **1. 准备工作** 在安装ElasticSearch 2.0之前,首先需要确保系统环境满足官方的要求。具体步骤可以参考官方文档: - [官方文档...
**Elasticsearch技术文档V2.0概览** Elasticsearch是一种开源的全文搜索引擎,它以其分布式、实时、可扩展的特性,广泛应用于日志分析、监控、搜索和数据分析等领域。本技术文档针对Elasticsearch的初学者,旨在...
赠送原API文档:elasticsearch-6.8.3-javadoc.jar; 赠送源代码:elasticsearch-6.8.3-sources.jar; 赠送Maven依赖信息文件:elasticsearch-6.8.3.pom; 包含翻译后的API文档:elasticsearch-6.8.3-javadoc-API文档...
1. Elasticsearch的安装和配置:该培训课程涉及了如何安装和配置Elasticsearch集群。这包括在不同操作系统(如Mac、Linux和Windows 7或更高版本)上安装Elasticsearch,并对其环境进行配置,使之能够正常运行。 2. ...
赠送原API文档:elasticsearch-6.3.0-javadoc.jar; 赠送源代码:elasticsearch-6.3.0-sources.jar; 赠送Maven依赖信息文件:elasticsearch-6.3.0.pom; 包含翻译后的API文档:elasticsearch-6.3.0-javadoc-API文档...
赠送原API文档:elasticsearch-6.2.3-javadoc.jar; 赠送源代码:elasticsearch-6.2.3-sources.jar; 赠送Maven依赖信息文件:elasticsearch-6.2.3.pom; 包含翻译后的API文档:elasticsearch-6.2.3-javadoc-API文档...
标签《ES Java API 中文文档》强调了文档的内容属性,它属于ElasticSearch的一个重要组成部分,即用Java语言进行数据交互和操作的应用程序接口部分。 从部分内容中可以提取出以下知识点: 1. **Transport Client**...
ElasticSearch学习文档V2.0 本文档对ElasticSearch进行了详细的介绍,涵盖其基本概念、原理、应用场景、安装步骤等方面的知识点。 一、RESTful架构风格 ElasticSearch学习文档首先介绍了RESTful架构风格的概念。...
学习elasticsearch,决定把自己用过的整成中文,已整理一部份,虽然不尽人意,但也尽力,有query dsl与一部分API,后续整理完了会继续更新。
3. 配置:根据需求,可能需要编辑`elasticsearch-1.7.2/config/elasticsearch.yml`配置文件。常见的设置有数据存储路径、网络监听地址、端口等。 4. 启动:进入解压后的目录,然后运行`bin/elasticsearch`脚本来启动...
Elasticsearch 客户端 API 离线文档是一份详尽的资源,涵盖了 Java、Ruby、Python 和 JavaScript 等多种编程语言的客户端接口。这些 API 为开发者提供了与 Elasticsearch 集群进行交互的能力,使他们能够方便地执行...
本技术文档将深入探讨Elasticsearch的核心概念、架构、安装与配置、索引管理、查询与聚合、性能优化以及常见问题的解决。 **一、核心概念** 1. **节点(Node)**:Elasticsearch运行的单个实例称为节点,节点之间...
Spring-Data-Elasticsearch 中文文档
**Spring-Data-Elasticsearch中文使用文档** Spring Data Elasticsearch 是一个强大的Java库,它使得在Elasticsearch数据库中操作数据变得更加简单。这个框架是Spring Data项目的一部分,它为Elasticsearch提供了...
**Elasticsearch Python 使用文档** Elasticsearch 是一个开源的分布式全文搜索引擎,它提供了一个分布式、多用户能力的全文搜索引擎,基于 Lucene 库。Python 客户端库 Elasticsearch-py 则允许开发者轻松地与 ...
### Elasticsearch配置优化要点 #### 一、Java (JVM) 版本的选择 Elasticsearch 是基于 Java 构建的应用程序,它至少需要 Java 8(即 Java 1.8)来运行。根据官方建议,建议使用 **1.8.0_73 或更高版本** 的 Java...