ElasticSearch搭建
Linux系统添加用户
[root@local]#useradd elastic
[root@local]#password 123456
下载ElasticSearch,我的版本是elasticsearch-5.5.2,解压后更改文件持有者
[root@local]#chown -R elastic:elastic elasticsearch-5.5.2
修改配置文件elasticsearch.yml,修改以下配置
#集群名称
cluster.name: es_prd_cluster
#节点名称,不做集群不需要设置
node.name:node01
#配置外网访问
network.host: 0.0.0.0
http.port: 9200
#momery下配置
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#Various下配置
http.cors.enabled: true
http.cors.allow-origin: "*"
配置完,需要修改一些系统配置
更改文件句柄数
[root@localhost ~]# vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
增加线程数
[root@localhost ~]# vi /etc/security/limits.d/90-nproc.conf
将其中的
* soft nproc 1024
修改为
* soft nproc 4096
增加虚拟内存
[root@localhost ~]# vim /etc/sysctl.conf
#在其中添加
vm.max_map_count=655360
这些修改完成后,并没有生效,需要使用以下命令使其生效。
[root@localhost ~]# sysctl -p
切换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]#./logstash-plugin install logstash-input-jdbc
编写配置文件(jdbc.sql和jdbc.conf,最后在bin目录下)
jdbc.sql
--你的sql语句
select * from table
jdbc.conf
input {
jdbc {
# 连接的数据库地址和哪⼀一个数据库,指定编码格式,禁⽤用 SSL 协议,设定⾃自动重连
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"
#sql 语句句
statement_filepath => "/usr/local/logstash/bin/jdbc.sql"
# 这是控制定时的,重复执⾏行行导⼊入任务的时间间隔,第⼀一位是分钟
schedule => "* * * * *"
type => "jdbc"
}
}
filter {
json {
source => "message"
remove_field => ["message"]
}
}
output {
elasticsearch {
# 要导⼊入到的 Elasticsearch 所在的主机
hosts => "192.168.1.79:9200"
protocol => "http"
# 要导⼊入到的 Elasticsearch 的索引的名称
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 &
来源:CSDN
作者:可遇_不可求
链接:https://blog.csdn.net/zhangkexin_z/article/details/103888174