ElasticSearch搭建及配置
Linux系统添加用户
[root@local]
[root@local]
下载ElasticSearch,我的版本是elasticsearch-5.5.2,解压后更改文件持有者
[root@local]
修改配置文件elasticsearch.yml,修改以下配置
cluster.name: es_prd_cluster
node.name:node01
network.host: 0.0.0.0
http.port: 9200
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
http.cors.enabled: true
http.cors.allow-origin: "*"
配置完,需要修改一些系统配置
更改文件句柄数
[root@localhost ~]
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
增加线程数
[root@localhost ~]
将其中的
* soft nproc 1024
修改为
* soft nproc 4096
增加虚拟内存
[root@localhost ~]
vm.max_map_count=655360
这些修改完成后,并没有生效,需要使用以下命令使其生效。
[root@localhost ~]
切换elasticsearch用户,启动
[elasticsearch@localhost elasticsearch-5.5.2]$ bin/elasticsearch –d
搭建完ElasticSearch后,需要安装管道插件logstash,logstash可以连接ES和数据库、redis等数据层。
下载logstash,https://githup.com/elastic/logstash/releases 或 https://elastic.com/downloads/logstash
安装logstash-input-jdbc插件
[root@local bin]
编写配置文件(jdbc.sql和jdbc.conf,最后在bin目录下)
jdbc.sql
select * from table
jdbc.conf
input {
jdbc {
jdbc_connection_string => "jdbc:mysql://192.168.1.85:3306/weibo?characterEncoding=UTF8&useSSL=false&autoReconnect=true"
jdbc_user => "root"
jdbc_password => "root"
jdbc_driver_library => "/usr/local/logstash/config/mysqlconnector-java-5.1.47.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_paging_enabled => "true"
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
jdbc_default_timezone => "Asia/Shanghai"
statement_filepath => "/usr/local/logstash/bin/jdbc.sql"
schedule => "* * * * *"
type => "jdbc"
}
}
filter {
json {
source => "message"
remove_field => ["message"]
}
}
output {
elasticsearch {
hosts => "192.168.1.79:9200"
protocol => "http"
index => "opinion_system"
document_type => "opinion_type"
document_id => "%{id}"
}
stdout {
codec => json_lines
}
}
启动命令
nohup bin/logstash -f jdbc-prd-all.conf> /mnt/logstash/logs/pro_output.log 1>/dev/null 2>&1 &